hescobox.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. class HescoBox extends Inventory_Base
  2. {
  3. static const int FOLDED = 0;
  4. static const int UNFOLDED = 1;
  5. static const int FILLED = 2;
  6. static const int PERCENTUAL_DAMAGE = 1;
  7. ref Timer m_Timer;
  8. protected int m_State;
  9. void HescoBox()
  10. {
  11. m_State = FOLDED;
  12. //synchronized variables
  13. RegisterNetSyncVariableInt( "m_State", FOLDED, FILLED );
  14. RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
  15. RegisterNetSyncVariableBool("m_IsDeploySound");
  16. }
  17. override bool HasProxyParts()
  18. {
  19. return true;
  20. }
  21. override bool CanPutIntoHands( EntityAI parent )
  22. {
  23. if( !super.CanPutIntoHands( parent ) )
  24. {
  25. return false;
  26. }
  27. return CanBeManipulated();
  28. }
  29. void Synchronize()
  30. {
  31. SetSynchDirty();
  32. }
  33. override void OnVariablesSynchronized()
  34. {
  35. super.OnVariablesSynchronized();
  36. //refresh visuals
  37. RefreshVisuals();
  38. if ( IsDeploySound() )
  39. {
  40. PlayDeploySound();
  41. }
  42. }
  43. void RefreshVisuals()
  44. {
  45. }
  46. int GetState()
  47. {
  48. return m_State;
  49. }
  50. void SetState( int state )
  51. {
  52. m_State = state;
  53. }
  54. bool CanBeFilledAtPosition( vector position )
  55. {
  56. string surface_type;
  57. GetGame().SurfaceGetType( position[0], position[2], surface_type );
  58. return GetGame().IsSurfaceDigable(surface_type);
  59. }
  60. bool CanBeManipulated()
  61. {
  62. if ( GetState() == FOLDED )
  63. {
  64. return true;
  65. }
  66. else
  67. {
  68. return false;
  69. }
  70. }
  71. void Fold()
  72. {
  73. this.ShowSelection( "inventory" );
  74. this.HideSelection( "placing" );
  75. this.HideSelection( "filled" );
  76. SetState( FOLDED );
  77. RefreshPhysics();
  78. if ( GetGame().IsServer() )
  79. {
  80. SetAllowDamage(true);
  81. Synchronize();
  82. float fold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
  83. DecreaseHealth( "", "", fold_damage );
  84. }
  85. }
  86. void Unfold()
  87. {
  88. this.HideSelection( "inventory" );
  89. this.ShowSelection( "placing" );
  90. this.HideSelection( "filled" );
  91. SetState( UNFOLDED );
  92. RefreshPhysics();
  93. if ( GetGame().IsServer() )
  94. {
  95. SetAllowDamage(true);
  96. Synchronize();
  97. float unfold_damage = ( GetMaxHealth( "", "" ) / 100 ) * PERCENTUAL_DAMAGE;
  98. DecreaseHealth( "", "", unfold_damage );
  99. }
  100. }
  101. override void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
  102. {
  103. super.EEItemLocationChanged (oldLoc, newLoc);
  104. //RefreshPhysics();
  105. }
  106. override void RefreshPhysics()
  107. {
  108. super.RefreshPhysics();
  109. if ( this && !ToDelete() )
  110. {
  111. RemoveProxyPhysics( "inventory" );
  112. RemoveProxyPhysics( "placing" );
  113. RemoveProxyPhysics( "filled" );
  114. int state = GetState();
  115. switch (state)
  116. {
  117. case UNFOLDED:
  118. //ShowSelection( "placing" );
  119. AddProxyPhysics( "placing" );
  120. return;
  121. case FOLDED:
  122. AddProxyPhysics( "inventory" );
  123. return;
  124. case FILLED:
  125. AddProxyPhysics( "filled" );
  126. return;
  127. }
  128. }
  129. }
  130. void Fill()
  131. {
  132. this.HideSelection( "inventory" );
  133. this.HideSelection( "placing" );
  134. this.ShowSelection( "filled" );
  135. SetState( FILLED );
  136. RefreshPhysics();
  137. if ( GetGame().IsServer() )
  138. {
  139. Synchronize();
  140. DecreaseHealth( "", "", 5 ); //TODO Daniel implement soft skill bonus via useraction
  141. SetAllowDamage(false);
  142. }
  143. }
  144. override void OnStoreSave(ParamsWriteContext ctx)
  145. {
  146. super.OnStoreSave(ctx);
  147. // Save state
  148. ctx.Write( m_State );
  149. }
  150. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  151. {
  152. if ( !super.OnStoreLoad(ctx, version) )
  153. return false;
  154. // Load folded/unfolded state
  155. int state = FOLDED;
  156. if ( !ctx.Read(state) )
  157. state = FOLDED;
  158. switch (state)
  159. {
  160. case FOLDED:
  161. {
  162. Fold();
  163. break;
  164. }
  165. case UNFOLDED:
  166. {
  167. Unfold();
  168. break;
  169. }
  170. case FILLED:
  171. {
  172. Fill();
  173. break;
  174. }
  175. }
  176. return true;
  177. }
  178. //================================================================
  179. // ADVANCED PLACEMENT
  180. //================================================================
  181. override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
  182. {
  183. super.OnPlacementComplete( player, position, orientation );
  184. if ( GetGame().IsServer() )
  185. {
  186. Unfold();
  187. SetIsDeploySound( true );
  188. }
  189. }
  190. override bool IsDeployable()
  191. {
  192. return true;
  193. }
  194. override string GetDeploySoundset()
  195. {
  196. return "placeHescoBox_SoundSet";
  197. }
  198. override string GetLoopDeploySoundset()
  199. {
  200. return "hescobox_deploy_SoundSet";
  201. }
  202. override void SetActions()
  203. {
  204. super.SetActions();
  205. AddAction(ActionTogglePlaceObject);
  206. AddAction(ActionFoldObject);
  207. AddAction(ActionDeployObject);
  208. }
  209. //!DEPRECATED
  210. protected ref EffectSound m_DeployLoopSound; //DEPRECATED in favor of m_DeployLoopSoundEx
  211. void PlayDeployLoopSound(); //!DEPRECATED
  212. void StopDeployLoopSound(); //!DEPRECATED
  213. }