Example #1
0
        private AIObjective GetCurrentObjective()
        {
            var  previousObjective       = CurrentObjective;
            var  firstObjective          = Objectives.FirstOrDefault();
            bool currentObjectiveIsOrder = CurrentOrder != null && firstObjective != null && CurrentOrder.Priority > firstObjective.Priority;

            if (currentObjectiveIsOrder)
            {
                CurrentObjective = CurrentOrder;
            }
            else
            {
                CurrentObjective = firstObjective;
            }
            if (previousObjective != CurrentObjective)
            {
                previousObjective?.OnDeselected();
                CurrentObjective?.OnSelected();
                GetObjective <AIObjectiveIdle>().CalculatePriority(Math.Max(CurrentObjective.Priority - 10, 0));
                if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer)
                {
                    GameMain.NetworkMember.CreateEntityEvent(character, new object[]
                    {
                        NetEntityEvent.Type.ObjectiveManagerState,
                        currentObjectiveIsOrder ? "order" : "objective"
                    });
                }
            }
            return(CurrentObjective);
        }
Example #2
0
 public void SortObjectives()
 {
     if (Objectives.Any())
     {
         Objectives.Sort((x, y) => y.GetPriority().CompareTo(x.GetPriority()));
     }
     CurrentObjective?.SortSubObjectives();
 }
Example #3
0
 /// <summary>
 /// Returns all active objectives of the specific type. Creates a new collection -> don't use too frequently.
 /// </summary>
 public IEnumerable <T> GetActiveObjectives <T>() where T : AIObjective
 {
     if (CurrentObjective == null)
     {
         return(Enumerable.Empty <T>());
     }
     return(CurrentObjective.GetSubObjectivesRecursive(includingSelf: true).Where(so => so is T).Select(so => so as T));
 }
Example #4
0
 public void DoCurrentObjective(float deltaTime)
 {
     if (WaitTimer > 0.0f)
     {
         WaitTimer -= deltaTime;
     }
     CurrentObjective?.TryComplete(deltaTime);
 }
 public void DoCurrentObjective(float deltaTime)
 {
     if (CurrentObjective == null || (CurrentObjective.GetPriority(this) < OrderPriority && WaitTimer > 0.0f))
     {
         WaitTimer -= deltaTime;
         character.AIController.SteeringManager.Reset();
         return;
     }
     CurrentObjective?.TryComplete(deltaTime);
 }
Example #6
0
 public void DoCurrentObjective(float deltaTime)
 {
     if (WaitTimer <= 0)
     {
         CurrentObjective?.TryComplete(deltaTime);
     }
     else
     {
         character.AIController.SteeringManager.Reset();
     }
 }
Example #7
0
        private AIObjective GetCurrentObjective()
        {
            var previousObjective = CurrentObjective;
            var firstObjective    = Objectives.FirstOrDefault();

            if (CurrentOrder != null && firstObjective != null && CurrentOrder.GetPriority(this) > firstObjective.GetPriority(this))
            {
                CurrentObjective = CurrentOrder;
            }
            else
            {
                CurrentObjective = firstObjective;
            }
            if (previousObjective != CurrentObjective)
            {
                CurrentObjective?.OnSelected();
            }
            return(CurrentObjective);
        }
Example #8
0
        private AIObjective GetCurrentObjective()
        {
            var previousObjective = CurrentObjective;
            var firstObjective    = Objectives.FirstOrDefault();

            if (CurrentOrder != null && firstObjective != null && CurrentOrder.Priority > firstObjective.Priority)
            {
                CurrentObjective = CurrentOrder;
            }
            else
            {
                CurrentObjective = firstObjective;
            }
            if (previousObjective != CurrentObjective)
            {
                previousObjective?.OnDeselected();
                CurrentObjective?.OnSelected();
                GetObjective <AIObjectiveIdle>().CalculatePriority(Math.Max(CurrentObjective.Priority - 10, 0));
            }
            return(CurrentObjective);
        }
Example #9
0
        private AIObjective GetCurrentObjective()
        {
            var previousObjective = CurrentObjective;
            var firstObjective    = Objectives.FirstOrDefault();

            if (CurrentOrder != null && firstObjective != null && CurrentOrder.GetPriority() > firstObjective.GetPriority())
            {
                CurrentObjective = CurrentOrder;
            }
            else
            {
                CurrentObjective = firstObjective;
            }
            if (previousObjective != CurrentObjective)
            {
                previousObjective?.OnDeselected();
                CurrentObjective?.OnSelected();
                GetObjective <AIObjectiveIdle>().SetRandom();
            }
            return(CurrentObjective);
        }
Example #10
0
 public float GetCurrentPriority()
 {
     return(CurrentObjective == null ? 0.0f : CurrentObjective.GetPriority());
 }
Example #11
0
 public bool HasActiveObjective <T>() where T : AIObjective => CurrentObjective is T || CurrentObjective != null && CurrentObjective.GetSubObjectivesRecursive().Any(so => so is T);
Example #12
0
 /// <summary>
 /// Returns all active objectives of the specific type. Creates a new collection -> don't use too frequently.
 /// </summary>
 public IEnumerable <T> GetActiveObjectives <T>() where T : AIObjective => CurrentObjective?.GetSubObjectivesRecursive(includingSelf : true).Where(so => so is T).Select(so => so as T);
Example #13
0
 /// <summary>
 /// Returns the last active objective of the specific type.
 /// </summary>
 public T GetActiveObjective <T>() where T : AIObjective => CurrentObjective?.GetSubObjectivesRecursive(includingSelf : true).LastOrDefault(so => so is T) as T;
Example #14
0
 public AIObjective GetActiveObjective() => CurrentObjective?.GetActiveObjective();