handanimatedswapping.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. class HandSwappingAnimated_Show extends HandForceSwappingAnimated_Show
  2. {
  3. };
  4. class HandAnimatedSwapping extends HandStateBase
  5. {
  6. ref InventoryLocation m_Src1 = null;
  7. ref InventoryLocation m_Src2 = null;
  8. ref InventoryLocation m_Dst1 = null;
  9. ref InventoryLocation m_Dst2 = null;
  10. ref HandStartHidingAnimated m_Hide;
  11. ref HandSwappingAnimated_Show m_Show;
  12. void HandAnimatedSwapping(Man player = null, HandStateBase parent = null)
  13. {
  14. // setup nested state machine
  15. m_Hide = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
  16. m_Show = new HandSwappingAnimated_Show(player, this, WeaponActions.SHOW, -1);
  17. // events:
  18. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  19. HandEventBase _AEh_ = new HandAnimEventChanged;
  20. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  21. m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show ));
  22. m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
  23. m_FSM.SetInitialState(m_Hide);
  24. }
  25. override void OnEntry(HandEventBase e)
  26. {
  27. HandEventSwap es = HandEventSwap.Cast(e);
  28. if (es)
  29. {
  30. m_Src1 = es.GetSrc();
  31. m_Src2 = es.m_Src2;
  32. m_Dst1 = es.GetDst();
  33. m_Dst2 = es.m_Dst2;
  34. m_Show.m_Src1 = m_Src1;
  35. m_Show.m_Src2 = m_Src2;
  36. m_Show.m_Dst1 = m_Dst1;
  37. m_Show.m_Dst2 = m_Dst2;
  38. m_Hide.m_ActionType = es.m_AnimationID;
  39. m_Show.m_ActionType = es.m_Animation2ID;
  40. if (!GetGame().IsDedicatedServer())
  41. {
  42. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst2.GetItem(), m_Dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  43. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst1.GetItem(), m_Dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  44. }
  45. }
  46. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  47. }
  48. override void OnAbort(HandEventBase e)
  49. {
  50. if ( !GetGame().IsDedicatedServer())
  51. {
  52. if (m_Dst2)
  53. {
  54. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  55. }
  56. if (m_Dst1)
  57. {
  58. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  59. }
  60. }
  61. else
  62. {
  63. if (m_Dst2)
  64. {
  65. GetGame().ClearJuncture(e.m_Player, m_Dst2.GetItem());
  66. }
  67. if (m_Dst1)
  68. {
  69. GetGame().ClearJuncture(e.m_Player, m_Dst1.GetItem());
  70. }
  71. }
  72. m_Src1 = null;
  73. m_Src2 = null;
  74. m_Dst1 = null;
  75. m_Dst2 = null;
  76. super.OnAbort(e);
  77. }
  78. override void OnExit(HandEventBase e)
  79. {
  80. if ( !GetGame().IsDedicatedServer())
  81. {
  82. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst2.GetItem(), m_Dst2);
  83. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst1.GetItem(), m_Dst1);
  84. }
  85. m_Src1 = null;
  86. m_Src2 = null;
  87. m_Dst1 = null;
  88. m_Dst2 = null;
  89. super.OnExit(e);
  90. }
  91. };