protected override void Act(float deltaTime) { if (container == null || (container.Item != null && container.Item.IsThisOrAnyContainerIgnoredByAI())) { Abandon = true; return; } ItemToContain = item ?? character.Inventory.FindItem(i => CheckItem(i) && i.Container != container.Item, recursive: true); if (ItemToContain != null) { if (!character.CanInteractWith(ItemToContain, checkLinked: false)) { Abandon = true; return; } if (character.CanInteractWith(container.Item, checkLinked: false)) { if (RemoveExisting) { HumanAIController.UnequipContainedItems(container.Item); } else if (RemoveEmpty) { HumanAIController.UnequipEmptyItems(container.Item); } Inventory originalInventory = ItemToContain.ParentInventory; var slots = originalInventory?.FindIndices(ItemToContain); if (container.Inventory.TryPutItem(ItemToContain, null)) { if (MoveWholeStack && slots != null) { foreach (int slot in slots) { foreach (Item item in originalInventory.GetItemsAt(slot).ToList()) { container.Inventory.TryPutItem(item, null); } } IsCompleted = true; } } else { if (ItemToContain.ParentInventory == character.Inventory && character.Submarine == Submarine.MainSub) { ItemToContain.Drop(character); } Abandon = true; } } else { TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(container.Item, character, objectiveManager, getDivingGearIfNeeded: AllowToFindDivingGear) { DialogueIdentifier = "dialogcannotreachtarget", TargetName = container.Item.Name, abortCondition = obj => !ItemToContain.IsOwnedBy(character), SpeakIfFails = !objectiveManager.IsCurrentOrder <AIObjectiveCleanupItems>() }, onAbandon: () => Abandon = true, onCompleted: () => RemoveSubObjective(ref goToObjective)); } } else { if (character.Submarine == null) { Abandon = true; } else { // No matching items in the inventory, try to get an item TryAddSubObjective(ref getItemObjective, () => new AIObjectiveGetItem(character, itemIdentifiers, objectiveManager, equip: Equip, checkInventory: checkInventory, spawnItemIfNotFound: spawnItemIfNotFound) { GetItemPriority = GetItemPriority, ignoredContainerIdentifiers = ignoredContainerIdentifiers, ignoredItems = containedItems, AllowToFindDivingGear = AllowToFindDivingGear, AllowDangerousPressure = AllowDangerousPressure, TargetCondition = ConditionLevel }, onAbandon: () => { Abandon = true; }, onCompleted: () => { if (getItemObjective?.TargetItem != null) { containedItems.Add(getItemObjective.TargetItem); } RemoveSubObjective(ref getItemObjective); }); } } }
protected override void Act(float deltaTime) { if (container == null || (container.Item != null && container.Item.IsThisOrAnyContainerIgnoredByAI())) { Abandon = true; return; } ItemToContain = item ?? character.Inventory.FindItem(i => CheckItem(i) && i.Container != container.Item, recursive: true); if (ItemToContain != null) { if (!character.CanInteractWith(ItemToContain, checkLinked: false)) { Abandon = true; return; } if (character.CanInteractWith(container.Item, checkLinked: false)) { if (RemoveEmpty && container.Inventory.AllItems.Any(it => it.Condition <= 0.0f)) { foreach (var emptyItem in container.Inventory.AllItemsMod) { if (emptyItem.Condition <= 0) { emptyItem.Drop(character); } } } // Contain the item if (ItemToContain.ParentInventory == character.Inventory) { if (!container.Inventory.CanBePut(ItemToContain)) { Abandon = true; } else { character.Inventory.RemoveItem(ItemToContain); if (container.Inventory.TryPutItem(ItemToContain, null)) { IsCompleted = true; } else { ItemToContain.Drop(character); Abandon = true; } } } else { if (container.Combine(ItemToContain, character)) { IsCompleted = true; } else { Abandon = true; } } } else { TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(container.Item, character, objectiveManager, getDivingGearIfNeeded: AllowToFindDivingGear) { DialogueIdentifier = "dialogcannotreachtarget", TargetName = container.Item.Name, abortCondition = () => !ItemToContain.IsOwnedBy(character) }, onAbandon: () => Abandon = true, onCompleted: () => RemoveSubObjective(ref goToObjective)); } } else { if (character.Submarine == null) { Abandon = true; } else { // No matching items in the inventory, try to get an item TryAddSubObjective(ref getItemObjective, () => new AIObjectiveGetItem(character, itemIdentifiers, objectiveManager, equip: Equip, checkInventory: checkInventory, spawnItemIfNotFound: spawnItemIfNotFound) { GetItemPriority = GetItemPriority, ignoredContainerIdentifiers = ignoredContainerIdentifiers, ignoredItems = containedItems, AllowToFindDivingGear = AllowToFindDivingGear, AllowDangerousPressure = AllowDangerousPressure, TargetCondition = ConditionLevel }, onAbandon: () => { Abandon = true; }, onCompleted: () => { if (getItemObjective?.TargetItem != null) { containedItems.Add(getItemObjective.TargetItem); } RemoveSubObjective(ref getItemObjective); }); } } }
protected override void Act(float deltaTime) { if (container?.Item == null || container.Item.Removed || container.Item.IsThisOrAnyContainerIgnoredByAI(character)) { Abandon = true; return; } ItemToContain = item ?? character.Inventory.FindItem(i => CheckItem(i) && i.Container != container.Item, recursive: true); if (ItemToContain != null) { if (!character.CanInteractWith(ItemToContain, checkLinked: false)) { Abandon = true; return; } if (character.CanInteractWith(container.Item, checkLinked: false)) { if (RemoveExisting) { HumanAIController.UnequipContainedItems(container.Item); } else if (RemoveEmpty) { HumanAIController.UnequipEmptyItems(container.Item); } Inventory originalInventory = ItemToContain.ParentInventory; var slots = originalInventory?.FindIndices(ItemToContain); if (container.Inventory.TryPutItem(ItemToContain, null)) { if (MoveWholeStack && slots != null) { foreach (int slot in slots) { foreach (Item item in originalInventory.GetItemsAt(slot).ToList()) { container.Inventory.TryPutItem(item, null); } } IsCompleted = true; } } else { if (ItemToContain.ParentInventory == character.Inventory && character.IsInFriendlySub) { ItemToContain.Drop(character); } Abandon = true; } } else { TryAddSubObjective(ref goToObjective, () => new AIObjectiveGoTo(container.Item, character, objectiveManager, getDivingGearIfNeeded: AllowToFindDivingGear) { DialogueIdentifier = "dialogcannotreachtarget", TargetName = container.Item.Name, AbortCondition = obj => container?.Item == null || container.Item.Removed || container.Item.IsThisOrAnyContainerIgnoredByAI(character) || ItemToContain == null || ItemToContain.Removed || !ItemToContain.IsOwnedBy(character) || container.Item.GetRootInventoryOwner() is Character c && c != character, SpeakIfFails = !objectiveManager.IsCurrentOrder <AIObjectiveCleanupItems>() },