public override GoalStatus Process()
        {
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Remove all completed subgoals
            Subgoals.RemoveAll(g => g.GoalStatus == GoalStatus.Completed || g.GoalStatus == GoalStatus.Failed);

            // If hunger or sleep is below a certain point attent to vitality
            if (!Subgoals.OfType <VitalityGoal>().Any() && GetDesirability(Entity.Hunger, Entity.Sleep) < 0.5)
            {
                AddSubgoal(new VitalityGoal(Entity));
            }

            Console.WriteLine($"Des: {GetDesirability(Entity.Hunger, Entity.Sleep)}        hung: {Entity.Hunger}, sleep: { Entity.Sleep}");

            // If the target changes follow the new target
            if (oldTarget != GameWorld.Instance.Target)
            {
                AddSubgoal(new FollowTargetGoal(Entity));
                oldTarget = GameWorld.Instance.Target;
            }

            // Process all subgoals
            Subgoals.ForEach(g => g.Process());

            return(GoalStatus);
        }
示例#2
0
        public override GoalStatus Process()
        {
            // Activate goal when inactive
            if (GoalStatus == GoalStatus.Inactive)
            {
                Activate();
            }

            // Stop condition
            if (Path.Count == 0)
            {
                Terminate();
            }

            // When the target changes the goal has failed
            if (target != GameWorld.Instance.Target)
            {
                GoalStatus = GoalStatus.Failed;
            }

            // When completed or failed return
            if (GoalStatus == GoalStatus.Completed || GoalStatus == GoalStatus.Failed)
            {
                return(GoalStatus);
            }

            // Remove all completed subgoals
            Subgoals.RemoveAll(g => g.GoalStatus == GoalStatus.Completed);

            // Add subgoal
            if (Path.Count != 0 && !Subgoals.OfType <TraverseVertexGoal>().Any())
            {
                AddSubgoal(new TraverseVertexGoal(Entity, Path.First(), Path.Count));
                Path.RemoveFirst();
            }

            // Process all subgoals
            Subgoals.ForEach(g => g.Process());

            return(GoalStatus);
        }