handanimatedmovingtoatt.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. class HandStartHidingAnimated extends HandStartAction
  2. {
  3. void HandStartHidingAnimated(Man player = null, HandStateBase parent = null, WeaponActions action = WeaponActions.NONE, int actionType = -1)
  4. { }
  5. override void OnEntry(HandEventBase e)
  6. {
  7. super.OnEntry(e);
  8. }
  9. override void OnAbort(HandEventBase e)
  10. {
  11. super.OnAbort(e);
  12. }
  13. override void OnExit(HandEventBase e)
  14. {
  15. super.OnExit(e);
  16. }
  17. override bool IsWaitingForActionFinish() { return m_ActionType == -1; }
  18. };
  19. // When editing this, take a look at HandAnimatedMoveToDst_W4T_Basic as well
  20. // They can not be inherited from each other because of different inheritance
  21. class HandAnimatedMoveToDst_W4T extends HandStartAction
  22. {
  23. ref InventoryLocation m_Dst;
  24. override void OnEntry(HandEventBase e)
  25. {
  26. Man player = e.m_Player;
  27. if (m_Dst && m_Dst.IsValid())
  28. {
  29. EntityAI item = m_Dst.GetItem();
  30. InventoryLocation src = new InventoryLocation;
  31. if (item.GetInventory().GetCurrentInventoryLocation(src))
  32. {
  33. if (GameInventory.LocationSyncMoveEntity(src, m_Dst))
  34. {
  35. player.OnItemInHandsChanged();
  36. }
  37. else
  38. {
  39. #ifdef ENABLE_LOGGING
  40. if ( LogManager.IsInventoryHFSMLogEnable() )
  41. {
  42. Debug.InventoryHFSMLog("[hndfsm] HandAnimatedMoveToDst_W4T - not allowed");
  43. }
  44. #endif
  45. }
  46. }
  47. else
  48. Error("[hndfsm] " + Object.GetDebugName(e.m_Player) + " STS = " + e.m_Player.GetSimulationTimeStamp() + " HandAnimatedMoveToDst_W4T - item " + item + " has no Inventory or Location, inv=" + item.GetInventory());
  49. }
  50. else
  51. Error("[hndfsm] HandAnimatedMoveToDst_W4T - event has no valid m_Dst");
  52. super.OnEntry(e);
  53. }
  54. override void OnAbort(HandEventBase e)
  55. {
  56. m_Dst = null;
  57. super.OnAbort(e);
  58. }
  59. override void OnExit(HandEventBase e)
  60. {
  61. m_Dst = null;
  62. super.OnExit(e);
  63. }
  64. override bool IsWaitingForActionFinish() { return true; }
  65. };
  66. class HandAnimatedMovingToAtt extends HandStateBase
  67. {
  68. EntityAI m_Entity; /// weapon to be taken
  69. ref HandStartHidingAnimated m_Hide;
  70. ref HandAnimatedMoveToDst_W4T m_Show;
  71. ref InventoryLocation m_ilEntity;
  72. void HandAnimatedMovingToAtt(Man player = null, HandStateBase parent = null)
  73. {
  74. // setup nested state machine
  75. m_Hide = new HandStartHidingAnimated(player, this, WeaponActions.HIDE, -1);
  76. m_Show = new HandAnimatedMoveToDst_W4T(player, this, WeaponActions.SHOW, -1);
  77. // events:
  78. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  79. HandEventBase _AEh_ = new HandAnimEventChanged;
  80. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  81. m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show ));
  82. m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
  83. m_FSM.SetInitialState(m_Hide);
  84. }
  85. override void OnEntry(HandEventBase e)
  86. {
  87. m_Entity = e.GetSrcEntity();
  88. HandEventMoveTo ev_move = HandEventMoveTo.Cast(e);
  89. if (ev_move)
  90. {
  91. m_Show.m_Dst = ev_move.GetDst();
  92. m_Hide.m_ActionType = ev_move.GetAnimationID();
  93. m_Show.m_ActionType = ev_move.GetAnimationID();
  94. m_ilEntity = m_Show.m_Dst;
  95. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Entity, m_ilEntity, GameInventory.c_InventoryReservationTimeoutShortMS);
  96. }
  97. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  98. }
  99. override void OnAbort(HandEventBase e)
  100. {
  101. if ( !GetGame().IsDedicatedServer())
  102. {
  103. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Entity, m_ilEntity);
  104. }
  105. else
  106. {
  107. GetGame().ClearJunctureEx(e.m_Player, m_Entity);
  108. }
  109. m_Entity = null;
  110. m_ilEntity = null;
  111. super.OnAbort(e);
  112. }
  113. override void OnExit(HandEventBase e)
  114. {
  115. if ( !GetGame().IsDedicatedServer())
  116. {
  117. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Entity, m_ilEntity);
  118. }
  119. m_Entity = null;
  120. m_ilEntity = null;
  121. super.OnExit(e);
  122. }
  123. };