4 using System.Collections.Generic;
5 using System.Collections.Immutable;
7 using Microsoft.Xna.Framework;
22 private readonly
bool spawnItemIfNotFound;
27 private readonly
Item item;
35 private readonly HashSet<Item> containedItems =
new HashSet<Item>();
52 private int _itemCount = 1;
55 get {
return _itemCount; }
58 _itemCount = Math.Max(value, 1);
76 this.spawnItemIfNotFound = spawnItemIfNotFound;
98 private bool CountItems()
100 int containedItemCount = 0;
105 containedItemCount++;
111 private bool CheckItem(Item item)
116 protected override void Act(
float deltaTime)
137 static bool CanBePut(
Inventory inventory,
int? targetSlot,
Item itemToContain)
139 if (targetSlot.HasValue)
145 return inventory.
CanBePut(itemToContain);
160 bool TryPutItem(
Inventory inventory,
int? targetSlot,
Item itemToContain)
162 if (targetSlot.HasValue)
164 return inventory.
TryPutItem(itemToContain, targetSlot.Value, allowSwapping:
false, allowCombine:
false, user:
character);
176 foreach (
int slot
in slots)
178 foreach (
Item item
in originalInventory.
GetItemsAt(slot).ToList())
199 TargetName = container.Item.Name,
200 AbortCondition = obj =>
201 container?.Item == null || container.Item.Removed || !container.Item.HasAccess(character) ||
202 (container.Item.RootContainer?.OwnInventory?.Locked ?? false) ||
203 ItemToContain == null || ItemToContain.Removed ||
204 !ItemToContain.IsOwnedBy(character) || container.Item.GetRootInventoryOwner() is Character c && c != character,
205 SpeakIfFails = !objectiveManager.IsCurrentOrder<AIObjectiveCleanupItems>(),
206 endNodeFilter = n => Vector2.DistanceSquared(n.Waypoint.WorldPosition, container.Item.WorldPosition) <= MathUtils.Pow2(AIObjectiveGetItem.MaxReach)
208 onAbandon: () =>
Abandon =
true,
209 onCompleted: () => RemoveSubObjective(ref goToObjective));
221 TryAddSubObjective(ref getItemObjective, () =>
226 ignoredItems = containedItems,
230 ItemFilter = (
Item potentialItem) =>
239 }, onCompleted: () =>
241 if (getItemObjective?.TargetItem !=
null)
243 containedItems.Add(getItemObjective.TargetItem);
245 RemoveSubObjective(ref getItemObjective);
256 return inventory.IsInSlot(item, (
int)
TargetSlot);
264 getItemObjective =
null;
265 goToObjective =
null;
266 containedItems.Clear();
void UnequipContainedItems(Item parentItem, Func< Item, bool > predicate=null, bool avoidDroppingInSea=true, int? unequipMax=null)
void UnequipEmptyItems(Item parentItem, bool avoidDroppingInSea=true)
bool AllowDangerousPressure
AIObjectiveContainItem(Character character, Item item, ItemContainer container, AIObjectiveManager objectiveManager, float priorityModifier=1)
override bool AllowWhileHandcuffed
AIObjectiveContainItem(Character character, Identifier itemIdentifier, ItemContainer container, AIObjectiveManager objectiveManager, float priorityModifier=1, bool spawnItemIfNotFound=false)
AIObjectiveContainItem(Character character, ImmutableHashSet< Identifier > itemIdentifiers, ItemContainer container, AIObjectiveManager objectiveManager, float priorityModifier=1, bool spawnItemIfNotFound=false)
bool IsInTargetSlot(Item item)
Func< Item, bool > RemoveExistingPredicate
ImmutableHashSet< Identifier > ignoredContainerIdentifiers
override void Act(float deltaTime)
bool AllowToFindDivingGear
readonly ItemContainer container
Func< Item, float > GetItemPriority
override bool CheckObjectiveSpecific()
Should return whether the objective is completed or not.
override Identifier Identifier
readonly ImmutableHashSet< Identifier > itemIdentifiers
bool RemoveExistingWhenNecessary
Only remove existing items when the contain target can't be put in the inventory
readonly Character character
readonly AIObjectiveManager objectiveManager
bool CanInteractWith(Character c, float maxDist=200.0f, bool checkVisibility=true, bool skipDistanceCheck=false)
CharacterInventory Inventory
virtual bool CanBePutInSlot(Item item, int i, bool ignoreCondition=false)
Can the item be put in the specified slot.
virtual bool TryPutItem(Item item, Character user, IEnumerable< InvSlotType > allowedSlots=null, bool createNetworkEvent=true, bool ignoreCondition=false)
If there is room, puts the item in the inventory and returns true, otherwise returns false
bool Contains(Item item)
Is the item contained in this inventory. Does not recursively check items inside items.
List< int > FindIndices(Item item)
Find the indices of all the slots the item is contained in (two-hand items for example can be in mult...
Item FindItem(Func< Item, bool > predicate, bool recursive)
virtual IEnumerable< Item > AllItems
All items contained in the inventory. Stacked items are returned as individual instances....
int FindIndex(Item item)
Find the index of the first slot the item is contained in.
IEnumerable< Item > GetItemsAt(int index)
Get all the item stored in the specified inventory slot. Can return more than one item if the slot co...
bool CanBePut(Item item)
Can the item be put in the inventory (i.e. is there a suitable free slot or a stack the item can be p...
void Drop(Character dropper, bool createNetworkEvent=true, bool setTransform=true)
ItemInventory OwnInventory
Inventory ParentInventory
bool HasAccess(Character character)
Used by the AI to check whether they can (in principle) and are allowed (in practice) to interact wit...
readonly ItemInventory Inventory
bool ShouldBeContained(string[] identifiersOrTags, out bool isRestrictionsDefined)
bool CanBeContained(Item item)