Exemple #1
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var backpack = agent.GetComponent <Container>();

            backpack.items[resource] += amountToHarvest;
            return(base.OnDone(agent, context));
        }
Exemple #2
0
        protected override bool OnDone(GoapAgent agent, WithContext context)
        {
            // Done harvesting.
            var inventory = agent.GetComponent <Container> ();

            inventory.items [resource] += amountToCollect;
            return(base.OnDone(agent, context));
        }
Exemple #3
0
 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));
     }
 }
Exemple #4
0
    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)}");
 }
Exemple #7
0
    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);
    }
Exemple #8
0
 void AddGoals(ref GoapAgent agent, int Goals)
 {
     agent.Goals.Clear();
     for (int i = 0; i < Goals; ++i)
     {
         AddGoal(ref agent, (GoalEnum)i);
     }
 }
Exemple #9
0
 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));
     }
 }
Exemple #10
0
 private GoapAction GetAction(GoapAgent agent)
 {
     if (!actions.ContainsKey(agent))
     {
         actions.Add(agent, new GrabItemAction(agent).SetTarget(gameObject));
     }
     return(actions[agent]);
 }
Exemple #11
0
 private bool GetGcdState(GoapAgent agent)
 {
     if (agent.GetComponent <AbilityUser>().GCDTime > 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #12
0
 public bool IsMet(GoapAgent agent)
 {
     if (!this.resolved)
     {
         this.conditionMet = Resolve(agent);
     }
     return(this.conditionMet);
 }
Exemple #13
0
 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));
 }
Exemple #14
0
    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));
        }
Exemple #16
0
 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));
 }
Exemple #17
0
    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);
    }
Exemple #18
0
 protected virtual void Awake()
 {
     if (Backpack == null)
         Backpack = GetComponent<BackpackComponent>();
     
     PathfindingUnit = GetComponent<IUnit>();
     _agent = GetComponent<GoapAgent>();
     _animManager = GetComponent<AnimationManager>();
 }
Exemple #19
0
 protected override bool Exit(GoapAgent agent)
 {
     _bar.SetValue(0);
     _farmer.ToolCount--;
     _farmer.HerbCount++;
     Destroy(Target);
     //Debug.Log("pick up exit");
     return(true);
 }
Exemple #20
0
 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;
    }
Exemple #22
0
        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);
    }
Exemple #24
0
 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);
     }
 }
Exemple #25
0
 /// <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));
     }
 }
Exemple #26
0
    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));
        }
Exemple #29
0
 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();
 }
Exemple #30
0
 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));
     }
 }