3 protected static const string PORT_MAGAZINE_COMPONENT =
"MagazineComponent";
7 protected bool m_bReloadingTimer;
8 protected float m_fReloadFinishTime_ms;
11 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
13 if (!m_WeaponMgrComp || !m_ControlComp || !m_InventoryMgr)
14 return ENodeResult.FAIL;
16 BaseMagazineComponent newMagazineComp =
null;
17 GetVariableIn(PORT_MAGAZINE_COMPONENT, newMagazineComp);
22 AddDebugMessage(
"Skipped magazine switch, no magazine was provided");
24 return ENodeResult.SUCCESS;
28 BaseCompartmentSlot compartmentSlot = m_CompartmentAccessComp.GetCompartment();
29 BaseWeaponManagerComponent weaponMgr;
31 weaponMgr = BaseWeaponManagerComponent.Cast(compartmentSlot.GetOwner().FindComponent(BaseWeaponManagerComponent));
33 weaponMgr = m_WeaponMgrComp;
36 BaseMagazineComponent currentMagazineComp = SCR_AIWeaponHandling.GetCurrentMagazineComponent(weaponMgr);
37 if (currentMagazineComp == newMagazineComp)
41 if (m_ControlComp.IsReloading())
42 return ENodeResult.RUNNING;
44 if (!SCR_AIWeaponHandling.IsCurrentMuzzleChambered(weaponMgr))
47 AddDebugMessage(
"Muzzle is not chambered, requesting reload");
50 m_ControlComp.ReloadWeapon();
51 return ENodeResult.RUNNING;
57 AddDebugMessage(
"Magazine switch completed");
59 return ENodeResult.SUCCESS;
68 IEntity compartmentParentEntity = compartmentSlot.GetOwner();
72 if (turretInventoryMgr.Contains(newMagazineComp.GetOwner()))
74 if (!m_bReloadingTimer)
77 m_bReloadingTimer =
true;
78 float reloadDuration_ms = 1000 * turretController.GetReloadDuration();
79 m_fReloadFinishTime_ms =
GetGame().GetWorld().GetWorldTime() + reloadDuration_ms;
82 AddDebugMessage(
string.Format(
"Started turret reload timer: %1s %2 %3 %4", reloadDuration_ms/1000.0, newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().GetPrefabData().GetPrefabName()));
87 float currentTime_ms =
GetGame().GetWorld().GetWorldTime();
88 if (currentTime_ms >= m_fReloadFinishTime_ms)
90 m_bReloadingTimer =
false;
93 AddDebugMessage(
string.Format(
"StartMagazineSwitchTurret() %1 %2 %3", newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().GetPrefabData().GetPrefabName()));
95 SCR_AIWeaponHandling.StartMagazineSwitchTurret(turretController, newMagazineComp);
99 return ENodeResult.RUNNING;
104 AddDebugMessage(
"Failed magazine switch, the magazine was not found in turret inventory");
106 return ENodeResult.FAIL;
114 if (m_ControlComp.IsReloading())
116 return ENodeResult.RUNNING;
123 if (m_InventoryMgr.Contains(newMagazineComp.GetOwner()))
126 AddDebugMessage(
string.Format(
"StartMagazineSwitchCharacter() %1 %2 %3", newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().GetPrefabData().GetPrefabName()));
128 SCR_AIWeaponHandling.StartMagazineSwitchCharacter(m_ControlComp, newMagazineComp);
129 return ENodeResult.RUNNING;
134 AddDebugMessage(
"Failed magazine switch, the magazine was not found in inventory");
136 return ENodeResult.FAIL;
141 return ENodeResult.FAIL;
145 protected static ref TStringArray s_aVarsIn = {PORT_MAGAZINE_COMPONENT};
146 override TStringArray GetVariablesIn() {
return s_aVarsIn; }
148 override bool VisibleInPalette() {
return true; }