9
3

Quests.cpp 54 KB

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