11 void Invalidate() {
m_Task =
null; }
14 override protected void OnComplete()
18 m_Task.OnMoveWeaponFinished(
true);
25 override protected void OnFailed()
29 m_Task.OnMoveWeaponFinished(
false);
39 protected static const int WEAPON_STATE_IDLE = 0;
40 protected static const int WEAPON_STATE_MOVING = 1;
41 protected static const int WEAPON_STATE_MOVED = 2;
43 protected static const string PORT_WEAPON_COMPONENT =
"WeaponComponent";
45 protected int m_iWeaponState;
47 protected EquipedWeaponStorageComponent m_EqWeaponStorageComp;
51 void OnMoveWeaponFinished(
bool result)
54 AddDebugMessage(
string.Format(
"OnMoveWeaponFinished: %1", result));
57 m_iWeaponState = WEAPON_STATE_MOVED;
61 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
63 if (!m_WeaponMgrComp || !m_ControlComp || !m_InventoryMgr)
64 return ENodeResult.FAIL;
67 GetVariableIn(PORT_WEAPON_COMPONENT, newWeaponComp);
69 return ENodeResult.FAIL;
72 BaseCompartmentSlot compartmentSlot = m_CompartmentAccessComp.GetCompartment();
73 BaseWeaponManagerComponent weaponMgr;
75 weaponMgr = BaseWeaponManagerComponent.Cast(compartmentSlot.GetOwner().FindComponent(BaseWeaponManagerComponent));
77 weaponMgr = m_WeaponMgrComp;
80 return ENodeResult.FAIL;
89 IEntity compartmentParentEntity = compartmentSlot.GetOwner();
92 if (!turretController)
95 AddDebugMessage(
"Weapon switch failed: no turret controller on turret", LogLevel.WARNING);
97 return ENodeResult.FAIL;
100 if (currentWeaponComp == newWeaponComp)
103 AddDebugMessage(
"Weapon switch completed");
105 return ENodeResult.SUCCESS;
109 AddDebugMessage(
string.Format(
"StartWeaponSwitchTurret: %1 %2 %3", newWeaponComp, newWeaponComp.GetOwner(), newWeaponComp.GetOwner().GetPrefabData().GetPrefabName()));
111 SCR_AIWeaponHandling.StartWeaponSwitchTurret(turretController, newWeaponComp, owner.GetControlledEntity());
118 if (m_ControlComp.IsChangingItem())
119 return ENodeResult.RUNNING;
121 if (currentWeaponComp == newWeaponComp)
124 AddDebugMessage(
"Weapon switch completed");
126 return ENodeResult.SUCCESS;
129 if (!m_InventoryMgr.Contains(newWeaponComp.GetOwner()))
132 AddDebugMessage(
"Weapon switch failed: weapon is not in inventory", LogLevel.WARNING);
134 return ENodeResult.FAIL;
138 AddDebugMessage(
string.Format(
"StartWeaponSwitchCharacter: %1 %2 %3", newWeaponComp, newWeaponComp.GetOwner(), newWeaponComp.GetOwner().GetPrefabData().GetPrefabName()));
141 if (m_iWeaponState == WEAPON_STATE_MOVING)
142 return ENodeResult.RUNNING;
144 array<IEntity> weapons = {};
145 m_WeaponMgrComp.GetWeaponsList(weapons);
147 IEntity newWeaponEnt = newWeaponComp.GetOwner();
149 if (!weapons.Contains(newWeaponEnt))
152 if (m_iWeaponState == WEAPON_STATE_MOVED)
153 return ENodeResult.FAIL;
155 IEntity controlledEnt = owner.GetControlledEntity();
157 if (!m_EqWeaponStorageComp)
158 m_EqWeaponStorageComp = EquipedWeaponStorageComponent.Cast(controlledEnt.FindComponent(EquipedWeaponStorageComponent));
160 if (!m_EqWeaponStorageComp)
161 return ENodeResult.FAIL;
163 m_iWeaponState = WEAPON_STATE_MOVING;
165 if (m_WeaponMoveCallback)
166 m_WeaponMoveCallback.Invalidate();
171 IEntity existingEntityAtSlot =
null;
173 existingEntityAtSlot = slot.GetAttachedEntity();
175 if (existingEntityAtSlot)
178 AddDebugMessage(
"Weapon is not in the weapon manager list, slot already occupied, requesting swap of weapon and existing entity in slot");
180 m_InventoryMgr.TrySwapItemStorages(newWeaponEnt, existingEntityAtSlot, m_WeaponMoveCallback);
185 AddDebugMessage(
"Weapon is not in the weapon manager list, requesting move to EquipedWeaponStorageComponent");
187 m_InventoryMgr.TryMoveItemToStorage(newWeaponEnt, m_EqWeaponStorageComp, -1, m_WeaponMoveCallback);
190 return ENodeResult.RUNNING;
193 m_iWeaponState = WEAPON_STATE_IDLE;
194 SCR_AIWeaponHandling.StartWeaponSwitchCharacter(m_ControlComp, newWeaponComp);
196 return ENodeResult.RUNNING;
199 return ENodeResult.FAIL;
203 override void OnAbort(AIAgent owner, Node nodeCausingAbort)
205 m_iWeaponState = WEAPON_STATE_IDLE;
207 if (m_WeaponMoveCallback)
208 m_WeaponMoveCallback.Invalidate();
210 m_WeaponMoveCallback =
null;
214 protected static ref TStringArray s_aVarsIn = {PORT_WEAPON_COMPONENT};
215 override TStringArray GetVariablesIn() {
return s_aVarsIn; }
217 override bool VisibleInPalette() {
return true; }