public bool MoveAgent(GOAPAction nextAction) { Vector2 delta = nextAction.Target.Position - Position; if (delta.Length() == 0.0f) { nextAction.InRange = true; return(true); } float step = MoveSpeed * (float)Global.gameTime.ElapsedGameTime.TotalSeconds; delta.Normalize(); delta *= step; Position += delta; if ((nextAction.Target.Position - Position).Length() < 16) { nextAction.InRange = true; return(true); } else { return(false); } }
private List <GOAPAction> ActionSubset(List <GOAPAction> actions, GOAPAction remove) { List <GOAPAction> Subset = new List <GOAPAction>(); foreach (GOAPAction a in actions) { if (!a.Equals(remove)) { Subset.Add(a); } } return(Subset); }
private void CreatePerformActionState() { PerformActionState = (fsm, agent) => { if (!HasActionPlan()) { fsm.PopState(); fsm.PushState(IdleState); DataProvider.ActionsFinished(); } GOAPAction action = CurrentActions.Peek(); if (action.IsDone()) { AddThought("Completed action " + action.ToString(), Color.DarkOrange); CurrentActions.Dequeue(); } if (HasActionPlan()) { action = CurrentActions.Peek(); bool InRange = action.RequiresInRange() ? action.InRange : true; if (InRange) { bool Success = action.Run(agent); if (!Success) { fsm.PopState(); fsm.PushState(IdleState); DataProvider.PlanAborted(action); } } else { fsm.PushState(MoveToState); AddThought("Moving to " + action.Target.Name, Color.DarkOliveGreen); } } else { fsm.PopState(); fsm.PushState(IdleState); DataProvider.ActionsFinished(); } }; }
private void CreateMoveToState() { MoveToState = (fsm, agent) => { GOAPAction Action = CurrentActions.Peek(); if (Action.RequiresInRange() && Action.Target == null) { fsm.PopState(); fsm.PopState(); fsm.PushState(IdleState); return; } if (DataProvider.MoveAgent(Action)) { fsm.PopState(); AddThought("Performing action " + Action.ToString(), Color.Blue); } }; }
public Node(Node parent, float totalCost, Dictionary <Tuple <string, object>, object> state, GOAPAction action) { Parent = parent; TotalCost = totalCost; State = state; Action = action; }
public void RemoveAction(GOAPAction action) { AvailableActions.Remove(action); }
public void AddAction(GOAPAction action) { AvailableActions.Add(action); }
public void PlanAborted(GOAPAction aborter) { }