Пример #1
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes) &&
                inputCondition.levelType == outputChange.levelType)
            {
                // Same EntityType and same TagType - match adding tag to needing tag and removing tag to can't have tag
                if (!outputChange.boolValue &&
                    ((HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.DoesNotHaveOwnerTag ||
                     (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.DoesNotHaveTag))
                {
                    return(true);
                }
                else if (outputChange.boolValue &&
                         ((HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagButNotOwner ||
                          (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagIgnoreOwnership ||
                          (HasTagICT.Scope)inputCondition.enumValueIndex == HasTagICT.Scope.HasTagIsOwner))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            Agent otherAgent = target as Agent;

            if (otherAgent == null)
            {
                return(false);
            }

            // Condition is satisfied if agent is the target and the other agent is performing the correct action
            if (otherAgent.decider.CurrentMapping != null && otherAgent.decider.CurrentMapping.target == agent &&
                otherAgent.decider.CurrentMapping.mappingType.actionType == inputCondition.levelType &&
                (inputCondition.floatValue <= 0f || Time.time - otherAgent.decider.PlanStartTime < inputCondition.floatValue))
            {
                // Possible to also have an R level requirement - set max to 0 to ignore this check
                if (inputCondition.max == 0)
                {
                    return(true);
                }
                else
                {
                    MemoryType.EntityInfo entityInfo = agent.memoryType.KnownEntity(agent, target);
                    if (entityInfo != null && entityInfo.rLevel >= inputCondition.min && entityInfo.rLevel <= inputCondition.max)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #3
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            if (isRecheck)
            {
                return(true);
            }

            Mapping currentMapping = agent.decider.CurrentMapping;

            if (currentMapping == null)
            {
                currentMapping = agent.decider.PreviousMapping;
                if (currentMapping == null)
                {
                    return(false);
                }
            }

            if (!inputCondition.boolValue && currentMapping.parent != null && currentMapping.mappingType.goToActionType != null &&
                currentMapping.mappingType.goToActionType == currentMapping.parent.mappingType.actionType)
            {
                currentMapping = currentMapping.parent;
            }

            if (inputCondition.levelTypes.Contains(currentMapping.mappingType.actionType))
            {
                return(true);
            }

            return(false);
        }
Пример #4
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            // If boolValue is true - use the agent's memory - else use the global truth
            if (inputCondition.boolValue)
            {
                List <MemoryType.EntityInfo> entityInfos = agent.memoryType.GetKnownEntities(agent, inputCondition.entityType);

                if (entityInfos.Count >= inputCondition.min && entityInfos.Count <= inputCondition.max)
                {
                    return(true);
                }
            }
            else
            {
                // TODO: Some kind of game manager to cache world state
                Entity[] entities = FindObjectsOfType <Entity>();

                int count = 0;
                foreach (Entity entity in entities)
                {
                    if (entity.entityType == inputCondition.entityType)
                    {
                        ++count;
                    }
                }

                if (count >= inputCondition.min && count <= inputCondition.max)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            float     attributeLevel = agent.attributes[(AttributeType)inputCondition.levelType].GetLevel();
            RangeType rangeType      = (RangeType)inputCondition.enumValueIndex;

            switch (rangeType)
            {
            case RangeType.GreaterThanOrEqual:
                if (attributeLevel >= inputCondition.floatValue)
                {
                    return(true);
                }
                break;

            case RangeType.LessThanOrEqual:
                if (attributeLevel <= inputCondition.floatValue)
                {
                    return(true);
                }
                break;

            case RangeType.RangeInclusive:
                if (attributeLevel >= inputCondition.min && attributeLevel <= inputCondition.max)
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
Пример #6
0
        public override bool PreMatch(OutputChange outputChange, MappingType outputChangeMappingType, InputCondition inputCondition,
                                      MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            // Matches OtherInventoryAmountICT
            // This needs to be giving the corrent EntityType (InventoryGroupings) based on what the ICT needs (InventoryGroupings)
            if (outputChange.inventoryTypeGroupMatchIndex == -1)
            {
                return(false);
            }

            InputCondition   outputChangeInputCondition = outputChangeMappingType.inputConditions[outputChange.inventoryTypeGroupMatchIndex];
            List <TypeGroup> groupings = outputChangeInputCondition.InventoryTypeGroups(outputChangeMappingType, out List <int> indexesToSet);

            // groupings is now the EntityTypes that are possible to be given
            List <EntityType> entityTypes = TypeGroup.InAllTypeGroups(groupings, allEntityTypes);

            // See if any of these EntityTypes matches what the IC of OtherInventoryAmountICT needs
            bool inventoryGroupMatches = inputCondition.AnyInventoryGroupingMatches(inputConditionMappingType, entityTypes);

            // Also need to make sure that possible EntityTypes from both MappingTypes have some overlap
            bool groupMatches = outputChangeMappingType.AnyEntityTypeMatchesTypeGroups(inputConditionMappingType, allEntityTypes);

            if (inventoryGroupMatches && groupMatches)
            {
                return(true);
            }
            return(false);
        }
Пример #7
0
        // Returns the index of the first OutputChangeType that matches the InputConditionType or -1 if no matches
        public int OutputChangeTypeMatch(InputCondition inputCondition, MappingType inputConditionMappingType, List <EntityType> allEntityTypes)
        {
            for (int i = 0; i < outputChanges.Count; i++)
            {
                OutputChange outputChange = outputChanges[i];

                if (inputCondition.inputConditionType == null)
                {
                    Debug.LogError("MappingType " + inputConditionMappingType.name + " has an InputCondition with no InputConditionType.  Please Fix.");
                    return(-1);
                }
                if (outputChange.outputChangeType == null)
                {
                    Debug.LogError("MappingType " + name + " has an OutputChange with no OutputChangeType.  Please Fix.");
                    return(-1);
                }
                if (inputCondition.inputConditionType.matchingOCTs != null &&
                    inputCondition.inputConditionType.matchingOCTs.Contains(outputChange.outputChangeType) &&
                    outputChange.outputChangeType.PreMatch(outputChange, this, inputCondition, inputConditionMappingType, allEntityTypes))
                {
                    return(i);
                }
            }
            return(-1);
        }
Пример #8
0
 public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
 {
     if (target.inEntityInventory != null)
     {
         return(false);
     }
     return(true);
 }
Пример #9
0
 public List <FixInputCondition> FindMappingTypeMatches(InputCondition inputCondition)
 {
     if (fixesInputCondition.TryGetValue(inputCondition, out List <FixInputCondition> fixInputConditions))
     {
         return(fixInputConditions);
     }
     return(null);
 }
Пример #10
0
 public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
 {
     // Agent needs permission to create this event based on his or her faction role
     if (((AgentEventType)inputCondition.entityType).CanCreate(agent))
     {
         return(true);
     }
     return(false);
 }
Пример #11
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);
        }
Пример #12
0
 public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
 {
     if (inputCondition.boolValue)
     {
         agent.inventoryType.FindInventorySlotsToClear(agent, target.entityType, out InventorySlot inventorySlot, 1, true);
         return(inventorySlot != null);
     }
     return(agent.inventoryType.FindInventorySlot(agent, target.entityType) != null);
 }
Пример #13
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            WorldObject worldObject = (WorldObject)target;

            if (worldObject.currentState != null && worldObject.currentState.name == inputCondition.stringValue)
            {
                return(true);
            }
            return(false);
        }
Пример #14
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            float driveLevel = agent.drives[(DriveType)inputCondition.levelType].GetLevel();

            if (driveLevel >= inputCondition.min && driveLevel <= inputCondition.max)
            {
                return(true);
            }
            return(false);
        }
Пример #15
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            AgentEvent agentEvent = target as AgentEvent;

            if (agentEvent.state == (AgentEvent.State)inputCondition.enumValueIndex)
            {
                return(true);
            }
            return(false);
        }
Пример #16
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);
        }
Пример #17
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            Agent targetAgent = (Agent)target;

            if (targetAgent != null && ((inputCondition.boolValue && targetAgent.faction == agent.faction) ||
                                        (!inputCondition.boolValue && targetAgent.faction != agent.faction)))
            {
                return(true);
            }
            return(false);
        }
