23 enum EResupplyUnavailableReason
29 NOT_IN_GIVEN_STORAGE = 30,
33 RESUPPLY_VALID = 99999,
36 class SCR_HoldableItemPredicate : InventorySearchPredicate
42 void SCR_HoldableItemPredicate()
48 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
51 return optionalAttribute.GetInterestType() == wanted;
55 class SCR_BandagePredicate : InventorySearchPredicate
59 void SCR_BandagePredicate()
61 QueryComponentTypes.Insert(SCR_ConsumableItemComponent);
65 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
67 return (SCR_ConsumableItemComponent.Cast(queriedComponents[0])).GetConsumableType() ==
SCR_EConsumableType.BANDAGE;
71 class SCR_ApplicableMedicalItemPredicate : InventorySearchPredicate
73 IEntity characterEntity;
78 void SCR_ApplicableMedicalItemPredicate()
80 QueryComponentTypes.Insert(SCR_ConsumableItemComponent);
84 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
96 SCR_ConsumableItemComponent medicalItem = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
101 return effect.CanApplyEffectToHZ(characterEntity, characterEntity, hitZoneGroup);
105 class SCR_ItemTypeSearchPredicate : InventorySearchPredicate
107 int m_iItemType = -1;
108 IEntity m_iOriginalItem;
115 void SCR_ItemTypeSearchPredicate(
typename type,
int wantedItemType, IEntity originalItem)
117 QueryComponentTypes.Insert(
type);
118 m_iItemType = wantedItemType;
122 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
124 return (item != m_iOriginalItem) && (SCR_CharacterInventoryStorageComponent.GetItemType(item) == m_iItemType);
129 class SCR_CompatibleAttachmentPredicate : InventorySearchPredicate
131 typename attachmentType;
135 void SCR_CompatibleAttachmentPredicate()
141 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
157 if (!itemAttachmentType)
160 typename itemAttachmentTypename = itemAttachmentType.Type();
161 if (!itemAttachmentTypename)
164 return itemAttachmentTypename.IsInherited(attachmentType);
168 class SCR_SalinePredicate : InventorySearchPredicate
172 void SCR_SalinePredicate()
174 QueryComponentTypes.Insert(SCR_ConsumableItemComponent);
178 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
180 if (storage.Type().IsInherited(EquipmentStorageComponent))
188 class SCR_MagazinePredicate : InventorySearchPredicate
190 typename magWellType;
194 void SCR_MagazinePredicate()
196 QueryComponentTypes.Insert(BaseMagazineComponent);
200 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
202 BaseMagazineComponent iMag = BaseMagazineComponent.Cast(queriedComponents[0]);
210 return (iMagWell.IsInherited(magWellType));
215 class SCR_PrefabNamePredicate : InventorySearchPredicate
220 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
222 EntityPrefabData pd = item.GetPrefabData();
223 return pd.GetPrefabName() == this.prefabName;
228 class SCR_PrefabDataPredicate : InventorySearchPredicate
230 EntityPrefabData prefabData;
233 override protected bool IsMatch(BaseInventoryStorageComponent storage, IEntity item, array<GenericComponent> queriedComponents, array<BaseItemAttributeData> queriedAttributes)
235 return item.GetPrefabData() == this.prefabData;
244 SCR_InventoryStorageManagerComponent m_Manager;
246 bool m_bIstakenFromArsenal;
247 bool m_bDeleteItemIfEmpty;
248 ref array<IEntity> m_aItemsToMove = {};
249 ECallbackState m_ECurrentState = 0;
254 switch (m_ECurrentState)
256 case ECallbackState.DROP:
262 case ECallbackState.INSERT:
268 case ECallbackState.MOVE:
274 case ECallbackState.DELETE:
280 case ECallbackState.FINAL:
289 protected void OnDropComplete()
292 m_Manager.TryMoveItemToStorage(m_ItemAfter.GetOwner(), m_TargetSlot.GetStorage(), m_TargetSlot.GetID(),
this);
296 protected void OnInsertComplete()
298 if (!m_bIstakenFromArsenal)
300 m_ECurrentState = ECallbackState.FINAL;
312 protected void OnMoveComplete()
327 if (m_bDeleteItemIfEmpty)
334 m_ECurrentState = ECallbackState.FINAL;
342 protected void OnDeleteComplete()
344 m_aItemsToMove.Clear();
345 BaseInventoryStorageComponent itemIsStorage = BaseInventoryStorageComponent.Cast(m_ItemBefore);
346 m_Manager.GetAllItems(m_aItemsToMove, itemIsStorage);
348 if (m_aItemsToMove.IsEmpty())
349 m_Manager.AskServerToDeleteEntity(m_ItemBefore.GetOwner());
355 protected void OnFinalState()
358 m_FinalCB.InternalComplete();
364 protected SCR_InventoryStorageManagerComponent m_Manager;
365 protected ref map<ResourceName, int> m_MagazinesToSpawn =
new map<ResourceName, int>();
371 void Insert(ResourceName prefab,
int count)
374 m_MagazinesToSpawn.Find(prefab, currentCount);
375 m_MagazinesToSpawn.Insert(prefab, currentCount + count);
391 if (!m_MagazinesToSpawn.IsEmpty())
394 ResourceName prefab = m_MagazinesToSpawn.GetKey(0);
395 int count = m_MagazinesToSpawn.GetElement(0);
399 m_MagazinesToSpawn.Remove(prefab);
401 m_MagazinesToSpawn.Set(prefab, count);
403 m_Manager.TrySpawnPrefabToStorage(prefab, cb:
this);
416 GetGame().GetCallqueue().CallLater(m_Manager.EndResupplyMagazines, 1,
false);
422 void SCR_ResupplyMagazinesCallback(SCR_InventoryStorageManagerComponent manager)
428 class SCR_InventoryStorageManagerComponent : ScriptedInventoryStorageManagerComponent
430 private SCR_CharacterInventoryStorageComponent
m_Storage;
432 private ref SCR_BandagePredicate m_BandagePredicate =
new SCR_BandagePredicate();
433 protected EInventoryRetCode m_ERetCode;
434 protected int m_iHealthEquipment = 0;
435 protected bool m_bIsInventoryLocked =
false;
437 private bool m_bWasRaised;
438 private IEntity m_StorageToOpen;
439 protected ref SCR_ResupplyMagazinesCallback m_ResupplyMagazineCallback;
448 int GetAllRootItems(out notnull array<IEntity> rootItems)
451 array<BaseInventoryStorageComponent> storages = {};
457 array<IEntity> items = {};
458 array<BaseInventoryStorageComponent> clothStorages;
459 foreach (BaseInventoryStorageComponent storage : storages)
462 if (ClothNodeStorageComponent.Cast(storage))
468 storage.GetOwnedStorages(clothStorages, 1,
false);
470 foreach (BaseInventoryStorageComponent clothStorage : clothStorages)
475 clothStorage.GetAll(items);
476 rootItems.Copy(items);
483 storage.GetAll(items);
484 rootItems.Copy(items);
488 return rootItems.Count();
493 override protected void OnItemAdded(BaseInventoryStorageComponent storageOwner, IEntity item)
495 super.OnItemAdded(storageOwner, item);
497 SCR_ConsumableItemComponent consumable = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
499 m_iHealthEquipment++;
504 override protected void OnItemRemoved(BaseInventoryStorageComponent storageOwner, IEntity item)
506 super.OnItemRemoved(storageOwner, item);
508 SCR_ConsumableItemComponent consumable = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
510 m_iHealthEquipment--;
514 override protected bool ShouldForbidRemoveByInstigator(
InventoryStorageManagerComponent instigatorManager, BaseInventoryStorageComponent fromStorage, IEntity item)
517 SCR_ConsumableItemComponent consumableItemComp = SCR_ConsumableItemComponent.Cast(item.FindComponent(SCR_ConsumableItemComponent));
518 if (consumableItemComp)
531 void PlayItemSound(IEntity entity,
string soundEvent)
536 RplComponent rplComp = RplComponent.Cast(entity.FindComponent(RplComponent));
539 Rpc(RpcAsk_PlaySound, rplComp.Id(), soundEvent);
543 SoundComponent soundComp = SoundComponent.Cast(entity.FindComponent(SoundComponent));
546 soundComp.SoundEvent(soundEvent);
551 if (!soundManagerEntity)
554 soundManagerEntity.CreateAndPlayAudioSource(entity, soundEvent);
563 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
564 void RpcAsk_PlaySound(RplId targetRplId,
string soundAction)
566 Rpc(RpcDo_PlaySound, targetRplId, soundAction);
567 RpcDo_PlaySound(targetRplId, soundAction);
574 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
575 void RpcDo_PlaySound(RplId targetRplId,
string soundAction)
577 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(targetRplId));
581 IEntity entity = rplComp.GetEntity();
585 SoundComponent soundComp = SoundComponent.Cast(entity.FindComponent(SoundComponent));
588 soundComp.SoundEvent(soundAction);
593 if (!soundManagerEntity)
596 soundManagerEntity.CreateAndPlayAudioSource(entity, soundAction);
600 #ifndef DISABLE_INVENTORY
604 SCR_CharacterInventoryStorageComponent GetCharacterStorage()
616 bool CanInsertItemInActualStorage(IEntity item, BaseInventoryStorageComponent storage,
int slotID = -1)
618 if (!IsAnimationReady() || IsInventoryLocked())
621 array<BaseInventoryStorageComponent> pStorages = {};
622 storage.GetOwnedStorages( pStorages, 1,
false );
623 pStorages.Insert( storage );
625 foreach ( BaseInventoryStorageComponent pStorage : pStorages )
627 bool bCanInsert = CanInsertItemInStorage( item, pStorage, -1 );
628 bool bCanMove = CanMoveItemToStorage( item, pStorage, -1 );
629 if ( bCanInsert || bCanMove )
639 void SetReturnCode( EInventoryRetCode ERetCode )
641 m_ERetCode &= ~ERetCode;
647 void SetReturnCodeDefault()
649 m_ERetCode = EInventoryRetCode.RETCODE_DEFAULT_STATE;
654 EInventoryRetCode GetReturnCode()
661 float GetTotalWeightOfAllStorages()
663 array<BaseInventoryStorageComponent> storages = {};
664 float fTotalWeight = 0.0;
667 storages.Insert(
m_Storage.GetWeaponStorage());
670 foreach (BaseInventoryStorageComponent storage : storages)
672 fTotalWeight += storage.GetTotalWeight();
692 void InsertItem( IEntity pItem, BaseInventoryStorageComponent pStorageTo =
null, BaseInventoryStorageComponent pStorageFrom =
null,
SCR_InvCallBack cb =
null )
694 if (!pItem || !IsAnimationReady() || IsInventoryLocked())
697 SetInventoryLocked(
true);
699 bool canInsert =
true;
704 if ( !TryInsertItem( pItem,
EStoragePurpose.PURPOSE_WEAPON_PROXY, cb ) )
708 if ( !TryMoveItemToStorage( pItem, FindStorageForItem( pItem,
EStoragePurpose.PURPOSE_ANY ), -1, cb ) )
709 canInsert = TryMoveItemToStorage(pItem,
m_Storage, -1, cb);
720 PlayItemSound(pItem, soundEvent);
726 canInsert = TryReplaceItem( pStorageTo, pItem, 0, cb );
729 SetInventoryLocked(
false);
735 BaseInventoryStorageComponent validStorage = FindStorageForInsert( pItem, pStorageTo,
EStoragePurpose.PURPOSE_ANY );
738 pStorageTo = validStorage;
745 if (universalStorage)
747 array<BaseInventoryStorageComponent> linkedStorages = {};
748 universalStorage.GetLinkedStorages(linkedStorages);
750 foreach(BaseInventoryStorageComponent linkedStorage : linkedStorages)
753 if (FindStorageForInsert(pItem, linkedStorage,
EStoragePurpose.PURPOSE_ANY))
755 pStorageTo = linkedStorage;
763 canInsert = TryInsertItemInStorage( pItem, pStorageTo, -1, cb );
765 canInsert = TryMoveItemToStorage( pItem, pStorageTo, -1, cb );
776 SetInventoryLocked(
false);
785 bool TryRemoveItemFromInventory(IEntity pItem, BaseInventoryStorageComponent storage =
null,
InventoryOperationCallback cb =
null)
787 if (!CanMoveItem(pItem))
798 storage = parentSlot.GetStorage();
801 SetInventoryLocked(
true);
802 bool result = TryRemoveItemFromStorage(pItem, storage, cb);
803 SetInventoryLocked(
false);
812 bool CanMoveItem(IEntity item)
814 if (!item || item.IsDeleted() || !IsAnimationReady() || IsInventoryLocked())
846 bool TrySwapItems( IEntity pOwnerEntity, BaseInventoryStorageComponent pStorageTo,
SCR_InvCallBack cb =
null )
855 if ( slot.GetAttachedEntity() )
857 if (!TrySwapItemStorages( pOwnerEntity, slot.GetAttachedEntity(), cb ))
859 CharacterHandWeaponSlotComponent handWeaponSlot = CharacterHandWeaponSlotComponent.Cast(slot.GetParentContainer());
863 if (TryRemoveItemFromInventory(slot.GetAttachedEntity()))
877 return TryMoveItemToStorage( pOwnerEntity, pStorageTo, slot.GetID(), cb );
888 void EquipWeapon( IEntity pOwnerEntity,
SCR_InvCallBack cb =
null,
bool bFromVicinity =
true )
890 if ( !bFromVicinity )
892 if (!TrySwapItems(pOwnerEntity,
m_Storage.GetWeaponStorage(), cb))
904 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(user.FindComponent(BaseWeaponManagerComponent));
911 preferred = slot.GetWeaponSlotIndex();
913 if (!EquipAny(
m_Storage.GetWeaponStorage(), pOwnerEntity, preferred, cb))
916 if (cb && cb.m_pStorageFrom != cb.m_pStorageTo)
930 void EquipWeaponAttachment( IEntity pOwnerEntity, IEntity pUserEntity,
SCR_InvCallBack cb =
null )
932 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(pUserEntity.FindComponent(BaseWeaponManagerComponent));
940 IEntity weaponEntity = slot.GetWeaponEntity();
944 BaseInventoryStorageComponent storage = BaseInventoryStorageComponent.Cast(weaponEntity.FindComponent(BaseInventoryStorageComponent));
948 EquipAny(storage, pOwnerEntity, -1, cb );
961 BaseInventoryStorageComponent storageComp = FindStorageForItem(pOwnerEntity,
EStoragePurpose.PURPOSE_EQUIPMENT_ATTACHMENT);
964 EquipAny( storageComp, pOwnerEntity, -1, cb );
974 void EquipCloth( IEntity pOwnerEntity )
990 bool EquipAny(BaseInventoryStorageComponent storage, IEntity item,
int preferred = -1,
SCR_InvCallBack cb =
null)
992 if (!storage || !item)
1003 if (preferred > 0 && preferred < storage.GetSlotsCount())
1004 m_TargetSlot = storage.GetSlot(preferred);
1006 preferred = m_TargetSlot.GetID();
1010 if (!sourceSlot || !sourceSlot.GetStorage())
1014 if (m_TargetSlot.GetAttachedEntity())
1015 return TryReplaceItem(item, storage, preferred, cb);
1018 return TryInsertItemInStorage(item, storage, preferred, cb);
1023 if (!m_TargetSlot.GetAttachedEntity())
1024 return TryMoveItemToStorage(item, storage, preferred, cb);
1026 BaseInventoryStorageComponent sourceStorage = sourceSlot.GetStorage();
1028 bool isTakenFromBody =
false;
1030 ChimeraCharacter lootedBodyCharacter = ChimeraCharacter.Cast(sourceStorage.GetOwner());
1033 if (lootedBodyCharacter)
1034 lootedBodyDamageManager = lootedBodyCharacter.GetDamageManager();
1036 if (lootedBodyDamageManager)
1037 isTakenFromBody = lootedBodyDamageManager.GetState() ==
EDamageState.DESTROYED;
1039 bool performDropOfOriginalItem = isTakenFromBody || isTakenFromArsenal || sourceStorage.GetOwner().FindComponent(SCR_CampaignArmoryStorageComponent) ;
1042 if (performDropOfOriginalItem)
1052 if (!CanSwapItemStorages(item, m_TargetSlot.GetAttachedEntity()))
1055 DropAndMoveOperationCallback chainedCallback =
new DropAndMoveOperationCallback();
1056 chainedCallback.m_Manager =
this;
1057 chainedCallback.m_ItemAfter = itemComp;
1059 chainedCallback.m_TargetSlot = m_TargetSlot;
1060 chainedCallback.m_FinalCB = cb;
1061 chainedCallback.m_bDeleteItemIfEmpty =
true;
1062 chainedCallback.m_bIstakenFromArsenal = isTakenFromArsenal;
1064 return TryRemoveItemFromStorage(m_TargetSlot.GetAttachedEntity(), m_TargetSlot.GetStorage(), chainedCallback);
1068 return TrySwapItemStorages(item, m_TargetSlot.GetAttachedEntity(), cb);
1080 bool TryReplaceAndDropItemAtSlot(BaseInventoryStorageComponent storage, IEntity item,
int slotID,
SCR_InvCallBack cb =
null,
bool isTakenFromArsenal =
false,
bool deleteOriginalItemIfEmpty =
false)
1082 if (!storage || !item)
1095 if (!sourceSlot || !sourceSlot.GetStorage())
1099 if (m_TargetSlot.GetAttachedEntity())
1100 return TryReplaceItem(item, storage, slotID, cb);
1102 return TryInsertItemInStorage(item, storage, slotID, cb);
1107 if (!m_TargetSlot.GetAttachedEntity())
1108 return TryMoveItemToStorage(item, storage, slotID, cb);
1118 if (!CanSwapItemStorages(item, m_TargetSlot.GetAttachedEntity()))
1121 DropAndMoveOperationCallback chainedCallback =
new DropAndMoveOperationCallback();
1122 chainedCallback.m_Manager =
this;
1123 chainedCallback.m_ItemAfter = itemComp;
1125 chainedCallback.m_TargetSlot = m_TargetSlot;
1126 chainedCallback.m_bDeleteItemIfEmpty = deleteOriginalItemIfEmpty;
1127 chainedCallback.m_bIstakenFromArsenal = isTakenFromArsenal;
1128 chainedCallback.m_FinalCB = cb;
1130 return TryRemoveItemFromStorage(m_TargetSlot.GetAttachedEntity(), m_TargetSlot.GetStorage(), chainedCallback);
1140 bool TryReplaceItem( BaseInventoryStorageComponent storage, IEntity item,
int preferred,
SCR_InvCallBack cb )
1142 int slotCount = storage.GetSlotsCount();
1144 for (
int i = 0; i < slotCount; i++ )
1146 int j = ( i + preferred ) % slotCount;
1149 if ( TryReplaceItem( item, storage, j, cb ) )
1161 void EquipItem( EquipedWeaponStorageComponent weaponStorage, IEntity weapon )
1164 if ( CanInsertItemInStorage( weapon, weaponStorage, -1) )
1166 TryInsertItemInStorage( weapon, weaponStorage, -1 );
1171 BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(
GetOwner().FindComponent(BaseWeaponManagerComponent) );
1176 int slotCount = weaponStorage.GetSlotsCount();
1179 preferred = slot.GetWeaponSlotIndex();
1181 for (
int i = 0; i < slotCount; i++ )
1183 int j = ( i + preferred ) % slotCount;
1186 TryReplaceItem( weapon, weaponStorage, j );
1200 bool IsResupplyMagazinesAvailable(
int resupplyMagazineCount = 4, out EResupplyUnavailableReason resupplyUnavailableReason = EResupplyUnavailableReason.NONE,
EMuzzleType muzzleType = -1,
InventoryStorageManagerComponent mustBeInStorage =
null)
1202 BaseWeaponManagerComponent weaponsManager = BaseWeaponManagerComponent.Cast(
GetOwner().FindComponent(BaseWeaponManagerComponent));
1203 if (!weaponsManager)
1206 array<IEntity> weaponList = {};
1207 weaponsManager.GetWeaponsList(weaponList);
1209 bool foundValidWeapon =
false;
1210 ResourceName magazineOrProjectilePrefab;
1211 IEntity spawnedMagazine;
1214 array<BaseMuzzleComponent> muzzles;
1215 SCR_MuzzleInMagComponent inMagMuzzle;
1216 SCR_ArsenalInventoryStorageManagerComponent arsenalStorage;
1217 foreach (IEntity weapon : weaponList)
1223 string weaponSlotType = comp.GetWeaponSlotType();
1226 if ((weaponSlotType !=
"primary" && weaponSlotType !=
"secondary"))
1232 comp.GetMuzzlesList(muzzles);
1235 if (muzzleType != -1 && muzzle.GetMuzzleType() != muzzleType)
1238 inMagMuzzle = SCR_MuzzleInMagComponent.Cast(muzzle);
1239 if (inMagMuzzle && !inMagMuzzle.CanBeReloaded())
1242 magazineOrProjectilePrefab = muzzle.GetDefaultMagazineOrProjectileName();
1247 foundValidWeapon =
true;
1250 if (mustBeInStorage)
1252 arsenalStorage = SCR_ArsenalInventoryStorageManagerComponent.Cast(mustBeInStorage);
1253 if ((arsenalStorage && !arsenalStorage.IsPrefabInArsenalStorage(magazineOrProjectilePrefab)) || (!arsenalStorage && mustBeInStorage.GetDepositItemCountByResource(magazineOrProjectilePrefab) < 1))
1255 if (resupplyUnavailableReason < EResupplyUnavailableReason.NOT_IN_GIVEN_STORAGE)
1256 resupplyUnavailableReason = EResupplyUnavailableReason.NOT_IN_GIVEN_STORAGE;
1263 if (resupplyMagazineCount - GetMagazineCountByMuzzle(muzzle) <= 0)
1265 if (resupplyUnavailableReason < EResupplyUnavailableReason.ENOUGH_ITEMS)
1266 resupplyUnavailableReason = EResupplyUnavailableReason.ENOUGH_ITEMS;
1272 if (!FindStorageForResourceInsert(magazineOrProjectilePrefab,
m_Storage))
1274 if (resupplyUnavailableReason < EResupplyUnavailableReason.INVENTORY_FULL)
1275 resupplyUnavailableReason = EResupplyUnavailableReason.INVENTORY_FULL;
1282 resupplyUnavailableReason = EResupplyUnavailableReason.NONE;
1290 if (!foundValidWeapon)
1291 resupplyUnavailableReason = EResupplyUnavailableReason.NO_VALID_WEAPON;
1304 validResupplyItems.Clear();
1306 BaseWeaponManagerComponent weaponsManager = BaseWeaponManagerComponent.Cast(
GetOwner().FindComponent(BaseWeaponManagerComponent));
1307 if (!weaponsManager)
1310 array<IEntity> weaponList = {};
1311 weaponsManager.GetWeaponsList(weaponList);
1314 array<BaseMuzzleComponent> muzzles;
1315 SCR_MuzzleInMagComponent inMagMuzzle;
1316 SCR_ArsenalInventoryStorageManagerComponent arsenalStorage;
1317 foreach (IEntity weapon : weaponList)
1320 string weaponSlotType = comp.GetWeaponSlotType();
1323 if (!(weaponSlotType ==
"primary" || weaponSlotType ==
"secondary"))
1329 comp.GetMuzzlesList(muzzles);
1332 if (muzzleType != -1 && muzzle.GetMuzzleType() != muzzleType)
1335 inMagMuzzle = SCR_MuzzleInMagComponent.Cast(muzzle);
1336 if (inMagMuzzle && !inMagMuzzle.CanBeReloaded())
1339 ResourceName magazineOrProjectilePrefab = muzzle.GetDefaultMagazineOrProjectileName();
1344 int resupplyCount = maxMagazineCount - GetMagazineCountByMuzzle(muzzle);
1345 if (resupplyCount <= 0)
1349 if (mustBeInStorage)
1351 arsenalStorage = SCR_ArsenalInventoryStorageManagerComponent.Cast(mustBeInStorage);
1352 if ((arsenalStorage && !arsenalStorage.IsPrefabInArsenalStorage(magazineOrProjectilePrefab)) || (!arsenalStorage && mustBeInStorage.GetDepositItemCountByResource(magazineOrProjectilePrefab) < 1))
1357 if (!validResupplyItems.Contains(magazineOrProjectilePrefab))
1358 validResupplyItems.Insert(magazineOrProjectilePrefab, resupplyCount);
1361 validResupplyItems[magazineOrProjectilePrefab] = Math.Clamp(validResupplyItems[magazineOrProjectilePrefab] + resupplyCount, 0, maxMagazineCount);
1369 void ResupplyMagazines(notnull map<ResourceName, int> validResupplyItems)
1372 if (validResupplyItems.IsEmpty())
1375 if (!m_ResupplyMagazineCallback)
1376 m_ResupplyMagazineCallback =
new SCR_ResupplyMagazinesCallback(
this);
1379 foreach (ResourceName itemPrefab,
int count : validResupplyItems)
1381 m_ResupplyMagazineCallback.Insert(itemPrefab, count);
1384 m_ResupplyMagazineCallback.Start();
1395 map<ResourceName, int> validResupplyItems =
new map<ResourceName, int>();
1396 GetValidResupplyItemsAndCount(validResupplyItems, maxMagazineCount, muzzleType, mustBeInStorage);
1399 ResupplyMagazines(validResupplyItems);
1404 void EndResupplyMagazines()
1406 delete m_ResupplyMagazineCallback;
1419 SCR_MuzzleInMagComponent inMagMuzzle = SCR_MuzzleInMagComponent.Cast(muzzle);
1420 if (inMagMuzzle && !inMagMuzzle.CanBeReloaded())
1421 return EResupplyUnavailableReason.NO_VALID_WEAPON;
1424 ResourceName magazineToResupply = muzzle.GetDefaultMagazineOrProjectileName();
1426 return EResupplyUnavailableReason.NO_VALID_WEAPON;
1429 if (mustBeInStorage)
1431 SCR_ArsenalInventoryStorageManagerComponent arsenalStorage = SCR_ArsenalInventoryStorageManagerComponent.Cast(mustBeInStorage);
1432 if ((arsenalStorage && !arsenalStorage.IsPrefabInArsenalStorage(magazineToResupply)) || (!arsenalStorage && mustBeInStorage.GetDepositItemCountByResource(magazineToResupply) < 1))
1433 return EResupplyUnavailableReason.NOT_IN_GIVEN_STORAGE;
1437 currentMagazineAmount = GetMagazineCountByMuzzle(muzzle);
1438 if (maxMagazineCount > 0 && currentMagazineAmount >= maxMagazineCount)
1439 return EResupplyUnavailableReason.ENOUGH_ITEMS;
1442 if (!FindStorageForResourceInsert(magazineToResupply,
m_Storage))
1443 return EResupplyUnavailableReason.INVENTORY_FULL;
1445 return EResupplyUnavailableReason.RESUPPLY_VALID;
1455 EResupplyUnavailableReason CanResupplyItem(ResourceName itemToResupply,
int maxItemCount = -1,
InventoryStorageManagerComponent mustBeInStorage =
null, out
int currentItemAmount = -1)
1458 if (mustBeInStorage)
1460 SCR_ArsenalInventoryStorageManagerComponent arsenalStorage = SCR_ArsenalInventoryStorageManagerComponent.Cast(mustBeInStorage);
1461 if ((arsenalStorage && !arsenalStorage.IsPrefabInArsenalStorage(itemToResupply)) || (!arsenalStorage && mustBeInStorage.GetDepositItemCountByResource(itemToResupply) < 1))
1462 return EResupplyUnavailableReason.NOT_IN_GIVEN_STORAGE;
1466 currentItemAmount = GetDepositItemCountByResource(itemToResupply);
1467 if (maxItemCount > 0 && currentItemAmount >= maxItemCount)
1468 return EResupplyUnavailableReason.ENOUGH_ITEMS;
1471 if (!FindStorageForResourceInsert(itemToResupply,
m_Storage))
1472 return EResupplyUnavailableReason.INVENTORY_FULL;
1474 return EResupplyUnavailableReason.RESUPPLY_VALID;
1481 void MoveItemToVicinity(IEntity pItem, BaseInventoryStorageComponent pStorageTo =
null);
1485 void OpenInventory()
1490 MenuManager menuManager =
GetGame().GetMenuManager();
1493 MenuBase inventoryMenu = menuManager.FindMenuByPreset(menu);
1497 menuManager.OpenMenu( menu );
1498 m_OnInventoryOpenInvoker.Invoke(
true);
1518 void CloseInventory()
1520 MenuManager menuManager =
GetGame().GetMenuManager();
1529 IEntity GetStorageToOpen()
1531 IEntity result = m_StorageToOpen;
1532 m_StorageToOpen =
null;
1539 void SetStorageToOpen(IEntity storage)
1541 m_StorageToOpen = storage;
1546 void Action_OpenInventory()
1548 CompartmentAccessComponent cac =
m_CharacterController.GetCharacter().GetCompartmentAccessComponent();
1549 if (cac && cac.IsInCompartment())
1551 IEntity owner = cac.GetCompartment().GetOwner();
1554 UniversalInventoryStorageComponent comp = UniversalInventoryStorageComponent.Cast(owner.FindComponent(UniversalInventoryStorageComponent));
1557 SetStorageToOpen(owner);
1561 owner = owner.GetParent();
1569 void OnInventoryMenuClosed()
1571 m_OnInventoryOpenInvoker.Invoke(
false);
1579 override void OnStorageAdded(BaseInventoryStorageComponent storage)
1595 void DebugListAllItemsInInventory()
1597 array<IEntity> items = {};
1599 Print(
"INV: no item", LogLevel.NORMAL);
1602 foreach (IEntity item : items)
1607 attribs = pInvComp.GetAttributes();
1611 string sName = attribs.GetUIInfo().GetName();
1612 Print(
"INV: " + sName, LogLevel.NORMAL);
1619 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1620 protected void RpcAsk_ServerToDeleteEntity(RplId targetRplId)
1622 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(targetRplId));
1626 IEntity entity = rplComp.GetEntity();
1630 RplComponent.DeleteRplEntity(entity,
false);
1636 void AskServerToDeleteEntity(IEntity ent)
1638 RplComponent rplComp = RplComponent.Cast(ent.FindComponent(RplComponent));
1642 RplId rplId = rplComp.Id();
1643 Rpc(RpcAsk_ServerToDeleteEntity, rplId);
1648 void EnablePostFrame(
bool enable)
1651 SetEventMask(
GetOwner(), EntityEvent.POSTFRAME);
1653 ClearEventMask(
GetOwner(), EntityEvent.POSTFRAME);
1658 int GetHealthComponentCount()
1660 return m_iHealthEquipment;
1665 IEntity GetBandageItem()
1672 void ~SCR_InventoryStorageManagerComponent()
1674 m_ERetCode = EInventoryRetCode.RETCODE_DEFAULT_STATE;
1679 bool IsAnimationReady()
1688 bool IsInventoryLocked()
1690 return m_bIsInventoryLocked;
1695 void SetInventoryLocked(
bool isLocked)
1697 m_bIsInventoryLocked = isLocked;
1704 int GetAllItems(inout array<IEntity> items, BaseInventoryStorageComponent storage)
1706 if (!storage || !items)
1711 if (!ClothNodeStorageComponent.Cast(storage))
1712 count = storage.GetAll(items);
1714 array<BaseInventoryStorageComponent> itemToReplaceAttachedStorages = {};
1715 storage.GetOwnedStorages(itemToReplaceAttachedStorages, 1,
false);
1716 foreach (BaseInventoryStorageComponent attachedStorage : itemToReplaceAttachedStorages)
1718 if (ClothNodeStorageComponent.Cast(attachedStorage))
1719 attachedStorage.GetOwnedStorages(itemToReplaceAttachedStorages, 1,
false);
1721 count += attachedStorage.GetAll(items);
1732 void GetWeaponPrefabsOfType(notnull array<IEntity> weapons,
EWeaponType weaponType, notnull out array<EntityPrefabData> prefabs)
1735 EntityPrefabData prefabData;
1736 foreach (IEntity item : weapons)
1739 if (weapon.GetWeaponType() != weaponType)
1743 prefabData = item.GetPrefabData();
1744 if (prefabData && !prefabs.Contains(prefabData))
1745 prefabs.Insert(prefabData);
1755 IEntity FindNextWeaponOfType(
EWeaponType weaponType, IEntity currentItem =
null,
bool allowCurrentPrefab =
false)
1757 array<EntityPrefabData> prefabs = {};
1760 EntityPrefabData currentPrefab;
1764 currentPrefab = currentItem.GetPrefabData();
1767 if (currentPrefab && currentWeapon.GetWeaponType() == weaponType)
1768 prefabs.Insert(currentPrefab);
1772 array<IEntity> items = {};
1774 GetWeaponPrefabsOfType(items, weaponType, prefabs);
1777 if (prefabs.IsEmpty())
1789 int nextPrefabID = (prefabs.Find(currentPrefab) + 1) % prefabs.Count();
1790 EntityPrefabData nextPrefab = prefabs[nextPrefabID];
1793 if (!allowCurrentPrefab && nextPrefab == currentPrefab)
1797 foreach (IEntity item : items)
1799 if (item && item.GetPrefabData() == nextPrefab)
1810 void SetReturnCode( EInventoryRetCode ERetCode ) ;
1813 void SetReturnCodeDefault() ;
1817 EInventoryRetCode GetReturnCode()
1824 float GetTotalWeightOfAllStorages();
1840 void EquipWeapon( IEntity pOwnerEntity,
SCR_InvCallBack cb =
null,
bool bFromVicinity =
true );
1845 void EquipGadget( IEntity pOwnerEntity );
1850 void EquipCloth( IEntity pOwnerEntity );
1857 void EquipAny(BaseInventoryStorageComponent storage, IEntity item,
int preferred = 0);
1863 void EquipItem( EquipedWeaponStorageComponent weaponStorage, IEntity weapon );
1867 void OpenInventory();
1871 void Action_OpenInventory();
1874 override void OnStorageAdded(BaseInventoryStorageComponent storage);
1879 void EnablePostFrame(
bool enable);
1883 int GetHealthComponentCount();
1887 IEntity GetBandageItem();
1896 void SCR_InventoryStorageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
1898 #ifndef DISABLE_INVENTORY
1903 m_Storage = SCR_CharacterInventoryStorageComponent.Cast(ent.FindComponent(CharacterInventoryStorageComponent));