9
3

Tradeskills.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. client->QueuePacket(packet->serialize());
  193. safe_delete(packet);
  194. }
  195. if (tradeskill->currentProgress >= 1000) {
  196. itr++;
  197. StopCrafting(client, false);
  198. continue;
  199. }
  200. else
  201. tradeskill->nextUpdateTime = Timer::GetCurrentTime2() + 4000;
  202. }
  203. itr++;
  204. }
  205. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  206. }
  207. void TradeskillMgr::BeginCrafting(Client* client, vector<pair<int32,int16>> components) {
  208. Recipe* recipe = master_recipe_list.GetRecipe(client->GetPlayer()->GetCurrentRecipe());
  209. if (!recipe) {
  210. LogWrite(TRADESKILL__ERROR, 0, "Recipe", "Recipe (%u) not found in TradeskillMgr::BeginCrafting()", client->GetPlayer()->GetCurrentRecipe());
  211. ClientPacketFunctions::StopCrafting(client);
  212. return;
  213. }
  214. // TODO: use the vecotr to lock inventory slots
  215. vector<pair<int32, int16>>::iterator itr;
  216. bool missingItem = false;
  217. int32 itemid = 0;
  218. vector<Item*> tmpItems;
  219. for (itr = components.begin(); itr != components.end(); itr++) {
  220. itemid = itr->first;
  221. Item* item = client->GetPlayer()->item_list.GetItemFromUniqueID(itemid);
  222. if(!item)
  223. {
  224. missingItem = true;
  225. break;
  226. }
  227. item->details.item_locked = true;
  228. tmpItems.push_back(item);
  229. }
  230. if (missingItem) {
  231. LogWrite(TRADESKILL__ERROR, 0, "Recipe", "Recipe (%u) player missing item %u",itemid);
  232. vector<Item*>::iterator itemitr;
  233. for (itemitr = tmpItems.begin(); itemitr != tmpItems.end(); itemitr++) {
  234. Item* tmpItem = *itemitr;
  235. tmpItem->details.item_locked = false;
  236. }
  237. ClientPacketFunctions::StopCrafting(client);
  238. return;
  239. }
  240. ClientPacketFunctions::SendItemCreationUI(client, recipe);
  241. Tradeskill* tradeskill = new Tradeskill;
  242. tradeskill->player = client->GetPlayer();
  243. tradeskill->table = client->GetPlayer()->GetTarget();
  244. tradeskill->recipe = recipe;
  245. tradeskill->currentDurability = 1000;
  246. tradeskill->currentProgress = 0;
  247. tradeskill->nextUpdateTime = Timer::GetCurrentTime2() + 500;
  248. tradeskill->usedComponents = components;
  249. tradeskill->CurrentEvent = 0;
  250. tradeskill->eventChecked = false;
  251. tradeskill->eventCountered = false;
  252. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  253. tradeskillList.insert(make_pair(client, tradeskill));
  254. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  255. // Unlock TS Spells and lock all others
  256. client->GetPlayer()->UnlockTSSpells();
  257. client->ClearSentItemDetails();
  258. EQ2Packet* outapp = client->GetPlayer()->SendInventoryUpdate(client->GetVersion());
  259. if (outapp)
  260. client->QueuePacket(outapp);
  261. }
  262. void TradeskillMgr::StopCrafting(Client* client, bool lock) {
  263. if (lock)
  264. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  265. if (tradeskillList.count(client) == 0) {
  266. if (lock)
  267. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  268. return;
  269. }
  270. Tradeskill* tradeskill = 0;
  271. tradeskill = tradeskillList[client];
  272. //TODO: unlock inventory slots, give the product to the player, give tradeskill xp
  273. ClientPacketFunctions::StopCrafting(client);
  274. int32 dur = tradeskill->currentDurability;
  275. int32 progress = tradeskill->currentProgress;
  276. Recipe* recipe = tradeskill->recipe;
  277. vector<pair<int32, int16>>::iterator itr;
  278. Item* item = 0;
  279. int32 item_id = 0;
  280. int8 i = 0;
  281. int8 qty = 0;
  282. Recipe* playerRecipe = client->GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID());
  283. if(!playerRecipe)
  284. {
  285. 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());
  286. client->Message(CHANNEL_COLOR_RED, "%s: StopCrafting Error finding player recipe in their recipe book for recipe id %u!", client->GetPlayer()->GetName(), recipe->GetID());
  287. if (lock)
  288. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  289. return;
  290. }
  291. bool updateInvReq = false;
  292. // cycle through the list of used items and remove them
  293. for (itr = tradeskill->usedComponents.begin(); itr != tradeskill->usedComponents.end(); itr++, i++) {
  294. // Get the item in the players inventory and remove or reduce the quantity
  295. int32 itmid = itr->first;
  296. qty = itr->second;
  297. item = client->GetPlayer()->item_list.GetItemFromUniqueID(itmid);
  298. if (item && item->details.count <= qty)
  299. {
  300. item->details.item_locked = false;
  301. client->GetPlayer()->item_list.RemoveItem(item);
  302. }
  303. else if(item) {
  304. item->details.count -= qty;
  305. item->details.item_locked = false;
  306. item->save_needed = true;
  307. updateInvReq = true;
  308. }
  309. else
  310. {
  311. 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());
  312. client->Message(CHANNEL_COLOR_RED, "%s: StopCrafting Error finding item %u to remove quantity for recipe id %u!", client->GetPlayer()->GetName(), itmid, recipe->GetID());
  313. }
  314. }
  315. if(updateInvReq)
  316. {
  317. EQ2Packet* outapp = client->GetPlayer()->SendInventoryUpdate(client->GetVersion());
  318. if (outapp)
  319. client->QueuePacket(outapp);
  320. }
  321. item = 0;
  322. qty = recipe->GetFuelComponentQuantity();
  323. item_id = recipe->components[5][0];
  324. float tsx = 0;
  325. int8 HS = playerRecipe->GetHighestStage();
  326. if (progress < 400) { //stage 0
  327. if (recipe->products.count(0) > 0) {
  328. item_id = recipe->products[0]->product_id;
  329. qty = recipe->products[0]->product_qty;
  330. }
  331. tsx = 1;
  332. }
  333. else if (progress >= 400 && progress < 600) { //stage 1
  334. if (HS & (1 << (1 - 1))) {
  335. }
  336. else {
  337. playerRecipe->SetHighestStage(HS + 1 );
  338. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  339. }
  340. if (recipe->products.count(1) > 0) {
  341. item_id = recipe->products[1]->product_id;
  342. qty = recipe->products[1]->product_qty;
  343. }
  344. tsx = .45;
  345. }
  346. else if (progress >= 600 && progress < 800) { //stage 2
  347. //else if ((dur < 200 && progress >= 600) || (dur >= 200 && progress >= 600 && progress < 800)) { //stage 2
  348. if (HS & (1 << (2 - 1))) {
  349. }
  350. else {
  351. playerRecipe->SetHighestStage(HS + 2);
  352. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  353. }
  354. if (recipe->products.count(2) > 0) {
  355. item_id = recipe->products[2]->product_id;
  356. qty = recipe->products[2]->product_qty;
  357. }
  358. tsx = .30;
  359. }
  360. //else if ((dur >= 200 && dur < 800 && progress >= 800) || (dur >= 800 && progress >= 800 && progress < 1000)) { // stage 3
  361. else if (progress >= 800 && progress < 1000) { // stage 3
  362. if (HS & (1 << (3 - 1))) {
  363. }
  364. else {
  365. playerRecipe->SetHighestStage(HS + 4);
  366. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  367. }
  368. if (recipe->products.count(3) > 0) {
  369. item_id = recipe->products[3]->product_id;
  370. qty = recipe->products[3]->product_qty;
  371. }
  372. tsx = .15;
  373. }
  374. //else if (dur >= 800 && progress >= 1000) { // stage 4
  375. else if (progress >= 1000) { // stage 4
  376. if (HS & (1 << (4 - 1))) {
  377. }
  378. else {
  379. playerRecipe->SetHighestStage(HS + 8);
  380. database.UpdatePlayerRecipe(client->GetPlayer(), recipe->GetID(), playerRecipe->GetHighestStage());
  381. }
  382. if (recipe->products.count(4) > 0) {
  383. item_id = recipe->products[4]->product_id;
  384. qty = recipe->products[4]->product_qty;
  385. }
  386. }
  387. item = new Item(master_item_list.GetItem(item_id));
  388. if (!item) {
  389. LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "Item (%u) not found.", item_id);
  390. }
  391. else {
  392. item->details.count = qty;
  393. // use CHANNEL_COLOR_CHAT_RELATIONSHIP as that is the same value (4) as it is in a log for this message
  394. client->Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "You created %s.", item->CreateItemLink(client->GetVersion()).c_str());
  395. client->AddItem(item);
  396. //Check for crafting quest updates
  397. int8 update_amt = 0;
  398. if(item->stack_count > 1)
  399. update_amt = 1;
  400. else
  401. update_amt = qty;
  402. client->GetPlayer()->CheckQuestsCraftUpdate(item, update_amt);
  403. }
  404. float xp = client->GetPlayer()->CalculateTSXP(recipe->GetLevel());
  405. xp = xp - (xp * tsx);
  406. if (xp > 0) {
  407. int16 level = client->GetPlayer()->GetTSLevel();
  408. if (client->GetPlayer()->AddTSXP((int32)xp)) {
  409. client->Message(CHANNEL_REWARD, "You gain %u Tradeskill XP!", (int32)xp);
  410. LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u tradeskill experience.", client->GetPlayer()->GetName(), (int32)xp);
  411. if(client->GetPlayer()->GetTSLevel() != level)
  412. client->ChangeTSLevel(level, client->GetPlayer()->GetTSLevel());
  413. client->GetPlayer()->SetCharSheetChanged(true);
  414. }
  415. }
  416. tradeskillList.erase(client);
  417. safe_delete(tradeskill);
  418. if (lock)
  419. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  420. // Lock TS spells and unlock all others
  421. client->GetPlayer()->LockTSSpells();
  422. }
  423. bool TradeskillMgr::IsClientCrafting(Client* client) {
  424. bool ret = false;
  425. m_tradeskills.readlock(__FUNCTION__, __LINE__);
  426. ret = tradeskillList.count(client) > 0;
  427. m_tradeskills.releasereadlock(__FUNCTION__, __LINE__);
  428. return ret;
  429. }
  430. void TradeskillMgr::CheckTradeskillEvent(Client* client, int16 icon) {
  431. // Check to see if the given client is crafting
  432. if (!IsClientCrafting(client))
  433. return;
  434. m_tradeskills.writelock(__FUNCTION__, __LINE__);
  435. // check to see if the client currently has an event and if it does if we had already tried to counter it this round
  436. if (tradeskillList[client]->CurrentEvent == 0 || tradeskillList[client]->eventChecked) {
  437. // No current event, or we already tried to counter it, return out
  438. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  439. return;
  440. }
  441. // set the eventChecked flag so we don't try to counter it again
  442. tradeskillList[client]->eventChecked = true;
  443. // compare the event icon with the given spell icon to see if we countered it and store the result for the update
  444. bool countered = (icon == tradeskillList[client]->CurrentEvent->Icon);
  445. tradeskillList[client]->eventCountered = countered;
  446. // send the success or fail message to the client
  447. client->Message(CHANNEL_NARRATIVE, "You %s %s.", countered ? "successfully countered" : "failed to counter", tradeskillList[client]->CurrentEvent->Name);
  448. // unlock the list and send the result packet
  449. m_tradeskills.releasewritelock(__FUNCTION__, __LINE__);
  450. ClientPacketFunctions::CounterReaction(client, countered);
  451. }
  452. Tradeskill* TradeskillMgr::GetTradeskill(Client* client) {
  453. if (tradeskillList.count(client) == 0)
  454. return 0;
  455. return tradeskillList[client];
  456. }
  457. MasterTradeskillEventsList::MasterTradeskillEventsList() {
  458. m_eventList.SetName("MasterTradeskillEventsList::eventList");
  459. }
  460. MasterTradeskillEventsList::~MasterTradeskillEventsList() {
  461. m_eventList.writelock(__FUNCTION__, __LINE__);
  462. map<int32, vector<TradeskillEvent*> >::iterator itr;
  463. vector<TradeskillEvent*>::iterator ts_itr;
  464. for (itr = eventList.begin(); itr != eventList.end(); itr++){
  465. for (ts_itr = itr->second.begin(); ts_itr != itr->second.end(); ts_itr++){
  466. safe_delete(*ts_itr);
  467. }
  468. }
  469. eventList.clear();
  470. m_eventList.releasewritelock(__FUNCTION__, __LINE__);
  471. }
  472. void MasterTradeskillEventsList::AddEvent(TradeskillEvent* tradeskillEvent) {
  473. m_eventList.writelock(__FUNCTION__, __LINE__);
  474. eventList[tradeskillEvent->Technique].push_back(tradeskillEvent);
  475. m_eventList.releasewritelock(__FUNCTION__, __LINE__);
  476. }
  477. vector<TradeskillEvent*>* MasterTradeskillEventsList::GetEventByTechnique(int32 technique) {
  478. if (eventList.count(technique) == 0)
  479. return 0;
  480. return &eventList[technique];
  481. }
  482. int32 MasterTradeskillEventsList::Size() {
  483. int32 count = 0;
  484. m_eventList.readlock(__FUNCTION__, __LINE__);
  485. map<int32, vector<TradeskillEvent*> >::iterator itr;
  486. for (itr = eventList.begin(); itr != eventList.end(); itr++)
  487. count += itr->second.size();
  488. m_eventList.releasereadlock(__FUNCTION__, __LINE__);
  489. return count;
  490. }