9
3

Tradeskills.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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 "Tradeskills.h"
  17. #include "../client.h"
  18. #include "../../common/ConfigReader.h"
  19. #include "../classes.h"
  20. //#include "../../common/debug.h"
  21. #include "../../common/Log.h"
  22. //#include "../zoneserver.h"
  23. //#include "../Skills.h"
  24. //#include "../classes.h"
  25. #include "../World.h"
  26. //#include "../LuaInterface.h"
  27. #include "../ClientPacketFunctions.h"
  28. #include "../WorldDatabase.h"
  29. #include "../Rules/Rules.h"
  30. extern Classes classes;
  31. extern ConfigReader configReader;
  32. extern MasterSkillList master_skill_list;
  33. extern MasterRecipeList master_recipe_list;
  34. extern MasterTradeskillEventsList master_tradeskillevent_list;
  35. extern WorldDatabase database;
  36. extern RuleManager rule_manager;
  37. TradeskillMgr::TradeskillMgr() {
  38. m_tradeskills.SetName("TradeskillMgr::tradeskillsList");
  39. // % chance for each was made up by me (Jabantiz) and may need some tweaking
  40. // 2% for crit fail
  41. m_success = rule_manager.GetGlobalRule(R_World, TradeskillSuccessChance)->GetFloat();
  42. m_critSuccess = rule_manager.GetGlobalRule(R_World, TradeskillCritSuccessChance)->GetFloat();
  43. m_fail = rule_manager.GetGlobalRule(R_World, TradeskillFailChance)->GetFloat();
  44. m_critFail = rule_manager.GetGlobalRule(R_World, TradeskillCritFailChance)->GetFloat();
  45. m_eventChance = rule_manager.GetGlobalRule(R_World, TradeskillEventChance)->GetFloat();
  46. if ((m_success + m_critSuccess + m_fail + m_critFail) != 100.0f) {
  47. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "Success, crit success, fail, and crit fail MUST add up to 100, reverting to defaults...");
  48. m_success = 87.0f;
  49. m_critSuccess = 2.0f;
  50. m_fail = 10.0f;
  51. m_critFail = 1.0f;
  52. }
  53. }
  54. TradeskillMgr::~TradeskillMgr() {
  55. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  56. map<Client*, Tradeskill*>::iterator itr;
  57. for (itr = tradeskillList.begin(); itr != tradeskillList.end(); itr++)
  58. safe_delete(itr->second);
  59. tradeskillList.clear();
  60. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  61. }
  62. void TradeskillMgr::Process() {
  63. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  64. map<Client*, Tradeskill*>::iterator itr = tradeskillList.begin();
  65. while (itr != tradeskillList.end()) {
  66. Tradeskill* tradeskill = 0;
  67. tradeskill = itr->second;
  68. if (!tradeskill)
  69. continue;
  70. if (Timer::GetCurrentTime2() >= tradeskill->nextUpdateTime) {
  71. Client* client = itr->first;
  72. sint32 progress = 0;
  73. sint32 durability = 0;
  74. /*
  75. Following was grabbed from
  76. http://eq2.stratics.com/content/guides/padasher_crafting_2.php
  77. old but the base fail/succes should still be the same
  78. -100 Durability / -50 Progress (Critical Failure)
  79. -50 Durability / 0 Progress (Failure)
  80. -10 Durability / +50 Progress (Standard tick)
  81. +10 Durability / + 100 Progress (Critical Success)
  82. */
  83. float roll = MakeRandomFloat(0, 100);
  84. int8 effect = 0; //1 is critical success, 2 is success, 3 is failure, and 4 is critical failure.
  85. float success = m_success;
  86. float crit_success = m_critSuccess;
  87. float fail = m_fail;
  88. float crit_fail = m_critFail;
  89. // Modify the % chance for success based off of stats
  90. client->GetPlayer()->MStats.lock();
  91. fail -= client->GetPlayer()->stats[ITEM_STAT_SUCCESS_MOD];
  92. success += client->GetPlayer()->stats[ITEM_STAT_SUCCESS_MOD];
  93. client->GetPlayer()->MStats.unlock();
  94. // add values together for the if
  95. crit_success += crit_fail;
  96. fail += crit_success;
  97. success += fail;
  98. // Crit fail
  99. if (roll <= crit_fail) {
  100. progress = -50;
  101. durability = -100;
  102. effect = 4;
  103. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Critical failure!");
  104. }
  105. // Crit success
  106. else if (roll > crit_fail && roll <= crit_success) {
  107. progress = 100;
  108. durability = 10;
  109. effect = 1;
  110. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Critical success!");
  111. }
  112. // Fail
  113. else if (roll > crit_success && roll <= fail) {
  114. progress = 0;
  115. durability = -50;
  116. effect = 3;
  117. }
  118. // Success
  119. else if (roll > fail && roll <= success) {
  120. progress = 50;
  121. durability = -10;
  122. effect = 2;
  123. }
  124. else {
  125. // Just a debug, should never end up in this, if we do write out a log but treat as a success for the player
  126. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "Process roll was not within valid range. roll = %f, crit fail = %f, crit success = %f, fail = %f, success = %f", roll, crit_fail, crit_success, fail, success);
  127. progress = 50;
  128. durability = -10;
  129. effect = 2;
  130. }
  131. // Check to see if there was an event, if there was give out the rewards/penalties for it
  132. if (tradeskill->CurrentEvent) {
  133. if (tradeskill->eventCountered) {
  134. progress += tradeskill->CurrentEvent->SuccessProgress;
  135. durability += tradeskill->CurrentEvent->SuccessDurability;
  136. }
  137. else {
  138. progress += tradeskill->CurrentEvent->FailProgress;
  139. durability += tradeskill->CurrentEvent->FailDurability;
  140. }
  141. }
  142. // Modify the progress/durability by the players stats
  143. client->GetPlayer()->MStats.lock();
  144. progress += client->GetPlayer()->stats[ITEM_STAT_PROGRESS_ADD];
  145. durability += client->GetPlayer()->stats[ITEM_STAT_DURABILITY_ADD];
  146. client->GetPlayer()->MStats.unlock();
  147. tradeskill->currentDurability += durability;
  148. tradeskill->currentProgress += progress;
  149. PacketStruct* packet = configReader.getStruct("WS_UpdateCreateItem", client->GetVersion());
  150. if (packet) {
  151. packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(tradeskill->table));
  152. packet->setDataByName("effect", effect);
  153. packet->setDataByName("total_durability", tradeskill->currentDurability);
  154. packet->setDataByName("total_progress", tradeskill->currentProgress);
  155. packet->setDataByName("durability_change", durability);
  156. packet->setDataByName("progress_change", progress);
  157. if (tradeskill->currentProgress >= 1000)
  158. packet->setDataByName("progress_level", 4);
  159. else if (tradeskill->currentProgress >= 800)
  160. packet->setDataByName("progress_level", 3);
  161. else if (tradeskill->currentProgress >= 600)
  162. packet->setDataByName("progress_level", 2);
  163. else if (tradeskill->currentProgress >= 400)
  164. packet->setDataByName("progress_level", 1);
  165. else
  166. packet->setDataByName("progress_level", 0);
  167. // Reset the tradeskill event
  168. tradeskill->CurrentEvent = 0;
  169. tradeskill->eventChecked = false;
  170. tradeskill->eventCountered = false;
  171. // 15% chance for an event (change this to a rule probably)
  172. int eventRoll = MakeRandomFloat(0, 100);
  173. if (eventRoll <= m_eventChance) {
  174. // Get a vector of all possible events for this crafting technique
  175. vector<TradeskillEvent*>* events = master_tradeskillevent_list.GetEventByTechnique(tradeskill->recipe->GetTechnique());
  176. if (events) {
  177. // Get the size of the vector
  178. int size = events->size();
  179. // Get a random number from 0 to size - 1 to use as an index
  180. int index = MakeRandomInt(0, size - 1);
  181. // use the index to get an event
  182. TradeskillEvent* TSEvent = events->at(index);
  183. if (TSEvent) {
  184. // Now that we got a random event set it in the packet
  185. packet->setDataByName("reaction_icon", TSEvent->Icon);
  186. packet->setDataByName("reaction_name", TSEvent->Name);
  187. // Set the current tradeskill event
  188. tradeskill->CurrentEvent = TSEvent;
  189. }
  190. }
  191. }
  192. EQ2Packet* pack = packet->serialize();
  193. packet->PrintPacket();
  194. client->QueuePacket(pack);
  195. safe_delete(packet);
  196. }
  197. if (tradeskill->currentProgress >= 1000) {
  198. itr++;
  199. StopCrafting(client, false);
  200. continue;
  201. }
  202. else
  203. tradeskill->nextUpdateTime = Timer::GetCurrentTime2() + 4000;
  204. }
  205. itr++;
  206. }
  207. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  208. }
  209. void TradeskillMgr::BeginCrafting(Client* client, vector<pair<int32,int16>> components) {
  210. Recipe* recipe = master_recipe_list.GetRecipe(client->GetPlayer()->GetCurrentRecipe());
  211. if (!recipe) {
  212. LogWrite(TRADESKILL__ERROR, 0, "Recipe", "Recipe (%u) not found in TradeskillMgr::BeginCrafting()", client->GetPlayer()->GetCurrentRecipe());
  213. ClientPacketFunctions::StopCrafting(client);
  214. return;
  215. }
  216. // TODO: use the vecotr to lock inventory slots
  217. vector<pair<int32, int16>>::iterator itr;
  218. bool missingItem = false;
  219. int32 itemid = 0;
  220. vector<Item*> tmpItems;
  221. for (itr = components.begin(); itr != components.end(); itr++) {
  222. itemid = itr->first;
  223. Item* item = client->GetPlayer()->item_list.GetItemFromUniqueID(itemid);
  224. if(!item)
  225. {
  226. missingItem = true;
  227. break;
  228. }
  229. item->details.item_locked = true;
  230. tmpItems.push_back(item);
  231. }
  232. if (missingItem) {
  233. LogWrite(TRADESKILL__ERROR, 0, "Recipe", "Recipe (%u) player missing item %u",itemid);
  234. vector<Item*>::iterator itemitr;
  235. for (itemitr = tmpItems.begin(); itemitr != tmpItems.end(); itemitr++) {
  236. Item* tmpItem = *itemitr;
  237. tmpItem->details.item_locked = false;
  238. }
  239. ClientPacketFunctions::StopCrafting(client);
  240. return;
  241. }
  242. ClientPacketFunctions::SendItemCreationUI(client, recipe);
  243. Tradeskill* tradeskill = new Tradeskill;
  244. tradeskill->player = client->GetPlayer();
  245. tradeskill->table = client->GetPlayer()->GetTarget();
  246. tradeskill->recipe = recipe;
  247. tradeskill->currentDurability = 1000;
  248. tradeskill->currentProgress = 0;
  249. tradeskill->nextUpdateTime = Timer::GetCurrentTime2() + 500;
  250. tradeskill->usedComponents = components;
  251. tradeskill->CurrentEvent = 0;
  252. tradeskill->eventChecked = false;
  253. tradeskill->eventCountered = false;
  254. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  255. tradeskillList.insert(make_pair(client, tradeskill));
  256. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  257. // Unlock TS Spells and lock all others
  258. client->GetPlayer()->UnlockTSSpells();
  259. client->ClearSentItemDetails();
  260. EQ2Packet* outapp = client->GetPlayer()->SendInventoryUpdate(client->GetVersion());
  261. if (outapp)
  262. client->QueuePacket(outapp);
  263. }
  264. void TradeskillMgr::StopCrafting(Client* client, bool lock) {
  265. if (lock)
  266. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  267. if (tradeskillList.count(client) == 0) {
  268. if (lock)
  269. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  270. return;
  271. }
  272. Tradeskill* tradeskill = 0;
  273. tradeskill = tradeskillList[client];
  274. //TODO: unlock inventory slots, give the product to the player, give tradeskill xp
  275. ClientPacketFunctions::StopCrafting(client);
  276. int32 dur = tradeskill->currentDurability;
  277. int32 progress = tradeskill->currentProgress;
  278. Recipe* recipe = tradeskill->recipe;
  279. vector<pair<int32, int16>>::iterator itr;
  280. Item* item = 0;
  281. int32 item_id = 0;
  282. int8 i = 0;
  283. int8 qty = 0;
  284. Recipe* playerRecipe = client->GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID());
  285. if(!playerRecipe)
  286. {
  287. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "%s: TradeskillMgr::StopCrafting Error finding player recipe in their recipe book for recipe id %u", client->GetPlayer()->GetName(), recipe->GetID());
  288. client->Message(CHANNEL_COLOR_RED, "%s: StopCrafting Error finding player recipe in their recipe book for recipe id %u!", client->GetPlayer()->GetName(), recipe->GetID());
  289. if (lock)
  290. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  291. return;
  292. }
  293. bool updateInvReq = false;
  294. // cycle through the list of used items and remove them
  295. for (itr = tradeskill->usedComponents.begin(); itr != tradeskill->usedComponents.end(); itr++, i++) {
  296. // Get the item in the players inventory and remove or reduce the quantity
  297. int32 itmid = itr->first;
  298. qty = itr->second;
  299. item = client->GetPlayer()->item_list.GetItemFromUniqueID(itmid);
  300. if (item && item->details.count <= qty)
  301. {
  302. item->details.item_locked = false;
  303. client->GetPlayer()->item_list.RemoveItem(item);
  304. }
  305. else if(item) {
  306. item->details.count -= qty;
  307. item->details.item_locked = false;
  308. item->save_needed = true;
  309. updateInvReq = true;
  310. }
  311. else
  312. {
  313. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "%s: TradeskillMgr::StopCrafting Error finding item %u to remove quantity for recipe id %u", client->GetPlayer()->GetName(), itmid, recipe->GetID());
  314. client->Message(CHANNEL_COLOR_RED, "%s: StopCrafting Error finding item %u to remove quantity for recipe id %u!", client->GetPlayer()->GetName(), itmid, recipe->GetID());
  315. }
  316. }
  317. if(updateInvReq)
  318. {
  319. EQ2Packet* outapp = client->GetPlayer()->SendInventoryUpdate(client->GetVersion());
  320. if (outapp)
  321. client->QueuePacket(outapp);
  322. }
  323. item = 0;
  324. qty = recipe->GetFuelComponentQuantity();
  325. item_id = recipe->components[5][0];
  326. float tsx = 0;
  327. int8 HS = playerRecipe->GetHighestStage();
  328. if (progress < 400) { //stage 0
  329. if (recipe->products.count(0) > 0) {
  330. item_id = recipe->products[0]->product_id;
  331. qty = recipe->products[0]->product_qty;
  332. }
  333. tsx = 1;
  334. }
  335. else if (progress >= 400 && progress < 600) { //stage 1
  336. if (HS & (1 << (1 - 1))) {
  337. }
  338. else {
  339. playerRecipe->SetHighestStage(HS + 1 );
  340. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  341. }
  342. if (recipe->products.count(1) > 0) {
  343. item_id = recipe->products[1]->product_id;
  344. qty = recipe->products[1]->product_qty;
  345. }
  346. tsx = .45;
  347. }
  348. else if (progress >= 600 && progress < 800) { //stage 2
  349. //else if ((dur < 200 && progress >= 600) || (dur >= 200 && progress >= 600 && progress < 800)) { //stage 2
  350. if (HS & (1 << (2 - 1))) {
  351. }
  352. else {
  353. playerRecipe->SetHighestStage(HS + 2);
  354. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  355. }
  356. if (recipe->products.count(2) > 0) {
  357. item_id = recipe->products[2]->product_id;
  358. qty = recipe->products[2]->product_qty;
  359. }
  360. tsx = .30;
  361. }
  362. //else if ((dur >= 200 && dur < 800 && progress >= 800) || (dur >= 800 && progress >= 800 && progress < 1000)) { // stage 3
  363. else if (progress >= 800 && progress < 1000) { // stage 3
  364. if (HS & (1 << (3 - 1))) {
  365. }
  366. else {
  367. playerRecipe->SetHighestStage(HS + 4);
  368. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  369. }
  370. if (recipe->products.count(3) > 0) {
  371. item_id = recipe->products[3]->product_id;
  372. qty = recipe->products[3]->product_qty;
  373. }
  374. tsx = .15;
  375. }
  376. //else if (dur >= 800 && progress >= 1000) { // stage 4
  377. else if (progress >= 1000) { // stage 4
  378. if (HS & (1 << (4 - 1))) {
  379. }
  380. else {
  381. playerRecipe->SetHighestStage(HS + 8);
  382. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  383. }
  384. if (recipe->products.count(4) > 0) {
  385. item_id = recipe->products[4]->product_id;
  386. qty = recipe->products[4]->product_qty;
  387. }
  388. }
  389. item = new Item(master_item_list.GetItem(item_id));
  390. if (!item) {
  391. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "Item (%u) not found.", item_id);
  392. }
  393. else {
  394. item->details.count = qty;
  395. // use CHANNEL_COLOR_CHAT_RELATIONSHIP as that is the same value (4) as it is in a log for this message
  396. client->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "You created %s.", item->CreateItemLink(client->GetVersion()).c_str());
  397. client->AddItem(item);
  398. //Check for crafting quest updates
  399. int8 update_amt = 0;
  400. if(item->stack_count > 1)
  401. update_amt = 1;
  402. else
  403. update_amt = qty;
  404. client->GetPlayer()->CheckQuestsCraftUpdate(item, update_amt);
  405. }
  406. float xp = client->GetPlayer()->CalculateTSXP(recipe->GetLevel());
  407. xp = xp - (xp * tsx);
  408. if (xp > 0) {
  409. int16 level = client->GetPlayer()->GetTSLevel();
  410. if (client->GetPlayer()->AddTSXP((int32)xp)) {
  411. client->Message(CHANNEL_REWARD, "You gain %u Tradeskill XP!", (int32)xp);
  412. LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u tradeskill experience.", client->GetPlayer()->GetName(), (int32)xp);
  413. if(client->GetPlayer()->GetTSLevel() != level)
  414. client->ChangeTSLevel(level, client->GetPlayer()->GetTSLevel());
  415. client->GetPlayer()->SetCharSheetChanged(true);
  416. }
  417. }
  418. tradeskillList.erase(client);
  419. safe_delete(tradeskill);
  420. if (lock)
  421. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  422. // Lock TS spells and unlock all others
  423. client->GetPlayer()->LockTSSpells();
  424. }
  425. bool TradeskillMgr::IsClientCrafting(Client* client) {
  426. bool ret = false;
  427. m_tradeskills.readlock(__FUNCTION__, __LINE__);
  428. ret = tradeskillList.count(client) > 0;
  429. m_tradeskills.releasereadlock(__FUNCTION__, __LINE__);
  430. return ret;
  431. }
  432. void TradeskillMgr::CheckTradeskillEvent(Client* client, int16 icon) {
  433. // Check to see if the given client is crafting
  434. if (!IsClientCrafting(client))
  435. return;
  436. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  437. // check to see if the client currently has an event and if it does if we had already tried to counter it this round
  438. if (tradeskillList[client]->CurrentEvent == 0 || tradeskillList[client]->eventChecked) {
  439. // No current event, or we already tried to counter it, return out
  440. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  441. return;
  442. }
  443. // set the eventChecked flag so we don't try to counter it again
  444. tradeskillList[client]->eventChecked = true;
  445. // compare the event icon with the given spell icon to see if we countered it and store the result for the update
  446. bool countered = (icon == tradeskillList[client]->CurrentEvent->Icon);
  447. tradeskillList[client]->eventCountered = countered;
  448. // send the success or fail message to the client
  449. client->Message(CHANNEL_NARRATIVE, "You %s %s.", countered ? "successfully countered" : "failed to counter", tradeskillList[client]->CurrentEvent->Name);
  450. // unlock the list and send the result packet
  451. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  452. ClientPacketFunctions::CounterReaction(client, countered);
  453. }
  454. Tradeskill* TradeskillMgr::GetTradeskill(Client* client) {
  455. if (tradeskillList.count(client) == 0)
  456. return 0;
  457. return tradeskillList[client];
  458. }
  459. MasterTradeskillEventsList::MasterTradeskillEventsList() {
  460. m_eventList.SetName("MasterTradeskillEventsList::eventList");
  461. }
  462. MasterTradeskillEventsList::~MasterTradeskillEventsList() {
  463. m_eventList.writelock(__FUNCTION__, __LINE__);
  464. map<int32, vector<TradeskillEvent*> >::iterator itr;
  465. vector<TradeskillEvent*>::iterator ts_itr;
  466. for (itr = eventList.begin(); itr != eventList.end(); itr++){
  467. for (ts_itr = itr->second.begin(); ts_itr != itr->second.end(); ts_itr++){
  468. safe_delete(*ts_itr);
  469. }
  470. }
  471. eventList.clear();
  472. m_eventList.releasewritelock(__FUNCTION__, __LINE__);
  473. }
  474. void MasterTradeskillEventsList::AddEvent(TradeskillEvent* tradeskillEvent) {
  475. m_eventList.writelock(__FUNCTION__, __LINE__);
  476. eventList[tradeskillEvent->Technique].push_back(tradeskillEvent);
  477. m_eventList.releasewritelock(__FUNCTION__, __LINE__);
  478. }
  479. vector<TradeskillEvent*>* MasterTradeskillEventsList::GetEventByTechnique(int32 technique) {
  480. if (eventList.count(technique) == 0)
  481. return 0;
  482. return &eventList[technique];
  483. }
  484. int32 MasterTradeskillEventsList::Size() {
  485. int32 count = 0;
  486. m_eventList.readlock(__FUNCTION__, __LINE__);
  487. map<int32, vector<TradeskillEvent*> >::iterator itr;
  488. for (itr = eventList.begin(); itr != eventList.end(); itr++)
  489. count += itr->second.size();
  490. m_eventList.releasereadlock(__FUNCTION__, __LINE__);
  491. return count;
  492. }