5 #ifndef DISABLE_INVENTORY
7 [
Attribute(
"#AR-Inventory_Equip",
desc:
"What text should be displayed when the Equip action is available?" )]
8 protected string m_sEquipActionString;
9 [
Attribute(
"#AR-Inventory_Replaces",
desc:
"What text should be displayed when the Replace action is available?" )]
10 protected string m_sReplaceActionString;
12 int m_iTargetSlotID = -1;
13 bool m_bWasUnequipping =
false;
18 override void OnConfirmed(IEntity pUserEntity)
21 if (m_bWasUnequipping)
23 m_bWasUnequipping =
false;
24 CharacterControllerComponent controller = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
26 if (!controller.TryPlayItemGesture(
EItemGesture.EItemGesturePickUp,
this,
"Character_ActionGrab"))
32 IEntity pOwnerEntity =
m_Item.GetOwner();
33 SCR_InventoryStorageManagerComponent manager = SCR_InventoryStorageManagerComponent.Cast(pUserEntity.FindComponent(SCR_InventoryStorageManagerComponent));
34 EquipedWeaponStorageComponent weaponStorage = EquipedWeaponStorageComponent.Cast(pUserEntity.FindComponent(EquipedWeaponStorageComponent));
36 if (!manager || !weaponStorage)
38 m_pEquipCB.m_pWeapon = pOwnerEntity;
41 if (weaponStorage.GetSlot(m_iTargetSlotID) ==
null || weaponStorage.GetSlot(m_iTargetSlotID).GetAttachedEntity() !=
null)
46 if (manager.TryInsertItemInStorage(pOwnerEntity, weaponStorage, m_iTargetSlotID, m_pEquipCB))
56 override void OnRejected(IEntity pUserEntity)
58 m_bWasUnequipping =
false;
62 override protected void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
64 CharacterControllerComponent controller = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
65 if (!controller || controller.IsPlayingGesture())
67 if (m_iTargetSlotID > -1)
69 m_pEquipCB.m_pController = controller;
70 EquipedWeaponStorageComponent weaponStorage = EquipedWeaponStorageComponent.Cast(pUserEntity.FindComponent(EquipedWeaponStorageComponent));
72 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(pUserEntity.FindComponent(BaseWeaponManagerComponent));
74 if (!weaponStorage || !weaponManager)
77 WeaponComponent weapon = WeaponComponent.Cast(pOwnerEntity.FindComponent(WeaponComponent));
80 array<WeaponSlotComponent> weaponsList = {};
81 int weaponCount = weaponManager.GetWeaponsSlots(weaponsList);
82 array<int> suitableSlots = {};
84 for (
int i = 0; i < weaponCount; i++)
87 string weaponSlotType = weaponSlot.GetWeaponSlotType();
89 if (weaponSlotType.Compare(weapon.GetWeaponSlotType()) != 0 && !CharacterHandWeaponSlotComponent.Cast(weaponSlot))
93 suitableSlots.Insert(i);
96 if (suitableSlots.Count() == 0)
101 if (suitableSlots.Count() > 1)
103 for (
int j = 0; j < suitableSlots.Count(); j++)
107 if (slot.GetWeaponEntity() ==
null)
113 if (slot == weaponSlotCurr)
121 if (slot.GetWeaponEntity())
123 m_pRemoveWeaponCB.m_pController = controller;
124 m_pRemoveWeaponCB.m_pParentAction =
this;
125 m_iTargetSlotID = slot.GetWeaponSlotIndex();
128 m_pEquipCB.m_bNoEquipAnims = weaponSlotCurr == slot;
129 m_bWasUnequipping =
true;
130 if (!manager.TryRemoveItemFromStorage(slot.GetWeaponEntity(), weaponStorage, m_pRemoveWeaponCB))
132 m_iTargetSlotID = -1;
133 m_bWasUnequipping =
false;
134 m_pEquipCB.m_bNoEquipAnims =
false;
138 m_bWasUnequipping =
false;
139 m_pEquipCB.m_bNoEquipAnims = weaponSlotCurr ==
null;
142 if (CharacterHandWeaponSlotComponent.Cast(slot))
144 if (manager.TryInsertItemInStorage(pOwnerEntity, weaponStorage, slot.GetWeaponSlotIndex()))
152 if (controller.TryPlayItemGesture(
EItemGesture.EItemGesturePickUp,
this,
"Character_ActionGrab"))
153 m_iTargetSlotID = slot.GetWeaponSlotIndex();
158 override bool CanBePerformedScript(IEntity user)
160 if ( !super.CanBePerformedScript( user ) )
162 CharacterControllerComponent controller = CharacterControllerComponent.Cast(user.FindComponent(CharacterControllerComponent));
163 if (m_pWeaponOnGroundComponent.CanBeEquipped(controller) ==
ECanBeEquippedResult.STANCE_TOO_LOW)
165 SetCannotPerformReason(
"#AR-Inventory_StanceTooLow");
169 return CanEquipOrReplaceWeapon( user ) && !controller.IsReloading() && controller.CanPlayItemGesture();
174 override bool GetActionNameScript(out
string outName)
176 if (m_bIsSwappingWeapons)
178 string replaceAction =
string.Format(WidgetManager.Translate(m_sReplaceActionString), WidgetManager.Translate(m_sWeaponToSwapName));
179 outName =
string.Format(
"%1 %2", m_sEquipActionString, replaceAction);
182 outName = m_sEquipActionString;
193 CharacterControllerComponent m_pController;
195 bool m_bNoEquipAnims;
196 protected override void OnComplete()
198 m_pController.TryEquipRightHandItem(m_pWeapon,
EEquipItemType.EEquipTypeWeapon, m_bNoEquipAnims);
207 CharacterControllerComponent m_pController;
208 protected override void OnComplete()
210 m_pParentAction.OnConfirmed(m_pController.GetOwner());
219 #ifndef DISABLE_INVENTORY
221 [
Attribute(
"#AR-Inventory_PickUp",
desc:
"What text should be displayed when the Pick up action is available?" )]
222 protected string m_sPickUpActionString;
223 [
Attribute(
"#AR-Inventory_Replaces",
desc:
"What text should be displayed when the Replace text is visible?" )]
224 protected string m_sReplaceActionString;
225 [
Attribute(
"#AR-Inventory_EquipSling",
desc:
"What text should be displayed when the picked up weapons type is a primary" )]
226 protected string m_sEquipingSlingString;
227 [
Attribute(
"#AR-Inventory_EquipHolster",
desc:
"What text should be displayed when the picked up weapons type is a secondary" )]
228 protected string m_sEquipingHolsterString;
230 int m_iTargetSlotID = -1;
232 override void OnConfirmed(IEntity pUserEntity)
234 IEntity pOwnerEntity =
m_Item.GetOwner();
235 SCR_InventoryStorageManagerComponent manager = SCR_InventoryStorageManagerComponent.Cast(pUserEntity.FindComponent(SCR_InventoryStorageManagerComponent));
236 EquipedWeaponStorageComponent weaponStorage = EquipedWeaponStorageComponent.Cast(pUserEntity.FindComponent(EquipedWeaponStorageComponent));
238 if (!manager || !weaponStorage)
241 if (weaponStorage.GetSlot(m_iTargetSlotID) !=
null)
243 if (weaponStorage.GetSlot(m_iTargetSlotID).GetAttachedEntity() !=
null)
245 manager.TryReplaceItem(pOwnerEntity, weaponStorage, m_iTargetSlotID);
249 manager.TryInsertItemInStorage(pOwnerEntity, weaponStorage, m_iTargetSlotID);
252 m_iTargetSlotID = -1;
258 override protected void PerformActionInternal(SCR_InventoryStorageManagerComponent manager, IEntity pOwnerEntity, IEntity pUserEntity)
260 CharacterControllerComponent controller = CharacterControllerComponent.Cast(pUserEntity.FindComponent(CharacterControllerComponent));
261 if (!controller || controller.IsChangingItem() || controller.IsPlayingGesture())
263 if (m_iTargetSlotID > -1)
266 EquipedWeaponStorageComponent weaponStorage = EquipedWeaponStorageComponent.Cast(pUserEntity.FindComponent(EquipedWeaponStorageComponent));
268 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(pUserEntity.FindComponent(BaseWeaponManagerComponent));
270 if (!weaponStorage || !weaponManager)
273 WeaponComponent weapon = WeaponComponent.Cast(pOwnerEntity.FindComponent(WeaponComponent));
276 array<WeaponSlotComponent> weaponsList = {};
277 int weaponCount = weaponManager.GetWeaponsSlots(weaponsList);
278 array<int> suitableSlots = {};
279 for (
int i = 0; i < weaponCount; i++)
282 string weaponSlotType = weaponSlot.GetWeaponSlotType();
284 if (weaponSlotType.Compare(weapon.GetWeaponSlotType()) != 0 && !CharacterHandWeaponSlotComponent.Cast(weaponSlot))
288 suitableSlots.Insert(i);
291 if (suitableSlots.Count() == 0)
298 if (suitableSlots.Count() > 1)
300 for (
int j = 0; j < suitableSlots.Count(); j++)
303 if (weaponSlotCurr !=
null)
315 if (!slotComp.GetWeaponEntity())
326 if (weaponSlotFinal == weaponSlotCurr && weaponSlotCurr !=
null && weaponSlotCurr.GetWeaponEntity() !=
null)
329 if (controller.TryPlayItemGesture(
EItemGesture.EItemGesturePickUp,
this,
"Character_ActionGrab"))
330 m_iTargetSlotID = weaponSlotFinal.GetWeaponSlotIndex();
334 override bool CanBePerformedScript(IEntity user)
336 if ( !super.CanBePerformedScript( user ) )
338 CharacterControllerComponent controller = CharacterControllerComponent.Cast(user.FindComponent(CharacterControllerComponent));
339 return CanEquipOrReplaceWeapon( user ) && controller.CanPlayItemGesture();
343 override bool GetActionNameScript(out
string outName)
345 if (m_bIsSwappingWeapons)
347 string replaceAction =
string.Format(WidgetManager.Translate(m_sReplaceActionString), WidgetManager.Translate(m_sWeaponToSwapName));
348 outName =
string.Format(
"%1 %2", m_sPickUpActionString, replaceAction);
350 else if (m_sWeaponOnGroundType == PRIMARY_WEAPON_TYPE)
351 outName =
string.Format(
"%1 %2", m_sPickUpActionString, m_sEquipingSlingString);
352 else if (m_sWeaponOnGroundType == SECONDARY_WEAPON_TYPE)
353 outName =
string.Format(
"%1 %2", m_sPickUpActionString, m_sEquipingHolsterString);
355 outName = m_sPickUpActionString;
361 override BaseWeaponComponent GetWeaponToSwap( notnull BaseWeaponManagerComponent weaponManager )
365 string weaponSlotType;
369 weaponSlotType = weaponSlot.GetWeaponSlotType();
371 if ( weaponSlotType != m_sWeaponOnGroundType )
375 if ( m_iSameTypeSlotsCount <= 1 )
377 if ( weaponSlot == currentWeaponSlot )
386 if ( weaponSlot != currentWeaponSlot )
388 if ( weaponSlot.GetWeaponEntity() )