9
3

Quests.cpp 53 KB

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