private void LateUpdate() { if (currentAction != null && currentAction.isActionRunning) { //float distanceToTarget = Vector3.Distance(currentAction.target.transform.position, this.transform.position); if (currentAction.navAgent.hasPath && currentAction.navAgent.remainingDistance < 2.0f) { if (!invoked) { Invoke("CompleteAction", currentAction.duration); invoked = true; } } return; } if (planner == null || actionQueue == null) { planner = new GOAPPlanner(); var sortedGoals = from entry in goals orderby entry.Value descending select entry;//sort goals in order of priority foreach (KeyValuePair <Goal, int> sgoal in sortedGoals) { actionQueue = planner.plan(actions, sgoal.Key.subGoals, beliefs); if (actionQueue != null) { currentGoal = sgoal.Key; break; } } } if (actionQueue != null && actionQueue.Count == 0) { if (currentGoal.remove) { goals.Remove(currentGoal); } planner = null; } if (actionQueue != null && actionQueue.Count > 0) { currentAction = actionQueue.Dequeue(); if (currentAction.PrePerform()) { if (currentAction.target == null && currentAction.targetTag != "") { currentAction.target = GameObject.FindGameObjectWithTag(currentAction.targetTag); } if (currentAction.target != null) { currentAction.isActionRunning = true; currentAction.navAgent.SetDestination(currentAction.target.transform.position); } } else { actionQueue = null; } } }
// Start is called before the first frame update protected virtual void Awake() { //Creates NPC State planner = GetComponent <GOAPPlanner>(); npcUI = GameObject.Find("NPC UI"); currentPlan = "No plan"; foreach (Condition c in Enum.GetValues(typeof(Condition))) { switch (c) { case Condition.nearIron: npcState.Add(c, float.MaxValue); break; case Condition.nearShop: npcState.Add(c, float.MaxValue); break; case Condition.nearWood: npcState.Add(c, float.MaxValue); break; default: npcState.Add(c, false); break; } } }
void LateUpdate() { if (currentAction != null && currentAction.running) { if (currentAction.agent.hasPath && currentAction.agent.remainingDistance < 1f) { if (!invoked) { Invoke("CompleteAction", currentAction.duration); invoked = true; } } return; } if (planner == null || actionQueue == null) { planner = new GOAPPlanner(); var sortedGoals = from entry in goals orderby entry.Value descending select entry; foreach (KeyValuePair <SubGoal, int> sg in sortedGoals) { actionQueue = planner.plan(actions, sg.Key.sgoals, null); if (actionQueue != null) { currentGoal = sg.Key; break; } } } if (actionQueue != null && actionQueue.Count == 0) { if (currentGoal.remove) { goals.Remove(currentGoal); } planner = null; } if (actionQueue != null && actionQueue.Count > 0) { currentAction = actionQueue.Dequeue(); if (currentAction.PrePerform()) { if (currentAction.target != null) { currentAction.running = true; currentAction.agent.SetDestination(currentAction.target.transform.position); } } else { actionQueue = null; } } }
private void Start() { actionOptions = new HashSet <GOAPAction>(); fsm = new FiniteStateMachine(); planner = new GOAPPlanner(); fsm.setState(idleInst); GetActions(); }
public override void Initialize(Transform[] objects) { worldStateComponent = GetComponentInChildren <WorldStateComponent>(); // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance EnemyComponent ec = objects[i].GetComponent <EnemyComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); HealthComponent hc = objects[i].GetComponent <HealthComponent>(); GOAPComponent aic = objects[i].GetComponent <GOAPComponent>(); if (cc && hc && ec && aic) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ec, cc, hc, aic)); aic.stateMachine = new FSM(); aic.availableActions = new HashSet <GOAPAction>(); aic.currentActions = new Queue <GOAPAction>(); GOAPAction[] actions = aic.gameObject.GetComponents <GOAPAction>(); foreach (GOAPAction action in actions) { aic.availableActions.Add(action); action.constantTarget = worldStateComponent.gameObject; } CreateIdleState(aic); CreateMoveToState(aic); CreatePerformActionState(aic); aic.stateMachine.pushState(aic.idleState); } } filters = tmpFilters.ToArray(); planner = new GOAPPlanner(); //currentWorldState = new HashSet<KeyValuePair<string, object>>(); KeyValuePair <string, object> playerDmgState = new KeyValuePair <string, object>("damagePlayer", false); KeyValuePair <string, object> playerStalkState = new KeyValuePair <string, object>("stalkPlayer", false); worldStateComponent.worldState.Add(playerLitState); worldStateComponent.worldState.Add(playerDmgState); worldStateComponent.worldState.Add(playerStalkState); /*currentWorldState.Add(playerLitState); * currentWorldState.Add(playerDmgState); * currentWorldState.Add(playerStalkState);*/ }
// Use this for initialization void Start() { stateMachine = new FSM(); availableActions = new HashSet <GOAPAction> (); currentActions = new Queue <GOAPAction> (); planner = new GOAPPlanner(); findDataProvider(); createIdleState(); createMoveToState(); createPerformActionState(); stateMachine.pushState(idleState); loadActions(); }
void Start() { //Set the planner planner = new GOAPPlanner(); //Create the state machine stateMachine = new FSM(); //Create the states idleStateInit(); animateStateInit(); goToStateInit(); //Push the idleState so that we start from there stateMachine.pushState(idleState); }
private List <IGOAPReadOnlyAction> GetGOAPPlan(Scholar scholar, string goalKey) { var context = new GOAPStateContext(scholar.GoapContext, scholar.ClassRoom.GoapContext); var comparer = new BaseCostComparer(); var planner = new GOAPPlanner(context, comparer); List <IGOAPReadOnlyAction> plan; if (!planner.TryGetBestPlan(GOAPGoalsManager.Instance.Goals[goalKey], out plan)) { throw new Exception($"{scholar} не нашел план для цели \"{goalKey}\""); } return(plan); }
public static void ConstructBest(string goalKey) { var context = new GOAPStateContext(GOAPConxtextFactory.ScholarContext, GOAPConxtextFactory.ClassContext); var comparer = new BaseCostComparer(); var planer = new GOAPPlanner(context, comparer); if (!planer.TryGetBestPlan(GOAPGoalsManager.Instance.Goals[goalKey], out var plan)) { throw new Exception("Мы проебались!"); } Console.ForegroundColor = ConsoleColor.Magenta; GOAPConsoleWriter.WritePlan(plan); Console.ResetColor(); }
public static void ConstructAllBest(string goalKey) { var context = new GOAPStateContext(GOAPConxtextFactory.ScholarContext, GOAPConxtextFactory.ClassContext); var comparer = new BaseCostComparer(); var planer = new GOAPPlanner(context, comparer); if (!planer.TryGetAllBestPlans(GOAPGoalsManager.Instance.Goals[goalKey], out var plans)) { throw new Exception("Мы проебались!"); } GOAPConsoleWriter.WritePlans(plans); }
private void Awake() { activeTask = new GOAPAction(); planner = GetComponent <GOAPPlanner>(); agent = GetComponent <NavMeshAgent>(); //Debug start age = 1; hunger = 0; thirst = 0; reproduction_urge = 0; max_speed = 10; energy = 100; sight_radius = 100; determinedness = 0; diet_type = 0; is_male = true; //Debug end }
// Use this for initialization void Awake() { planner = this; }