[Show Table of Contents]

The Task System consists of several Classes...


class TaskManager {

   int  GetActivityCount(int TaskID);
   bool LoadTasks(int ZoneID);
   bool LoadTaskSets();
   bool LoadClientState(Client *c, ClientTaskState *state);
   bool SaveClientState(Client *c, ClientTaskState *state);
   void SendTaskSelector(Client *c, Mob *mob, int TaskCount, int *TaskList);
   void TaskSetSelector(Client *c, ClientTaskState *state, Mob *mob, int TaskSetID);
   void SendActiveTasksToClient(Client *c, bool TaskComplete=false);
   void SendSingleActiveTaskToClient(Client *c, int TaskIndex, bool TaskComplete, bool BringUpTaskJournal=false);
   void SendTaskActivityShort(Client *c, int TaskID, int ActivityID, int ClientTaskIndex);
   void SendTaskActivityLong(Client *c, int TaskID, int ActivityID, int ClientTaskIndex,
                             bool Optional, bool TaskComplete=false);
   void SendCompletedTasksToClient(Client *c, ClientTaskState *state);
   void ExplainTask(Client *c, int TaskID);
   friend class ClientTaskState;

   TaskGoalListManager GoalListManager;
   TaskProximityManager ProximityManager;
   TaskInformation* Tasks[MAXTASKS];
   vector<int> TaskSets[MAXTASKSETS];
   void SendActiveTaskDescription(Client *c, int TaskID, int SequenceNumber, int StartTime, int Duration, bool BringUpTaskJournal=false);

The Taskmanager class handles loading of the global task and activity data (things that don't change while the server is running). It also loads per-character task/activity information and does some other things on behalf ot the Clienttaskstate class.
TaskManager uses two further classes.


class TaskGoalListManager {

   bool LoadLists();
   int GetListByID(int ListID);
   bool IsInList(int ListIndex, int Entry);
   vector<int> GetListContents(int ListIndex);


   TaskGoalList_Struct *TaskGoalLists;
   int NumberOfLists;
  • This loads the goallist table and contains the method to check if an entry exists in a given list.


class TaskProximityManager {

   bool LoadProximities(int ZoneID);
   int CheckProximities(float X, float Y, float Z);

   vector<TaskProximity> TaskProximities;
  • This handles loading and checking of proximities for Explore tasks.
The final class is:


class ClientTaskState {

   void ShowClientTasks(Client *c);
   inline int GetActiveTaskCount() { return ActiveTaskCount; }
   int GetActiveTaskID(int index);
   bool IsTaskActivityCompleted(int index, int ActivityID);
   int GetTaskActivityDoneCount(int index, int ActivityID);
   int GetTaskStartTime(int index);
   void AcceptNewTask(Client *c, int TaskID, int NPCID);
   void FailTask(Client *c, int TaskID);
   int TaskTimeLeft(int TaskID);
   int IsTaskCompleted(int TaskID);
   bool IsTaskActive(int TaskID);
   bool IsTaskActivityActive(int TaskID, int ActivityID);
   ActivityState GetTaskActivityState(int index, int ActivityID);
   void UpdateTaskActivity(Client *c, int TaskID, int ActivityID, int Count);
   void CancelTask(Client *c, int SequenceNumber);
   void RemoveTask(Client *c, int SequenceNumber);
   void UpdateTasksByNPC(Client *c, int ActivityType, int NPCTypeID);
   void UpdateTasksOnKill(Client *c, int NPCTypeID);
   void UpdateTasksForItem(Client *c, ActivityType Type, int ItemID, int Count=1);
   void UpdateTasksOnExplore(Client *c, int ExploreID);
   void UpdateTasksOnSpeakWith(Client *c, int NPCTypeID);
   void UpdateTasksOnDeliver(Client *c, int32 *Items, int Cash, int NPCTypeID);
   void UpdateTasksOnTouch(Client *c, int ZoneID);
   void ProcessTaskProximities(Client *c, float X, float Y, float Z);
   bool TaskOutOfTime(int Index);
   void TaskPeriodicChecks(Client *c);
   void SendTaskHistory(Client *c, int TaskIndex);
   void RewardTask(Client *c, TaskInformation *Task);
   void EnableTask(int CharID, int TaskCount, int *TaskList);
   void DisableTask(int CharID, int TaskCount, int *TaskList);
   bool IsTaskEnabled(int TaskID);
   int EnabledTaskCount(int TaskSetID);
   friend class TaskManager;

   bool UnlockActivities(int CharID, int TaskIndex);
   void IncrementDoneCount(Client *c, TaskInformation *Task, int TaskIndex, int ActivityID, int Count=1);
   int ActiveTaskCount;
   ClientTaskInformation ActiveTasks[MAXACTIVETASKS];
   vector<CompletedTaskInformation> CompletedTasks;
   int LastCompletedTaskLoaded;
   bool CheckedTouchActivities;
This contains details of the active tasks, activity progress and completed tasks for each connected client along with the routines for updating activity progress.
The vast majority the Task System code is in zone/tasks.cpp.