Пример #18
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            WorldObject worldObject = target as WorldObject;

            if (worldObject == null)
            {
                Debug.LogError(agent.name + ": DamagableICT is trying to damage a non-WorldObject - " + target.name);
                ;               return(false);
            }
            return(worldObject.IsDamagable == !inputCondition.boolValue);
        }
Пример #19
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            WorldObject worldObject = (WorldObject)target;

            if ((!worldObject.isComplete && !inputCondition.boolValue) ||
                (worldObject.isComplete && inputCondition.boolValue))
            {
                return(true);
            }
            return(false);
        }
Пример #20
0
        public override void UpdateAnimations(Agent agent)
        {
            List <AgentType.AnimatorOverride> activeOverrides = new List <AgentType.AnimatorOverride>();
            bool needChange = false;

            for (int i = 0; i < agent.agentType.animatorOverrides.Count; i++)
            {
                AgentType.AnimatorOverride animatorOverride = agent.agentType.animatorOverrides[i];
                bool isActive = animatorsOverrideIsActives[agent][i];
                bool passes   = true;
                foreach (int index in animatorOverride.conditionIndexes)
                {
                    InputCondition condition = agent.agentType.animatorOverridesConditions[index];
                    if (!condition.inputConditionType.Check(condition, agent, null, null, false))
                    {
                        passes = false;
                        break;
                    }
                }

                if (passes)
                {
                    activeOverrides.Add(animatorOverride);
                }

                if (isActive && !passes)
                {
                    animatorsOverrideIsActives[agent][i] = false;
                    needChange = true;
                }
                else if (!isActive && passes)
                {
                    animatorsOverrideIsActives[agent][i] = true;
                    needChange = true;
                }
            }

            if (needChange)
            {
                // Priority is based on location in List (AgentType.animatorOverrides) - ones at the top (lower index) have higher priority
                // So go from bottom of active list to top
                if (activeOverrides.Count == 0)
                {
                    ClearOverrides(agent);
                }
                else
                {
                    for (int i = activeOverrides.Count - 1; i >= 0; i--)
                    {
                        ApplyOverride(agent, activeOverrides[i].controller);
                    }
                }
            }
        }
