weaponfireandchambernext.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. class WeaponFireAndChamberNext extends WeaponStateBase
  2. {
  3. WeaponActions m_action;
  4. int m_actionType;
  5. float m_dtAccumulator;
  6. ref WeaponFire m_fire;
  7. void WeaponFireAndChamberNext (Weapon_Base w = NULL, WeaponStateBase parent = NULL, WeaponActions action = WeaponActions.NONE, int actionType = -1)
  8. {
  9. m_action = action;
  10. m_actionType = actionType;
  11. // setup nested state machine
  12. m_fire = new WeaponFireAndChamber(m_weapon, this, m_action, m_actionType);
  13. // events
  14. WeaponEventBase _fin_ = new WeaponEventHumanCommandActionFinished;
  15. WeaponEventAnimBulletEject __be_ = new WeaponEventAnimBulletEject;
  16. WeaponEventReloadTimeout __to_ = new WeaponEventReloadTimeout;
  17. m_fsm = new WeaponFSM(this); // @NOTE: set owner of the submachine fsm
  18. // transitions
  19. m_fsm.AddTransition(new WeaponTransition(m_fire, _fin_, NULL));
  20. m_fsm.AddTransition(new WeaponTransition(m_fire, __to_, NULL));
  21. m_fsm.SetInitialState(m_fire);
  22. }
  23. override void OnEntry (WeaponEventBase e)
  24. {
  25. super.OnEntry(e);
  26. if (e)
  27. m_dtAccumulator = 0;
  28. }
  29. override void OnUpdate (float dt)
  30. {
  31. m_dtAccumulator += dt;
  32. DayZPlayerImplement p;
  33. Class.CastTo(p, m_weapon.GetHierarchyParent());
  34. if( p )
  35. {
  36. HumanInputController hic = p.GetInputController();
  37. int muzzleIndex = m_weapon.GetCurrentMuzzle();
  38. float reloadTime = m_weapon.GetReloadTime(muzzleIndex);
  39. if ( m_dtAccumulator >= reloadTime && ( hic.IsAttackButton() || (m_weapon.GetBurstCount() < m_weapon.GetCurrentModeBurstSize(muzzleIndex))))
  40. {
  41. if (m_weapon.CanProcessWeaponEvents())
  42. {
  43. m_weapon.ProcessWeaponEvent(new WeaponEventReloadTimeout(p));
  44. }
  45. }
  46. }
  47. }
  48. override void OnExit (WeaponEventBase e)
  49. {
  50. //m_weapon.ResetBurstCount();
  51. m_dtAccumulator = 0;
  52. super.OnExit(e);
  53. }
  54. override void OnAbort (WeaponEventBase e)
  55. {
  56. m_weapon.SetCoolDown(GetCoolDown());
  57. m_weapon.ResetBurstCount();
  58. super.OnAbort(e);
  59. }
  60. override float GetCoolDown()
  61. {
  62. int muzzleIndex = m_weapon.GetCurrentMuzzle();
  63. float reloadTime = m_weapon.GetReloadTime(muzzleIndex);
  64. return reloadTime - m_dtAccumulator;
  65. }
  66. };