protected override bool OnDone(GoapAgent agent, WithContext context) { // Done harvesting. var backpack = agent.GetComponent <Container>(); backpack.items[resource] += amountToHarvest; return(base.OnDone(agent, context)); }
protected override bool OnDone(GoapAgent agent, WithContext context) { // Done harvesting. var inventory = agent.GetComponent <Container> (); inventory.items [resource] += amountToCollect; return(base.OnDone(agent, context)); }
public void planFound(KeyValuePair <string, bool> goal, Queue <GoapAction> actions) { // Yay we found a plan for our goal if (EnableLog) { Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions)); } }
public void planFound(HashSet <KeyValuePair <string, object> > goal, Queue <Action> actions) { // write to the log the queue of actions found Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions)); //set the text on the action display done here for static actions purposes m_indicator.text = actions.Peek().GetType().ToString(); }
public override void Run(GoapAgent agent) { if (statusEffectHost == null) { statusEffectHost = agent.GetComponent <StatusEffectHost>(); } agent.state["paralyzed"] = IsParalyzed(); }
void IGoap.PlanAborted(GoapAction aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal again // that it can succeed. _planPreview = "aborted"; Debug.Log($"<color=red>Plan Aborted</color> {GoapAgent.PrettyPrint(aborter)}"); }
public StateMachine(GoapAgent goapAgent) { this.goapAgent = goapAgent; StateDic[StateEnum.Idle] = new StateIdle(goapAgent); StateDic[StateEnum.Run] = new StateRun(goapAgent); StateDic[StateEnum.Attack] = new StateAttack(goapAgent); }
void AddGoals(ref GoapAgent agent, int Goals) { agent.Goals.Clear(); for (int i = 0; i < Goals; ++i) { AddGoal(ref agent, (GoalEnum)i); } }
public void planFound(HashSet <KeyValuePair <string, object> > goal, Queue <GoapAction> actions) { // Yay we found a plan for our goal if (goalDebug) { Debug.Log("<color=green>Plan found</color> " + GoapAgent.prettyPrint(actions)); } }
private GoapAction GetAction(GoapAgent agent) { if (!actions.ContainsKey(agent)) { actions.Add(agent, new GrabItemAction(agent).SetTarget(gameObject)); } return(actions[agent]); }
private bool GetGcdState(GoapAgent agent) { if (agent.GetComponent <AbilityUser>().GCDTime > 0) { return(false); } return(true); }
public bool IsMet(GoapAgent agent) { if (!this.resolved) { this.conditionMet = Resolve(agent); } return(this.conditionMet); }
public void PlanFailed(HashSet <KeyValuePair <string, object> > failedGoal) { foreach (KeyValuePair <string, object> kvp in failedGoal) { lastFailedGoal = kvp; } Debug.Log("<color=red>Plan failed!</color> " + GoapAgent.PrettyPrint(failedGoal)); }
private GoapStatus goalStatus = new GoapStatus(); // 要完成的目标 public GoapStateManager(GoapAgent goapAgent) { this.goapAgent = goapAgent; SetGoal(GoapCondition.attackEnemy, true); SetGoal(GoapCondition.inAttackRange, true); SetGoal(GoapCondition.idle, true); }
protected override bool OnDone(GoapAgent agent, WithContext context) { // Done harvesting. var inventory = agent.GetComponent <Container>(); inventory.items[Item.Part2] += 1; return(base.OnDone(agent, context)); }
public void PlanAborted(GoapAction aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal again // that it can succeed. // Console.WriteLine("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter)); _actorTextOutput.Tell("Plan Aborted " + GoapAgent.prettyPrint(aborter)); }
private List <GoapAction> FindUsableActions(List <KeyValuePair <string, object> > currentState, List <GoapAction> exclude, KeyValuePair <string, object> goal, float cost) { List <GoapAction> newActions = new List <GoapAction>(); List <KeyValuePair <GoapAction, int> > actionPriority = new List <KeyValuePair <GoapAction, int> >(); int goalS = (int)goal.Value; int invS = (int)currentState.Find(e => e.Key.Equals("In" + goal.Key.Substring(2))).Value; int carS = (int)currentState.Find(e => e.Key.Equals("Ca" + goal.Key.Substring(2))).Value; foreach (GoapAction a in actionList) { if (a.IsActionUsable(currentState)) { List <KeyValuePair <string, object> > actionEffects = a.effects; int potential = 0; if (a.GetType().Name == "InventoryToCar") { potential += invS; } if (a.GetType().Name == "CarToInventory") { potential += goalS; } foreach (KeyValuePair <string, object> effect in actionEffects) { if (effect.Key.Substring(2).Equals(goal.Key.Substring(2))) { potential += (int)effect.Value * Mathf.Max(goalS - invS - carS, 0) + Mathf.Max(goalS - carS, 0); isGoalActionVisited = true; } } potential -= usedActionList.Contains(a) ? 2 : -1; actionPriority.Add(new KeyValuePair <GoapAction, int>(a, potential)); Debug.Log(GoapAgent.Display(a) + ": " + potential); } } actionPriority.Sort((a, b) => - 1 * a.Value.CompareTo(b.Value));//Desc foreach (KeyValuePair <GoapAction, int> action in actionPriority) { GoapAction a = action.Key; newActions.Add(a); usedActionList.Add(a); } if (isGoalActionVisited) { usedActionList = new HashSet <GoapAction>(); isGoalActionVisited = false; } return(newActions); }
protected virtual void Awake() { if (Backpack == null) Backpack = GetComponent<BackpackComponent>(); PathfindingUnit = GetComponent<IUnit>(); _agent = GetComponent<GoapAgent>(); _animManager = GetComponent<AnimationManager>(); }
protected override bool Exit(GoapAgent agent) { _bar.SetValue(0); _farmer.ToolCount--; _farmer.HerbCount++; Destroy(Target); //Debug.Log("pick up exit"); return(true); }
protected override bool Enter(GoapAgent agent) { _time = 0; Target = agent.SearchActionData("targetHerb") as GameObject; _bar = agent.GetComponent <ProgressBar>(); _farmer = agent.GetComponent <Farmer>(); //Debug.Log("pick up enter"); return(true); }
protected override IEnumerator <SimpleActionExecutionControlElements> Execute(PrototypeActionSettings settings, Action fail) { Debug.Log("picking item"); //settings. GoapAgent agent = settings.agent as GoapAgent; agent.GetComponent <RPGHands>().DropItemRight(); yield break; }
public SpawnMage(GoapAgent agent) : base(agent) { goal = GoapGoal.Goals.SPAWN_TROOPS; preconditions.Add(Effects.HAS_SUFFICIENT_GOLD_MAGE, true); requiredRange = 1000f; cost = 1; }
public void deselectAgent() { MovementCamera movCam = Camera.main.gameObject.GetComponent <MovementCamera>(); movCam.target = null; agentSelected.isSelected = false; agentSelected = null; toggleVisiblePanels(false); }
private void ContinueAction(GoapAgent agent) { timer += Time.deltaTime; agent.transform.rotation = Quaternion.Slerp(Quaternion.Euler(startRotation), Quaternion.Euler(targetLookRotation), timer / turnTime); if (timer >= turnTime) { FinishTurn(agent); } }
/// <summary> /// 计划发现 /// </summary> /// <param name="goal"></param> /// <param name="actions"></param> public void PlanFound(KeyValuePair <string, bool> goal, Queue <GoapAction> actions) { // Yay we found a plan for our goal //我们为我们的目标找到了一个计划 if (EnableLog) { Debug.Log("<color=green> 计划发现</color> " + GoapAgent.PrettyPrint(actions)); } }
public CombatGoal(GoapAgent agent) : base(agent) { GoalName = "Combat Goal"; RequiredWorldState.Add(new GoapState("Player Detected", true)); RequiredWorldState.Add(new GoapState("Shoot At Player", true)); myAI = agent.GetComponent <GoapAI>(); }
public virtual void Awake() { ourGoapAgent = GetComponent <GoapAgent>(); ourThreatTrigger = GetComponentInChildren <ThreatTrigger>(); ourThreatTrigger.threatInArea += this.importantEventTriggered; gameStateHandler = GameObject.Find("Game State Handler").GetComponent <GameStateHandler>(); enemySpawner = GameObject.Find("EnemySpawner").GetComponent <EnemySpawner>(); ourType = GetComponent <IGoap>(); }
protected override bool OnDone(GoapAgent agent, WithContext context) { var backpack = agent.GetComponent <Container>(); var target = context.target as HarvestPoint; ++target.GetComponent <Container>().items[itemToDrop]; --backpack.items[itemToDrop]; return(base.OnDone(agent, context)); }
public override void Run(GoapAgent agent) { if (boss == null) { boss = agent.GetComponent <Boss>(); } agent.state["bossMeleeAttackAvailable"] = IsMeleeAttackAvailable(); agent.state["bossRangedAttackAvailable"] = IsRangedAttackAvailable(); agent.state["bossUtilityAbilityAvailable"] = IsUtilityAbilityAvailable(); }
public void planAborted(GoapAction aborter) { // An action bailed out of the plan. State has been reset to plan again. // Take note of what happened and make sure if you run the same goal again // that it can succeed. if (EnableLog) { Debug.Log("<color=red>Plan Aborted</color> " + GoapAgent.prettyPrint(aborter)); } }