hand_actions.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. ///@{ actions
  2. /**@class HandActionBase
  3. * @brief represents action executed on transition just between OnExit from old state and OnEntry to new state
  4. **/
  5. class HandActionBase
  6. {
  7. /**@fn Action
  8. * @brief executed when transition occurs
  9. **/
  10. void Action (HandEventBase e) { }
  11. };
  12. class HandActionCreated extends HandActionBase
  13. {
  14. override void Action (HandEventBase e)
  15. {
  16. #ifdef ENABLE_LOGGING
  17. if ( LogManager.IsInventoryHFSMLogEnable() )
  18. {
  19. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionCreated", e.m_Player.ToString() );
  20. }
  21. #endif
  22. e.m_Player.OnItemInHandsChanged();
  23. }
  24. };
  25. class HandActionTake extends HandActionBase
  26. {
  27. override void Action (HandEventBase e)
  28. {
  29. #ifdef ENABLE_LOGGING
  30. if ( LogManager.IsInventoryHFSMLogEnable() )
  31. {
  32. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionTake", e.m_Player.ToString() );
  33. }
  34. #endif
  35. GameInventory.LocationSyncMoveEntity(e.GetSrc(), e.GetDst());
  36. e.m_Player.OnItemInHandsChanged();
  37. }
  38. };
  39. class HandActionDrop extends HandActionBase
  40. {
  41. override void Action (HandEventBase e)
  42. {
  43. #ifdef ENABLE_LOGGING
  44. if ( LogManager.IsInventoryHFSMLogEnable() )
  45. {
  46. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionDrop", e.m_Player.ToString() );
  47. }
  48. #endif
  49. GameInventory.LocationSyncMoveEntity(e.GetSrc(), e.GetDst());
  50. e.m_Player.OnItemInHandsChanged();
  51. }
  52. };
  53. class HandActionThrow extends HandActionBase
  54. {
  55. override void Action (HandEventBase e)
  56. {
  57. #ifdef ENABLE_LOGGING
  58. if ( LogManager.IsInventoryHFSMLogEnable() )
  59. {
  60. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionThrow", e.m_Player.ToString() );
  61. }
  62. #endif
  63. HandEventThrow throwEvent = HandEventThrow.Cast(e);
  64. GameInventory.LocationSyncMoveEntity(e.GetSrc(), e.GetDst());
  65. DayZPlayer player = DayZPlayer.Cast(e.m_Player);
  66. if ( player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_REMOTE )
  67. {
  68. InventoryItem item = InventoryItem.Cast(e.GetSrcEntity());
  69. if( item )
  70. item.ThrowPhysically(player, throwEvent.GetForce());
  71. else
  72. Error("[hndfsm] HandActionThrow - src entity null!");
  73. }
  74. player.OnItemInHandsChanged();
  75. }
  76. };
  77. class HandActionMoveTo extends HandActionBase
  78. {
  79. override void Action (HandEventBase e)
  80. {
  81. #ifdef ENABLE_LOGGING
  82. if ( LogManager.IsInventoryHFSMLogEnable() )
  83. {
  84. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionMoveTo", e.m_Player.ToString() );
  85. }
  86. #endif
  87. HandEventMoveTo es = HandEventMoveTo.Cast(e);
  88. if (es)
  89. {
  90. GameInventory.LocationSyncMoveEntity(e.GetSrc(), es.m_Dst);
  91. e.m_Player.OnItemInHandsChanged();
  92. }
  93. else
  94. Error("[hndfsm] HandActionMoveTo - this is no HandEventMoveTo");
  95. }
  96. };
  97. class HandActionDestroy extends HandActionBase
  98. {
  99. override void Action (HandEventBase e)
  100. {
  101. #ifdef ENABLE_LOGGING
  102. if ( LogManager.IsInventoryHFSMLogEnable() )
  103. {
  104. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionDestroy", e.m_Player.ToString() );
  105. }
  106. #endif
  107. GetGame().ObjectDelete(e.GetSrcEntity());
  108. e.m_Player.OnItemInHandsChanged();
  109. }
  110. };
  111. class HandActionDestroyed extends HandActionBase
  112. {
  113. override void Action (HandEventBase e)
  114. {
  115. #ifdef ENABLE_LOGGING
  116. if ( LogManager.IsInventoryHFSMLogEnable() )
  117. {
  118. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionDestroyed", e.m_Player.ToString() );
  119. }
  120. #endif
  121. e.m_Player.OnItemInHandsChanged();
  122. }
  123. };
  124. class HandActionDestroyAndReplaceWithNew extends HandActionBase
  125. {
  126. override void Action (HandEventBase e)
  127. {
  128. #ifdef ENABLE_LOGGING
  129. if ( LogManager.IsInventoryHFSMLogEnable() )
  130. {
  131. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionDestroyAndReplaceWithNew", e.m_Player.ToString() );
  132. }
  133. #endif
  134. Man player = e.m_Player;
  135. EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands();
  136. InventoryLocation src = new InventoryLocation;
  137. if (itemInHands.GetInventory().GetCurrentInventoryLocation(src))
  138. {
  139. HandEventDestroyAndReplaceWithNew edr = HandEventDestroyAndReplaceWithNew.Cast(e);
  140. if (edr)
  141. {
  142. edr.m_Lambda.Execute();
  143. return;
  144. }
  145. else
  146. Error("[hndfsm] HandActionDestroyAndReplaceWithNew - not a HandEventDestroyAndReplaceWithNew event");
  147. }
  148. else
  149. Error("[hndfsm] HandActionDestroyAndReplaceWithNew - itemInHands has no InventoryLocation");
  150. }
  151. };
  152. class HandActionDestroyAndReplaceWithNewElsewhere extends HandActionDestroyAndReplaceWithNew
  153. {
  154. override void Action (HandEventBase e)
  155. {
  156. super.Action(e);
  157. }
  158. };
  159. class HandActionReplaced extends HandActionBase
  160. {
  161. override void Action (HandEventBase e)
  162. {
  163. #ifdef ENABLE_LOGGING
  164. if ( LogManager.IsInventoryHFSMLogEnable() )
  165. {
  166. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionReplaced", e.m_Player.ToString() );
  167. }
  168. #endif
  169. Man player = e.m_Player;
  170. player.OnItemInHandsChanged();
  171. }
  172. };
  173. class HandActionSwap extends HandActionBase
  174. {
  175. override void Action (HandEventBase e)
  176. {
  177. #ifdef ENABLE_LOGGING
  178. if ( LogManager.IsInventoryHFSMLogEnable() )
  179. {
  180. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionSwap", e.m_Player.ToString() );
  181. }
  182. #endif
  183. HandEventSwap es = HandEventSwap.Cast(e);
  184. if (es)
  185. {
  186. GameInventory.LocationSwap(es.GetSrc(), es.m_Src2, es.GetDst(), es.m_Dst2);
  187. e.m_Player.OnItemInHandsChanged();
  188. }
  189. else
  190. Error("[hndfsm] HandActionSwap - this is no HandEventSwap");
  191. }
  192. };
  193. class HandActionForceSwap extends HandActionBase
  194. {
  195. override void Action (HandEventBase e)
  196. {
  197. #ifdef ENABLE_LOGGING
  198. if ( LogManager.IsInventoryHFSMLogEnable() )
  199. {
  200. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "HandActionForceSwap", e.m_Player.ToString() );
  201. }
  202. #endif
  203. HandEventForceSwap es = HandEventForceSwap.Cast(e);
  204. if (es)
  205. {
  206. GameInventory.LocationSwap(es.GetSrc(), es.m_Src2, es.GetDst(), es.m_Dst2);
  207. e.m_Player.OnItemInHandsChanged();
  208. }
  209. else
  210. Error("[hndfsm] HandActionForceSwap - this is no HandEventForceSwap");
  211. }
  212. };
  213. ///@} actions