handanimatedforceswapping.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // When editing this, take a look at HandAnimatedMoveToDst_W4T_Basic as well
  2. // They can not be inherited from each other because of different inheritance
  3. class HandAnimatedMoveToDst_W4T_Basic extends HandStateBase
  4. {
  5. ref InventoryLocation m_Dst;
  6. override void OnEntry(HandEventBase e)
  7. {
  8. Man player = e.m_Player;
  9. if (m_Dst && m_Dst.IsValid())
  10. {
  11. EntityAI item = m_Dst.GetItem();
  12. InventoryLocation src = new InventoryLocation;
  13. if (item.GetInventory().GetCurrentInventoryLocation(src))
  14. {
  15. if (GameInventory.LocationSyncMoveEntity(src, m_Dst))
  16. {
  17. player.OnItemInHandsChanged();
  18. }
  19. else
  20. {
  21. #ifdef ENABLE_LOGGING
  22. if ( LogManager.IsInventoryHFSMLogEnable() )
  23. {
  24. Debug.InventoryHFSMLog("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - not allowed");
  25. }
  26. #endif
  27. }
  28. }
  29. else
  30. Error("[hndfsm] " + Object.GetDebugName(e.m_Player) + " STS = " + e.m_Player.GetSimulationTimeStamp() + " HandAnimatedMoveToDst_W4T_Basic - item " + item + " has no Inventory or Location, inv=" + item.GetInventory());
  31. }
  32. else
  33. Error("[hndfsm] HandAnimatedMoveToDst_W4T_Basic - event has no valid m_Dst");
  34. super.OnEntry(e);
  35. }
  36. override void OnAbort(HandEventBase e)
  37. {
  38. m_Dst = null;
  39. super.OnAbort(e);
  40. }
  41. override void OnExit(HandEventBase e)
  42. {
  43. m_Dst = null;
  44. super.OnExit(e);
  45. }
  46. override bool IsWaitingForActionFinish() { return true; }
  47. };
  48. class HandForceSwappingAnimated_Show extends HandStartAction
  49. {
  50. ref InventoryLocation m_Src1 = null;
  51. ref InventoryLocation m_Src2 = null;
  52. ref InventoryLocation m_Dst1 = null;
  53. ref InventoryLocation m_Dst2 = null;
  54. void HandForceSwapingAnimated_Show(Man player = null, HandStateBase parent = null, WeaponActions action = WeaponActions.NONE, int actionType = -1) { }
  55. override void OnEntry(HandEventBase e)
  56. {
  57. if (m_Src1 && m_Src2 && m_Dst1 && m_Dst2)
  58. {
  59. if (!GetGame().IsMultiplayer())
  60. {
  61. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  62. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  63. if (GameInventory.CanForceSwapEntitiesEx(m_Src1.GetItem(), m_Dst1, m_Src2.GetItem(), m_Dst2))
  64. {
  65. GameInventory.LocationSwap(m_Src1, m_Src2, m_Dst1, m_Dst2);
  66. e.m_Player.OnItemInHandsChanged();
  67. }
  68. }
  69. else
  70. {
  71. if (!GetGame().IsDedicatedServer())
  72. {
  73. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  74. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  75. m_Player.GetHumanInventory().PostDeferredForceSwapEntities(InventoryMode.JUNCTURE, m_Dst1.GetItem(), m_Dst2.GetItem(), m_Dst1, m_Dst2);
  76. }
  77. else
  78. {
  79. GetGame().ClearJunctureEx(m_Player, m_Dst1.GetItem());
  80. GetGame().ClearJunctureEx(m_Player, m_Dst2.GetItem());
  81. }
  82. }
  83. }
  84. else
  85. Error("[hndfsm] HandForceSwappingAnimated_Show is not properly configured!");
  86. super.OnEntry(e);
  87. }
  88. override void OnAbort(HandEventBase e)
  89. {
  90. m_Src1 = null;
  91. m_Src2 = null;
  92. m_Dst1 = null;
  93. m_Dst2 = null;
  94. super.OnAbort(e);
  95. }
  96. override void OnExit(HandEventBase e)
  97. {
  98. m_Src1 = null;
  99. m_Src2 = null;
  100. m_Dst1 = null;
  101. m_Dst2 = null;
  102. super.OnExit(e);
  103. }
  104. override bool IsWaitingForActionFinish() { return true; }
  105. };
  106. class HandAnimatedForceSwapping extends HandStateBase
  107. {
  108. ref InventoryLocation m_Src1 = null;
  109. ref InventoryLocation m_Src2 = null;
  110. ref InventoryLocation m_Dst1 = null;
  111. ref InventoryLocation m_Dst2 = null;
  112. ref HandStartHidingAnimated m_Start;
  113. ref HandAnimatedMoveToDst_W4T m_Show;
  114. ref HandAnimatedMoveToDst_W4T_Basic m_Hide;
  115. void HandAnimatedForceSwapping(Man player = null, HandStateBase parent = null)
  116. {
  117. // setup nested state machine
  118. m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
  119. m_Show = new HandAnimatedMoveToDst_W4T(player, this, WeaponActions.SHOW, -1);
  120. m_Hide = new HandAnimatedMoveToDst_W4T_Basic(player, this);
  121. // events:
  122. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  123. HandEventBase _AEh_ = new HandAnimEventChanged;
  124. HandEventBase __Xd_ = new HandEventDestroyed;
  125. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  126. m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Hide ));
  127. m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show )); // no animation in Hide step
  128. m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
  129. m_FSM.AddTransition(new HandTransition( m_Hide, _fin_, null ));
  130. m_FSM.AddTransition(new HandTransition( m_Show, __Xd_, null ));
  131. m_FSM.AddTransition(new HandTransition( m_Hide, __Xd_, null ));
  132. m_FSM.SetInitialState(m_Start);
  133. }
  134. override void OnEntry(HandEventBase e)
  135. {
  136. HandEventForceSwap efs = HandEventForceSwap.Cast(e);
  137. if (efs)
  138. {
  139. if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
  140. {
  141. m_Start.m_ActionType = efs.m_AnimationID;
  142. m_Src1 = efs.m_Src2;
  143. m_Src2 = efs.GetSrc();
  144. m_Dst1 = efs.m_Dst2;
  145. m_Dst2 = efs.GetDst();
  146. m_Show.m_ActionType = efs.m_Animation2ID;
  147. }
  148. else
  149. {
  150. m_Start.m_ActionType = efs.m_Animation2ID;
  151. m_Src1 = efs.GetSrc();
  152. m_Src2 = efs.m_Src2;
  153. m_Dst1 = efs.GetDst();
  154. m_Dst2 = efs.m_Dst2;
  155. m_Show.m_ActionType = efs.m_AnimationID;
  156. }
  157. m_Show.m_Dst = m_Dst1;
  158. m_Hide.m_Dst = m_Dst2;
  159. if (!GetGame().IsDedicatedServer())
  160. {
  161. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  162. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  163. }
  164. }
  165. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  166. }
  167. override void OnAbort(HandEventBase e)
  168. {
  169. if ( !GetGame().IsDedicatedServer())
  170. {
  171. if (m_Dst1)
  172. {
  173. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  174. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  175. }
  176. }
  177. else
  178. {
  179. if (m_Dst1)
  180. {
  181. GetGame().ClearJunctureEx(m_Player, m_Dst1.GetItem());
  182. GetGame().ClearJunctureEx(m_Player, m_Dst2.GetItem());
  183. }
  184. }
  185. m_Src1 = null;
  186. m_Src2 = null;
  187. m_Dst1 = null;
  188. m_Dst2 = null;
  189. super.OnAbort(e);
  190. }
  191. override void OnExit(HandEventBase e)
  192. {
  193. if ( !GetGame().IsDedicatedServer())
  194. {
  195. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  196. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  197. }
  198. else
  199. {
  200. GetGame().ClearJunctureEx(m_Player, m_Dst1.GetItem());
  201. GetGame().ClearJunctureEx(m_Player, m_Dst2.GetItem());
  202. }
  203. m_Src1 = null;
  204. m_Src2 = null;
  205. m_Dst1 = null;
  206. m_Dst2 = null;
  207. super.OnExit(e);
  208. }
  209. };
  210. class HandAnimatedForceSwapping_Inst extends HandStateBase
  211. {
  212. ref InventoryLocation m_Src1 = null;
  213. ref InventoryLocation m_Src2 = null;
  214. ref InventoryLocation m_Dst1 = null;
  215. ref InventoryLocation m_Dst2 = null;
  216. ref HandStartHidingAnimated m_Start;
  217. ref HandForceSwappingAnimated_Show m_Swap;
  218. void HandAnimatedForceSwapping_Inst(Man player = null, HandStateBase parent = null)
  219. {
  220. // setup nested state machine
  221. m_Start = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
  222. m_Swap = new HandForceSwappingAnimated_Show(player, this, WeaponActions.SHOW, -1);
  223. // events:
  224. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  225. HandEventBase _AEh_ = new HandAnimEventChanged;
  226. HandEventBase __Xd_ = new HandEventDestroyed;
  227. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  228. m_FSM.AddTransition(new HandTransition( m_Start, _AEh_, m_Swap ));
  229. m_FSM.AddTransition(new HandTransition( m_Swap, _fin_, null ));
  230. m_FSM.AddTransition(new HandTransition( m_Swap, __Xd_, null ));
  231. m_FSM.SetInitialState(m_Start);
  232. }
  233. override void OnEntry(HandEventBase e)
  234. {
  235. HandEventForceSwap efs = HandEventForceSwap.Cast(e);
  236. if (efs)
  237. {
  238. if ( efs.GetSrc().GetType() == InventoryLocationType.HANDS )
  239. {
  240. m_Start.m_ActionType = efs.m_AnimationID;
  241. m_Src1 = efs.m_Src2;
  242. m_Src2 = efs.GetSrc();
  243. m_Dst1 = efs.m_Dst2;
  244. m_Dst2 = efs.GetDst();
  245. m_Swap.m_ActionType = efs.m_Animation2ID;
  246. }
  247. else
  248. {
  249. m_Start.m_ActionType = efs.m_Animation2ID;
  250. m_Src1 = efs.GetSrc();
  251. m_Src2 = efs.m_Src2;
  252. m_Dst1 = efs.GetDst();
  253. m_Dst2 = efs.m_Dst2;
  254. m_Swap.m_ActionType = efs.m_AnimationID;
  255. }
  256. m_Swap.m_Src1 = m_Src1;
  257. m_Swap.m_Dst1 = m_Dst1;
  258. m_Swap.m_Src2 = m_Src2;
  259. m_Swap.m_Dst2 = m_Dst2;
  260. if (!GetGame().IsDedicatedServer())
  261. {
  262. m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  263. m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  264. }
  265. }
  266. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  267. }
  268. override void OnAbort(HandEventBase e)
  269. {
  270. if ( !GetGame().IsDedicatedServer())
  271. {
  272. if (m_Dst1)
  273. {
  274. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  275. }
  276. if (m_Dst2)
  277. {
  278. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  279. }
  280. }
  281. else
  282. {
  283. if (m_Dst1)
  284. {
  285. GetGame().ClearJunctureEx(m_Player, m_Dst1.GetItem());
  286. }
  287. if (m_Dst2)
  288. {
  289. GetGame().ClearJunctureEx(m_Player, m_Dst2.GetItem());
  290. }
  291. }
  292. m_Src1 = null;
  293. m_Src2 = null;
  294. m_Dst1 = null;
  295. m_Dst2 = null;
  296. super.OnAbort(e);
  297. }
  298. override void OnExit(HandEventBase e)
  299. {
  300. if ( !GetGame().IsDedicatedServer())
  301. {
  302. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  303. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  304. }
  305. else
  306. {
  307. GetGame().ClearJunctureEx(m_Player, m_Dst1.GetItem());
  308. GetGame().ClearJunctureEx(m_Player, m_Dst2.GetItem());
  309. }
  310. m_Src1 = null;
  311. m_Src2 = null;
  312. m_Dst1 = null;
  313. m_Dst2 = null;
  314. super.OnExit(e);
  315. }
  316. };