Quests.cpp 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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. #include "Quests.h"
  17. #include "../common/ConfigReader.h"
  18. #include "Player.h"
  19. #include "LuaInterface.h"
  20. #include "Spells.h"
  21. #include "RaceTypes/RaceTypes.h"
  22. #include "../common/Log.h"
  23. #ifdef WIN32
  24. #include <time.h>
  25. #else
  26. #include <sys/time.h>
  27. #endif
  28. extern LuaInterface* lua_interface;
  29. extern ConfigReader configReader;
  30. extern MasterFactionList master_faction_list;
  31. extern MasterRaceTypeList race_types_list;
  32. QuestStep::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){
  33. type = in_type;
  34. description = in_description;
  35. ids = 0;
  36. locations = 0;
  37. if(in_task_group)
  38. task_group = string(in_task_group);
  39. if(type != QUEST_STEP_TYPE_LOCATION) {
  40. if (in_ids){
  41. ids = new std::map<int32, bool>();
  42. for(int32 i=0;i<in_ids->size();i++)
  43. ids->insert(make_pair(in_ids->at(i), true));
  44. }
  45. }
  46. else { // location step
  47. if (in_locations) {
  48. locations = new vector<Location>;
  49. for(int32 i=0; i < in_locations->size(); i++)
  50. locations->push_back(in_locations->at(i));
  51. }
  52. }
  53. max_variation = in_max_variation;
  54. quantity = in_quantity;
  55. step_progress = 0;
  56. icon = 11;
  57. id = in_id;
  58. updated = false;
  59. percentage = in_percentage;
  60. usableitemid = in_usableitemid;
  61. }
  62. QuestStep::QuestStep(QuestStep* old_step){
  63. type = old_step->type;
  64. description = old_step->description;
  65. task_group = old_step->task_group;
  66. quantity = old_step->quantity;
  67. max_variation = old_step->max_variation;
  68. step_progress = 0;
  69. ids = 0;
  70. locations = 0;
  71. if(type != QUEST_STEP_TYPE_LOCATION) {
  72. if (old_step->ids){
  73. ids = new std::map<int32, bool>();
  74. std::map<int32, bool>::iterator itr;
  75. for(itr = old_step->ids->begin();itr != old_step->ids->end();itr++)
  76. ids->insert(make_pair(itr->first, itr->second));
  77. }
  78. }
  79. else { // location step
  80. if (old_step->locations) {
  81. locations = new vector<Location>;
  82. for(int32 i=0; i < old_step->locations->size(); i++)
  83. locations->push_back(old_step->locations->at(i));
  84. }
  85. }
  86. icon = old_step->icon;
  87. id = old_step->id;
  88. updated = false;
  89. percentage = old_step->percentage;
  90. usableitemid = old_step->usableitemid;
  91. }
  92. QuestStep::~QuestStep(){
  93. safe_delete(ids);
  94. safe_delete(locations);
  95. }
  96. bool QuestStep::WasUpdated(){
  97. return updated;
  98. }
  99. void QuestStep::WasUpdated(bool val){
  100. updated = val;
  101. }
  102. float QuestStep::GetPercentage(){
  103. return percentage;
  104. }
  105. int32 QuestStep::GetStepID(){
  106. return id;
  107. }
  108. int32 QuestStep::GetItemID() {
  109. return usableitemid;
  110. }
  111. void QuestStep::SetComplete(){
  112. step_progress = quantity;
  113. updated = true;
  114. }
  115. bool QuestStep::Complete(){
  116. return step_progress >= quantity;
  117. }
  118. int8 QuestStep::GetStepType(){
  119. return type;
  120. }
  121. bool QuestStep::CheckStepReferencedID(int32 id){
  122. bool ret = false;
  123. if(ids){
  124. std::map<int32, bool>::iterator itr;
  125. itr = ids->find(id);
  126. if(itr != ids->end())
  127. ret = true;
  128. }
  129. return ret;
  130. }
  131. bool QuestStep::CheckStepKillRaceReqUpdate(Spawn* spawn){
  132. bool ret = false;
  133. if(ids){
  134. std::map<int32, bool>::iterator itr;
  135. for(itr = ids->begin();itr != ids->end();itr++){
  136. int32 curid = itr->first;
  137. if(curid == spawn->GetRace() ||
  138. curid == race_types_list.GetRaceType(spawn->GetModelType()) ||
  139. curid == race_types_list.GetRaceBaseType(spawn->GetModelType())){
  140. ret = true;
  141. break;
  142. }
  143. }
  144. }
  145. return ret;
  146. }
  147. int16 QuestStep::GetIcon(){
  148. return icon;
  149. }
  150. void QuestStep::SetIcon(int16 in_icon){
  151. icon = in_icon;
  152. }
  153. const char* QuestStep::GetUpdateName(){
  154. if(update_name.length() > 0)
  155. return update_name.c_str();
  156. return 0;
  157. }
  158. void QuestStep::SetUpdateName(const char* name){
  159. update_name = string(name);
  160. }
  161. const char* QuestStep::GetUpdateTargetName(){
  162. if(update_target_name.length() > 0)
  163. return update_target_name.c_str();
  164. return 0;
  165. }
  166. void QuestStep::SetUpdateTargetName(const char* name){
  167. update_target_name = string(name);
  168. }
  169. bool QuestStep::CheckStepLocationUpdate(float char_x, float char_y, float char_z, int32 zone_id){
  170. bool ret = false;
  171. if (locations) {
  172. for (int32 i=0; i < locations->size(); i++) {
  173. float total_diff = 0;
  174. Location loc = locations->at(i);
  175. if(loc.zone_id > 0 && loc.zone_id != zone_id)
  176. continue;
  177. float diff = loc.x - char_x; //Check X
  178. if(diff < 0)
  179. diff *= -1;
  180. if(diff <= max_variation) {
  181. total_diff += diff;
  182. diff = loc.z - char_z; //Check Z (we check Z first because it is far more likely to be a much greater variation than y)
  183. if(diff < 0)
  184. diff *= -1;
  185. if(diff <= max_variation) {
  186. total_diff += diff;
  187. if(total_diff <= max_variation) { //Check Total
  188. diff = loc.y - char_y; //Check Y
  189. if(diff < 0)
  190. diff *= -1;
  191. if(diff <= max_variation) {
  192. total_diff += diff;
  193. if(total_diff <= max_variation) { //Check Total
  194. ret = true;
  195. break;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. }
  203. return ret;
  204. }
  205. void QuestStep::SetStepProgress(int32 val){
  206. step_progress = val;
  207. }
  208. int32 QuestStep::AddStepProgress(int32 val){
  209. updated = true;
  210. if (val > (quantity - step_progress)){
  211. step_progress += (quantity - step_progress);
  212. return (quantity - step_progress);
  213. }
  214. else
  215. step_progress += val;
  216. return val;
  217. }
  218. int32 QuestStep::GetStepProgress() {
  219. return step_progress;
  220. }
  221. void QuestStep::ResetTaskGroup(){
  222. task_group = "";
  223. }
  224. const char* QuestStep::GetTaskGroup(){
  225. if(task_group.length() > 0)
  226. return task_group.c_str();
  227. return 0;
  228. }
  229. const char* QuestStep::GetDescription(){
  230. if(description.length() > 0)
  231. return description.c_str();
  232. return 0;
  233. }
  234. void QuestStep::SetDescription(string desc){
  235. description = desc;
  236. }
  237. int16 QuestStep::GetQuestCurrentQuantity(){
  238. return (int16)step_progress;
  239. }
  240. int16 QuestStep::GetQuestNeededQuantity(){
  241. return (int16)quantity;
  242. }
  243. Quest::Quest(int32 in_id){
  244. id = in_id;
  245. reward_status = 0;
  246. quest_giver = 0;
  247. deleted = false;
  248. turned_in = false;
  249. update_needed = true;
  250. player = 0;
  251. return_id = 0;
  252. task_group_num = 1;
  253. prereq_level = 1;
  254. prereq_tslevel = 0;
  255. prereq_max_level = 0;
  256. prereq_max_tslevel = 0;
  257. reward_coins = 0;
  258. reward_coins_max = 0;
  259. completed_flag = false;
  260. has_sent_last_update = false;
  261. enc_level = 0;
  262. reward_exp = 0;
  263. reward_tsexp = 0;
  264. m_featherColor = 0;
  265. m_repeatable = false;
  266. yellow_name = false;
  267. m_hidden = false;
  268. generated_coin = 0;
  269. m_questFlags = 0;
  270. m_timestamp = 0;
  271. m_completeCount = 0;
  272. MQuestSteps.SetName("Quest::MQuestSteps");
  273. MCompletedActions.SetName("Quest::MCompletedActions");
  274. MProgressActions.SetName("Quest::MProgressActions");
  275. MFailedActions.SetName("Quest::failed_Actions");
  276. quest_state_temporary = false;
  277. tmp_reward_status = 0;
  278. tmp_reward_coins = 0;
  279. completed_description = string("");
  280. quest_temporary_description = string("");
  281. quest_shareable_flag = 0;
  282. can_delete_quest = false;
  283. }
  284. Quest::Quest(Quest* old_quest){
  285. task_group_num = 1;
  286. name = old_quest->name;
  287. type = old_quest->type;
  288. zone = old_quest->zone;
  289. level = old_quest->level;
  290. enc_level = old_quest->enc_level;
  291. description = old_quest->description;
  292. prereq_level = old_quest->prereq_level;
  293. prereq_tslevel = old_quest->prereq_tslevel;
  294. prereq_max_level = old_quest->prereq_max_level;
  295. prereq_max_tslevel = old_quest->prereq_max_tslevel;
  296. prereq_quests = old_quest->prereq_quests;
  297. prereq_classes = old_quest->prereq_classes;
  298. prereq_tradeskillclass = old_quest->prereq_tradeskillclass;
  299. prereq_races = old_quest->prereq_races;
  300. prereq_factions = old_quest->prereq_factions;
  301. reward_coins = old_quest->reward_coins;
  302. reward_coins_max = old_quest->reward_coins_max;
  303. reward_factions = old_quest->reward_factions;
  304. reward_status = old_quest->reward_status;
  305. reward_comment = old_quest->reward_comment;
  306. reward_exp = old_quest->reward_exp;
  307. reward_tsexp = old_quest->reward_tsexp;
  308. generated_coin = old_quest->generated_coin;
  309. completed_flag = old_quest->completed_flag;
  310. has_sent_last_update = old_quest->has_sent_last_update;
  311. yellow_name = old_quest->yellow_name;
  312. m_questFlags = old_quest->m_questFlags;
  313. id = old_quest->id;
  314. vector<QuestStep*> quest_steps;
  315. for(int32 i=0;i<old_quest->quest_steps.size();i++)
  316. AddQuestStep(new QuestStep(old_quest->quest_steps[i]));
  317. for(int32 i=0;i<old_quest->prereq_items.size();i++)
  318. AddPrereqItem(new Item(old_quest->prereq_items[i]));
  319. for(int32 i=0;i<old_quest->reward_items.size();i++)
  320. AddRewardItem(new Item(old_quest->reward_items[i]));
  321. for(int32 i=0;i<old_quest->selectable_reward_items.size();i++)
  322. AddSelectableRewardItem(new Item(old_quest->selectable_reward_items[i]));
  323. complete_actions = old_quest->complete_actions;
  324. progress_actions = old_quest->progress_actions;
  325. failed_actions = old_quest->failed_actions;
  326. time_t raw;
  327. struct tm *newtime;
  328. time(&raw);
  329. newtime = localtime(&raw);
  330. day = newtime->tm_mday;
  331. month = newtime->tm_mon + 1;
  332. year = newtime->tm_year - 100;
  333. visible = 1;
  334. step_updates.clear();
  335. step_failures.clear();
  336. completed_description = old_quest->completed_description;
  337. deleted = old_quest->deleted;
  338. update_needed = old_quest->update_needed;
  339. turned_in = old_quest->turned_in;
  340. quest_giver = old_quest->quest_giver;
  341. player = old_quest->player;
  342. return_id = old_quest->return_id;
  343. m_featherColor = old_quest->m_featherColor;
  344. m_repeatable = old_quest->IsRepeatable();
  345. m_hidden = false;
  346. m_timestamp = 0;
  347. m_completeCount = old_quest->GetCompleteCount();
  348. MQuestSteps.SetName("Quest::MQuestSteps");
  349. MProgressActions.SetName("Quest::MProgressActions");
  350. MCompletedActions.SetName("Quest::MCompletedActions");
  351. quest_state_temporary = false;
  352. tmp_reward_status = 0;
  353. tmp_reward_coins = 0;
  354. quest_temporary_description = string("");
  355. quest_shareable_flag = old_quest->GetQuestShareableFlag();
  356. can_delete_quest = old_quest->CanDeleteQuest();
  357. }
  358. Quest::~Quest(){
  359. for(int32 i=0;i<quest_steps.size();i++)
  360. safe_delete(quest_steps[i]);
  361. for(int32 i=0;i<prereq_items.size();i++)
  362. safe_delete(prereq_items[i]);
  363. for(int32 i=0;i<reward_items.size();i++)
  364. safe_delete(reward_items[i]);
  365. for(int32 i=0;i<tmp_reward_items.size();i++)
  366. safe_delete(tmp_reward_items[i]);
  367. for(int32 i=0;i<selectable_reward_items.size();i++)
  368. safe_delete(selectable_reward_items[i]);
  369. quest_step_map.clear();
  370. task_group_order.clear();
  371. task_group.clear();
  372. complete_actions.clear();
  373. progress_actions.clear();
  374. failed_actions.clear();
  375. }
  376. void Quest::RegisterQuest(string in_name, string in_type, string in_zone, int8 in_level, string in_desc){
  377. name = in_name;
  378. type = in_type;
  379. zone = in_zone;
  380. level = in_level;
  381. description = in_desc;
  382. }
  383. const char* Quest::GetDescription(){
  384. return description.c_str();
  385. }
  386. const char* Quest::GetName(){
  387. return name.c_str();
  388. }
  389. const char* Quest::GetType(){
  390. return type.c_str();
  391. }
  392. void Quest::SetZone(string in_zone) {
  393. zone = in_zone;
  394. }
  395. const char* Quest::GetZone(){
  396. return zone.c_str();
  397. }
  398. int8 Quest::GetLevel(){
  399. return level;
  400. }
  401. int8 Quest::GetDay(){
  402. return day;
  403. }
  404. int8 Quest::GetMonth(){
  405. return month;
  406. }
  407. int8 Quest::GetYear(){
  408. return year;
  409. }
  410. int32 Quest::GetStatusPoints(){
  411. return reward_status;
  412. }
  413. void Quest::SetDay(int8 value){
  414. day = value;
  415. }
  416. void Quest::SetMonth(int8 value){
  417. month = value;
  418. }
  419. void Quest::SetYear(int8 value){
  420. year = value;
  421. }
  422. QuestStep* Quest::GetQuestStep(int32 step_id){
  423. QuestStep* ret = 0;
  424. MQuestSteps.lock();
  425. for(int32 i=0;i<quest_steps.size(); i++){
  426. if(quest_steps[i] && quest_steps[i]->GetStepID() == step_id){
  427. ret = quest_steps[i];
  428. break;
  429. }
  430. }
  431. MQuestSteps.unlock();
  432. return ret;
  433. }
  434. vector<QuestStep*>* Quest::GetQuestSteps(){
  435. return &quest_steps;
  436. }
  437. vector<QuestStep*>* Quest::GetQuestUpdates(){
  438. return &step_updates;
  439. }
  440. vector<QuestStep*>* Quest::GetQuestFailures(){
  441. return &step_failures;
  442. }
  443. bool Quest::CheckQuestReferencedSpawns(Spawn* spawn){
  444. QuestStep* step = 0;
  445. bool ret = false;
  446. int32 spawnDBID = spawn->GetDatabaseID();
  447. MQuestSteps.lock();
  448. for(int32 i=0;i<quest_steps.size(); i++){
  449. step = quest_steps[i];
  450. if(!step || step->Complete())
  451. continue;
  452. switch(step->GetStepType())
  453. {
  454. case QUEST_STEP_TYPE_KILL:
  455. case QUEST_STEP_TYPE_NORMAL: {
  456. if(step->CheckStepReferencedID(spawnDBID))
  457. ret = true;
  458. break;
  459. }
  460. case QUEST_STEP_TYPE_KILL_RACE_REQ: {
  461. if(step->CheckStepKillRaceReqUpdate(spawn))
  462. ret = true;
  463. break;
  464. }
  465. }
  466. }
  467. MQuestSteps.unlock();
  468. return ret;
  469. }
  470. bool Quest::CheckQuestKillUpdate(Spawn* spawn, bool update){
  471. QuestStep* step = 0;
  472. bool ret = false;
  473. int32 id = spawn->GetDatabaseID();
  474. int32 prog_added = 0;
  475. MQuestSteps.lock();
  476. for(int32 i=0;i<quest_steps.size(); i++){
  477. step = quest_steps[i];
  478. if(!step)
  479. continue;
  480. if((step->GetStepType() == QUEST_STEP_TYPE_KILL && !step->Complete() && step->CheckStepReferencedID(id)) ||
  481. (step->GetStepType() == QUEST_STEP_TYPE_KILL_RACE_REQ && !step->Complete() && step->CheckStepKillRaceReqUpdate(spawn)))
  482. {
  483. if (update == true) {
  484. bool passed = true;
  485. if (step->GetPercentage() < 100)
  486. passed = (step->GetPercentage() > MakeRandomFloat(0, 100));
  487. if (passed) {
  488. //Call the progress action function with the total amount of progress actually granted
  489. prog_added = step->AddStepProgress(1);
  490. if (lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  491. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  492. step_updates.push_back(step);
  493. step->SetUpdateName(spawn->GetName());
  494. ret = true;
  495. }
  496. else
  497. step_failures.push_back(step);
  498. }
  499. else {
  500. ret = true;
  501. }
  502. }
  503. }
  504. MQuestSteps.unlock();
  505. if(ret && update)
  506. SetSaveNeeded(true);
  507. return ret;
  508. }
  509. int16 Quest::GetTaskGroupStep(){
  510. int16 ret = task_group_order.size();
  511. map<int16, string>::iterator itr;
  512. MQuestSteps.lock();
  513. for(itr = task_group_order.begin(); itr != task_group_order.end(); itr++){
  514. if(task_group.count(itr->second) > 0){
  515. vector<QuestStep*> tmp_steps = task_group[itr->second];
  516. bool complete = true;
  517. for(int32 i=0;i<tmp_steps.size();i++){
  518. if(tmp_steps[i]->Complete() == false)
  519. complete = false;
  520. }
  521. if(!complete){
  522. if(itr->first < ret)
  523. ret = itr->first;
  524. }
  525. }
  526. }
  527. MQuestSteps.unlock();
  528. return ret;
  529. }
  530. bool Quest::SetStepComplete(int32 step){
  531. QuestStep* quest_step = 0;
  532. bool ret = false;
  533. MQuestSteps.lock();
  534. for(int32 i=0;i<quest_steps.size(); i++){
  535. quest_step = quest_steps[i];
  536. if(quest_step && quest_step->GetStepID() == step){
  537. quest_step->SetComplete();
  538. step_updates.push_back(quest_step);
  539. ret = true;
  540. break;
  541. }
  542. }
  543. MQuestSteps.unlock();
  544. if (ret) {
  545. SetSaveNeeded(true);
  546. }
  547. return ret;
  548. }
  549. bool Quest::AddStepProgress(int32 step_id, int32 progress) {
  550. QuestStep* quest_step = 0;
  551. bool ret = false;
  552. int32 prog_added = 0;
  553. MQuestSteps.lock();
  554. for (int32 i = 0; i < quest_steps.size(); i++) {
  555. quest_step = quest_steps[i];
  556. if (quest_step && quest_step->GetStepID() == step_id) {
  557. bool passed = true;
  558. if(quest_step->GetPercentage() < 100 && quest_step->GetPercentage() != 0)
  559. passed = (quest_step->GetPercentage() > MakeRandomFloat(0, 100));
  560. if(passed) {
  561. //Call the progress action function with the total amount of progress actually granted
  562. prog_added = quest_step->AddStepProgress(progress);
  563. if(lua_interface && progress_actions[step_id].length() > 0 && prog_added > 0)
  564. lua_interface->CallQuestFunction(this, progress_actions[step_id].c_str(), player, prog_added);
  565. step_updates.push_back(quest_step);
  566. ret = true;
  567. break;
  568. }
  569. else {
  570. step_failures.push_back(quest_step);
  571. break;
  572. }
  573. }
  574. }
  575. MQuestSteps.unlock();
  576. if(ret)
  577. SetSaveNeeded(true);
  578. return ret;
  579. }
  580. int32 Quest::GetStepProgress(int32 step_id) {
  581. QuestStep* quest_step = 0;
  582. int32 ret = 0;
  583. MQuestSteps.lock();
  584. for (int32 i = 0; i < quest_steps.size(); i++) {
  585. quest_step = quest_steps[i];
  586. if (quest_step && quest_step->GetStepID() == step_id) {
  587. ret = quest_step->GetStepProgress();
  588. break;
  589. }
  590. }
  591. MQuestSteps.unlock();
  592. return ret;
  593. }
  594. bool Quest::GetQuestStepCompleted(int32 step_id){
  595. bool ret = false;
  596. QuestStep* quest_step = 0;
  597. MQuestSteps.lock();
  598. for(int32 i=0;i<quest_steps.size(); i++){
  599. quest_step = quest_steps[i];
  600. if(quest_step && quest_step->GetStepID() == step_id && quest_step->Complete()){
  601. ret = true;
  602. break;
  603. }
  604. }
  605. MQuestSteps.unlock();
  606. return ret;
  607. }
  608. int16 Quest::GetQuestStep(){
  609. int16 ret = 0;
  610. QuestStep* step = 0;
  611. MQuestSteps.lock();
  612. for(int32 i=0;i<quest_steps.size(); i++){
  613. step = quest_steps[i];
  614. if(step && !step->Complete()){
  615. ret = step->GetStepID();
  616. break;
  617. }
  618. }
  619. MQuestSteps.unlock();
  620. return ret;
  621. }
  622. bool Quest::QuestStepIsActive(int16 quest_step_id) {
  623. bool ret = false;
  624. QuestStep* step = 0;
  625. MQuestSteps.lock();
  626. for (int32 i = 0; i < quest_steps.size(); i++) {
  627. step = quest_steps[i];
  628. if (step->GetStepID() == quest_step_id && !step->Complete()) {
  629. ret = true;
  630. break;
  631. }
  632. }
  633. MQuestSteps.unlock();
  634. return ret;
  635. }
  636. bool Quest::CheckQuestChatUpdate(int32 id, bool update){
  637. QuestStep* step = 0;
  638. bool ret = false;
  639. int32 prog_added = 0;
  640. MQuestSteps.lock();
  641. for(int32 i=0;i<quest_steps.size(); i++){
  642. step = quest_steps[i];
  643. if(step && step->GetStepType() == QUEST_STEP_TYPE_CHAT && !step->Complete() && step->CheckStepReferencedID(id)){
  644. if(update){
  645. //Call the progress action function with the total amount of progress actually granted
  646. prog_added = step->AddStepProgress(1);
  647. if(lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  648. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  649. step_updates.push_back(step);
  650. }
  651. ret = true;
  652. }
  653. }
  654. MQuestSteps.unlock();
  655. if(ret)
  656. SetSaveNeeded(true);
  657. return ret;
  658. }
  659. bool Quest::CheckQuestItemUpdate(int32 id, int8 quantity){
  660. QuestStep* step = 0;
  661. bool ret = false;
  662. int32 prog_added = 0;
  663. MQuestSteps.lock();
  664. for(int32 i=0;i<quest_steps.size(); i++){
  665. step = quest_steps[i];
  666. if(step && step->GetStepType() == QUEST_STEP_TYPE_OBTAIN_ITEM && !step->Complete() && step->CheckStepReferencedID(id)){
  667. bool passed = true;
  668. if(step->GetPercentage() < 100)
  669. passed = (step->GetPercentage() > MakeRandomFloat(0, 100));
  670. if(passed){
  671. //Call the progress action function with the total amount of progress actually granted
  672. prog_added = step->AddStepProgress(quantity);
  673. if(lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  674. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  675. step_updates.push_back(step);
  676. ret = true;
  677. }
  678. else
  679. step_failures.push_back(step);
  680. }
  681. }
  682. MQuestSteps.unlock();
  683. if(ret)
  684. SetSaveNeeded(true);
  685. return ret;
  686. }
  687. bool Quest::CheckQuestRefIDUpdate(int32 id, int32 quantity){
  688. QuestStep* step = 0;
  689. bool ret = false;
  690. int32 prog_added = 0;
  691. MQuestSteps.lock();
  692. for(int32 i=0;i<quest_steps.size(); i++){
  693. step = quest_steps[i];
  694. if(step)
  695. {
  696. if(step->Complete())
  697. continue;
  698. switch(step->GetStepType()) {
  699. case QUEST_STEP_TYPE_HARVEST:
  700. case QUEST_STEP_TYPE_CRAFT: {
  701. map<int32, bool>* id_list = step->GetUpdateIDs();
  702. map<int32, bool>::iterator itr;
  703. for(itr = id_list->begin();itr != id_list->end(); itr++){
  704. int32 update_id = itr->first;
  705. if(update_id == id){
  706. bool passed = true;
  707. if(step->GetPercentage() < 100)
  708. passed = (step->GetPercentage() > MakeRandomFloat(0, 100));
  709. if(passed){
  710. //Call the progress action function with the total amount of progress actually granted
  711. prog_added = step->AddStepProgress(quantity);
  712. if(lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  713. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  714. step_updates.push_back(step);
  715. }
  716. else
  717. step_failures.push_back(step);
  718. ret = true;
  719. }
  720. }
  721. break;
  722. }
  723. }
  724. }
  725. }
  726. MQuestSteps.unlock();
  727. if(ret)
  728. SetSaveNeeded(true);
  729. return ret;
  730. }
  731. bool Quest::CheckQuestLocationUpdate(float char_x, float char_y, float char_z, int32 zone_id){
  732. QuestStep* step = 0;
  733. bool ret = false;
  734. int32 prog_added = 0;
  735. MQuestSteps.lock();
  736. for(int32 i=0;i<quest_steps.size(); i++){
  737. step = quest_steps[i];
  738. if(step && step->GetStepType() == QUEST_STEP_TYPE_LOCATION && !step->Complete() && step->CheckStepLocationUpdate(char_x, char_y, char_z, zone_id)){
  739. //Call the progress action function with the total amount of progress actually granted
  740. prog_added = step->AddStepProgress(1);
  741. if(lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  742. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  743. step_updates.push_back(step);
  744. ret = true;
  745. }
  746. }
  747. MQuestSteps.unlock();
  748. if(ret)
  749. SetSaveNeeded(true);
  750. return ret;
  751. }
  752. bool Quest::CheckQuestSpellUpdate(Spell* spell){
  753. QuestStep* step = 0;
  754. bool ret = false;
  755. int32 id = spell->GetSpellID();
  756. int32 prog_added = 0;
  757. MQuestSteps.lock();
  758. for (int32 i = 0; i < quest_steps.size(); i++) {
  759. step = quest_steps[i];
  760. if(step && step->GetStepType() == QUEST_STEP_TYPE_SPELL && !step->Complete() && step->CheckStepReferencedID(id)){
  761. bool passed = true;
  762. if(step->GetPercentage() < 100)
  763. passed = (step->GetPercentage() > MakeRandomFloat(0, 100));
  764. if(passed) {
  765. //Call the progress action function with the total amount of progress actually granted
  766. prog_added = step->AddStepProgress(1);
  767. if(lua_interface && progress_actions[step->GetStepID()].length() > 0 && prog_added > 0)
  768. lua_interface->CallQuestFunction(this, progress_actions[step->GetStepID()].c_str(), player, prog_added);
  769. step_updates.push_back(step);
  770. //step->SetUpdateName(spawn->GetName());
  771. ret = true;
  772. }
  773. else
  774. step_failures.push_back(step);
  775. }
  776. }
  777. MQuestSteps.unlock();
  778. if (ret)
  779. SetSaveNeeded(true);
  780. return ret;
  781. }
  782. void Quest::SetQuestID(int32 in_id){
  783. id = in_id;
  784. }
  785. EQ2Packet* Quest::OfferQuest(int16 version, Player* player){
  786. PacketStruct* packet = configReader.getStruct("WS_OfferQuest", version);
  787. if(packet){
  788. packet->setDataByName("reward", "Quest Reward!");
  789. packet->setDataByName("title", name.c_str());
  790. packet->setDataByName("description", description.c_str());
  791. if(type == "Tradeskill")
  792. packet->setDataByName("quest_difficulty", player->GetTSArrowColor(level));
  793. else
  794. packet->setDataByName("quest_difficulty", player->GetArrowColor(level));
  795. packet->setDataByName("encounter_level", enc_level);
  796. packet->setDataByName("unknown0", 255);
  797. if (version >= 1188)
  798. packet->setDataByName("unknown4b", 1);
  799. else
  800. packet->setDataByName("unknown", 5);
  801. packet->setDataByName("level", level);
  802. if(reward_coins > 0){
  803. packet->setDataByName("min_coin", reward_coins);
  804. if (reward_coins_max)
  805. packet->setDataByName("max_coin", reward_coins_max);
  806. }
  807. packet->setDataByName("status_points", reward_status);
  808. if(reward_comment.length() > 0)
  809. packet->setDataByName("text", reward_comment.c_str());
  810. if(reward_items.size() > 0){
  811. player->GetClient()->PopulateQuestRewardItems(&reward_items, packet);
  812. }
  813. if(selectable_reward_items.size() > 0){
  814. player->GetClient()->PopulateQuestRewardItems(&selectable_reward_items, packet, std::string("num_select_rewards"),
  815. std::string("select_reward_id"), std::string("select_item"));
  816. }
  817. map<int32, sint32>* reward_factions = GetRewardFactions();
  818. if (reward_factions && reward_factions->size() > 0) {
  819. packet->setArrayLengthByName("num_factions", reward_factions->size());
  820. map<int32, sint32>::iterator itr;
  821. int16 index = 0;
  822. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  823. int32 faction_id = itr->first;
  824. sint32 amount = itr->second;
  825. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  826. if (faction_name) {
  827. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  828. packet->setArrayDataByName("amount", amount, index);
  829. }
  830. index++;
  831. }
  832. }
  833. char accept[35] = {0};
  834. char decline[35] = {0};
  835. sprintf(accept, "q_accept_pending_quest %u", id);
  836. sprintf(decline, "q_deny_pending_quest %u", id);
  837. packet->setDataByName("accept_command", accept);
  838. packet->setDataByName("decline_command", decline);
  839. EQ2Packet* outapp = packet->serialize();
  840. #if EQDEBUG >= 9
  841. DumpPacket(outapp);
  842. #endif
  843. safe_delete(packet);
  844. return outapp;
  845. }
  846. return 0;
  847. }
  848. int32 Quest::GetQuestID(){
  849. return id;
  850. }
  851. int8 Quest::GetQuestLevel(){
  852. return level;
  853. }
  854. int8 Quest::GetVisible(){
  855. return visible;
  856. }
  857. EQ2Packet* Quest::QuestJournalReply(int16 version, int32 player_crc, Player* player, QuestStep* updateStep, int8 update_count, bool old_completed_quest, bool quest_failure, bool display_quest_helper) {
  858. PacketStruct* packet = configReader.getStruct("WS_QuestJournalReply", version);
  859. if (packet) {
  860. packet->setDataByName("quest_id", id);
  861. packet->setDataByName("player_crc", player_crc);
  862. packet->setDataByName("name", name.c_str());
  863. packet->setDataByName("description", description.c_str());
  864. packet->setDataByName("zone", zone.c_str());
  865. packet->setDataByName("type", type.c_str());
  866. packet->setDataByName("complete_header", "To complete this quest, I must do the following tasks:");
  867. packet->setDataByName("day", day);
  868. packet->setDataByName("month", month);
  869. packet->setDataByName("year", year);
  870. packet->setDataByName("level", level);
  871. packet->setDataByName("visible", 1);
  872. /* To get the quest timer to work you need to set unknown, index 4 to 1 and the time stamp
  873. to the current time + the time in seconds you want to show in the journal*/
  874. if (m_timestamp > 0) {
  875. packet->setDataByName("unknown", 1, 4);
  876. packet->setDataByName("time_stamp", m_timestamp);
  877. }
  878. int8 difficulty = 0;
  879. if (type == "Tradeskill")
  880. difficulty = player->GetTSArrowColor(level);
  881. else
  882. difficulty = player->GetArrowColor(level);
  883. packet->setDataByName("difficulty", difficulty);
  884. if (enc_level > 4)
  885. packet->setDataByName("encounter_level", enc_level);
  886. else
  887. packet->setDataByName("encounter_level", 4);
  888. packet->setDataByName("unknown2b", 4);
  889. int16 task_groups_completed = 0;
  890. int16 total_task_groups = 0;
  891. vector<QuestStep*> primary_order;
  892. vector<QuestStep*> secondary_order;
  893. packet->setDataByName("unknown8", 1, 1);
  894. packet->setSubstructArrayDataByName("reward_data", "unknown8", 1, 1);
  895. packet->setDataByName("unknown8b", 255);
  896. if (version >= 1096) {
  897. packet->setDataByName("deletable", (int8)CanDeleteQuest());
  898. packet->setDataByName("shareable", (int8)CanShareQuestCriteria(player->GetClient(),false));
  899. }
  900. else {
  901. packet->setDataByName("unknown3", 1, 5); // this supposed to be CanDeleteQuest?
  902. packet->setDataByName("unknown3", 1, 6); // this supposed to be CanShareQuestCriteria?
  903. }
  904. int8 map_data_count = 0;
  905. packet->setDataByName("bullets", 1);
  906. if (old_completed_quest) {
  907. if (version >= 1096 || version == 546) {
  908. packet->setDataByName("complete", 1);
  909. packet->setDataByName("complete2", 1);
  910. packet->setDataByName("complete3", 1);
  911. }
  912. else {
  913. packet->setDataByName("unknown3", 1);
  914. packet->setDataByName("unknown3", 1, 1);
  915. packet->setDataByName("unknown3", 1, 2);
  916. packet->setDataByName("unknown3", 1, 5);
  917. packet->setDataByName("unknown3", 1, 6);
  918. }
  919. }
  920. // must always send for newer clients like AoM or else crash!
  921. else if (GetCompleted() && ((version >= 1096) || (version == 546 && HasSentLastUpdate()))) { //need to send last quest update before erasing all progress of the quest
  922. packet->setDataByName("complete", 1);
  923. packet->setDataByName("complete2", 1);
  924. packet->setDataByName("complete3", 1);
  925. packet->setDataByName("num_task_groups", 1);
  926. packet->setArrayDataByName("task_group", completed_description.c_str());
  927. packet->setArrayDataByName("unknown4", 0xFFFFFFFF);
  928. packet->setDataByName("onscreen_update", 1);
  929. packet->setDataByName("update_task_number", 1);
  930. packet->setDataByName("onscreen_update", 1);
  931. packet->setDataByName("onscreen_update_text", completed_description.c_str());
  932. if (updateStep)
  933. packet->setDataByName("onscreen_update_icon", updateStep->GetIcon());
  934. else
  935. packet->setDataByName("onscreen_update_icon", 0);
  936. // Is Heritage or db entry for classic eq quest turn in sound
  937. packet->setDataByName("classic_eq_sound", 0);
  938. // No clue what this does, set it to mach live packets
  939. packet->setDataByName("unknown12b", 1, 0);
  940. }
  941. else {
  942. map<QuestStep*, string> task_group_names;
  943. map<int16, string>::iterator order_itr;
  944. vector<QuestStep*>* steps = 0;
  945. MQuestSteps.lock();
  946. for (order_itr = task_group_order.begin(); order_itr != task_group_order.end(); order_itr++) {
  947. //The following is kind of crazy, but necessary to order the quests with completed ones first. This is to make the packet like live's packet
  948. //for(itr = task_group.begin(); itr != task_group.end(); itr++){
  949. bool complete = true;
  950. if (task_group.count(order_itr->second) > 0) {
  951. steps = &(task_group[order_itr->second]);
  952. for (int32 i = 0; i < steps->size(); i++) {
  953. if (steps->at(i)->Complete() == false)
  954. complete = false;
  955. }
  956. if (complete) {
  957. for (int32 i = 0; i < steps->size(); i++) {
  958. if (i == 0)
  959. task_group_names[steps->at(i)] = order_itr->second;
  960. primary_order.push_back(steps->at(i));
  961. }
  962. task_groups_completed++;
  963. total_task_groups++;
  964. }
  965. else {
  966. for (int32 i = 0; i < steps->size(); i++) {
  967. if (i == 0)
  968. task_group_names[steps->at(i)] = order_itr->second;
  969. secondary_order.push_back(steps->at(i));
  970. }
  971. total_task_groups++;
  972. }
  973. }
  974. }
  975. packet->setDataByName("task_groups_completed", task_groups_completed);
  976. packet->setArrayLengthByName("num_task_groups", total_task_groups);
  977. if (IsTracked() /*display_quest_helper*/ && task_groups_completed < total_task_groups)
  978. packet->setDataByName("display_quest_helper", 1);
  979. int16 index = 0;
  980. QuestStep* step = 0;
  981. for (int32 i = 0; i < primary_order.size(); i++) {
  982. if (primary_order[i]->GetTaskGroup()) {
  983. if (task_group_names.count(primary_order[i]) > 0)
  984. packet->setArrayDataByName("task_group", primary_order[i]->GetTaskGroup(), index);
  985. else
  986. continue;
  987. packet->setSubArrayLengthByName("num_tasks", task_group[primary_order[i]->GetTaskGroup()].size(), index);
  988. packet->setSubArrayLengthByName("num_updates", task_group[primary_order[i]->GetTaskGroup()].size(), index);
  989. map_data_count += task_group[primary_order[i]->GetTaskGroup()].size();
  990. if (task_group[primary_order[i]->GetTaskGroup()].size() > 0) {
  991. packet->setDataByName("bullets", 1);
  992. }
  993. for (int32 x = 0; x < task_group[primary_order[i]->GetTaskGroup()].size(); x++) {
  994. step = task_group[primary_order[i]->GetTaskGroup()].at(x);
  995. if (!step)
  996. continue;
  997. if (step->GetDescription())
  998. packet->setSubArrayDataByName("task", step->GetDescription(), index, x);
  999. packet->setSubArrayDataByName("task_completed", 1, index, x);
  1000. packet->setSubArrayDataByName("index", x, index, x);
  1001. packet->setSubArrayDataByName("update_currentval", step->GetQuestCurrentQuantity(), index, x);
  1002. if(step->GetQuestCurrentQuantity() > 0)
  1003. packet->setDataByName("journal_updated", 1);
  1004. packet->setSubArrayDataByName("update_maxval", step->GetQuestNeededQuantity(), index, x);
  1005. if (step->GetUpdateTargetName())
  1006. packet->setSubArrayDataByName("update_target_name", step->GetUpdateTargetName(), index, x);
  1007. packet->setSubArrayDataByName("icon", step->GetIcon(), index, x);
  1008. if (updateStep && step == updateStep) {
  1009. packet->setDataByName("update", 1);
  1010. // packet->setDataByName("unknown5d", 1);
  1011. if (!quest_failure)
  1012. packet->setDataByName("onscreen_update", 1);
  1013. packet->setDataByName("onscreen_update_count", update_count);
  1014. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1015. if (step->GetUpdateName())
  1016. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1017. else if (step->GetDescription())
  1018. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1019. packet->setDataByName("update_task_number", x);
  1020. packet->setDataByName("update_taskgroup_number", index);
  1021. }
  1022. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, x);
  1023. }
  1024. index++;
  1025. }
  1026. else {
  1027. if (task_group_names.count(primary_order[i]) > 0) {
  1028. step = primary_order[i];
  1029. if (updateStep && step == updateStep) {
  1030. packet->setDataByName("update", 1);
  1031. // packet->setDataByName("unknown5d", 1);
  1032. if (!quest_failure)
  1033. packet->setDataByName("onscreen_update", 1);
  1034. packet->setDataByName("onscreen_update_count", update_count);
  1035. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1036. if (step->GetUpdateName())
  1037. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1038. else if (step->GetDescription())
  1039. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1040. packet->setDataByName("update_task_number", i);
  1041. packet->setDataByName("update_taskgroup_number", index);
  1042. }
  1043. packet->setArrayDataByName("task_group", primary_order[i]->GetDescription(), index);
  1044. index++;
  1045. }
  1046. }
  1047. }
  1048. for (int32 i = 0; i < secondary_order.size(); i++) {
  1049. if (secondary_order[i]->GetTaskGroup()) {
  1050. if (task_group_names.count(secondary_order[i]) > 0)
  1051. packet->setArrayDataByName("task_group", secondary_order[i]->GetTaskGroup(), index);
  1052. else
  1053. continue;
  1054. packet->setSubArrayLengthByName("num_tasks", task_group[secondary_order[i]->GetTaskGroup()].size(), index);
  1055. packet->setSubArrayLengthByName("num_updates", task_group[secondary_order[i]->GetTaskGroup()].size(), index);
  1056. map_data_count += task_group[secondary_order[i]->GetTaskGroup()].size();
  1057. if (task_group[secondary_order[i]->GetTaskGroup()].size() > 0)
  1058. packet->setDataByName("bullets", 1);
  1059. for (int32 x = 0; x < task_group[secondary_order[i]->GetTaskGroup()].size(); x++) {
  1060. step = task_group[secondary_order[i]->GetTaskGroup()].at(x);
  1061. if (!step)
  1062. continue;
  1063. if (step->GetDescription())
  1064. packet->setSubArrayDataByName("task", step->GetDescription(), index, x);
  1065. if (step->Complete())
  1066. packet->setSubArrayDataByName("task_completed", 1, index, x);
  1067. else
  1068. packet->setSubArrayDataByName("task_completed", 0, index, x);
  1069. packet->setSubArrayDataByName("index", x, index, x);
  1070. packet->setSubArrayDataByName("update_currentval", step->GetQuestCurrentQuantity(), index, x);
  1071. if (step->GetQuestCurrentQuantity() > 0)
  1072. packet->setDataByName("journal_updated", 1);
  1073. packet->setSubArrayDataByName("update_maxval", step->GetQuestNeededQuantity(), index, x);
  1074. packet->setSubArrayDataByName("icon", step->GetIcon(), index, x);
  1075. if (step->GetUpdateTargetName())
  1076. packet->setSubArrayDataByName("update_target_name", step->GetUpdateTargetName(), index, x);
  1077. if (updateStep && step == updateStep) {
  1078. packet->setDataByName("update", 1);
  1079. if (!quest_failure)
  1080. packet->setDataByName("onscreen_update", 1);
  1081. packet->setDataByName("onscreen_update_count", update_count);
  1082. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1083. if (step->GetUpdateName())
  1084. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1085. else if (step->GetDescription())
  1086. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1087. if (quest_failure)
  1088. packet->setDataByName("onscreen_update_text2", "failed");
  1089. packet->setDataByName("update_task_number", x);
  1090. packet->setDataByName("update_taskgroup_number", index);
  1091. }
  1092. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, x);
  1093. }
  1094. index++;
  1095. }
  1096. else {
  1097. if (task_group_names.count(secondary_order[i]) > 0) {
  1098. step = secondary_order[i];
  1099. if (updateStep && step == updateStep) {
  1100. packet->setDataByName("update", 1);
  1101. if (!quest_failure)
  1102. packet->setDataByName("onscreen_update", 1);
  1103. packet->setDataByName("onscreen_update_count", update_count);
  1104. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1105. if (step->GetUpdateName())
  1106. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1107. else if (step->GetDescription())
  1108. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1109. packet->setDataByName("update_task_number", i);
  1110. packet->setDataByName("update_taskgroup_number", index);
  1111. }
  1112. if (task_group_names.size() == 1) {
  1113. packet->setSubArrayLengthByName("num_tasks", 1, index);
  1114. packet->setSubArrayDataByName("task", secondary_order[i]->GetDescription(), index);
  1115. packet->setDataByName("bullets", 0);
  1116. }
  1117. else
  1118. packet->setArrayDataByName("task_group", secondary_order[i]->GetDescription(), index);
  1119. index++;
  1120. }
  1121. }
  1122. }
  1123. for (int16 i = 0; i < total_task_groups; i++)
  1124. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, i);
  1125. if (step && step->GetItemID() > 0) {
  1126. packet->setArrayLengthByName("usable_item_count", 1);
  1127. Item* item = player->GetPlayerItemList()->GetItemFromID(step->GetItemID(), 1);
  1128. if (item) {
  1129. packet->setArrayDataByName("item_id", item->details.item_id, 0);
  1130. packet->setArrayDataByName("item_unique_id", item->details.unique_id, 0);
  1131. packet->setArrayDataByName("item_icon", item->details.icon, 0);
  1132. packet->setArrayDataByName("unknown2", 0xFFFFFFFF, 0);//item->details.item_id, 0);
  1133. }
  1134. }
  1135. if (GetCompleted()) { //mark the last update as being sent, next time we send the quest reply, it will only be a brief portion
  1136. SetSentLastUpdate(true);
  1137. }
  1138. }
  1139. MQuestSteps.unlock();
  1140. string reward_str = "";
  1141. if (version >= 1096 || version == 546)
  1142. reward_str = "reward_data_";
  1143. string tmp = reward_str + "reward";
  1144. packet->setDataByName(tmp.c_str(), "Quest Reward!");
  1145. if (reward_coins > 0) {
  1146. tmp = reward_str + "min_coin";
  1147. packet->setDataByName(tmp.c_str(), reward_coins);
  1148. tmp = reward_str + "max_coin";
  1149. packet->setDataByName(tmp.c_str(), reward_coins_max);
  1150. }
  1151. tmp = reward_str + "status_points";
  1152. packet->setDataByName(tmp.c_str(), reward_status);
  1153. if (reward_comment.length() > 0) {
  1154. tmp = reward_str + "text";
  1155. packet->setDataByName(tmp.c_str(), reward_comment.c_str());
  1156. }
  1157. if (reward_items.size() > 0) {
  1158. tmp = reward_str + "num_rewards";
  1159. packet->setArrayLengthByName(tmp.c_str(), reward_items.size());
  1160. Item* item = 0;
  1161. for (int32 i = 0; i < reward_items.size(); i++) {
  1162. item = reward_items[i];
  1163. packet->setArrayDataByName("reward_id", item->details.item_id, i);
  1164. if (version < 860)
  1165. packet->setItemArrayDataByName("item", item, player, i, 0, -1);
  1166. else if (version < 1193)
  1167. packet->setItemArrayDataByName("item", item, player, i);
  1168. else
  1169. packet->setItemArrayDataByName("item", item, player, i, 0, 2);
  1170. }
  1171. }
  1172. if (selectable_reward_items.size() > 0) {
  1173. tmp = reward_str + "num_select_rewards";
  1174. packet->setArrayLengthByName(tmp.c_str(), selectable_reward_items.size());
  1175. Item* item = 0;
  1176. for (int32 i = 0; i < selectable_reward_items.size(); i++) {
  1177. item = selectable_reward_items[i];
  1178. packet->setArrayDataByName("select_reward_id", item->details.item_id, i);
  1179. if (version < 860)
  1180. packet->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  1181. else if (version < 1193)
  1182. packet->setItemArrayDataByName("select_item", item, player, i);
  1183. else
  1184. packet->setItemArrayDataByName("select_item", item, player, i, 0, 2);
  1185. }
  1186. }
  1187. map<int32, sint32>* reward_factions = GetRewardFactions();
  1188. if (reward_factions && reward_factions->size() > 0) {
  1189. tmp = reward_str + "num_factions";
  1190. packet->setArrayLengthByName(tmp.c_str(), reward_factions->size());
  1191. map<int32, sint32>::iterator itr;
  1192. int16 index = 0;
  1193. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  1194. int32 faction_id = itr->first;
  1195. sint32 amount = itr->second;
  1196. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  1197. if (faction_name) {
  1198. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  1199. packet->setArrayDataByName("amount", amount, index);
  1200. }
  1201. index++;
  1202. }
  1203. }
  1204. //packet->setArrayLengthByName("map_data_array_size", map_data_count);
  1205. EQ2Packet* outapp = packet->serialize();
  1206. //packet->PrintPacket();
  1207. //DumpPacket(outapp);
  1208. safe_delete(packet);
  1209. return outapp;
  1210. }
  1211. return 0;
  1212. }
  1213. bool Quest::AddQuestStep(QuestStep* step){
  1214. bool ret = true;
  1215. MQuestSteps.lock();
  1216. if(quest_step_map.count(step->GetStepID()) == 0){
  1217. quest_steps.push_back(step);
  1218. quest_step_reverse_map[step] = step->GetStepID();
  1219. quest_step_map[step->GetStepID()] = step;
  1220. if(step->GetTaskGroup()){
  1221. string tmp_task_group = string(step->GetTaskGroup());
  1222. if(task_group.count(tmp_task_group) == 0){
  1223. task_group_order[task_group_num] = tmp_task_group;
  1224. task_group_num++;
  1225. }
  1226. task_group[tmp_task_group].push_back(step);
  1227. }
  1228. else{
  1229. string tmp_task_group = string(step->GetDescription());
  1230. if(task_group.count(tmp_task_group) == 0){
  1231. task_group_order[task_group_num] = tmp_task_group;
  1232. task_group_num++;
  1233. }
  1234. task_group[tmp_task_group].push_back(step);
  1235. }
  1236. }
  1237. else{
  1238. LogWrite(QUEST__ERROR, 0, "Quest", "Quest Warning in '%s': step %u used multiple times!", GetName(), step->GetStepID());
  1239. ret = false;
  1240. }
  1241. MQuestSteps.unlock();
  1242. return ret;
  1243. }
  1244. bool Quest::RemoveQuestStep(int32 step, Client* client) {
  1245. bool ret = true;
  1246. MQuestSteps.writelock(__FUNCTION__, __LINE__);
  1247. if (quest_step_map.count(step) > 0) {
  1248. QuestStep* quest_step = quest_step_map[step];
  1249. if (quest_step) {
  1250. client->QueuePacket(QuestJournalReply(client->GetVersion(), client->GetNameCRC(), client->GetPlayer(), quest_step, 0, 0, true));
  1251. int32 step2 = step - 1;
  1252. QuestStep* reset_step = quest_step_map[step2];
  1253. reset_step->SetStepProgress(0);
  1254. MCompletedActions.lock();
  1255. complete_actions.erase(step);
  1256. MCompletedActions.unlock();
  1257. string tmp_task_group = string(quest_step->GetTaskGroup());
  1258. if(task_group.count(tmp_task_group) > 0) {
  1259. task_group.erase(tmp_task_group);
  1260. int task_num = 0;
  1261. map<int16, string>::iterator itr;
  1262. for (itr = task_group_order.begin(); itr != task_group_order.end(); itr++) {
  1263. if (itr->second == tmp_task_group) {
  1264. task_num = itr->first;
  1265. break;
  1266. }
  1267. }
  1268. if (task_num > 0) {
  1269. task_group_order.erase(task_num);
  1270. task_group_num--;
  1271. }
  1272. }
  1273. // Remove the step from the various maps before we delete it
  1274. quest_step_map.erase(step);
  1275. quest_step_reverse_map.erase(quest_step);
  1276. vector<QuestStep*>::iterator itr;
  1277. for (itr = quest_steps.begin(); itr != quest_steps.end(); itr++) {
  1278. if ((*itr) == quest_step) {
  1279. quest_steps.erase(itr);
  1280. break;
  1281. }
  1282. }
  1283. safe_delete(quest_step);
  1284. }
  1285. else {
  1286. LogWrite(QUEST__ERROR, 0, "Quest", "Unable to get a valid step (%u) for quest %s", step, GetName());
  1287. ret = false;
  1288. }
  1289. }
  1290. else {
  1291. LogWrite(QUEST__ERROR, 0, "Quest", "Unable to remove step (%u) for quest %s", step, GetName());
  1292. ret = false;
  1293. }
  1294. MQuestSteps.releasewritelock(__FUNCTION__, __LINE__);
  1295. return ret;
  1296. }
  1297. QuestStep* Quest::AddQuestStep(int32 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){
  1298. QuestStep* step = new QuestStep(id, in_type, in_description, in_ids, in_quantity, in_task_group, in_locations, in_max_variation, in_percentage, in_usableitemid);
  1299. if(!AddQuestStep(step)){
  1300. safe_delete(step);
  1301. return 0;
  1302. }
  1303. return step;
  1304. }
  1305. void Quest::AddPrereqClass(int8 class_id){
  1306. prereq_classes.push_back(class_id);
  1307. }
  1308. void Quest::AddPrereqTradeskillClass(int8 class_id) {
  1309. prereq_tradeskillclass.push_back(class_id);
  1310. }
  1311. void Quest::AddPrereqModelType(int16 model_type){
  1312. prereq_model_types.push_back(model_type);
  1313. }
  1314. void Quest::AddPrereqRace(int8 race){
  1315. prereq_races.push_back(race);
  1316. }
  1317. void Quest::SetPrereqLevel(int8 lvl){
  1318. prereq_level = lvl;
  1319. }
  1320. void Quest::SetPrereqTSLevel(int8 lvl) {
  1321. prereq_tslevel = lvl;
  1322. }
  1323. void Quest::AddPrereqQuest(int32 quest_id){
  1324. prereq_quests.push_back(quest_id);
  1325. }
  1326. void Quest::AddPrereqFaction(int32 faction_id, sint32 min, sint32 max){
  1327. QuestFactionPrereq faction;
  1328. faction.faction_id = faction_id;
  1329. faction.min = min;
  1330. faction.max = max;
  1331. prereq_factions.push_back(faction);
  1332. }
  1333. void Quest::AddPrereqItem(Item* item){
  1334. prereq_items.push_back(item);
  1335. }
  1336. void Quest::AddRewardItemVec(vector<Item*>* items, Item* item, bool combine_items) {
  1337. if(!items || !item)
  1338. return;
  1339. bool stacked = false;
  1340. if(combine_items) {
  1341. for(int32 i=0;i<items->size();i++) {
  1342. Item* cur_item = (Item*)items->at(i);
  1343. if(cur_item->stack_count > 1) {
  1344. if(cur_item->details.item_id == item->details.item_id && cur_item->details.count+1 < cur_item->stack_count) {
  1345. if(!cur_item->details.count) // sometimes the count is 0, so we want it to be 2 now
  1346. cur_item->details.count = 2;
  1347. else
  1348. cur_item->details.count += 1;
  1349. stacked = true;
  1350. break;
  1351. }
  1352. }
  1353. }
  1354. }
  1355. if(!stacked) {
  1356. items->push_back(item);
  1357. }
  1358. }
  1359. void Quest::AddSelectableRewardItem(Item* item){
  1360. AddRewardItemVec(&selectable_reward_items, item, false);
  1361. }
  1362. void Quest::AddRewardItem(Item* item){
  1363. AddRewardItemVec(&reward_items, item);
  1364. }
  1365. void Quest::AddTmpRewardItem(Item* item){
  1366. AddRewardItemVec(&tmp_reward_items, item);
  1367. }
  1368. void Quest::GetTmpRewardItemsByID(std::vector<Item*>* items) {
  1369. if(!items)
  1370. return;
  1371. for(int32 i=0;i<tmp_reward_items.size();i++)
  1372. items->push_back(tmp_reward_items[i]);
  1373. }
  1374. void Quest::AddRewardCoins(int32 copper, int32 silver, int32 gold, int32 plat){
  1375. reward_coins = copper + (silver*100) + (gold*10000) + ((int64)plat*1000000);
  1376. }
  1377. void Quest::AddRewardCoinsMax(int64 coins){
  1378. reward_coins_max = coins;
  1379. }
  1380. void Quest::AddRewardFaction(int32 faction_id, sint32 amount){
  1381. reward_factions[faction_id] = amount;
  1382. }
  1383. void Quest::SetRewardStatus(int32 amount){
  1384. reward_status = amount;
  1385. }
  1386. void Quest::SetRewardComment(string comment){
  1387. reward_comment = comment;
  1388. }
  1389. void Quest::SetRewardXP(int32 xp){
  1390. reward_exp = xp;
  1391. }
  1392. vector<int8>* Quest::GetPrereqClasses(){
  1393. return &prereq_classes;
  1394. }
  1395. vector<int8>* Quest::GetPrereqTradeskillClasses(){
  1396. return &prereq_tradeskillclass;
  1397. }
  1398. vector<QuestFactionPrereq>* Quest::GetPrereqFactions(){
  1399. return &prereq_factions;
  1400. }
  1401. vector<int8>* Quest::GetPrereqRaces(){
  1402. return &prereq_races;
  1403. }
  1404. vector<int16>* Quest::GetPrereqModelTypes(){
  1405. return &prereq_model_types;
  1406. }
  1407. int8 Quest::GetPrereqLevel(){
  1408. return prereq_level;
  1409. }
  1410. int8 Quest::GetPrereqTSLevel() {
  1411. return prereq_tslevel;
  1412. }
  1413. vector<int32>* Quest::GetPrereqQuests(){
  1414. return &prereq_quests;
  1415. }
  1416. vector<Item*>* Quest::GetPrereqItems(){
  1417. return &prereq_items;
  1418. }
  1419. vector<Item*>* Quest::GetRewardItems(){
  1420. return &reward_items;
  1421. }
  1422. vector<Item*>* Quest::GetTmpRewardItems(){
  1423. return &tmp_reward_items;
  1424. }
  1425. vector<Item*>* Quest::GetSelectableRewardItems(){
  1426. return &selectable_reward_items;
  1427. }
  1428. map<int32, sint32>* Quest::GetRewardFactions() {
  1429. return &reward_factions;
  1430. }
  1431. void Quest::SetTaskGroupDescription(int32 step, string desc, bool display_bullets){
  1432. MQuestSteps.lock();
  1433. if(step <= task_group_num && task_group_order.count(step) > 0){
  1434. string old_desc = task_group_order[step];
  1435. if(display_bullets)
  1436. task_group[desc] = task_group[old_desc];
  1437. else{
  1438. if(task_group[old_desc].size() > 0){
  1439. task_group[desc].push_back(task_group[old_desc].at(0));
  1440. task_group[desc].at(0)->ResetTaskGroup();
  1441. task_group[desc].at(0)->SetDescription(desc);
  1442. }
  1443. }
  1444. task_group.erase(old_desc);
  1445. task_group_order[step] = desc;
  1446. }
  1447. MQuestSteps.unlock();
  1448. }
  1449. void Quest::SetStepDescription(int32 step, string desc){
  1450. MQuestSteps.lock();
  1451. for(int32 i=0;i<quest_steps.size();i++){
  1452. if(quest_steps[i]->GetStepID() == step){
  1453. quest_steps[i]->SetDescription(desc);
  1454. break;
  1455. }
  1456. }
  1457. MQuestSteps.unlock();
  1458. }
  1459. void Quest::SetDescription(string desc){
  1460. description = desc;
  1461. }
  1462. void Quest::SetCompletedDescription(string desc){
  1463. completed_description = desc;
  1464. }
  1465. const char* Quest::GetCompletedDescription(){
  1466. return completed_description.c_str();
  1467. }
  1468. void Quest::AddCompleteAction(int32 step, string action){
  1469. MCompletedActions.lock();
  1470. complete_actions[step] = action;
  1471. MCompletedActions.unlock();
  1472. }
  1473. void Quest::AddProgressAction(int32 step, string action){
  1474. MProgressActions.lock();
  1475. progress_actions[step] = action;
  1476. MProgressActions.unlock();
  1477. }
  1478. void Quest::AddFailedAction(int32 step, string action) {
  1479. MFailedActions.writelock(__FUNCTION__, __LINE__);
  1480. failed_actions[step] = action;
  1481. MFailedActions.releasewritelock(__FUNCTION__, __LINE__);
  1482. }
  1483. void Quest::SetCompleteAction(string action){
  1484. complete_action = action;
  1485. }
  1486. const char* Quest::GetCompleteAction(){
  1487. if(complete_action.length() > 0)
  1488. return complete_action.c_str();
  1489. return 0;
  1490. }
  1491. const char* Quest::GetCompleteAction(int32 step){
  1492. const char* ret = 0;
  1493. MCompletedActions.lock();
  1494. if(complete_actions.count(step) > 0)
  1495. ret = complete_actions[step].c_str();
  1496. MCompletedActions.unlock();
  1497. return ret;
  1498. }
  1499. void Quest::SetQuestReturnNPC(int32 id){
  1500. return_id = id;
  1501. }
  1502. int32 Quest::GetQuestReturnNPC(){
  1503. return return_id;
  1504. }
  1505. void Quest::SetQuestGiver(int32 id){
  1506. quest_giver = id;
  1507. if(return_id == 0)
  1508. return_id = id;
  1509. }
  1510. bool Quest::GetCompleted(){
  1511. bool ret = true;
  1512. for(int32 i=0;i<quest_steps.size();i++){
  1513. if(quest_steps[i]->Complete() == false){
  1514. ret = false;
  1515. break;
  1516. }
  1517. }
  1518. return ret;
  1519. }
  1520. bool Quest::CheckCategoryYellow(){
  1521. bool ret = false;
  1522. string category = GetType();
  1523. //Check for these category names, return true to set category as yellow in the quest journal
  1524. if (category == "Signature" || category == "Heritage" || category == "Hallmark" || category == "Deity" || category == "Miscellaneaous" || category == "Language" || category == "Lore and Legend" || category == "World Event" || category == "Tradeskill")
  1525. ret = true;
  1526. return ret;
  1527. }
  1528. Player* Quest::GetPlayer(){
  1529. return player;
  1530. }
  1531. void Quest::SetPlayer(Player* in_player){
  1532. player = in_player;
  1533. }
  1534. void Quest::SetGeneratedCoin(int64 coin){
  1535. generated_coin = coin;
  1536. }
  1537. int32 Quest::GetQuestGiver(){
  1538. return quest_giver;
  1539. }
  1540. int64 Quest::GetCoinsReward(){
  1541. return reward_coins;
  1542. }
  1543. int64 Quest::GetCoinsRewardMax(){
  1544. return reward_coins_max;
  1545. }
  1546. int64 Quest::GetGeneratedCoin(){
  1547. return generated_coin;
  1548. }
  1549. int32 Quest::GetExpReward(){
  1550. return reward_exp;
  1551. }
  1552. void Quest::GiveQuestReward(Player* player){
  1553. if(reward_coins > 0)
  1554. player->AddCoins(reward_coins);
  1555. if(!GetQuestTemporaryState())
  1556. reward_items.clear();
  1557. }
  1558. bool Quest::GetDeleted(){
  1559. return deleted;
  1560. }
  1561. void Quest::SetDeleted(bool val){
  1562. deleted = val;
  1563. }
  1564. bool Quest::GetUpdateRequired(){
  1565. return update_needed;
  1566. }
  1567. void Quest::SetUpdateRequired(bool val){
  1568. update_needed = val;
  1569. }
  1570. void Quest::SetTurnedIn(bool val){
  1571. turned_in = val;
  1572. visible = 0;
  1573. }
  1574. bool Quest::GetTurnedIn(){
  1575. return turned_in;
  1576. }
  1577. void Quest::SetName(string in_name) {
  1578. name = in_name;
  1579. }
  1580. void Quest::SetType(string in_type) {
  1581. type = in_type;
  1582. }
  1583. void Quest::SetLevel(int8 in_level) {
  1584. level = in_level;
  1585. }
  1586. void Quest::SetCompletedFlag(bool val) {
  1587. completed_flag = val;
  1588. SetUpdateRequired(true);
  1589. if(player && player->GetClient())
  1590. player->GetClient()->SendQuestJournalUpdate(this, true);
  1591. }
  1592. void Quest::SetStepTimer(int32 duration) {
  1593. m_timestamp = duration == 0 ? 0 : Timer::GetUnixTimeStamp() + duration;
  1594. }
  1595. void Quest::StepFailed(int32 step) {
  1596. if(lua_interface && failed_actions.count(step) > 0 && failed_actions[step].length() > 0)
  1597. lua_interface->CallQuestFunction(this, failed_actions[step].c_str(), player);
  1598. }
  1599. MasterQuestList::MasterQuestList(){
  1600. MQuests.SetName("MasterQuestList::MQuests");
  1601. }
  1602. void MasterQuestList::Reload(){
  1603. MQuests.lock();
  1604. quests.clear(); //deletes taken care of in LuaInterface
  1605. if(lua_interface)
  1606. lua_interface->DestroyQuests(true);
  1607. MQuests.unlock();
  1608. }
  1609. void MasterQuestList::LockQuests(){
  1610. MQuests.lock();
  1611. }
  1612. void MasterQuestList::UnlockQuests(){
  1613. MQuests.unlock();
  1614. }
  1615. void Quest::SetQuestTemporaryState(bool tempState, std::string customDescription)
  1616. {
  1617. if(!tempState)
  1618. {
  1619. tmp_reward_coins = 0;
  1620. tmp_reward_status = 0;
  1621. for(int32 i=0;i<tmp_reward_items.size();i++)
  1622. safe_delete(tmp_reward_items[i]);
  1623. tmp_reward_items.clear();
  1624. }
  1625. quest_state_temporary = tempState;
  1626. quest_temporary_description = customDescription;
  1627. }
  1628. bool Quest::CanShareQuestCriteria(Client* quest_sharer, bool display_client_msg) {
  1629. Quest* clientQuest = quest_sharer->GetPlayer()->GetQuest(GetQuestID()); // gets active quest if available
  1630. if(((GetQuestShareableFlag() & QUEST_SHAREABLE_COMPLETED) == 0) && quest_sharer->GetPlayer()->GetCompletedQuest(GetQuestID())) {
  1631. if(display_client_msg)
  1632. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest after it is already completed.");
  1633. return false;
  1634. }
  1635. else if((GetQuestShareableFlag() == QUEST_SHAREABLE_COMPLETED) && !quest_sharer->GetPlayer()->GetCompletedQuest(GetQuestID())) {
  1636. if(display_client_msg)
  1637. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest until it is completed.");
  1638. return false;
  1639. }
  1640. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_DURING) == 0) && clientQuest && clientQuest->GetQuestStep() > 1) {
  1641. if(display_client_msg)
  1642. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest after already completing a step.");
  1643. return false;
  1644. }
  1645. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_ACTIVE) == 0) && clientQuest) {
  1646. if(display_client_msg)
  1647. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest while it is active.");
  1648. return false;
  1649. }
  1650. else if(!GetQuestShareableFlag()) {
  1651. if(display_client_msg)
  1652. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest.");
  1653. return false;
  1654. }
  1655. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_COMPLETED) == 0) && clientQuest == nullptr) {
  1656. if(display_client_msg)
  1657. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You do not have this quest.");
  1658. return false;
  1659. }
  1660. return true;
  1661. }