Exemplo n.º 1
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;

            int intAmount = (int)actualAmount;

            if (intAmount > 0)
            {
                // Figure out possible EntityTypes from ICs InventoryGroupings - just pick first one
                List <EntityType> entityTypes;
                if (outputChange.inventoryTypeGroupMatchIndex > -1 && outputChange.inventoryTypeGroupMatchIndex < mapping.mappingType.inputConditions.Count)
                {
                    InputCondition inputCondition = mapping.mappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
                    entityTypes = inputCondition.GetInventoryTypeGroup().GetMatches(target.inventoryType.GetAllEntityTypes(target));
                }
                else if (outputChange.inventoryTypeGroupMatchIndex == -1)
                {
                    entityTypes = TypeGroup.PossibleEntityTypes(mapping.mappingType.inputConditions, agent.inventoryType.GetAllEntityTypes(agent), true);
                }
                else
                {
                    Debug.LogError(agent.name + ": InventoryDropOCT has an invalid value for inventoryGroupingMatchIndex in MT: " +
                                   mapping.mappingType.name);
                    return(false);
                }

                if (entityTypes == null || entityTypes.Count == 0)
                {
                    Debug.LogError(agent.name + ": InventoryDropOCT was unable to find an EntityType from ICs InventoryGroupings for MT: " +
                                   mapping.mappingType.name);
                    return(false);
                }
                // TODO: Add in InventoryTFs to MTs
                EntityType entityType = entityTypes[0];

                // This will do nothing if the target doesn't have all of the amount
                // TODO: Add in options to handle not enough inventory
                List <InventoryType.Item> items = target.inventoryType.Remove(target, entityType, intAmount, true);
                if (items == null)
                {
                    return(false);
                }

                foreach (InventoryType.Item item in items)
                {
                    // TODO: If Entity was created as Inventory it would have never gone through initialization
                    //       so it won't have an inventoryType set.  Make sure Entities created in inventory get initialized?
                    //item.entity.inventoryType.Dropped(item.entity, item.inventorySlot);
                    agent.inventoryType.Dropped(item.entity, item.inventorySlot);
                }
            }
            else if (intAmount < 0)
            {
                Debug.LogError("InventoryDropOCT has a negative amount to take.  Amount To Drop must be positive.");
            }
            return(true);
        }
Exemplo n.º 2
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;

            int intAmount = (int)actualAmount;

            if (intAmount > 0)
            {
                // Figure out possible EntityTypes from ICs InventoryGroupings - just pick first one
                List <EntityType> entityTypes;
                if (outputChange.inventoryTypeGroupMatchIndex > -1 && outputChange.inventoryTypeGroupMatchIndex < mapping.mappingType.inputConditions.Count)
                {
                    InputCondition inputCondition = mapping.mappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
                    entityTypes = inputCondition.GetInventoryTypeGroup().GetMatches(agent.inventoryType.GetAllEntityTypes(agent));
                }
                else if (outputChange.inventoryTypeGroupMatchIndex == -1)
                {
                    entityTypes = TypeGroup.PossibleEntityTypes(mapping.mappingType.inputConditions, agent.inventoryType.GetAllEntityTypes(agent), true);
                }
                else
                {
                    Debug.LogError(agent.name + ": InventoryGiveOCT has an invalid value for inventoryGroupingMatchIndex in MT: " +
                                   mapping.mappingType.name);
                    return(false);
                }

                if (entityTypes == null || entityTypes.Count == 0)
                {
                    Debug.LogError(agent.name + ": InventoryGiveOCT was unable to find an EntityType from ICs InventoryGroupings for MT: " +
                                   mapping.mappingType.name);
                    return(false);
                }
                // TODO: Add in InventoryTFs to MTs
                EntityType entityType = entityTypes[0];

                List <InventoryType.Item> items = agent.inventoryType.Remove(agent, entityType, intAmount, true);
                int numGiven = target.inventoryType.Add(target, items);

                if (numGiven != intAmount)
                {
                    // TODO: Handle partial gives
                    // Failed to Give items for some reason - give back inventory to agent
                    agent.inventoryType.Add(agent, items);

                    Debug.Log(agent.name + ": InventoryGiveOCT was unable to give all to target.  Tried to give " + intAmount + " - gave " + numGiven);
                    return(false);
                }
            }
            else if (intAmount < 0)
            {
                Debug.LogError(agent.name + ": InventoryGiveOCT has a negative amount to take.  Amount To Give must be positive.");
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            List <EntityType> possibleEntityTypes = inputCondition.GetInventoryTypeGroup().GetMatches(target.inventoryType.GetAllEntityTypes(target));

            foreach (EntityType entityType in possibleEntityTypes)
            {
                if (target.inventoryType.GetEntityTypeAmount(target, entityType) > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            List <EntityType> possibleEntityTypes = inputCondition.GetInventoryTypeGroup().GetMatches(agent.inventoryType.GetAllEntityTypes(agent));

            foreach (EntityType entityType in possibleEntityTypes)
            {
                bool equipped = agent.inventoryType.IsEquipped(agent, entityType);
                if ((inputCondition.boolValue && equipped) || (!inputCondition.boolValue && !equipped))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // Trying to match with ItemAmountICT with this (InventoryPickupOCT)
            // So make sure InventoryGrouping from ItemAmountICT overlaps with the Grouping for InventoryPickupOCT
            List <EntityType> entityTypes = TypeGroup.PossibleEntityTypes(outputChangeMappingType.inputConditions,
                                                                          agent.memoryType.GetKnownEntityTypes(agent));

            if (inputCondition.GetInventoryTypeGroup().AnyMatches(entityTypes))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            // Uses both Grouping (Container) and InventoryGrouping (Item)
            // Does Target have any items that are in the InventoryGrouping
            List <EntityType> possibleEntityTypes = inputCondition.GetInventoryTypeGroup().GetMatches(target.inventoryType.GetAllEntityTypes(target));

            foreach (EntityType entityType in possibleEntityTypes)
            {
                bool canAdd = true;
                if (!inputCondition.boolValue)
                {
                    canAdd = agent.inventoryType.FindInventorySlot(agent, entityType) != null;
                }

                if (canAdd && target.inventoryType.GetEntityTypeAmount(target, entityType) > 0)
                {
                    return(true);
                }
            }
            return(false);
        }