eqemu-server/zone/tasks.h
Michael Cook (mackal) 39544b4723 Shared Task WIP
2018-09-01 17:32:13 -04:00

409 lines
14 KiB
C++

/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2004 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TASKS_H
#define TASKS_H
#include "../common/types.h"
#include <list>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <map>
#define MAXTASKS 10000
#define MAXTASKSETS 1000
// The Client has a hard cap of 19 active quests, 29 in SoD+
#define MAXACTIVEQUESTS 19
// The Max Chooser (Task Selector entries) is capped at 40 in the Titanium Client.
#define MAXCHOOSERENTRIES 40
// The Client has a hard cap of 20 activities per task.
#define MAXACTIVITIESPERTASK 20
// This is used to determine if a client's active task slot is empty.
#define TASKSLOTEMPTY 0
// Command Codes for worldserver ServerOP_ReloadTasks
//
#define RELOADTASKS 0
#define RELOADTASKGOALLISTS 1
#define RELOADTASKPROXIMITIES 2
#define RELOADTASKSETS 3
class Client;
class Mob;
namespace EQEmu
{
class ItemInstance;
}
struct TaskGoalList_Struct {
int ListID;
int Min, Max;
std::vector<int> GoalItemEntries;
};
// This is used for handling lists, loading them from the database, searching them.
// Used for lists of NPCs to kill, items to loot, etc, as well as lists of items to
// reward the player with on completion of the task.
//
class TaskGoalListManager {
public:
TaskGoalListManager();
~TaskGoalListManager();
bool LoadLists();
int GetListByID(int ListID);
bool IsInList(int ListID, int Entry);
int GetFirstEntry(int ListID);
std::vector<int> GetListContents(int ListIndex);
private:
std::vector<TaskGoalList_Struct> TaskGoalLists;
int NumberOfLists;
};
typedef struct {
int ExploreID;
float MinX, MaxX, MinY, MaxY, MinZ, MaxZ;
} TaskProximity;
// This class is used for managing proximities so that Quest NPC proximities don't need to be used.
class TaskProximityManager {
public:
TaskProximityManager();
~TaskProximityManager();
bool LoadProximities(int ZoneID);
int CheckProximities(float X, float Y, float Z);
private:
std::vector<TaskProximity> TaskProximities;
};
typedef enum { METHODSINGLEID = 0, METHODLIST = 1, METHODQUEST = 2 } TaskMethodType;
struct ActivityInformation {
int StepNumber;
int Type;
std::string target_name; // name mob, location -- default empty
std::string item_list; // likely defaults to empty
std::string skill_list; // IDs ; separated -- default -1
std::string spell_list; // IDs ; separated -- default 0
std::string desc_override; // overrides auto generated description -- default empty
int skill_id; // older clients, first id from above
int spell_id; // older clients, first id from above
int GoalID;
TaskMethodType GoalMethod;
int GoalCount;
int DeliverToNPC;
std::vector<int> ZoneIDs;
std::string zones; // IDs ; searated, ZoneID is the first in this list for older clients -- default empty string
bool Optional;
inline bool CheckZone(int zone_id) {
if (ZoneIDs.empty())
return true;
return std::find(ZoneIDs.begin(), ZoneIDs.end(), zone_id) != ZoneIDs.end();
}
};
typedef enum { ActivitiesSequential = 0, ActivitiesStepped = 1 } SequenceType;
enum class TaskType {
Task = 0, // can have at max 1
Shared = 1, // can have at max 1
Quest = 2, // can have at max 19 or 29 depending on client
E = 3 // can have at max 19 or 29 depending on client, not present in live anymore
};
enum class DurationCode {
None = 0,
Short = 1,
Medium = 2,
Long = 3
};
// need to capture more, shared are just Radiant/Ebon though
enum class PointType {
None = 0,
Radiant = 4,
Ebon = 5,
};
struct TaskInformation {
TaskType type;
int Duration;
DurationCode dur_code; // description for time investment for when Duration == 0
std::string Title; // max length 64
std::string Description; // max length 4000, 2048 on Tit
std::string Reward;
std::string item_link; // max length 128 older clients, item link gets own string
std::string completion_emote; // emote after completing task, yellow. Maybe should make more generic ... but yellow for now!
int RewardID;
int CashReward; // Expressed in copper
int XPReward;
int faction_reward; // just a npc_faction_id
TaskMethodType RewardMethod;
int reward_points; // DoN crystals for shared. Generic "points" for non-shared
PointType reward_type; // 4 for Radiant Crystals else Ebon crystals when shared task
int ActivityCount;
SequenceType SequenceMode;
int LastStep;
short MinLevel;
short MaxLevel;
bool Repeatable;
int replay_group; // ID of our replay timer group (0 means none)
int min_players; // shared tasks
int max_players;
int task_lock_step; // task locks after this step is completed
uint32 instance_zone_id; // instance shit
uint32 zone_version;
uint16 zone_in_zone_id;
float zone_in_x;
float zone_in_y;
uint16 zone_in_object_id;
float dest_x;
float dest_y;
float dest_z;
float dest_h;
/* int graveyard_zone_id;
float graveyard_x;
float graveyard_y;
float graveyard_z;
float graveyard_radius; */
ActivityInformation Activity[MAXACTIVITIESPERTASK];
};
typedef enum { ActivityHidden = 0, ActivityActive = 1, ActivityCompleted = 2 } ActivityState;
typedef enum { ActivityDeliver = 1, ActivityKill = 2, ActivityLoot = 3, ActivitySpeakWith = 4, ActivityExplore = 5,
ActivityTradeSkill = 6, ActivityFish = 7, ActivityForage = 8, ActivityCastOn = 9, ActivitySkillOn = 10,
ActivityTouch = 11, ActivityCollect = 13, ActivityGiveCash = 100 } ActivityType;
struct ClientActivityInformation {
int ActivityID;
int DoneCount;
ActivityState State;
bool Updated; // Flag so we know if we need to update the database
};
struct ClientTaskInformation {
int slot; // intrusive, but makes things easier :P
int TaskID;
int CurrentStep;
int AcceptedTime;
bool Updated;
ClientActivityInformation Activity[MAXACTIVITIESPERTASK];
};
struct CompletedTaskInformation {
int TaskID;
int CompletedTime;
bool ActivityDone[MAXACTIVITIESPERTASK];
};
struct SharedTaskMember {
std::string name;
Mob *entity; // needs to be managed
bool leader;
SharedTaskMember() : entity(nullptr), leader(false) {}
};
class SharedTaskState {
public:
SharedTaskState() : locked(false) {}
// ~SharedTaskState();
inline const bool IsLocked() const { return locked; }
inline void SetLocked(bool v) { locked = v; }
void LockTask(); // notified clients (if they are etc)
void MemberZoned(Mob *player); // player left zone, update their pointer
void MemberEnterZone(Mob *player); // player entered zone, update their pointer
ClientTaskInformation *GetActivity() { return &activity; }
friend class TaskManager;
private:
std::vector<SharedTaskMember> members;
ClientTaskInformation activity;
bool locked;
};
class ClientTaskState {
public:
ClientTaskState();
~ClientTaskState();
void ShowClientTasks(Client *c);
inline int GetActiveTaskCount() { return ActiveTaskCount; }
int GetActiveTaskID(int index);
bool IsTaskActivityCompleted(TaskType type, int index, int ActivityID);
int GetTaskActivityDoneCount(TaskType type, int index, int ActivityID);
int GetTaskActivityDoneCountFromTaskID(int TaskID, int ActivityID);
int GetTaskStartTime(TaskType type, int index);
void AcceptNewTask(Client *c, int TaskID, int NPCID, bool enforce_level_requirement = false);
// void AcceptNewSharedTask(Client *c, int TaskID, int NPCID, bool enforce_level_requirement = false);
void PendSharedTask(Client *c, int TaskID, int NPCID, bool enforce_level_requirement = false);
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(TaskType type, int index, int ActivityID);
void UpdateTaskActivity(Client *c, int TaskID, int ActivityID, int Count, bool ignore_quest_update = false);
void ResetTaskActivity(Client *c, int TaskID, int ActivityID);
void CancelTask(Client *c, int SequenceNumber, TaskType type, bool RemoveFromDB = true);
void CancelAllTasks(Client *c);
void RemoveTask(Client *c, int SequenceNumber, TaskType type);
bool 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);
bool UpdateTasksOnSpeakWith(Client *c, int NPCTypeID);
bool UpdateTasksOnDeliver(Client *c, std::list<EQEmu::ItemInstance*>& Items, int Cash, int NPCTypeID);
void UpdateTasksOnTouch(Client *c, int ZoneID);
void ProcessTaskProximities(Client *c, float X, float Y, float Z);
bool TaskOutOfTime(TaskType type, 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);
int ActiveSpeakTask(int NPCID);
int ActiveSpeakActivity(int NPCID, int TaskID);
int ActiveTasksInSet(int TaskSetID);
int CompletedTasksInSet(int TaskSetID);
bool HasSlotForTask(TaskInformation *task);
inline bool HasFreeTaskSlot() { return ActiveTask.TaskID == TASKSLOTEMPTY; }
friend class TaskManager;
private:
bool UnlockActivities(int CharID, ClientTaskInformation &task_info);
void IncrementDoneCount(Client *c, TaskInformation *Task, int TaskIndex, int ActivityID, int Count = 1, bool ignore_quest_update = false);
inline ClientTaskInformation *GetClientTaskInfo(TaskType type, int index)
{
ClientTaskInformation *info = nullptr;
switch (type) {
case TaskType::Task:
if (index == 0)
info = &ActiveTask;
break;
case TaskType::Shared:
if (index == 0 && ActiveSharedTask)
info = ActiveSharedTask->GetActivity();
break;
case TaskType::Quest:
if (index < MAXACTIVEQUESTS)
info = &ActiveQuests[index];
break;
default:
break;
}
return info;
}
int ActiveTaskCount;
union { // easier to loop over
struct {
ClientTaskInformation ActiveTask; // only one
ClientTaskInformation ActiveQuests[MAXACTIVEQUESTS];
};
ClientTaskInformation ActiveTasks[MAXACTIVEQUESTS + 1];
};
SharedTaskState *ActiveSharedTask; // pointer to our shared task managed by TaskManager
// Shared tasks should be limited to 1 as well
std::vector<int> EnabledTasks;
std::vector<CompletedTaskInformation> CompletedTasks;
int LastCompletedTaskLoaded;
bool CheckedTouchActivities;
};
// used for timer lockouts and /tasktimers
struct TaskTimer {
int ID; // ID used in task timer
int original_id; // original ID of the task
int expires; // UNIX timestamp of when it expires, what happens with DLS? Fuck it.
};
struct TaskReplayGroups {
std::string name;
int duration;
};
class TaskManager {
public:
TaskManager();
~TaskManager();
int GetActivityCount(int TaskID);
bool LoadSingleTask(int TaskID);
bool LoadTasks(int SingleTask=0);
bool LoadReplayGroups();
void ReloadGoalLists();
inline void LoadProximities(int ZoneID) { ProximityManager.LoadProximities(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, bool shared = false); // dumb hack cuz we do dumb things
void SendTaskSelectorNew(Client *c, Mob *mob, int TaskCount, int *TaskList, bool shared = false);
bool AppropriateLevel(int TaskID, int PlayerLevel);
int GetTaskMinLevel(int TaskID);
int GetTaskMaxLevel(int TaskID);
void TaskSetSelector(Client *c, ClientTaskState *state, Mob *mob, int TaskSetID, bool shared = false);
void TaskQuestSetSelector(Client *c, ClientTaskState *state, Mob *mob, int count, int *tasks, bool shared = false); // task list provided by QuestManager (perl/lua)
void SendActiveTasksToClient(Client *c, bool TaskComplete=false);
void SendSingleActiveTaskToClient(Client *c, ClientTaskInformation &task_info, 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 SendTaskActivityNew(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);
int FirstTaskInSet(int TaskSet);
int LastTaskInSet(int TaskSet);
int NextTaskInSet(int TaskSet, int TaskID);
bool IsTaskRepeatable(int TaskID);
friend class ClientTaskState;
void LoadSharedTask(int id); // loads the shared task state
private:
TaskGoalListManager GoalListManager;
TaskProximityManager ProximityManager;
TaskInformation* Tasks[MAXTASKS];
std::vector<int> TaskSets[MAXTASKSETS];
void SendActiveTaskDescription(Client *c, int TaskID, ClientTaskInformation &task_info, int StartTime, int Duration, bool BringUpTaskJournal=false);
std::unordered_map<int, SharedTaskState> SharedTasks;
std::map<int, TaskReplayGroups> replay_groups;
};
#endif