weaponfireandchambernextfrominnermag.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. class WeaponFireAndChamberNextFromInnerMag extends WeaponStateBase
  2. {
  3. WeaponActions m_action;
  4. int m_actionType;
  5. float m_dtAccumulator;
  6. ref WeaponFire m_fire;
  7. void WeaponFireAndChamberNextFromInnerMag (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. DayZPlayer 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 ( hic.IsAttackButton() && m_dtAccumulator >= reloadTime)
  40. if (m_weapon.CanProcessWeaponEvents())
  41. m_weapon.ProcessWeaponEvent(new WeaponEventReloadTimeout(p));
  42. }
  43. }
  44. override void OnExit (WeaponEventBase e)
  45. {
  46. m_dtAccumulator = 0;
  47. super.OnExit(e);
  48. }
  49. };