コード例 #1
0
    public void ReplaceGoapGoalState(IGoapState <string, object> newValue)
    {
        var index     = AIComponentsLookup.GoapGoalState;
        var component = CreateComponent <GoapGoalStateComponent>(index);

        component.value = newValue;
        ReplaceComponent(index, component);
    }
コード例 #2
0
    public void AddGoapEffect(IGoapState <string, object> newValue)
    {
        var index     = AIComponentsLookup.GoapEffect;
        var component = CreateComponent <GoapEffectComponent>(index);

        component.value = newValue;
        AddComponent(index, component);
    }
コード例 #3
0
    public static AIEntity AddAgent(this AIContext context, IGoapState <string, object> worldState, IGoapState <string, object> goalState, IGoapPlanner <string, object> planner)
    {
        var entity = context.CreateEntity();

        entity.AddGoapWorldState(worldState);
        entity.AddGoapGoalState(goalState);
        entity.AddGoapPlanner(planner);
        entity.isGoapAgent = true;
        return(entity);
    }
コード例 #4
0
    public static AIEntity AddAction(this AIContext context, int cost, IGoapState <string, object> condition, IGoapState <string, object> effect, Func <GoapActionStatus> action)
    {
        var entity = context.CreateEntity();

        entity.AddCost(cost);
        entity.AddGoapCondition(condition);
        entity.AddGoapEffect(effect);
        entity.AddGoapAction(action);
        return(entity);
    }
コード例 #5
0
    public IEnumerator <int> Plan(AIContext context, IGoapState <string, object> goalState)
    {
        var goapAction = context.GetGroup(AIMatcher.AllOf(AIMatcher.GoapNodeChildren, AIMatcher.GoapEffect, AIMatcher.GoapAction));

        var IDList = Search(context, goapAction.GetEntities(), goalState);

        if (IDList == null || IDList.Count == 0)
        {
            return(null);
        }

        var RIDList = IDList.Reverse().ToList();

        return(RIDList.GetEnumerator());
    }
コード例 #6
0
    private IList <int> Search(AIContext context, IList <AIEntity> entities, IGoapState <string, object> goalState)
    {
        AIEntity startEntity = null;

        foreach (var currentEntity in entities)
        {
            if (goalState.Contains(currentEntity.goapEffect.value))
            {
                startEntity = currentEntity;
            }
        }

        if (startEntity == null)
        {
            return(null);
        }

        return(NextAction(context, startEntity, new List <int> ()));
    }
コード例 #7
0
 public bool Contains(IGoapState <K, V> b)
 {
     return(b.Keys.All(k => ContainsKey(k) && Equals(b[k], this [k])));
 }
コード例 #8
0
 public static void BuildGraphBranch(this AIContext context, AIEntity currentEntity, IList <AIEntity> entities, IGoapState <string, object> targetEffect)
 {
     foreach (var e in entities)
     {
         if (targetEffect.Contains(e.goapEffect.value))
         {
             if (currentEntity != null)
             {
                 if (!currentEntity.hasGoapNodeChildren)
                 {
                     currentEntity.AddGoapNodeChildren(new List <int> ());
                 }
                 if (!currentEntity.goapNodeChildren.value.Contains(e.iD.value))
                 {
                     currentEntity.goapNodeChildren.value.Add(e.iD.value);
                 }
             }
             context.BuildGraphBranch(e, entities, e.goapCondition.value);
         }
     }
 }