Пример #21
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            float lastTime = agent.historyType.GetLastTimePerformedActionType(agent, (ActionType)inputCondition.levelType);

            if (lastTime == -1f || Time.time - lastTime >= inputCondition.floatValue * agent.timeManager.RealTimeSecondsPerGameMinute())
            {
                return(true);
            }

            return(false);
        }
Пример #22
0
 public void AddChild(Mapping newChild, InputCondition reasonForChild)
 {
     if (children == null)
     {
         children          = new List <Mapping>();
         reasonForChildren = new List <InputCondition>();
     }
     newChild.parent     = this;
     newChild.childIndex = children.Count;
     reasonForChildren.Add(reasonForChild);
     children.Add(newChild);
 }
Пример #23
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes))
            {
                return(true);
            }
            return(false);
        }
Пример #24
0
        public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
        {
            if (agent.roles.TryGetValue((RoleType)inputCondition.levelType, out Role role))
            {
                if (role.GetLevel() >= inputCondition.min && role.GetLevel() <= inputCondition.max)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #25
0
 public override bool Check(InputCondition inputCondition, Agent agent, Mapping mapping, Entity target, bool isRecheck)
 {
     if (target != null)
     {
         MemoryType.EntityInfo entityInfo = agent.memoryType.KnownEntity(agent, target);
         if (entityInfo != null && entityInfo.rLevel >= inputCondition.min && entityInfo.rLevel <= inputCondition.max)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #26
0
        public void CreateICToMTDictionary()
        {
            if (settings.driveLevelICT == null)
            {
                return;
            }

            fixesInputCondition        = new Dictionary <InputCondition, List <FixInputCondition> >();
            fakeDriveLevelMappingTypes = new Dictionary <DriveType, MappingType>();

            // TODO: Will this work in runtime?
            List <MappingType> allMappingTypes = new List <MappingType>();

            string[] guids = AssetDatabase.FindAssets("t:MappingType");
            foreach (string guid in guids)
            {
                allMappingTypes.Add((MappingType)AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
            }

            List <DriveType> allDriveTypes = new List <DriveType>();

            guids = AssetDatabase.FindAssets("t:DriveType");
            foreach (string guid in guids)
            {
                allDriveTypes.Add((DriveType)AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
            }

            // Add in Drive InputConditions that don't exist in the MappingTypes (Goals)
            foreach (DriveType driveType in allDriveTypes)
            {
                MappingType mappingType = ScriptableObject.CreateInstance <MappingType>();
                mappingType.name = "AutoGeneratedFor" + driveType.name;
                InputCondition inputCondition = new InputCondition(driveType, settings.driveLevelICT, false);
                mappingType.inputConditions = new List <InputCondition>()
                {
                    inputCondition
                };
                fakeDriveLevelMappingTypes.Add(driveType, mappingType);

                FindMatchingMappingTypes(inputCondition, mappingType, allMappingTypes);
            }

            foreach (MappingType mappingType in allMappingTypes)
            {
                foreach (InputCondition inputCondition in mappingType.inputConditions)
                {
                    FindMatchingMappingTypes(inputCondition, mappingType, allMappingTypes);
                }
            }

            Debug.Log("ICT to MappingType Lookup Dictionary Created.");
        }
Пример #27
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);
        }
Пример #28
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);
        }
Пример #29
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);
        }
Пример #30
0
        public override bool Match(Agent agent, OutputChange outputChange, MappingType outputChangeMappingType,
                                   InputCondition inputCondition, MappingType inputConditionMappingType)
        {
            // This matches WorldObjectStateICT
            List <InputCondition> inputConditionsFromOC = outputChangeMappingType.EntityTypeInputConditions();
            List <EntityType>     entityTypes           = TypeGroup.PossibleEntityTypes(inputConditionsFromOC, agent.memoryType.GetKnownEntityTypes(agent));

            if (inputConditionMappingType.AnyEntityTypeMatchesTypeGroups(entityTypes) &&
                outputChange.stringValue == inputCondition.stringValue)
            {
                return(true);
            }
            return(false);
        }