9
3

Quests.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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_DISPLAY_STATUS_HIDDEN 0
  30. #define QUEST_DISPLAY_STATUS_NO_CHECK 1
  31. #define QUEST_DISPLAY_STATUS_YELLOW 2
  32. #define QUEST_DISPLAY_STATUS_COMPLETED 4
  33. #define QUEST_DISPLAY_STATUS_REPEATABLE 8
  34. #define QUEST_DISPLAY_STATUS_UNKNOWN1 16
  35. #define QUEST_DISPLAY_STATUS_COMPLETE_FLAG 32
  36. #define QUEST_DISPLAY_STATUS_UNKNOWN2 64
  37. #define QUEST_DISPLAY_STATUS_CHECK 128
  38. // Almost all quests have these values, but they don't see to effect anything
  39. #define QUEST_DISPLAY_STATUS_NORMAL QUEST_DISPLAY_STATUS_UNKNOWN1 + QUEST_DISPLAY_STATUS_UNKNOWN2
  40. struct QuestFactionPrereq{
  41. int32 faction_id;
  42. sint32 min;
  43. sint32 max;
  44. };
  45. struct Location {
  46. int32 id;
  47. float x;
  48. float y;
  49. float z;
  50. };
  51. class QuestStep{
  52. public:
  53. 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);
  54. QuestStep(QuestStep* old_step);
  55. ~QuestStep();
  56. bool CheckStepKillUpdate(int32 id);
  57. bool CheckStepChatUpdate(int32 id);
  58. bool CheckStepItemUpdate(int32 id);
  59. bool CheckStepLocationUpdate(float char_x, float char_y, float char_z);
  60. bool CheckStepSpellUpdate(int32 id);
  61. int32 AddStepProgress(int32 val);
  62. void SetStepProgress(int32 val);
  63. int32 GetStepProgress();
  64. int8 GetStepType();
  65. bool Complete();
  66. void SetComplete();
  67. void ResetTaskGroup();
  68. const char* GetTaskGroup();
  69. const char* GetDescription();
  70. void SetDescription(string desc);
  71. int16 GetQuestCurrentQuantity();
  72. int16 GetQuestNeededQuantity();
  73. vector<int32>* GetUpdateIDs() { return ids; }
  74. int16 GetIcon();
  75. void SetIcon(int16 in_icon);
  76. const char* GetUpdateTargetName();
  77. void SetUpdateTargetName(const char* name);
  78. const char* GetUpdateName();
  79. void SetUpdateName(const char* name);
  80. int32 GetStepID();
  81. int32 GetItemID();
  82. bool WasUpdated();
  83. void WasUpdated(bool val);
  84. float GetPercentage();
  85. void SetTaskGroup(string val) { task_group = val; }
  86. private:
  87. bool updated;
  88. int32 id;
  89. string update_name;
  90. string update_target_name;
  91. int16 icon;
  92. int8 type;
  93. string description;
  94. vector<int32>* ids;
  95. int32 quantity;
  96. string task_group;
  97. vector<Location>* locations;
  98. float max_variation;
  99. float percentage;
  100. int32 usableitemid;
  101. int32 step_progress;
  102. };
  103. class Player;
  104. class Spell;
  105. class Quest{
  106. public:
  107. Quest(int32 in_id);
  108. Quest(Quest* old_quest);
  109. ~Quest();
  110. EQ2Packet* OfferQuest(int16 version, Player* player);
  111. 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);
  112. void RegisterQuest(string in_name, string in_type, string in_zone, int8 in_level, string in_desc);
  113. void SetPrereqLevel(int8 lvl);
  114. void SetPrereqTSLevel(int8 lvl);
  115. void SetPrereqMaxLevel(int8 lvl) {prereq_max_level = lvl;}
  116. void SetPrereqMaxTSLevel(int8 lvl) {prereq_max_tslevel = lvl;}
  117. void AddPrereqClass(int8 class_id);
  118. void AddPrereqTradeskillClass(int8 class_id);
  119. void AddPrereqModelType(int16 model_type);
  120. void AddPrereqRace(int8 race);
  121. void AddPrereqQuest(int32 quest_id);
  122. void AddPrereqFaction(int32 faction_id, sint32 min, sint32 max = 0);
  123. void AddPrereqItem(Item* item);
  124. void AddRewardItem(Item* item);
  125. void AddSelectableRewardItem(Item* item);
  126. void AddRewardCoins(int32 copper, int32 silver, int32 gold, int32 plat);
  127. void AddRewardCoinsMax(int64 coins);
  128. void AddRewardFaction(int32 faction_id, sint32 amount);
  129. void SetRewardStatus(int32 amount);
  130. void SetRewardComment(string comment);
  131. void SetRewardXP(int32 xp);
  132. void SetRewardTSXP(int32 xp) { reward_tsexp = xp; }
  133. bool AddQuestStep(QuestStep* step);
  134. 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);
  135. bool SetStepComplete(int32 step);
  136. bool AddStepProgress(int32 step_id, int32 progress);
  137. int16 GetQuestStep();
  138. int32 GetStepProgress(int32 step_id);
  139. int16 GetTaskGroupStep();
  140. bool QuestStepIsActive(int16 quest_step_id);
  141. bool CheckQuestKillUpdate(Spawn* spawn, bool update = true);
  142. bool CheckQuestChatUpdate(int32 id, bool update = true);
  143. bool CheckQuestItemUpdate(int32 id, int8 quantity = 1);
  144. bool CheckQuestLocationUpdate(float char_x, float char_y, float char_z);
  145. bool CheckQuestSpellUpdate(Spell* spell);
  146. bool CheckQuestCraftUpdate(int32 id, int32 quantity = 1);
  147. bool CheckQuestHarvestUpdate(int32 id, int32 quantity = 1);
  148. int8 GetQuestLevel();
  149. int8 GetVisible();
  150. int32 GetQuestID();
  151. void SetQuestID(int32 in_id);
  152. int8 GetPrereqLevel();
  153. int8 GetPrereqTSLevel();
  154. int8 GetPrereqMaxLevel() {return prereq_max_level;}
  155. int8 GetPrereqMaxTSLevel() {return prereq_max_tslevel;}
  156. vector<QuestFactionPrereq>* GetPrereqFactions();
  157. vector<int8>* GetPrereqRaces();
  158. vector<int16>* GetPrereqModelTypes();
  159. vector<int8>* GetPrereqClasses();
  160. vector<int8>* GetPrereqTradeskillClasses();
  161. vector<int32>* GetPrereqQuests();
  162. vector<Item*>* GetPrereqItems();
  163. vector<Item*>* GetRewardItems();
  164. vector<Item*>* GetSelectableRewardItems();
  165. map<int32, sint32>* GetRewardFactions();
  166. void GiveQuestReward(Player* player);
  167. void AddCompleteAction(int32 step, string action);
  168. void AddProgressAction(int32 step, string action);
  169. void SetName(string in_name);
  170. void SetType(string in_type);
  171. void SetLevel(int8 in_level);
  172. void SetEncounterLevel(int8 level) {enc_level = level;}
  173. void SetDescription(string desc);
  174. void SetStepDescription(int32 step, string desc);
  175. void SetTaskGroupDescription(int32 step, string desc, bool display_bullets);
  176. int64 GetCoinsReward();
  177. int64 GetCoinsRewardMax();
  178. int64 GetGeneratedCoin();
  179. void SetGeneratedCoin(int64 coin);
  180. int8 GetLevel();
  181. int8 GetEncounterLevel() { return enc_level; }
  182. const char* GetName();
  183. const char* GetDescription();
  184. const char* GetType();
  185. void SetZone(string in_zone);
  186. const char* GetZone();
  187. int8 GetDay();
  188. int8 GetMonth();
  189. int8 GetYear();
  190. int32 GetStatusPoints();
  191. void SetDay(int8 value);
  192. void SetMonth(int8 value);
  193. void SetYear(int8 value);
  194. vector<QuestStep*>* GetQuestUpdates();
  195. vector<QuestStep*>* GetQuestFailures();
  196. vector<QuestStep*>* GetQuestSteps();
  197. bool GetQuestStepCompleted(int32 step_id);
  198. QuestStep* GetQuestStep(int32 step_id);
  199. void SetCompleteAction(string action);
  200. const char* GetCompleteAction();
  201. const char* GetCompleteAction(int32 step);
  202. void SetQuestGiver(int32 id);
  203. int32 GetQuestGiver();
  204. void SetQuestReturnNPC(int32 id);
  205. int32 GetQuestReturnNPC();
  206. Player* GetPlayer();
  207. void SetPlayer(Player* in_player);
  208. bool GetCompleted();
  209. bool HasSentLastUpdate() { return has_sent_last_update; }
  210. void SetSentLastUpdate(bool val) { has_sent_last_update = val; }
  211. void SetCompletedDescription(string desc);
  212. const char* GetCompletedDescription();
  213. int32 GetExpReward();
  214. int32 GetTSExpReward() { return reward_tsexp; }
  215. bool GetDeleted();
  216. void SetDeleted(bool val);
  217. bool GetUpdateRequired();
  218. void SetUpdateRequired(bool val);
  219. void SetTurnedIn(bool val);
  220. bool GetTurnedIn();
  221. bool GetSaveNeeded(){ return needs_save; }
  222. void SetSaveNeeded(bool val){ needs_save = val; }
  223. void SetFeatherColor(int8 val) { m_featherColor = val; }
  224. int8 GetFeatherColor() { return m_featherColor; }
  225. void SetRepeatable(bool val) { m_repeatable = val; }
  226. bool IsRepeatable() { return m_repeatable; }
  227. void SetTracked(bool val) { m_tracked = val; }
  228. bool IsTracked() { return m_tracked && !m_hidden; }
  229. void SetCompletedFlag(bool val);
  230. bool GetCompletedFlag() {return completed_flag;}
  231. bool GetYellowName() {return yellow_name;}
  232. void SetYellowName(bool val) {yellow_name = val;}
  233. bool CheckCategoryYellow();
  234. ///<summary>Sets the custom flags for use in lua</summary>
  235. ///<param name='flags'>Value to set the flags to</param>
  236. void SetQuestFlags(int32 flags) { m_questFlags = flags; SetSaveNeeded(true); }
  237. ///<summary>Gets the custom lua flags</summary>
  238. ///<returns>The current flags (int32)</returns>
  239. int32 GetQuestFlags() { return m_questFlags; }
  240. ///<summary>Checks to see if the quest is hidden</summary>
  241. ///<returns>True if the quest is hidden</returns>
  242. bool IsHidden() { return m_hidden; }
  243. ///<summary>Sets the quest hidden flag</summary>
  244. ///<param name='val'>Value to set the hidden flag to</param>
  245. void SetHidden(bool val) { m_hidden = val; SetSaveNeeded(true); }
  246. ///<summary>Gets the step timer</summary>
  247. ///<returns>Unix timestamp (int32)</returns>
  248. int32 GetStepTimer() { return m_timestamp; }
  249. ///<summary>Sets the step timer</summary>
  250. ///<param name='duration'>How long to set the timer for, in seconds</param>
  251. void SetStepTimer(int32 duration);
  252. ///<summary>Sets the step that the timer is for</summary>
  253. ///<param name='step'>Step to set the timer for</param>
  254. void SetTimerStep(int32 step) { m_timerStep = step; }
  255. ///<summary>Gets the step that the timer is for</summary>
  256. int32 GetTimerStep() { return m_timerStep; }
  257. ///<summary>Adds a lua call back function for when the step fails</summary>
  258. ///<param name='step'>The step to add the call back for</param>
  259. ///<param name='action'>The lua callback function</param>
  260. void AddFailedAction(int32 step, string action);
  261. ///<summary>Fail the given step</summary>
  262. ///<param name='step'>The step to fail</param>
  263. void StepFailed(int32 step);
  264. ///<summary>Removes the given step from the quest</summary>
  265. ///<param name='step'>The step id to remove</param>
  266. ///<param name='client'>The client who has this quest</param>
  267. ///<returns>True if able to remove the quest</returns>
  268. bool RemoveQuestStep(int32 step, Client* client);
  269. int16 GetCompleteCount() { return m_completeCount; }
  270. void SetCompleteCount(int16 val) { m_completeCount = val; }
  271. void IncrementCompleteCount() { m_completeCount += 1; }
  272. protected:
  273. bool needs_save;
  274. Mutex MQuestSteps;
  275. Mutex MCompletedActions;
  276. Mutex MProgressActions;
  277. Mutex MFailedActions;
  278. bool turned_in;
  279. bool update_needed;
  280. bool deleted;
  281. bool has_sent_last_update;
  282. string completed_description;
  283. map<int32, string> complete_actions;
  284. map<int32, string> progress_actions;
  285. map<int32, string> failed_actions;
  286. int8 day; //only here to make our lives easier
  287. int8 month;
  288. int8 year;
  289. int8 visible;
  290. int32 id;
  291. string name;
  292. string type;
  293. string zone;
  294. int8 level;
  295. int8 enc_level;
  296. string description;
  297. string complete_action;
  298. Player* player;
  299. vector<QuestFactionPrereq> prereq_factions;
  300. int8 prereq_level;
  301. int8 prereq_tslevel;
  302. int8 prereq_max_level;
  303. int8 prereq_max_tslevel;
  304. vector<int16> prereq_model_types;
  305. vector<int8> prereq_races;
  306. vector<int8> prereq_classes;
  307. vector<int8> prereq_tradeskillclass;
  308. vector<int32> prereq_quests;
  309. vector<Item*> prereq_items;
  310. vector<Item*> reward_items;
  311. vector<Item*> selectable_reward_items;
  312. int64 reward_coins;
  313. int64 reward_coins_max;
  314. int64 generated_coin;
  315. map<int32, sint32> reward_factions;
  316. int32 reward_status;
  317. string reward_comment;
  318. int32 reward_exp;
  319. int32 reward_tsexp;
  320. vector<QuestStep*> step_updates;
  321. vector<QuestStep*> step_failures;
  322. map<int32, QuestStep*> quest_step_map;
  323. map<QuestStep*, int32> quest_step_reverse_map;
  324. vector<QuestStep*> quest_steps;
  325. map<int16, string> task_group_order;
  326. int16 task_group_num;
  327. map<string, vector<QuestStep*> > task_group;
  328. int32 quest_giver;
  329. int32 return_id;
  330. int8 m_featherColor;
  331. bool m_repeatable;
  332. bool m_tracked;
  333. bool completed_flag;
  334. bool yellow_name;
  335. int32 m_questFlags;
  336. bool m_hidden;
  337. int32 m_timestamp; // timer for a quest step
  338. int32 m_timerStep; // used for the fail action when timer expires
  339. int16 m_completeCount;
  340. };
  341. class MasterQuestList{
  342. public:
  343. MasterQuestList();
  344. Quest* GetQuest(int32 id, bool copyQuest = true){
  345. if(quests.count(id) > 0)
  346. {
  347. if(copyQuest)
  348. return new Quest(quests[id]);
  349. else
  350. return quests[id];
  351. }
  352. else
  353. return 0;
  354. }
  355. map<int32, Quest*>* GetQuests(){
  356. return &quests;
  357. }
  358. void AddQuest(int32 id, Quest* quest){
  359. quests[id] = quest;
  360. }
  361. void Reload();
  362. void LockQuests();
  363. void UnlockQuests();
  364. private:
  365. Mutex MQuests;
  366. map<int32, Quest*> quests;
  367. };
  368. #endif