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;
97 private bool CountItems()
99 int containedItemCount = 0;
104 containedItemCount++;
110 private bool CheckItem(Item item)
115 protected override void Act(
float deltaTime)
136 static bool CanBePut(
Inventory inventory,
int? targetSlot,
Item itemToContain)
138 if (targetSlot.HasValue)
144 return inventory.
CanBePut(itemToContain);
159 bool TryPutItem(
Inventory inventory,
int? targetSlot,
Item itemToContain)
161 if (targetSlot.HasValue)
163 return inventory.
TryPutItem(itemToContain, targetSlot.Value, allowSwapping:
false, allowCombine:
false, user:
character);
175 foreach (
int slot
in slots)
177 foreach (
Item item
in originalInventory.
GetItemsAt(slot).ToList())
198 TargetName = container.Item.Name,
199 AbortCondition = obj =>
200 container?.Item == null || container.Item.Removed || !container.Item.HasAccess(character) ||
201 (container.Item.RootContainer?.OwnInventory?.Locked ?? false) ||
202 ItemToContain == null || ItemToContain.Removed ||
203 !ItemToContain.IsOwnedBy(character) || container.Item.GetRootInventoryOwner() is Character c && c != character,
204 SpeakIfFails = !objectiveManager.IsCurrentOrder<AIObjectiveCleanupItems>(),
205 endNodeFilter = n => Vector2.DistanceSquared(n.Waypoint.WorldPosition, container.Item.WorldPosition) <= MathUtils.Pow2(AIObjectiveGetItem.MaxReach)
207 onAbandon: () =>
Abandon =
true,
208 onCompleted: () => RemoveSubObjective(ref goToObjective));
220 TryAddSubObjective(ref getItemObjective, () =>
225 ignoredItems = containedItems,
229 ItemFilter = (
Item potentialItem) =>
238 }, onCompleted: () =>
240 if (getItemObjective?.TargetItem !=
null)
242 containedItems.Add(getItemObjective.TargetItem);
244 RemoveSubObjective(ref getItemObjective);
255 return inventory.IsInSlot(item, (
int)
TargetSlot);
263 getItemObjective =
null;
264 goToObjective =
null;
265 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
override bool CheckObjectiveState()
Should return whether the objective is completed or not.
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 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)