protected override void Act(float deltaTime)
        {
            if (item.IgnoreByAI(character))
            {
                Abandon = true;
                return;
            }
            if (item.ParentInventory != null)
            {
                if (item.Container != null && !AIObjectiveCleanupItems.IsValidContainer(item.Container, character, allowUnloading: objectiveManager.HasOrder <AIObjectiveCleanupItems>()))
                {
                    // Target was picked up or moved by someone.
                    Abandon = true;
                    return;
                }
            }
            // Only continue when the get item sub objectives have been completed.
            if (subObjectives.Any())
            {
                return;
            }
            if (HumanAIController.FindSuitableContainer(character, item, ignoredContainers, ref itemIndex, out Item suitableContainer))
            {
                itemIndex = 0;
                if (suitableContainer != null)
                {
                    bool equip = item.GetComponent <Holdable>() != null ||
                                 item.AllowedSlots.None(s =>
                                                        s == InvSlotType.Card ||
                                                        s == InvSlotType.Head ||
                                                        s == InvSlotType.Headset ||
                                                        s == InvSlotType.InnerClothes ||
                                                        s == InvSlotType.OuterClothes);

                    TryAddSubObjective(ref decontainObjective, () => new AIObjectiveDecontainItem(character, item, objectiveManager, targetContainer: suitableContainer.GetComponent <ItemContainer>())
                    {
                        Equip          = equip,
                        TakeWholeStack = true,
                        DropIfFails    = true
                    },
                                       onCompleted: () =>
                    {
                        if (equip)
                        {
                            HumanAIController.ReequipUnequipped();
                        }
                        IsCompleted = true;
                    },
                                       onAbandon: () =>
                    {
                        if (equip)
                        {
                            HumanAIController.ReequipUnequipped();
                        }
                        if (decontainObjective != null && decontainObjective.ContainObjective != null && decontainObjective.ContainObjective.CanBeCompleted)
                        {
                            ignoredContainers.Add(suitableContainer);
                        }
                        else
                        {
                            Abandon = true;
                        }
                    });
                }
                else
                {
                    Abandon = true;
                }
            }
            else
            {
                objectiveManager.GetObjective <AIObjectiveIdle>().Wander(deltaTime);
            }
        }
Exemple #2
0
        protected override void Act(float deltaTime)
        {
            Item itemToDecontain =
                targetItem ??
                sourceContainer.Inventory.FindItem(i => itemIdentifiers.Any(id => i.Prefab.Identifier == id || i.HasTag(id) && !i.IgnoreByAI(character)), recursive: false);

            if (itemToDecontain == null)
            {
                Abandon = true;
                return;
            }
            if (itemToDecontain.IgnoreByAI(character))
            {
                Abandon = true;
                return;
            }
            if (targetContainer == null)
            {
                if (sourceContainer == null)
                {
                    Abandon = true;
                    return;
                }
                if (itemToDecontain.Container != sourceContainer.Item)
                {
                    IsCompleted = true;
                    return;
                }
            }
            else if (targetContainer.Inventory.Contains(itemToDecontain))
            {
                IsCompleted = true;
                return;
            }
            if (getItemObjective == null && !itemToDecontain.IsOwnedBy(character))
            {
                TryAddSubObjective(ref getItemObjective,
                                   constructor: () => new AIObjectiveGetItem(character, targetItem, objectiveManager, Equip)
                {
                    TakeWholeStack = this.TakeWholeStack
                },
                                   onAbandon: () => Abandon = true);
                return;
            }
            if (targetContainer != null)
            {
                TryAddSubObjective(ref containObjective,
                                   constructor: () => new AIObjectiveContainItem(character, itemToDecontain, targetContainer, objectiveManager)
                {
                    MoveWholeStack              = TakeWholeStack,
                    Equip                       = Equip,
                    RemoveEmpty                 = false,
                    GetItemPriority             = GetItemPriority,
                    ignoredContainerIdentifiers = sourceContainer != null ? new string[] { sourceContainer.Item.Prefab.Identifier } : null
                },
                                   onCompleted: () => IsCompleted = true,
                                   onAbandon: () => Abandon       = true);
            }
            else
            {
                itemToDecontain.Drop(character);
                IsCompleted = true;
            }
        }