9
3

Quests.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  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. if(packet->GetVersion() <= 373) {
  797. std::string quotedName = std::string("\"" + name + "\"");
  798. packet->setDataByName("title", quotedName.c_str());
  799. }
  800. else {
  801. packet->setDataByName("title", name.c_str());
  802. }
  803. packet->setDataByName("description", description.c_str());
  804. if(type == "Tradeskill")
  805. packet->setDataByName("quest_difficulty", player->GetTSArrowColor(level));
  806. else
  807. packet->setDataByName("quest_difficulty", player->GetArrowColor(level));
  808. packet->setDataByName("encounter_level", enc_level);
  809. packet->setDataByName("unknown0", 255);
  810. if (version >= 1188)
  811. packet->setDataByName("unknown4b", 1);
  812. else
  813. packet->setDataByName("unknown", 5);
  814. packet->setDataByName("level", level);
  815. if(reward_coins > 0){
  816. packet->setDataByName("min_coin", reward_coins);
  817. if (reward_coins_max)
  818. packet->setDataByName("max_coin", reward_coins_max);
  819. }
  820. packet->setDataByName("status_points", reward_status);
  821. if(reward_comment.length() > 0)
  822. packet->setDataByName("text", reward_comment.c_str());
  823. if(reward_items.size() > 0){
  824. player->GetClient()->PopulateQuestRewardItems(&reward_items, packet);
  825. }
  826. if(selectable_reward_items.size() > 0){
  827. player->GetClient()->PopulateQuestRewardItems(&selectable_reward_items, packet, std::string("num_select_rewards"),
  828. std::string("select_reward_id"), std::string("select_item"));
  829. }
  830. map<int32, sint32>* reward_factions = GetRewardFactions();
  831. if (reward_factions && reward_factions->size() > 0) {
  832. packet->setArrayLengthByName("num_factions", reward_factions->size());
  833. map<int32, sint32>::iterator itr;
  834. int16 index = 0;
  835. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  836. int32 faction_id = itr->first;
  837. sint32 amount = itr->second;
  838. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  839. if (faction_name) {
  840. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  841. packet->setArrayDataByName("amount", amount, index);
  842. }
  843. index++;
  844. }
  845. }
  846. char accept[35] = {0};
  847. char decline[35] = {0};
  848. sprintf(accept, "q_accept_pending_quest %u", id);
  849. sprintf(decline, "q_deny_pending_quest %u", id);
  850. packet->setDataByName("accept_command", accept);
  851. packet->setDataByName("decline_command", decline);
  852. EQ2Packet* outapp = packet->serialize();
  853. #if EQDEBUG >= 9
  854. DumpPacket(outapp);
  855. #endif
  856. safe_delete(packet);
  857. return outapp;
  858. }
  859. return 0;
  860. }
  861. int32 Quest::GetQuestID(){
  862. return id;
  863. }
  864. int8 Quest::GetQuestLevel(){
  865. return level;
  866. }
  867. int8 Quest::GetVisible(){
  868. return visible;
  869. }
  870. 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) {
  871. PacketStruct* packet = configReader.getStruct("WS_QuestJournalReply", version);
  872. if (packet) {
  873. packet->setDataByName("quest_id", id);
  874. packet->setDataByName("player_crc", player_crc);
  875. packet->setDataByName("name", name.c_str());
  876. packet->setDataByName("description", description.c_str());
  877. packet->setDataByName("zone", zone.c_str());
  878. packet->setDataByName("type", type.c_str());
  879. packet->setDataByName("complete_header", "To complete this quest, I must do the following tasks:");
  880. packet->setDataByName("day", day);
  881. packet->setDataByName("month", month);
  882. packet->setDataByName("year", year);
  883. packet->setDataByName("level", level);
  884. packet->setDataByName("visible", 1);
  885. /* To get the quest timer to work you need to set unknown, index 4 to 1 and the time stamp
  886. to the current time + the time in seconds you want to show in the journal*/
  887. if (m_timestamp > 0) {
  888. packet->setDataByName("unknown", 1, 4);
  889. packet->setDataByName("time_stamp", m_timestamp);
  890. }
  891. int8 difficulty = 0;
  892. if (type == "Tradeskill")
  893. difficulty = player->GetTSArrowColor(level);
  894. else
  895. difficulty = player->GetArrowColor(level);
  896. packet->setDataByName("difficulty", difficulty);
  897. if (enc_level > 4)
  898. packet->setDataByName("encounter_level", enc_level);
  899. else
  900. packet->setDataByName("encounter_level", 4);
  901. packet->setDataByName("unknown2b", 4);
  902. int16 task_groups_completed = 0;
  903. int16 total_task_groups = 0;
  904. vector<QuestStep*> primary_order;
  905. vector<QuestStep*> secondary_order;
  906. packet->setDataByName("unknown8", 1, 1);
  907. packet->setSubstructArrayDataByName("reward_data", "unknown8", 1, 1);
  908. packet->setDataByName("unknown8b", 255);
  909. if (version >= 1096) {
  910. packet->setDataByName("deletable", (int8)CanDeleteQuest());
  911. packet->setDataByName("shareable", (int8)CanShareQuestCriteria(player->GetClient(),false));
  912. }
  913. else {
  914. packet->setDataByName("unknown3", 1, 5); // this supposed to be CanDeleteQuest?
  915. packet->setDataByName("unknown3", 1, 6); // this supposed to be CanShareQuestCriteria?
  916. }
  917. int8 map_data_count = 0;
  918. packet->setDataByName("bullets", 1);
  919. if (old_completed_quest) {
  920. if (version >= 1096 || version == 546 || version == 561) {
  921. packet->setDataByName("complete", 1);
  922. packet->setDataByName("complete2", 1);
  923. packet->setDataByName("complete3", 1);
  924. }
  925. else {
  926. packet->setDataByName("unknown3", 1);
  927. packet->setDataByName("unknown3", 1, 1);
  928. packet->setDataByName("unknown3", 1, 2);
  929. packet->setDataByName("unknown3", 1, 5);
  930. packet->setDataByName("unknown3", 1, 6);
  931. }
  932. }
  933. // must always send for newer clients like AoM or else crash!
  934. else if (GetCompleted() && ((version >= 1096) || ((version == 561 || version == 546) && HasSentLastUpdate()))) { //need to send last quest update before erasing all progress of the quest
  935. packet->setDataByName("complete", 1);
  936. packet->setDataByName("complete2", 1);
  937. packet->setDataByName("complete3", 1);
  938. packet->setDataByName("num_task_groups", 1);
  939. packet->setArrayDataByName("task_group", completed_description.c_str());
  940. packet->setArrayDataByName("unknown4", 0xFFFFFFFF);
  941. packet->setDataByName("onscreen_update", 1);
  942. packet->setDataByName("update_task_number", 1);
  943. packet->setDataByName("onscreen_update", 1);
  944. packet->setDataByName("onscreen_update_text", completed_description.c_str());
  945. if (updateStep)
  946. packet->setDataByName("onscreen_update_icon", updateStep->GetIcon());
  947. else
  948. packet->setDataByName("onscreen_update_icon", 0);
  949. // Is Heritage or db entry for classic eq quest turn in sound
  950. packet->setDataByName("classic_eq_sound", 0);
  951. // No clue what this does, set it to mach live packets
  952. packet->setDataByName("unknown12b", 1, 0);
  953. }
  954. else {
  955. map<QuestStep*, string> task_group_names;
  956. map<int16, string>::iterator order_itr;
  957. vector<QuestStep*>* steps = 0;
  958. MQuestSteps.lock();
  959. for (order_itr = task_group_order.begin(); order_itr != task_group_order.end(); order_itr++) {
  960. //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
  961. //for(itr = task_group.begin(); itr != task_group.end(); itr++){
  962. bool complete = true;
  963. if (task_group.count(order_itr->second) > 0) {
  964. steps = &(task_group[order_itr->second]);
  965. for (int32 i = 0; i < steps->size(); i++) {
  966. if (steps->at(i)->Complete() == false)
  967. complete = false;
  968. }
  969. if (complete) {
  970. for (int32 i = 0; i < steps->size(); i++) {
  971. if (i == 0)
  972. task_group_names[steps->at(i)] = order_itr->second;
  973. primary_order.push_back(steps->at(i));
  974. }
  975. task_groups_completed++;
  976. total_task_groups++;
  977. }
  978. else {
  979. for (int32 i = 0; i < steps->size(); i++) {
  980. if (i == 0)
  981. task_group_names[steps->at(i)] = order_itr->second;
  982. secondary_order.push_back(steps->at(i));
  983. }
  984. total_task_groups++;
  985. }
  986. }
  987. }
  988. packet->setDataByName("task_groups_completed", task_groups_completed);
  989. packet->setArrayLengthByName("num_task_groups", total_task_groups);
  990. if (IsTracked() /*display_quest_helper*/ && task_groups_completed < total_task_groups)
  991. packet->setDataByName("display_quest_helper", 1);
  992. int16 index = 0;
  993. QuestStep* step = 0;
  994. for (int32 i = 0; i < primary_order.size(); i++) {
  995. if (primary_order[i]->GetTaskGroup()) {
  996. if (task_group_names.count(primary_order[i]) > 0)
  997. packet->setArrayDataByName("task_group", primary_order[i]->GetTaskGroup(), index);
  998. else
  999. continue;
  1000. packet->setSubArrayLengthByName("num_tasks", task_group[primary_order[i]->GetTaskGroup()].size(), index);
  1001. packet->setSubArrayLengthByName("num_updates", task_group[primary_order[i]->GetTaskGroup()].size(), index);
  1002. map_data_count += task_group[primary_order[i]->GetTaskGroup()].size();
  1003. if (task_group[primary_order[i]->GetTaskGroup()].size() > 0) {
  1004. packet->setDataByName("bullets", 1);
  1005. }
  1006. for (int32 x = 0; x < task_group[primary_order[i]->GetTaskGroup()].size(); x++) {
  1007. step = task_group[primary_order[i]->GetTaskGroup()].at(x);
  1008. if (!step)
  1009. continue;
  1010. if (step->GetDescription())
  1011. packet->setSubArrayDataByName("task", step->GetDescription(), index, x);
  1012. packet->setSubArrayDataByName("task_completed", 1, index, x);
  1013. packet->setSubArrayDataByName("index", x, index, x);
  1014. packet->setSubArrayDataByName("update_currentval", step->GetQuestCurrentQuantity(), index, x);
  1015. if(step->GetQuestCurrentQuantity() > 0)
  1016. packet->setDataByName("journal_updated", 1);
  1017. packet->setSubArrayDataByName("update_maxval", step->GetQuestNeededQuantity(), index, x);
  1018. if (step->GetUpdateTargetName())
  1019. packet->setSubArrayDataByName("update_target_name", step->GetUpdateTargetName(), index, x);
  1020. packet->setSubArrayDataByName("icon", step->GetIcon(), index, x);
  1021. if (updateStep && step == updateStep) {
  1022. packet->setDataByName("update", 1);
  1023. // packet->setDataByName("unknown5d", 1);
  1024. if (!quest_failure)
  1025. packet->setDataByName("onscreen_update", 1);
  1026. packet->setDataByName("onscreen_update_count", update_count);
  1027. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1028. if (step->GetUpdateName())
  1029. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1030. else if (step->GetDescription())
  1031. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1032. packet->setDataByName("update_task_number", x);
  1033. packet->setDataByName("update_taskgroup_number", index);
  1034. }
  1035. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, x);
  1036. }
  1037. index++;
  1038. }
  1039. else {
  1040. if (task_group_names.count(primary_order[i]) > 0) {
  1041. step = primary_order[i];
  1042. if (updateStep && step == updateStep) {
  1043. packet->setDataByName("update", 1);
  1044. // packet->setDataByName("unknown5d", 1);
  1045. if (!quest_failure)
  1046. packet->setDataByName("onscreen_update", 1);
  1047. packet->setDataByName("onscreen_update_count", update_count);
  1048. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1049. if (step->GetUpdateName())
  1050. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1051. else if (step->GetDescription())
  1052. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1053. packet->setDataByName("update_task_number", i);
  1054. packet->setDataByName("update_taskgroup_number", index);
  1055. }
  1056. packet->setArrayDataByName("task_group", primary_order[i]->GetDescription(), index);
  1057. index++;
  1058. }
  1059. }
  1060. }
  1061. for (int32 i = 0; i < secondary_order.size(); i++) {
  1062. if (secondary_order[i]->GetTaskGroup()) {
  1063. if (task_group_names.count(secondary_order[i]) > 0)
  1064. packet->setArrayDataByName("task_group", secondary_order[i]->GetTaskGroup(), index);
  1065. else
  1066. continue;
  1067. packet->setSubArrayLengthByName("num_tasks", task_group[secondary_order[i]->GetTaskGroup()].size(), index);
  1068. packet->setSubArrayLengthByName("num_updates", task_group[secondary_order[i]->GetTaskGroup()].size(), index);
  1069. map_data_count += task_group[secondary_order[i]->GetTaskGroup()].size();
  1070. if (task_group[secondary_order[i]->GetTaskGroup()].size() > 0)
  1071. packet->setDataByName("bullets", 1);
  1072. for (int32 x = 0; x < task_group[secondary_order[i]->GetTaskGroup()].size(); x++) {
  1073. step = task_group[secondary_order[i]->GetTaskGroup()].at(x);
  1074. if (!step)
  1075. continue;
  1076. if (step->GetDescription())
  1077. packet->setSubArrayDataByName("task", step->GetDescription(), index, x);
  1078. if (step->Complete())
  1079. packet->setSubArrayDataByName("task_completed", 1, index, x);
  1080. else
  1081. packet->setSubArrayDataByName("task_completed", 0, index, x);
  1082. packet->setSubArrayDataByName("index", x, index, x);
  1083. packet->setSubArrayDataByName("update_currentval", step->GetQuestCurrentQuantity(), index, x);
  1084. if (step->GetQuestCurrentQuantity() > 0)
  1085. packet->setDataByName("journal_updated", 1);
  1086. packet->setSubArrayDataByName("update_maxval", step->GetQuestNeededQuantity(), index, x);
  1087. packet->setSubArrayDataByName("icon", step->GetIcon(), index, x);
  1088. if (step->GetUpdateTargetName())
  1089. packet->setSubArrayDataByName("update_target_name", step->GetUpdateTargetName(), index, x);
  1090. if (updateStep && step == updateStep) {
  1091. packet->setDataByName("update", 1);
  1092. if (!quest_failure)
  1093. packet->setDataByName("onscreen_update", 1);
  1094. packet->setDataByName("onscreen_update_count", update_count);
  1095. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1096. if (step->GetUpdateName())
  1097. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1098. else if (step->GetDescription())
  1099. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1100. if (quest_failure)
  1101. packet->setDataByName("onscreen_update_text2", "failed");
  1102. packet->setDataByName("update_task_number", x);
  1103. packet->setDataByName("update_taskgroup_number", index);
  1104. }
  1105. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, x);
  1106. }
  1107. index++;
  1108. }
  1109. else {
  1110. if (task_group_names.count(secondary_order[i]) > 0) {
  1111. step = secondary_order[i];
  1112. if (updateStep && step == updateStep) {
  1113. packet->setDataByName("update", 1);
  1114. if (!quest_failure)
  1115. packet->setDataByName("onscreen_update", 1);
  1116. packet->setDataByName("onscreen_update_count", update_count);
  1117. packet->setDataByName("onscreen_update_icon", step->GetIcon());
  1118. if (step->GetUpdateName())
  1119. packet->setDataByName("onscreen_update_text", step->GetUpdateName());
  1120. else if (step->GetDescription())
  1121. packet->setDataByName("onscreen_update_text", step->GetDescription());
  1122. packet->setDataByName("update_task_number", i);
  1123. packet->setDataByName("update_taskgroup_number", index);
  1124. }
  1125. if (task_group_names.size() == 1) {
  1126. packet->setSubArrayLengthByName("num_tasks", 1, index);
  1127. packet->setSubArrayDataByName("task", secondary_order[i]->GetDescription(), index);
  1128. packet->setDataByName("bullets", 0);
  1129. }
  1130. else
  1131. packet->setArrayDataByName("task_group", secondary_order[i]->GetDescription(), index);
  1132. index++;
  1133. }
  1134. }
  1135. }
  1136. for (int16 i = 0; i < total_task_groups; i++)
  1137. packet->setArrayDataByName("unknown4", 0xFFFFFFFF, i);
  1138. if (step && step->GetItemID() > 0) {
  1139. packet->setArrayLengthByName("usable_item_count", 1);
  1140. Item* item = player->GetPlayerItemList()->GetItemFromID(step->GetItemID(), 1);
  1141. if (item) {
  1142. packet->setArrayDataByName("item_id", item->details.item_id, 0);
  1143. packet->setArrayDataByName("item_unique_id", item->details.unique_id, 0);
  1144. packet->setArrayDataByName("item_icon", item->details.icon, 0);
  1145. packet->setArrayDataByName("unknown2", 0xFFFFFFFF, 0);//item->details.item_id, 0);
  1146. }
  1147. }
  1148. if (GetCompleted()) { //mark the last update as being sent, next time we send the quest reply, it will only be a brief portion
  1149. SetSentLastUpdate(true);
  1150. }
  1151. }
  1152. MQuestSteps.unlock();
  1153. string reward_str = "";
  1154. if (version >= 1096 || version == 546 || version == 561)
  1155. reward_str = "reward_data_";
  1156. string tmp = reward_str + "reward";
  1157. packet->setDataByName(tmp.c_str(), "Quest Reward!");
  1158. if (reward_coins > 0) {
  1159. tmp = reward_str + "min_coin";
  1160. packet->setDataByName(tmp.c_str(), reward_coins);
  1161. tmp = reward_str + "max_coin";
  1162. packet->setDataByName(tmp.c_str(), reward_coins_max);
  1163. }
  1164. tmp = reward_str + "status_points";
  1165. packet->setDataByName(tmp.c_str(), reward_status);
  1166. if (reward_comment.length() > 0) {
  1167. tmp = reward_str + "text";
  1168. packet->setDataByName(tmp.c_str(), reward_comment.c_str());
  1169. }
  1170. if (reward_items.size() > 0) {
  1171. tmp = reward_str + "num_rewards";
  1172. packet->setArrayLengthByName(tmp.c_str(), reward_items.size());
  1173. Item* item = 0;
  1174. for (int32 i = 0; i < reward_items.size(); i++) {
  1175. item = reward_items[i];
  1176. packet->setArrayDataByName("reward_id", item->details.item_id, i);
  1177. if (version < 860)
  1178. packet->setItemArrayDataByName("item", item, player, i, 0, version <= 373 ? -2 : -1);
  1179. else if (version < 1193)
  1180. packet->setItemArrayDataByName("item", item, player, i);
  1181. else
  1182. packet->setItemArrayDataByName("item", item, player, i, 0, 2);
  1183. }
  1184. }
  1185. if (selectable_reward_items.size() > 0) {
  1186. tmp = reward_str + "num_select_rewards";
  1187. packet->setArrayLengthByName(tmp.c_str(), selectable_reward_items.size());
  1188. Item* item = 0;
  1189. for (int32 i = 0; i < selectable_reward_items.size(); i++) {
  1190. item = selectable_reward_items[i];
  1191. packet->setArrayDataByName("select_reward_id", item->details.item_id, i);
  1192. if (version < 860)
  1193. packet->setItemArrayDataByName("select_item", item, player, i, 0, version <= 373 ? -2 : -1);
  1194. else if (version < 1193)
  1195. packet->setItemArrayDataByName("select_item", item, player, i);
  1196. else
  1197. packet->setItemArrayDataByName("select_item", item, player, i, 0, 2);
  1198. }
  1199. }
  1200. map<int32, sint32>* reward_factions = GetRewardFactions();
  1201. if (reward_factions && reward_factions->size() > 0) {
  1202. tmp = reward_str + "num_factions";
  1203. packet->setArrayLengthByName(tmp.c_str(), reward_factions->size());
  1204. map<int32, sint32>::iterator itr;
  1205. int16 index = 0;
  1206. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  1207. int32 faction_id = itr->first;
  1208. sint32 amount = itr->second;
  1209. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  1210. if (faction_name) {
  1211. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  1212. packet->setArrayDataByName("amount", amount, index);
  1213. }
  1214. index++;
  1215. }
  1216. }
  1217. //packet->setArrayLengthByName("map_data_array_size", map_data_count);
  1218. EQ2Packet* outapp = packet->serialize();
  1219. //packet->PrintPacket();
  1220. //DumpPacket(outapp);
  1221. safe_delete(packet);
  1222. return outapp;
  1223. }
  1224. return 0;
  1225. }
  1226. bool Quest::AddQuestStep(QuestStep* step){
  1227. bool ret = true;
  1228. MQuestSteps.lock();
  1229. if(quest_step_map.count(step->GetStepID()) == 0){
  1230. quest_steps.push_back(step);
  1231. quest_step_reverse_map[step] = step->GetStepID();
  1232. quest_step_map[step->GetStepID()] = step;
  1233. if(step->GetTaskGroup()){
  1234. string tmp_task_group = string(step->GetTaskGroup());
  1235. if(task_group.count(tmp_task_group) == 0){
  1236. task_group_order[task_group_num] = tmp_task_group;
  1237. task_group_num++;
  1238. }
  1239. task_group[tmp_task_group].push_back(step);
  1240. }
  1241. else{
  1242. string tmp_task_group = string(step->GetDescription());
  1243. if(task_group.count(tmp_task_group) == 0){
  1244. task_group_order[task_group_num] = tmp_task_group;
  1245. task_group_num++;
  1246. }
  1247. task_group[tmp_task_group].push_back(step);
  1248. }
  1249. }
  1250. else{
  1251. LogWrite(QUEST__ERROR, 0, "Quest", "Quest Warning in '%s': step %u used multiple times!", GetName(), step->GetStepID());
  1252. ret = false;
  1253. }
  1254. MQuestSteps.unlock();
  1255. return ret;
  1256. }
  1257. bool Quest::RemoveQuestStep(int32 step, Client* client) {
  1258. bool ret = true;
  1259. MQuestSteps.writelock(__FUNCTION__, __LINE__);
  1260. if (quest_step_map.count(step) > 0) {
  1261. QuestStep* quest_step = quest_step_map[step];
  1262. if (quest_step) {
  1263. client->QueuePacket(QuestJournalReply(client->GetVersion(), client->GetNameCRC(), client->GetPlayer(), quest_step, 0, 0, true));
  1264. int32 step2 = step - 1;
  1265. QuestStep* reset_step = quest_step_map[step2];
  1266. reset_step->SetStepProgress(0);
  1267. MCompletedActions.lock();
  1268. complete_actions.erase(step);
  1269. MCompletedActions.unlock();
  1270. string tmp_task_group = string(quest_step->GetTaskGroup());
  1271. if(task_group.count(tmp_task_group) > 0) {
  1272. task_group.erase(tmp_task_group);
  1273. int task_num = 0;
  1274. map<int16, string>::iterator itr;
  1275. for (itr = task_group_order.begin(); itr != task_group_order.end(); itr++) {
  1276. if (itr->second == tmp_task_group) {
  1277. task_num = itr->first;
  1278. break;
  1279. }
  1280. }
  1281. if (task_num > 0) {
  1282. task_group_order.erase(task_num);
  1283. task_group_num--;
  1284. }
  1285. }
  1286. // Remove the step from the various maps before we delete it
  1287. quest_step_map.erase(step);
  1288. quest_step_reverse_map.erase(quest_step);
  1289. vector<QuestStep*>::iterator itr;
  1290. for (itr = quest_steps.begin(); itr != quest_steps.end(); itr++) {
  1291. if ((*itr) == quest_step) {
  1292. quest_steps.erase(itr);
  1293. break;
  1294. }
  1295. }
  1296. safe_delete(quest_step);
  1297. }
  1298. else {
  1299. LogWrite(QUEST__ERROR, 0, "Quest", "Unable to get a valid step (%u) for quest %s", step, GetName());
  1300. ret = false;
  1301. }
  1302. }
  1303. else {
  1304. LogWrite(QUEST__ERROR, 0, "Quest", "Unable to remove step (%u) for quest %s", step, GetName());
  1305. ret = false;
  1306. }
  1307. MQuestSteps.releasewritelock(__FUNCTION__, __LINE__);
  1308. return ret;
  1309. }
  1310. 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){
  1311. 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);
  1312. if(!AddQuestStep(step)){
  1313. safe_delete(step);
  1314. return 0;
  1315. }
  1316. return step;
  1317. }
  1318. void Quest::AddPrereqClass(int8 class_id){
  1319. prereq_classes.push_back(class_id);
  1320. }
  1321. void Quest::AddPrereqTradeskillClass(int8 class_id) {
  1322. prereq_tradeskillclass.push_back(class_id);
  1323. }
  1324. void Quest::AddPrereqModelType(int16 model_type){
  1325. prereq_model_types.push_back(model_type);
  1326. }
  1327. void Quest::AddPrereqRace(int8 race){
  1328. prereq_races.push_back(race);
  1329. }
  1330. void Quest::SetPrereqLevel(int8 lvl){
  1331. prereq_level = lvl;
  1332. }
  1333. void Quest::SetPrereqTSLevel(int8 lvl) {
  1334. prereq_tslevel = lvl;
  1335. }
  1336. void Quest::AddPrereqQuest(int32 quest_id){
  1337. prereq_quests.push_back(quest_id);
  1338. }
  1339. void Quest::AddPrereqFaction(int32 faction_id, sint32 min, sint32 max){
  1340. QuestFactionPrereq faction;
  1341. faction.faction_id = faction_id;
  1342. faction.min = min;
  1343. faction.max = max;
  1344. prereq_factions.push_back(faction);
  1345. }
  1346. void Quest::AddPrereqItem(Item* item){
  1347. prereq_items.push_back(item);
  1348. }
  1349. void Quest::AddRewardItemVec(vector<Item*>* items, Item* item, bool combine_items) {
  1350. if(!items || !item)
  1351. return;
  1352. bool stacked = false;
  1353. if(combine_items) {
  1354. for(int32 i=0;i<items->size();i++) {
  1355. Item* cur_item = (Item*)items->at(i);
  1356. if(cur_item->stack_count > 1) {
  1357. if(cur_item->details.item_id == item->details.item_id && cur_item->details.count+1 < cur_item->stack_count) {
  1358. if(!cur_item->details.count) // sometimes the count is 0, so we want it to be 2 now
  1359. cur_item->details.count = 2;
  1360. else
  1361. cur_item->details.count += 1;
  1362. stacked = true;
  1363. break;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. if(!stacked) {
  1369. items->push_back(item);
  1370. }
  1371. }
  1372. void Quest::AddSelectableRewardItem(Item* item){
  1373. AddRewardItemVec(&selectable_reward_items, item, false);
  1374. }
  1375. void Quest::AddRewardItem(Item* item){
  1376. AddRewardItemVec(&reward_items, item);
  1377. }
  1378. void Quest::AddTmpRewardItem(Item* item){
  1379. AddRewardItemVec(&tmp_reward_items, item);
  1380. }
  1381. void Quest::GetTmpRewardItemsByID(std::vector<Item*>* items) {
  1382. if(!items)
  1383. return;
  1384. for(int32 i=0;i<tmp_reward_items.size();i++)
  1385. items->push_back(tmp_reward_items[i]);
  1386. }
  1387. void Quest::AddRewardCoins(int32 copper, int32 silver, int32 gold, int32 plat){
  1388. reward_coins = copper + (silver*100) + (gold*10000) + ((int64)plat*1000000);
  1389. }
  1390. void Quest::AddRewardCoinsMax(int64 coins){
  1391. reward_coins_max = coins;
  1392. }
  1393. void Quest::AddRewardFaction(int32 faction_id, sint32 amount){
  1394. reward_factions[faction_id] = amount;
  1395. }
  1396. void Quest::SetRewardStatus(int32 amount){
  1397. reward_status = amount;
  1398. }
  1399. void Quest::SetRewardComment(string comment){
  1400. reward_comment = comment;
  1401. }
  1402. void Quest::SetRewardXP(int32 xp){
  1403. reward_exp = xp;
  1404. }
  1405. vector<int8>* Quest::GetPrereqClasses(){
  1406. return &prereq_classes;
  1407. }
  1408. vector<int8>* Quest::GetPrereqTradeskillClasses(){
  1409. return &prereq_tradeskillclass;
  1410. }
  1411. vector<QuestFactionPrereq>* Quest::GetPrereqFactions(){
  1412. return &prereq_factions;
  1413. }
  1414. vector<int8>* Quest::GetPrereqRaces(){
  1415. return &prereq_races;
  1416. }
  1417. vector<int16>* Quest::GetPrereqModelTypes(){
  1418. return &prereq_model_types;
  1419. }
  1420. int8 Quest::GetPrereqLevel(){
  1421. return prereq_level;
  1422. }
  1423. int8 Quest::GetPrereqTSLevel() {
  1424. return prereq_tslevel;
  1425. }
  1426. vector<int32>* Quest::GetPrereqQuests(){
  1427. return &prereq_quests;
  1428. }
  1429. vector<Item*>* Quest::GetPrereqItems(){
  1430. return &prereq_items;
  1431. }
  1432. vector<Item*>* Quest::GetRewardItems(){
  1433. return &reward_items;
  1434. }
  1435. vector<Item*>* Quest::GetTmpRewardItems(){
  1436. return &tmp_reward_items;
  1437. }
  1438. vector<Item*>* Quest::GetSelectableRewardItems(){
  1439. return &selectable_reward_items;
  1440. }
  1441. map<int32, sint32>* Quest::GetRewardFactions() {
  1442. return &reward_factions;
  1443. }
  1444. void Quest::SetTaskGroupDescription(int32 step, string desc, bool display_bullets){
  1445. MQuestSteps.lock();
  1446. if(step <= task_group_num && task_group_order.count(step) > 0){
  1447. string old_desc = task_group_order[step];
  1448. if(display_bullets)
  1449. task_group[desc] = task_group[old_desc];
  1450. else{
  1451. if(task_group[old_desc].size() > 0){
  1452. task_group[desc].push_back(task_group[old_desc].at(0));
  1453. task_group[desc].at(0)->ResetTaskGroup();
  1454. task_group[desc].at(0)->SetDescription(desc);
  1455. }
  1456. }
  1457. task_group.erase(old_desc);
  1458. task_group_order[step] = desc;
  1459. }
  1460. MQuestSteps.unlock();
  1461. }
  1462. void Quest::SetStepDescription(int32 step, string desc){
  1463. MQuestSteps.lock();
  1464. for(int32 i=0;i<quest_steps.size();i++){
  1465. if(quest_steps[i]->GetStepID() == step){
  1466. quest_steps[i]->SetDescription(desc);
  1467. break;
  1468. }
  1469. }
  1470. MQuestSteps.unlock();
  1471. }
  1472. void Quest::SetDescription(string desc){
  1473. description = desc;
  1474. }
  1475. void Quest::SetCompletedDescription(string desc){
  1476. completed_description = desc;
  1477. }
  1478. const char* Quest::GetCompletedDescription(){
  1479. return completed_description.c_str();
  1480. }
  1481. void Quest::AddCompleteAction(int32 step, string action){
  1482. MCompletedActions.lock();
  1483. complete_actions[step] = action;
  1484. MCompletedActions.unlock();
  1485. }
  1486. void Quest::AddProgressAction(int32 step, string action){
  1487. MProgressActions.lock();
  1488. progress_actions[step] = action;
  1489. MProgressActions.unlock();
  1490. }
  1491. void Quest::AddFailedAction(int32 step, string action) {
  1492. MFailedActions.writelock(__FUNCTION__, __LINE__);
  1493. failed_actions[step] = action;
  1494. MFailedActions.releasewritelock(__FUNCTION__, __LINE__);
  1495. }
  1496. void Quest::SetCompleteAction(string action){
  1497. complete_action = action;
  1498. }
  1499. const char* Quest::GetCompleteAction(){
  1500. if(complete_action.length() > 0)
  1501. return complete_action.c_str();
  1502. return 0;
  1503. }
  1504. const char* Quest::GetCompleteAction(int32 step){
  1505. const char* ret = 0;
  1506. MCompletedActions.lock();
  1507. if(complete_actions.count(step) > 0)
  1508. ret = complete_actions[step].c_str();
  1509. MCompletedActions.unlock();
  1510. return ret;
  1511. }
  1512. void Quest::SetQuestReturnNPC(int32 id){
  1513. return_id = id;
  1514. }
  1515. int32 Quest::GetQuestReturnNPC(){
  1516. return return_id;
  1517. }
  1518. void Quest::SetQuestGiver(int32 id){
  1519. quest_giver = id;
  1520. if(return_id == 0)
  1521. return_id = id;
  1522. }
  1523. bool Quest::GetCompleted(){
  1524. bool ret = true;
  1525. for(int32 i=0;i<quest_steps.size();i++){
  1526. if(quest_steps[i]->Complete() == false){
  1527. ret = false;
  1528. break;
  1529. }
  1530. }
  1531. return ret;
  1532. }
  1533. bool Quest::CheckCategoryYellow(){
  1534. bool ret = false;
  1535. string category = GetType();
  1536. //Check for these category names, return true to set category as yellow in the quest journal
  1537. if (category == "Signature" || category == "Heritage" || category == "Hallmark" || category == "Deity" || category == "Miscellaneaous" || category == "Language" || category == "Lore and Legend" || category == "World Event" || category == "Tradeskill")
  1538. ret = true;
  1539. return ret;
  1540. }
  1541. Player* Quest::GetPlayer(){
  1542. return player;
  1543. }
  1544. void Quest::SetPlayer(Player* in_player){
  1545. player = in_player;
  1546. }
  1547. void Quest::SetGeneratedCoin(int64 coin){
  1548. generated_coin = coin;
  1549. }
  1550. int32 Quest::GetQuestGiver(){
  1551. return quest_giver;
  1552. }
  1553. int64 Quest::GetCoinsReward(){
  1554. return reward_coins;
  1555. }
  1556. int64 Quest::GetCoinsRewardMax(){
  1557. return reward_coins_max;
  1558. }
  1559. int64 Quest::GetGeneratedCoin(){
  1560. return generated_coin;
  1561. }
  1562. int32 Quest::GetExpReward(){
  1563. return reward_exp;
  1564. }
  1565. void Quest::GiveQuestReward(Player* player){
  1566. if(reward_coins > 0)
  1567. player->AddCoins(reward_coins);
  1568. if(!GetQuestTemporaryState())
  1569. reward_items.clear();
  1570. }
  1571. bool Quest::GetDeleted(){
  1572. return deleted;
  1573. }
  1574. void Quest::SetDeleted(bool val){
  1575. deleted = val;
  1576. }
  1577. bool Quest::GetUpdateRequired(){
  1578. return update_needed;
  1579. }
  1580. void Quest::SetUpdateRequired(bool val){
  1581. update_needed = val;
  1582. }
  1583. void Quest::SetTurnedIn(bool val){
  1584. turned_in = val;
  1585. visible = 0;
  1586. }
  1587. bool Quest::GetTurnedIn(){
  1588. return turned_in;
  1589. }
  1590. void Quest::SetName(string in_name) {
  1591. name = in_name;
  1592. }
  1593. void Quest::SetType(string in_type) {
  1594. type = in_type;
  1595. }
  1596. void Quest::SetLevel(int8 in_level) {
  1597. level = in_level;
  1598. }
  1599. void Quest::SetCompletedFlag(bool val) {
  1600. completed_flag = val;
  1601. SetUpdateRequired(true);
  1602. if(player && player->GetClient())
  1603. player->GetClient()->SendQuestJournalUpdate(this, true);
  1604. }
  1605. void Quest::SetStepTimer(int32 duration) {
  1606. m_timestamp = duration == 0 ? 0 : Timer::GetUnixTimeStamp() + duration;
  1607. }
  1608. void Quest::StepFailed(int32 step) {
  1609. if(lua_interface && failed_actions.count(step) > 0 && failed_actions[step].length() > 0)
  1610. lua_interface->CallQuestFunction(this, failed_actions[step].c_str(), player);
  1611. }
  1612. MasterQuestList::MasterQuestList(){
  1613. MQuests.SetName("MasterQuestList::MQuests");
  1614. }
  1615. void MasterQuestList::Reload(){
  1616. MQuests.lock();
  1617. quests.clear(); //deletes taken care of in LuaInterface
  1618. if(lua_interface)
  1619. lua_interface->DestroyQuests(true);
  1620. MQuests.unlock();
  1621. }
  1622. void MasterQuestList::LockQuests(){
  1623. MQuests.lock();
  1624. }
  1625. void MasterQuestList::UnlockQuests(){
  1626. MQuests.unlock();
  1627. }
  1628. void Quest::SetQuestTemporaryState(bool tempState, std::string customDescription)
  1629. {
  1630. if(!tempState)
  1631. {
  1632. tmp_reward_coins = 0;
  1633. tmp_reward_status = 0;
  1634. for(int32 i=0;i<tmp_reward_items.size();i++)
  1635. safe_delete(tmp_reward_items[i]);
  1636. tmp_reward_items.clear();
  1637. }
  1638. quest_state_temporary = tempState;
  1639. quest_temporary_description = customDescription;
  1640. }
  1641. bool Quest::CanShareQuestCriteria(Client* quest_sharer, bool display_client_msg) {
  1642. Quest* clientQuest = quest_sharer->GetPlayer()->GetQuest(GetQuestID()); // gets active quest if available
  1643. if(((GetQuestShareableFlag() & QUEST_SHAREABLE_COMPLETED) == 0) && quest_sharer->GetPlayer()->HasQuestBeenCompleted(GetQuestID())) {
  1644. if(display_client_msg)
  1645. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest after it is already completed.");
  1646. return false;
  1647. }
  1648. else if((GetQuestShareableFlag() == QUEST_SHAREABLE_COMPLETED) && !quest_sharer->GetPlayer()->HasQuestBeenCompleted(GetQuestID())) {
  1649. if(display_client_msg)
  1650. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest until it is completed.");
  1651. return false;
  1652. }
  1653. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_DURING) == 0) && clientQuest && clientQuest->GetQuestStep() > 1) {
  1654. if(display_client_msg)
  1655. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest after already completing a step.");
  1656. return false;
  1657. }
  1658. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_ACTIVE) == 0) && clientQuest) {
  1659. if(display_client_msg)
  1660. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest while it is active.");
  1661. return false;
  1662. }
  1663. else if(!GetQuestShareableFlag()) {
  1664. if(display_client_msg)
  1665. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You cannot share this quest.");
  1666. return false;
  1667. }
  1668. else if(((GetQuestShareableFlag() & QUEST_SHAREABLE_COMPLETED) == 0) && clientQuest == nullptr) {
  1669. if(display_client_msg)
  1670. quest_sharer->SimpleMessage(CHANNEL_COLOR_RED, "You do not have this quest.");
  1671. return false;
  1672. }
  1673. return true;
  1674. }