Quests.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef QUESTS_H
  17. #define QUESTS_H
  18. #include <map>
  19. #include <vector>
  20. #include "Items/Items.h"
  21. #define QUEST_STEP_TYPE_KILL 1
  22. #define QUEST_STEP_TYPE_CHAT 2
  23. #define QUEST_STEP_TYPE_OBTAIN_ITEM 3
  24. #define QUEST_STEP_TYPE_LOCATION 4
  25. #define QUEST_STEP_TYPE_SPELL 5
  26. #define QUEST_STEP_TYPE_NORMAL 6
  27. #define QUEST_STEP_TYPE_CRAFT 7
  28. #define QUEST_STEP_TYPE_HARVEST 8
  29. #define QUEST_STEP_TYPE_KILL_RACE_REQ 9 // kill using race type requirement instead of npc db id
  30. #define QUEST_DISPLAY_STATUS_HIDDEN 0
  31. #define QUEST_DISPLAY_STATUS_NO_CHECK 1
  32. #define QUEST_DISPLAY_STATUS_YELLOW 2
  33. #define QUEST_DISPLAY_STATUS_COMPLETED 4
  34. #define QUEST_DISPLAY_STATUS_REPEATABLE 8
  35. #define QUEST_DISPLAY_STATUS_CAN_SHARE 16
  36. #define QUEST_DISPLAY_STATUS_COMPLETE_FLAG 32
  37. #define QUEST_DISPLAY_STATUS_SHOW 64
  38. #define QUEST_DISPLAY_STATUS_CHECK 128
  39. #define QUEST_SHAREABLE_NONE 0
  40. #define QUEST_SHAREABLE_ACTIVE 1
  41. #define QUEST_SHAREABLE_DURING 2
  42. #define QUEST_SHAREABLE_COMPLETED 4
  43. struct QuestFactionPrereq{
  44. int32 faction_id;
  45. sint32 min;
  46. sint32 max;
  47. };
  48. struct Location {
  49. int32 id;
  50. float x;
  51. float y;
  52. float z;
  53. int32 zone_id;
  54. };
  55. class QuestStep{
  56. public:
  57. QuestStep(int32 in_id, int8 in_type, string in_description, vector<int32>* in_ids, int32 in_quantity, const char* in_task_group, vector<Location>* in_locations, float in_max_variation, float in_percentage, int32 in_usableitemid);
  58. QuestStep(QuestStep* old_step);
  59. ~QuestStep();
  60. bool CheckStepKillRaceReqUpdate(Spawn* spawn);
  61. bool CheckStepReferencedID(int32 id);
  62. bool CheckStepLocationUpdate(float char_x, float char_y, float char_z, int32 zone_id);
  63. int32 AddStepProgress(int32 val);
  64. void SetStepProgress(int32 val);
  65. int32 GetStepProgress();
  66. int8 GetStepType();
  67. bool Complete();
  68. void SetComplete();
  69. void ResetTaskGroup();
  70. const char* GetTaskGroup();
  71. const char* GetDescription();
  72. void SetDescription(string desc);
  73. int16 GetQuestCurrentQuantity();
  74. int16 GetQuestNeededQuantity();
  75. map<int32, bool>* GetUpdateIDs() { return ids; }
  76. int16 GetIcon();
  77. void SetIcon(int16 in_icon);
  78. const char* GetUpdateTargetName();
  79. void SetUpdateTargetName(const char* name);
  80. const char* GetUpdateName();
  81. void SetUpdateName(const char* name);
  82. int32 GetStepID();
  83. int32 GetItemID();
  84. bool WasUpdated();
  85. void WasUpdated(bool val);
  86. float GetPercentage();
  87. void SetTaskGroup(string val) { task_group = val; }
  88. private:
  89. bool updated;
  90. int32 id;
  91. string update_name;
  92. string update_target_name;
  93. int16 icon;
  94. int8 type;
  95. string description;
  96. std::map<int32, bool>* ids;
  97. int32 quantity;
  98. string task_group;
  99. vector<Location>* locations;
  100. float max_variation;
  101. float percentage;
  102. int32 usableitemid;
  103. int32 step_progress;
  104. };
  105. class Player;
  106. class Spell;
  107. class Quest{
  108. public:
  109. Quest(int32 in_id);
  110. Quest(Quest* old_quest);
  111. ~Quest();
  112. EQ2Packet* OfferQuest(int16 version, Player* player);
  113. EQ2Packet* QuestJournalReply(int16 version, int32 player_crc, Player* player, QuestStep* updateStep = 0, int8 update_count = 1, bool old_completed_quest=false, bool quest_failure = false, bool display_quest_helper = true);
  114. void RegisterQuest(string in_name, string in_type, string in_zone, int8 in_level, string in_desc);
  115. void SetPrereqLevel(int8 lvl);
  116. void SetPrereqTSLevel(int8 lvl);
  117. void SetPrereqMaxLevel(int8 lvl) {prereq_max_level = lvl;}
  118. void SetPrereqMaxTSLevel(int8 lvl) {prereq_max_tslevel = lvl;}
  119. void AddPrereqClass(int8 class_id);
  120. void AddPrereqTradeskillClass(int8 class_id);
  121. void AddPrereqModelType(int16 model_type);
  122. void AddPrereqRace(int8 race);
  123. void AddPrereqQuest(int32 quest_id);
  124. void AddPrereqFaction(int32 faction_id, sint32 min, sint32 max = 0);
  125. void AddPrereqItem(Item* item);
  126. void AddRewardItem(Item* item);
  127. void AddTmpRewardItem(Item* item);
  128. void GetTmpRewardItemsByID(std::vector<Item*>* items);
  129. void AddRewardItemVec(vector<Item*>* items, Item* item, bool combine_items = true);
  130. void AddSelectableRewardItem(Item* item);
  131. void AddRewardCoins(int32 copper, int32 silver, int32 gold, int32 plat);
  132. void AddRewardCoinsMax(int64 coins);
  133. void AddRewardFaction(int32 faction_id, sint32 amount);
  134. void SetRewardStatus(int32 amount);
  135. void SetRewardComment(string comment);
  136. void SetRewardXP(int32 xp);
  137. void SetRewardTSXP(int32 xp) { reward_tsexp = xp; }
  138. bool AddQuestStep(QuestStep* step);
  139. QuestStep* AddQuestStep(int32 id, int8 in_type, string in_description, vector<int32>* in_ids, int32 in_quantity, const char* in_task_group = 0, vector<Location>* in_locations = 0, float in_max_variation = 0, float in_percentage = 0,int32 in_usableitemid = 0);
  140. bool SetStepComplete(int32 step);
  141. bool AddStepProgress(int32 step_id, int32 progress);
  142. int16 GetQuestStep();
  143. int32 GetStepProgress(int32 step_id);
  144. int16 GetTaskGroupStep();
  145. bool QuestStepIsActive(int16 quest_step_id);
  146. bool CheckQuestReferencedSpawns(Spawn* spawn);
  147. bool CheckQuestKillUpdate(Spawn* spawn, bool update = true);
  148. bool CheckQuestChatUpdate(int32 id, bool update = true);
  149. bool CheckQuestItemUpdate(int32 id, int8 quantity = 1);
  150. bool CheckQuestLocationUpdate(float char_x, float char_y, float char_z, int32 zone_id);
  151. bool CheckQuestSpellUpdate(Spell* spell);
  152. bool CheckQuestRefIDUpdate(int32 id, int32 quantity = 1);
  153. int8 GetQuestLevel();
  154. int8 GetVisible();
  155. int32 GetQuestID();
  156. void SetQuestID(int32 in_id);
  157. int8 GetPrereqLevel();
  158. int8 GetPrereqTSLevel();
  159. int8 GetPrereqMaxLevel() {return prereq_max_level;}
  160. int8 GetPrereqMaxTSLevel() {return prereq_max_tslevel;}
  161. vector<QuestFactionPrereq>* GetPrereqFactions();
  162. vector<int8>* GetPrereqRaces();
  163. vector<int16>* GetPrereqModelTypes();
  164. vector<int8>* GetPrereqClasses();
  165. vector<int8>* GetPrereqTradeskillClasses();
  166. vector<int32>* GetPrereqQuests();
  167. vector<Item*>* GetPrereqItems();
  168. vector<Item*>* GetRewardItems();
  169. vector<Item*>* GetTmpRewardItems();
  170. vector<Item*>* GetSelectableRewardItems();
  171. map<int32, sint32>* GetRewardFactions();
  172. void GiveQuestReward(Player* player);
  173. void AddCompleteAction(int32 step, string action);
  174. void AddProgressAction(int32 step, string action);
  175. void SetName(string in_name);
  176. void SetType(string in_type);
  177. void SetLevel(int8 in_level);
  178. void SetEncounterLevel(int8 level) {enc_level = level;}
  179. void SetDescription(string desc);
  180. void SetStepDescription(int32 step, string desc);
  181. void SetTaskGroupDescription(int32 step, string desc, bool display_bullets);
  182. void SetStatusTmpReward(int32 status) { tmp_reward_status = status; }
  183. int64 GetStatusTmpReward() { return tmp_reward_status; }
  184. void SetCoinTmpReward(int64 coins) { tmp_reward_coins = coins; }
  185. int64 GetCoinTmpReward() { return tmp_reward_coins; }
  186. int64 GetCoinsReward();
  187. int64 GetCoinsRewardMax();
  188. int64 GetGeneratedCoin();
  189. void SetGeneratedCoin(int64 coin);
  190. int8 GetLevel();
  191. int8 GetEncounterLevel() { return enc_level; }
  192. const char* GetName();
  193. const char* GetDescription();
  194. const char* GetType();
  195. void SetZone(string in_zone);
  196. const char* GetZone();
  197. int8 GetDay();
  198. int8 GetMonth();
  199. int8 GetYear();
  200. int32 GetStatusPoints();
  201. void SetDay(int8 value);
  202. void SetMonth(int8 value);
  203. void SetYear(int8 value);
  204. vector<QuestStep*>* GetQuestUpdates();
  205. vector<QuestStep*>* GetQuestFailures();
  206. vector<QuestStep*>* GetQuestSteps();
  207. bool GetQuestStepCompleted(int32 step_id);
  208. QuestStep* GetQuestStep(int32 step_id);
  209. void SetCompleteAction(string action);
  210. const char* GetCompleteAction();
  211. const char* GetCompleteAction(int32 step);
  212. void SetQuestGiver(int32 id);
  213. int32 GetQuestGiver();
  214. void SetQuestReturnNPC(int32 id);
  215. int32 GetQuestReturnNPC();
  216. Player* GetPlayer();
  217. void SetPlayer(Player* in_player);
  218. bool GetCompleted();
  219. bool HasSentLastUpdate() { return has_sent_last_update; }
  220. void SetSentLastUpdate(bool val) { has_sent_last_update = val; }
  221. void SetCompletedDescription(string desc);
  222. const char* GetCompletedDescription();
  223. int32 GetExpReward();
  224. int32 GetTSExpReward() { return reward_tsexp; }
  225. bool GetDeleted();
  226. void SetDeleted(bool val);
  227. bool GetUpdateRequired();
  228. void SetUpdateRequired(bool val);
  229. void SetTurnedIn(bool val);
  230. bool GetTurnedIn();
  231. bool GetSaveNeeded(){ return needs_save; }
  232. void SetSaveNeeded(bool val){ needs_save = val; }
  233. void SetFeatherColor(int8 val) { m_featherColor = val; }
  234. int8 GetFeatherColor() { return m_featherColor; }
  235. void SetRepeatable(bool val) { m_repeatable = val; }
  236. bool IsRepeatable() { return m_repeatable; }
  237. void SetTracked(bool val) { m_tracked = val; }
  238. bool GetTracked() { return m_tracked; }
  239. bool IsTracked() { return m_tracked && !m_hidden; }
  240. void SetCompletedFlag(bool val);
  241. bool GetCompletedFlag() {return completed_flag;}
  242. bool GetYellowName() {return yellow_name;}
  243. void SetYellowName(bool val) {yellow_name = val;}
  244. bool CheckCategoryYellow();
  245. ///<summary>Sets the custom flags for use in lua</summary>
  246. ///<param name='flags'>Value to set the flags to</param>
  247. void SetQuestFlags(int32 flags) { m_questFlags = flags; SetSaveNeeded(true); }
  248. ///<summary>Gets the custom lua flags</summary>
  249. ///<returns>The current flags (int32)</returns>
  250. int32 GetQuestFlags() { return m_questFlags; }
  251. ///<summary>Checks to see if the quest is hidden</summary>
  252. ///<returns>True if the quest is hidden</returns>
  253. bool IsHidden() { return m_hidden; }
  254. ///<summary>Sets the quest hidden flag</summary>
  255. ///<param name='val'>Value to set the hidden flag to</param>
  256. void SetHidden(bool val) { m_hidden = val; SetSaveNeeded(true); }
  257. ///<summary>Gets the step timer</summary>
  258. ///<returns>Unix timestamp (int32)</returns>
  259. int32 GetStepTimer() { return m_timestamp; }
  260. ///<summary>Sets the step timer</summary>
  261. ///<param name='duration'>How long to set the timer for, in seconds</param>
  262. void SetStepTimer(int32 duration);
  263. ///<summary>Sets the step that the timer is for</summary>
  264. ///<param name='step'>Step to set the timer for</param>
  265. void SetTimerStep(int32 step) { m_timerStep = step; }
  266. ///<summary>Gets the step that the timer is for</summary>
  267. int32 GetTimerStep() { return m_timerStep; }
  268. ///<summary>Adds a lua call back function for when the step fails</summary>
  269. ///<param name='step'>The step to add the call back for</param>
  270. ///<param name='action'>The lua callback function</param>
  271. void AddFailedAction(int32 step, string action);
  272. ///<summary>Fail the given step</summary>
  273. ///<param name='step'>The step to fail</param>
  274. void StepFailed(int32 step);
  275. ///<summary>Removes the given step from the quest</summary>
  276. ///<param name='step'>The step id to remove</param>
  277. ///<param name='client'>The client who has this quest</param>
  278. ///<returns>True if able to remove the quest</returns>
  279. bool RemoveQuestStep(int32 step, Client* client);
  280. int16 GetCompleteCount() { return m_completeCount; }
  281. void SetCompleteCount(int16 val) { m_completeCount = val; }
  282. void IncrementCompleteCount() { m_completeCount += 1; }
  283. void SetQuestTemporaryState(bool tempState, std::string customDescription = string(""));
  284. bool GetQuestTemporaryState() { return quest_state_temporary; }
  285. std::string GetQuestTemporaryDescription() { return quest_temporary_description; }
  286. void SetQuestShareableFlag(int32 flag) { quest_shareable_flag = flag; }
  287. void SetCanDeleteQuest(bool newval) { can_delete_quest = newval; }
  288. int32 GetQuestShareableFlag() { return quest_shareable_flag; }
  289. bool CanDeleteQuest() { return can_delete_quest; }
  290. bool CanShareQuestCriteria(Client* quest_sharer, bool display_client_msg = true);
  291. Mutex MQuestSteps;
  292. protected:
  293. bool needs_save;
  294. Mutex MCompletedActions;
  295. Mutex MProgressActions;
  296. Mutex MFailedActions;
  297. bool turned_in;
  298. bool update_needed;
  299. bool deleted;
  300. bool has_sent_last_update;
  301. string completed_description;
  302. map<int32, string> complete_actions;
  303. map<int32, string> progress_actions;
  304. map<int32, string> failed_actions;
  305. int8 day; //only here to make our lives easier
  306. int8 month;
  307. int8 year;
  308. int8 visible;
  309. int32 id;
  310. string name;
  311. string type;
  312. string zone;
  313. int8 level;
  314. int8 enc_level;
  315. string description;
  316. string complete_action;
  317. Player* player;
  318. vector<QuestFactionPrereq> prereq_factions;
  319. int8 prereq_level;
  320. int8 prereq_tslevel;
  321. int8 prereq_max_level;
  322. int8 prereq_max_tslevel;
  323. vector<int16> prereq_model_types;
  324. vector<int8> prereq_races;
  325. vector<int8> prereq_classes;
  326. vector<int8> prereq_tradeskillclass;
  327. vector<int32> prereq_quests;
  328. vector<Item*> prereq_items;
  329. vector<Item*> reward_items;
  330. vector<Item*> selectable_reward_items;
  331. vector<Item*> tmp_reward_items;
  332. int64 reward_coins;
  333. int64 reward_coins_max;
  334. int32 tmp_reward_status;
  335. int64 tmp_reward_coins;
  336. int64 generated_coin;
  337. map<int32, sint32> reward_factions;
  338. int32 reward_status;
  339. string reward_comment;
  340. int32 reward_exp;
  341. int32 reward_tsexp;
  342. vector<QuestStep*> step_updates;
  343. vector<QuestStep*> step_failures;
  344. map<int32, QuestStep*> quest_step_map;
  345. map<QuestStep*, int32> quest_step_reverse_map;
  346. vector<QuestStep*> quest_steps;
  347. map<int16, string> task_group_order;
  348. int16 task_group_num;
  349. map<string, vector<QuestStep*> > task_group;
  350. int32 quest_giver;
  351. int32 return_id;
  352. int8 m_featherColor;
  353. bool m_repeatable;
  354. bool m_tracked;
  355. bool completed_flag;
  356. bool yellow_name;
  357. int32 m_questFlags;
  358. bool m_hidden;
  359. int32 m_timestamp; // timer for a quest step
  360. int32 m_timerStep; // used for the fail action when timer expires
  361. int16 m_completeCount;
  362. bool quest_state_temporary;
  363. std::string quest_temporary_description;
  364. int32 quest_shareable_flag;
  365. bool can_delete_quest;
  366. };
  367. class MasterQuestList{
  368. public:
  369. MasterQuestList();
  370. Quest* GetQuest(int32 id, bool copyQuest = true){
  371. if(quests.count(id) > 0)
  372. {
  373. if(copyQuest)
  374. return new Quest(quests[id]);
  375. else
  376. return quests[id];
  377. }
  378. else
  379. return 0;
  380. }
  381. map<int32, Quest*>* GetQuests(){
  382. return &quests;
  383. }
  384. void AddQuest(int32 id, Quest* quest){
  385. quests[id] = quest;
  386. }
  387. void Reload();
  388. void LockQuests();
  389. void UnlockQuests();
  390. private:
  391. Mutex MQuests;
  392. map<int32, Quest*> quests;
  393. };
  394. #endif