Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        QueuedTasks = new Queue <INPCTask>();

        foreach (NPCTaskMap mapItem in TasksWithParameters)
        {
            INPCTask newTask = NPCTaskFactory.CreateTaskFromTypeAndParameters(mapItem.TaskType, mapItem.TaskParameter);
            newTask.parentObject = this.gameObject;
            QueuedTasks.Enqueue(newTask);
        }

        CurrentTask = QueuedTasks.Dequeue();
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (IsDead)
        {
            return;
        }

        if (CurrentTask != null)
        {
            if (CurrentTask.IsFinished)
            {
                if (CurrentTask.FinishedState == INPCTask.FinishStates.FAILED)
                {
                    CurrentTask.Retried++;
                    if (!(CurrentTask.Retried >= CurrentTask.MaximumRetries))
                    {
                        QueuedTasks.Enqueue(CurrentTask);
                    }
                }

                if (CurrentTask.FinishedState != INPCTask.FinishStates.FAILED)
                {
                    CompletedTasks.Add(CurrentTask.TaskName);
                }

                if (QueuedTasks.Count > 0)
                {
                    CurrentTask = QueuedTasks.Dequeue();
                    CurrentTask.Reset();
                }
                else
                {
                    CurrentTask = NPCTaskFactory.CreateTaskFromTypeAndParameters(TaskTypes.RoamPassively, "");
                }
            }

            if (CurrentTask != null)
            {
                CurrentTask.RunUpdate();
            }

            this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + 0.5f, this.transform.position.z);
        }
    }