handanimatedtakingfromatt.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 (!GetGame().IsMultiplayer())
  26. {
  27. GameInventory.LocationSyncMoveEntity(m_Src, m_Dst);
  28. m_Player.OnItemInHandsChanged();
  29. }
  30. else
  31. {
  32. if (!GetGame().IsDedicatedServer())
  33. {
  34. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst.GetItem(), m_Dst);
  35. m_Player.GetHumanInventory().PostDeferredEventTakeToDst(InventoryMode.JUNCTURE, m_Src, m_Dst);
  36. }
  37. else
  38. {
  39. GetGame().ClearJunctureEx(e.m_Player, m_Dst.GetItem());
  40. }
  41. }
  42. }
  43. else
  44. {
  45. Error("[hndfsm] " + Object.GetDebugName(e.m_Player) + " STS = " + e.m_Player.GetSimulationTimeStamp() + " HandTakingAnimated_Show m_Src=invalid, item not in bubble?");
  46. }
  47. }
  48. else
  49. Error("[hndfsm] HandTakingAnimated_Show, error - m_Src not configured");
  50. }
  51. override void OnAbort(HandEventBase e)
  52. {
  53. m_Src = null;
  54. m_Dst = null;
  55. super.OnAbort(e);
  56. }
  57. override void OnExit(HandEventBase e)
  58. {
  59. m_Src = null;
  60. m_Dst = null;
  61. super.OnExit(e);
  62. }
  63. override bool IsWaitingForActionFinish() { return true; }
  64. };
  65. class HandAnimatedTakingFromAtt extends HandStateBase
  66. {
  67. ref HandTakingAnimated_Hide m_Hide;
  68. ref HandTakingAnimated_Show m_Show;
  69. ref InventoryLocation m_Dst;
  70. void HandAnimatedTakingFromAtt(Man player = null, HandStateBase parent = null)
  71. {
  72. // setup nested state machine
  73. m_Hide = new HandTakingAnimated_Hide(player, this, WeaponActions.HIDE, -1);
  74. m_Show = new HandTakingAnimated_Show(player, this, WeaponActions.SHOW, -1);
  75. // events:
  76. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  77. HandEventBase _AEh_ = new HandAnimEventChanged;
  78. HandEventBase __Xd_ = new HandEventDestroyed;
  79. m_FSM = new HandFSM(this); // @NOTE: set owner of the submachine fsm
  80. m_FSM.AddTransition(new HandTransition( m_Hide, _AEh_, m_Show ));
  81. m_FSM.AddTransition(new HandTransition( m_Hide, __Xd_, null ));
  82. m_FSM.AddTransition(new HandTransition( m_Show, _fin_, null ));
  83. m_FSM.AddTransition(new HandTransition( m_Show, __Xd_, null ));
  84. m_FSM.SetInitialState(m_Hide);
  85. }
  86. override void OnEntry(HandEventBase e)
  87. {
  88. m_Dst = e.GetDst();
  89. m_Show.m_Src = e.GetSrc();
  90. m_Show.m_Dst = e.GetDst();
  91. m_Hide.m_ActionType = e.GetAnimationID();
  92. m_Show.m_ActionType = e.GetAnimationID();
  93. m_Player.GetHumanInventory().AddInventoryReservationEx(m_Dst.GetItem(), m_Dst, GameInventory.c_InventoryReservationTimeoutShortMS);
  94. super.OnEntry(e); // @NOTE: super at the end (prevent override from submachine start)
  95. }
  96. override void OnAbort(HandEventBase e)
  97. {
  98. #ifdef ENABLE_LOGGING
  99. if ( LogManager.IsInventoryHFSMLogEnable() )
  100. {
  101. Debug.InventoryHFSMLog("Action - STS = " + e.m_Player.GetSimulationTimeStamp(), e.ToString() , "n/a", "OnAbort", e.m_Player.ToString() );
  102. }
  103. #endif
  104. if (m_Dst)
  105. {
  106. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst.GetItem(), m_Dst);
  107. if ( GetGame().IsServer() )
  108. GetGame().ClearJunctureEx(e.m_Player, m_Dst.GetItem());
  109. }
  110. m_Dst = null;
  111. super.OnAbort(e);
  112. }
  113. override void OnExit(HandEventBase e)
  114. {
  115. m_Player.GetHumanInventory().ClearInventoryReservationEx(m_Dst.GetItem(), m_Dst);
  116. m_Dst = null;
  117. super.OnExit(e);
  118. }
  119. };