Esempio n. 1
0
 /// <summary>
 /// Important to call!
 /// </summary>
 protected override void OnCancel(ActiveEntity e)
 {
     // Cancel currently active task.
     if (CurrentSubTask != null)
     {
         CurrentSubTask.Cancel(e);
     }
 }
Esempio n. 2
0
 public NPCJobSoldier(IWorkBuilding workLocation) : base("Soldier", workLocation, KingdomHierarchy.Citizen)
 {
     HasEquiptment  = false;
     SubTask        = CurrentSubTask.None;
     WorkItems      = new List <Item>();
     WorkEquiptment = new List <IWorkEquiptmentObject>(5);
     foreach (WorldObjectData obj in workLocation.WorkBuilding.GetBuildingExternalObjects())
     {
         if (obj is IWorkEquiptmentObject workObj)
         {
             WorkEquiptment.Add(workObj);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Important to call!
        /// </summary>
        /// <param name="e"></param>
        protected override void Update(ActiveEntity e)
        {
            if (CurrentSubTask != null)
            {
                switch (CurrentSubTask.State)
                {
                case TaskState.Idle:
                    CurrentSubTask.Start(e);
                    CurrentSubTask.InternalUpdate(e);
                    break;

                case TaskState.Running:
                    CurrentSubTask.InternalUpdate(e);
                    break;

                case TaskState.Cancelled:
                    // Since all tasks need to be completed in order, this global task must also cancel.
                    this.Cancel(e);
                    break;

                case TaskState.Completed:
                    // Set as no longer active and don't place it back into the queue.
                    CurrentSubTask = null;
                    CompletedTaskCount++;
                    break;
                }
            }
            if (CurrentSubTask == null)
            {
                // Try to take a new one from the queue.
                if (QueuedTaskCount != 0)
                {
                    CurrentSubTask = subTasks[0];
                    subTasks.RemoveAt(0);
                }
                else
                {
                    Complete();
                }
            }

            // Update progress.
            float perTask  = 1f / TotalTaskCount;
            float progress = perTask * CompletedTaskCount;

            progress     += CurrentSubTask == null ? 0f : CurrentSubTask.Progress * perTask;
            this.Progress = progress;
        }
Esempio n. 4
0
    private void SetSubTask(NPC npc, CurrentSubTask task)
    {
        SubTask = task;

        if (task == CurrentSubTask.GettingEquiptment)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Walking to go get equiptment");

            //Choose random spot at work building.
            //TODO - add specific parts to each building (perhaps, we define rooms)
            CurrentTargetPosition = GameManager.RNG.RandomFromList(WorkLocation.WorkBuilding.GetSpawnableTiles()).AsVector3();
            npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
            CurrentTaskTime = -1;
            //Ensure this task does not time out till completed
            CurrentTaskTimeout = float.MaxValue;
        }
        else if (task == CurrentSubTask.Patrolling)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Starting patrol");

            Settlement set = npc.NPCKingdomData.GetSettlement();
            CurrentTargetPosition = set.RandomPathPoint().AsVector3();
            npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Patrol target: " + CurrentTargetPosition);
        }
        else if (task == CurrentSubTask.Training)
        {
            npc.GetLoadedEntity().SpeechBubble.PushMessage("Starting to train");
            //Choose equiptment to work at
            CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
            for (int i = 0; i < 10; i++)
            {
                if (CurrentTargetEquiptment.CurrentUser != null)
                {
                    CurrentTargetEquiptment = GameManager.RNG.RandomFromList(WorkEquiptment);
                }
                else
                {
                    CurrentTargetEquiptment.CurrentUser = npc;
                }
            }
            //If no valid equiptment is found, we patrol
            if (CurrentTargetEquiptment == null)
            {
                SetSubTask(npc, CurrentSubTask.Patrolling);
            }
            else
            {
                //if the equiptment is non null, we target and travel to it
                CurrentTargetPosition = CurrentTargetEquiptment.WorkPosition();
                npc.GetLoadedEntity().LEPathFinder.SetTarget(CurrentTargetPosition);
                npc.GetLoadedEntity().SpeechBubble.PushMessage("Training on object " + CurrentTargetPosition);
            }


            if (npc.Position.WithinDistance(CurrentTargetPosition, 0.5f))
            {
                EquiptmentAssociatedTask(npc);
            }
        }
    }