hescobox.c 4.4 KB

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