public void Update(GOAPAgent agent) { if (StateStack.Peek() != null) { StateStack.Peek().Invoke(this, agent); } }
public abstract bool CheckProceduralPrecondition(GOAPAgent agent);
//public Queue<GOAPAction> Plan(GOAPAgent agent, List<GOAPAction> availableActions, Dictionary<Tuple<string, object>, object> worldState, Dictionary<Tuple<string, object>, object> goal) public Queue <GOAPAction> Plan(GOAPAgent agent, List <GOAPAction> availableActions, Dictionary <Tuple <string, object>, object> worldState, List <KeyValuePair <Tuple <string, object>, object> > goal) { bool Success = false; List <Node> Tree = new List <Node>(); foreach (KeyValuePair <Tuple <string, object>, object> kvp in goal) { foreach (GOAPAction a in availableActions) { a.Reset(); } List <GOAPAction> UseableActions = new List <GOAPAction>(); foreach (GOAPAction a in availableActions) { if (a.CheckProceduralPrecondition(agent)) { UseableActions.Add(a); } } Tree = new List <Node>(); Node Start = new Node(null, 0, worldState, null); Success = BuildGraph(Start, Tree, UseableActions, kvp); if (Success) { break; } } if (!Success) { return(null); } Node Cheapest = null; foreach (Node node in Tree) { if (Cheapest == null) { Cheapest = node; } else { if (node.TotalCost < Cheapest.TotalCost) { Cheapest = node; } } } List <GOAPAction> Result = new List <GOAPAction>(); Node n = Cheapest; while (n != null) { if (n.Action != null) { Result.Insert(0, n.Action); } n = n.Parent; } Queue <GOAPAction> queue = new Queue <GOAPAction>(); foreach (GOAPAction a in Result) { queue.Enqueue(a); } return(queue); }