handanimatedtakingfromatt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. class HandTakingAnimated_Hide extends HandStartAction
  2. { };
  3. class HandTakingAnimated_Show extends HandStartAction
  4. {
  5. ref InventoryLocation m_Src;
  6. ref InventoryLocation m_Dst;
  7. void HandTakingAnimated_Show(Man player = null, HandStateBase parent = null, WeaponActions action = WeaponActions.NONE, int actionType = -1)
  8. {
  9. m_Src = null;
  10. m_Dst = null;
  11. }
  12. override void OnEntry(HandEventBase e)
  13. {
  14. super.OnEntry(e);
  15. if (m_Src)
  16. {
  17. if (m_Src.IsValid())
  18. {
  19. #ifdef ENABLE_LOGGING
  20. if ( LogManager.IsInventoryHFSMLogEnable() )
  21. {
  22. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "OnEntry", e.m_Player.ToString() );
  23. }
  24. #endif
  25. //if (GameInventory.LocationCanMoveEntity(m_Src, m_Dst))
  26. //{
  27. GameInventory.LocationSyncMoveEntity(m_Src, m_Dst);
  28. e.m_Player.OnItemInHandsChanged();
  29. //}
  30. //else
  31. //{
  32. // if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] HandTakingAnimated_Show - not allowed");
  33. //}
  34. }
  35. else
  36. {
  37. Error("[hndfsm] " + Object.GetDebugName(e.m_Player) + " STS = " + e.m_Player.GetSimulationTimeStamp() + " HandTakingAnimated_Show m_Src=invalid, item not in bubble?");
  38. }
  39. }
  40. else
  41. Error("[hndfsm] HandTakingAnimated_Show, error - m_Src not configured");
  42. }
  43. override void OnAbort(HandEventBase e)
  44. {
  45. m_Src = null;
  46. m_Dst = null;
  47. super.OnAbort(e);
  48. }
  49. override void OnExit(HandEventBase e)
  50. {
  51. m_Src = null;
  52. m_Dst = null;
  53. super.OnExit(e);
  54. }
  55. override bool IsWaitingForActionFinish() { return true; }
  56. };
  57. class HandAnimatedTakingFromAtt extends HandStateBase
  58. {
  59. ref HandTakingAnimated_Hide m_Hide;
  60. ref HandTakingAnimated_Show m_Show;
  61. ref InventoryLocation m_Dst;
  62. void HandAnimatedTakingFromAtt(Man player = null, HandStateBase parent = null)
  63. {
  64. // setup nested state machine
  65. m_Hide = new HandTakingAnimated_Hide(player, this, WeaponActions.HIDE, -1);
  66. m_Show = new HandTakingAnimated_Show(player, this, WeaponActions.SHOW, -1);
  67. // events:
  68. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  69. HandEventBase _AEh_ = new HandAnimEventChanged;
  70. HandEventBase __Xd_ = new HandEventDestroyed;
  71. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  72. m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show ));
  73. m_FSM.AddTransition(new HandTransition( m_Hide, __Xd_, null ));
  74. m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
  75. m_FSM.AddTransition(new HandTransition( m_Show, __Xd_, null ));
  76. m_FSM.SetInitialState(m_Hide);
  77. }
  78. override void OnEntry(HandEventBase e)
  79. {
  80. m_Dst = e.GetDst();
  81. m_Show.m_Src = e.GetSrc();
  82. m_Show.m_Dst = e.GetDst();
  83. m_Hide.m_ActionType = e.GetAnimationID();
  84. m_Show.m_ActionType = e.GetAnimationID();
  85. e.m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst.GetItem(), m_Dst, GameInventory.c_InventoryReservationTimeoutShortMS);
  86. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  87. }
  88. override void OnAbort(HandEventBase e)
  89. {
  90. #ifdef ENABLE_LOGGING
  91. if ( LogManager.IsInventoryHFSMLogEnable() )
  92. {
  93. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "OnAbort", e.m_Player.ToString() );
  94. }
  95. #endif
  96. if (m_Dst)
  97. {
  98. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst.GetItem(), m_Dst);
  99. if ( GetGame().IsServer() )
  100. GetGame().ClearJuncture(e.m_Player, m_Dst.GetItem());
  101. }
  102. m_Dst = null;
  103. super.OnAbort(e);
  104. }
  105. override void OnExit(HandEventBase e)
  106. {
  107. e.m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst.GetItem(), m_Dst);
  108. m_Dst = null;
  109. super.OnExit(e);
  110. }
  111. };