GroundSpawn.cpp 22 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 "GroundSpawn.h"
  17. #include "World.h"
  18. #include "Spells.h"
  19. #include "../common/MiscFunctions.h"
  20. #include "../common/Log.h"
  21. extern ConfigReader configReader;
  22. extern MasterSpellList master_spell_list;
  23. extern World world;
  24. GroundSpawn::GroundSpawn(){
  25. packet_num = 0;
  26. appearance.encounter_level = 0;
  27. spawn_type = 2;
  28. appearance.pos.state = 129;
  29. number_harvests = 0;
  30. num_attempts_per_harvest = 0;
  31. groundspawn_id = 0;
  32. MHarvest.SetName("GroundSpawn::MHarvest");
  33. MHarvestUse.SetName("GroundSpawn::MHarvestUse");
  34. randomize_heading = true; // we by default randomize heading of groundspawns DB overrides
  35. }
  36. GroundSpawn::~GroundSpawn(){
  37. }
  38. EQ2Packet* GroundSpawn::serialize(Player* player, int16 version){
  39. return spawn_serialize(player, version);
  40. }
  41. int8 GroundSpawn::GetNumberHarvests(){
  42. return number_harvests;
  43. }
  44. void GroundSpawn::SetNumberHarvests(int8 val){
  45. number_harvests = val;
  46. }
  47. int8 GroundSpawn::GetAttemptsPerHarvest(){
  48. return num_attempts_per_harvest;
  49. }
  50. void GroundSpawn::SetAttemptsPerHarvest(int8 val){
  51. num_attempts_per_harvest = val;
  52. }
  53. int32 GroundSpawn::GetGroundSpawnEntryID(){
  54. return groundspawn_id;
  55. }
  56. void GroundSpawn::SetGroundSpawnEntryID(int32 val){
  57. groundspawn_id = val;
  58. }
  59. void GroundSpawn::SetCollectionSkill(const char* val){
  60. if(val)
  61. collection_skill = string(val);
  62. }
  63. const char* GroundSpawn::GetCollectionSkill(){
  64. return collection_skill.c_str();
  65. }
  66. void GroundSpawn::ProcessHarvest(Client* client) {
  67. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Process harvesting for player '%s' (%u)", client->GetPlayer()->GetName(), client->GetPlayer()->GetID());
  68. MHarvest.lock();
  69. vector<GroundSpawnEntry*>* groundspawn_entries = GetZone()->GetGroundSpawnEntries(groundspawn_id);
  70. vector<GroundSpawnEntryItem*>* groundspawn_items = GetZone()->GetGroundSpawnEntryItems(groundspawn_id);
  71. Item* master_item = 0;
  72. Item* master_rare = 0;
  73. Item* item = 0;
  74. Item* item_rare = 0;
  75. int16 lowest_skill_level = 0;
  76. int16 table_choice = 0;
  77. int32 item_choice = 0;
  78. int32 rare_choice = 0;
  79. int8 harvest_type = 0;
  80. int32 item_harvested = 0;
  81. int8 reward_total = 1;
  82. int32 rare_harvested = 0;
  83. int8 rare_item = 0;
  84. bool is_collection = false;
  85. if (!groundspawn_entries || !groundspawn_items) {
  86. LogWrite(GROUNDSPAWN__ERROR, 3, "GSpawn", "No groundspawn entries or items assigned to groundspawn id: %u", groundspawn_id);
  87. client->Message(CHANNEL_COLOR_RED, "Error: There are no groundspawn entries or items assigned to groundspawn id: %u", groundspawn_id);
  88. MHarvest.unlock();
  89. return;
  90. }
  91. if (number_harvests == 0) {
  92. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Total harvests depleated for groundspawn id: %u", groundspawn_id);
  93. client->SimpleMessage(CHANNEL_COLOR_RED, "Error: This spawn has nothing more to harvest!");
  94. MHarvest.unlock();
  95. return;
  96. }
  97. Skill* skill = 0;
  98. if (collection_skill == "Collecting") {
  99. skill = client->GetPlayer()->GetSkillByName("Gathering");
  100. is_collection = true;
  101. }
  102. else
  103. skill = client->GetPlayer()->GetSkillByName(collection_skill.c_str(), true);
  104. if (!skill) {
  105. LogWrite(GROUNDSPAWN__WARNING, 3, "GSpawn", "Player '%s' lacks the skill: '%s'", client->GetPlayer()->GetName(), collection_skill.c_str());
  106. client->Message(CHANNEL_COLOR_RED, "Error: You do not have the '%s' skill!", collection_skill.c_str());
  107. MHarvest.unlock();
  108. return;
  109. }
  110. int16 totalSkill = skill->current_val;
  111. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  112. if(skillID != 0xFFFFFFFF)
  113. {
  114. ((Entity*)client->GetPlayer())->MStats.lock();
  115. totalSkill += ((Entity*)client->GetPlayer())->stats[skillID];
  116. ((Entity*)client->GetPlayer())->MStats.unlock();
  117. }
  118. for (int8 i = 0; i < num_attempts_per_harvest; i++) {
  119. vector<GroundSpawnEntry*> mod_groundspawn_entries;
  120. if (groundspawn_entries) {
  121. vector<GroundSpawnEntry*> highest_match;
  122. vector<GroundSpawnEntry*>::iterator itr;
  123. GroundSpawnEntry* entry = 0; // current data
  124. GroundSpawnEntry* selected_table = 0; // selected table data
  125. // first, iterate through groundspawn_entries, discard tables player cannot use
  126. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++) {
  127. entry = *itr;
  128. // if player lacks skill, skip table
  129. if (entry->min_skill_level > totalSkill)
  130. continue;
  131. // if bonus, but player lacks level, skip table
  132. if (entry->bonus_table && (client->GetPlayer()->GetLevel() < entry->min_adventure_level))
  133. continue;
  134. // build modified entries table
  135. mod_groundspawn_entries.push_back(entry);
  136. LogWrite(GROUNDSPAWN__DEBUG, 5, "GSpawn", "Keeping groundspawn_entry: %i", entry->min_skill_level);
  137. }
  138. // if anything remains, find lowest min_skill_level in remaining set(s)
  139. if (mod_groundspawn_entries.size() > 0) {
  140. vector<GroundSpawnEntry*>::iterator itr;
  141. GroundSpawnEntry* entry = 0;
  142. for (itr = mod_groundspawn_entries.begin(); itr != mod_groundspawn_entries.end(); itr++) {
  143. entry = *itr;
  144. // find the low range of available tables for random roll
  145. if (lowest_skill_level > entry->min_skill_level || lowest_skill_level == 0)
  146. lowest_skill_level = entry->min_skill_level;
  147. }
  148. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Lowest Skill Level: %i", lowest_skill_level);
  149. }
  150. else {
  151. // if no tables chosen, you must lack the skills
  152. // TODO: move this check to LUA when harvest command is first selected
  153. client->Message(CHANNEL_COLOR_RED, "You lack the skills to harvest this node!");
  154. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "All groundspawn_entry tables tossed! No Skills? Something broke?");
  155. MHarvest.unlock();
  156. return;
  157. }
  158. // now roll to see which table to use
  159. table_choice = MakeRandomInt(lowest_skill_level, totalSkill);
  160. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Random INT for Table by skill level: %i", table_choice);
  161. int16 highest_score = 0;
  162. for (itr = mod_groundspawn_entries.begin(); itr != mod_groundspawn_entries.end(); itr++) {
  163. entry = *itr;
  164. // determines the highest min_skill_level in the current set of tables (if multiple tables)
  165. if (table_choice >= entry->min_skill_level && (highest_score == 0 || highest_score < table_choice)) {
  166. // removes old highest for the new one
  167. highest_match.clear();
  168. highest_score = entry->min_skill_level;
  169. }
  170. // if the score = level, push into highest_match set
  171. if (highest_score == entry->min_skill_level)
  172. highest_match.push_back(entry);
  173. }
  174. // if there is STILL more than 1 table player qualifies for, rand() and pick one
  175. if (highest_match.size() > 1) {
  176. int16 rand_index = rand() % highest_match.size();
  177. selected_table = highest_match.at(rand_index);
  178. }
  179. else if (highest_match.size() > 0)
  180. selected_table = highest_match.at(0);
  181. // by this point, we should have 1 table who's min skill matches the score (selected_table)
  182. if (selected_table) {
  183. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Using Table: %i, %i, %i, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %i",
  184. selected_table->min_skill_level,
  185. selected_table->min_adventure_level,
  186. selected_table->bonus_table,
  187. selected_table->harvest1,
  188. selected_table->harvest3,
  189. selected_table->harvest5,
  190. selected_table->harvest_imbue,
  191. selected_table->harvest_rare,
  192. selected_table->harvest10,
  193. selected_table->harvest_coin);
  194. // roll 1-100 for chance-to-harvest percentage
  195. float chance = MakeRandomFloat(0, 100);
  196. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Random FLOAT for harvest percentages: %.2f", chance);
  197. // starting with the lowest %, select a harvest type + reward qty
  198. if (chance <= selected_table->harvest10 && is_collection == false) {
  199. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest 10 items + Rare Item from table : %i", selected_table->min_skill_level);
  200. harvest_type = 6;
  201. reward_total = 10;
  202. }
  203. else if (chance <= selected_table->harvest_rare && is_collection == false) {
  204. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest Rare Item from table : %i", selected_table->min_skill_level);
  205. harvest_type = 5;
  206. }
  207. else if (chance <= selected_table->harvest_imbue && is_collection == false) {
  208. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest Imbue Item from table : %i", selected_table->min_skill_level);
  209. harvest_type = 4;
  210. }
  211. else if (chance <= selected_table->harvest5 && is_collection == false) {
  212. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest 5 Items from table : %i", selected_table->min_skill_level);
  213. harvest_type = 3;
  214. reward_total = 5;
  215. }
  216. else if (chance <= selected_table->harvest3 && is_collection == false) {
  217. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest 3 Items from table : %i", selected_table->min_skill_level);
  218. harvest_type = 2;
  219. reward_total = 3;
  220. }
  221. else if (chance <= selected_table->harvest1 || totalSkill >= skill->max_val || is_collection) {
  222. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest 1 Item from table : %i", selected_table->min_skill_level);
  223. harvest_type = 1;
  224. }
  225. else
  226. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Harvest nothing...");
  227. }
  228. // once you know how many and what type of item to harvest, pick an item from the list
  229. if (harvest_type) {
  230. vector<GroundSpawnEntryItem*> mod_groundspawn_items;
  231. vector<GroundSpawnEntryItem*> mod_groundspawn_rares;
  232. vector<GroundSpawnEntryItem*> mod_groundspawn_imbue;
  233. vector<GroundSpawnEntryItem*>::iterator itr;
  234. GroundSpawnEntryItem* entry = 0;
  235. // iterate through groundspawn_items, discard items player cannot roll for
  236. for (itr = groundspawn_items->begin(); itr != groundspawn_items->end(); itr++) {
  237. entry = *itr;
  238. // if this is a Rare, or an Imbue, but is_rare flag is 0, skip item
  239. if ((harvest_type == 5 || harvest_type == 4) && entry->is_rare == 0)
  240. continue;
  241. // if it is a 1, 3, or 5 and is_rare = 1, skip
  242. else if (harvest_type < 4 && entry->is_rare == 1)
  243. continue;
  244. // if the grid_id on the item matches player grid, or is 0, keep the item
  245. if (!entry->grid_id || (entry->grid_id == client->GetPlayer()->GetLocation())) {
  246. // build modified entries table
  247. if ((entry->is_rare == 1 && harvest_type == 5) || (entry->is_rare == 1 && harvest_type == 6)) {
  248. // if the matching item is rare, or harvest10 push to mod rares
  249. mod_groundspawn_rares.push_back(entry);
  250. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Keeping groundspawn_rare_item: %u", entry->item_id);
  251. }
  252. if (entry->is_rare == 0 && harvest_type != 4 && harvest_type != 5) {
  253. // if the matching item is normal,or harvest 10 push to mod items
  254. mod_groundspawn_items.push_back(entry);
  255. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Keeping groundspawn_common_item: %u", entry->item_id);
  256. }
  257. if (entry->is_rare == 2 && harvest_type == 4) {
  258. // if the matching item is imbue item, push to mod imbue
  259. mod_groundspawn_imbue.push_back(entry);
  260. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Keeping groundspawn_imbue_item: %u", entry->item_id);
  261. }
  262. }
  263. }
  264. // if any items remain in the list, random to see which one gets awarded
  265. if (mod_groundspawn_items.size() > 0) {
  266. // roll to see which item index to use
  267. item_choice = rand() % mod_groundspawn_items.size();
  268. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Random INT for which item to award: %i", item_choice);
  269. // set item_id to be awarded
  270. item_harvested = mod_groundspawn_items[item_choice]->item_id;
  271. // if reward is rare, set flag
  272. rare_item = mod_groundspawn_items[item_choice]->is_rare;
  273. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Item ID to award: %u, Rare = %i", item_harvested, item_rare);
  274. // if 10+rare, handle additional "rare" reward
  275. if (harvest_type == 6) {
  276. // make sure there is a rare table to choose from!
  277. if (mod_groundspawn_rares.size() > 0) {
  278. // roll to see which rare index to use
  279. rare_choice = rand() % mod_groundspawn_rares.size();
  280. // set (rare) item_id to be awarded
  281. rare_harvested = mod_groundspawn_rares[rare_choice]->item_id;
  282. // we're picking a rare here, so obviously this is true ;)
  283. rare_item = 1;
  284. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "RARE Item ID to award: %u", rare_harvested);
  285. }
  286. else {
  287. // all rare entries were eliminated above, or none are assigned. Either way, shouldn't be here!
  288. LogWrite(GROUNDSPAWN__ERROR, 3, "GSpawn", "Groundspawn Entry for '%s' (%i) has no RARE items!", GetName(), GetID());
  289. }
  290. }
  291. }
  292. else if (mod_groundspawn_rares.size() > 0) {
  293. // roll to see which rare index to use
  294. item_choice = rand() % mod_groundspawn_rares.size();
  295. // set (rare) item_id to be awarded
  296. item_harvested = mod_groundspawn_rares[item_choice]->item_id;
  297. // we're picking a rare here, so obviously this is true ;)
  298. rare_item = 1;
  299. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "RARE Item ID to award: %u", rare_harvested);
  300. }
  301. else if (mod_groundspawn_imbue.size() > 0) {
  302. // roll to see which rare index to use
  303. item_choice = rand() % mod_groundspawn_imbue.size();
  304. // set (rare) item_id to be awarded
  305. item_harvested = mod_groundspawn_imbue[item_choice]->item_id;
  306. // we're picking a rare here, so obviously this is true ;)
  307. rare_item = 0;
  308. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "imbue Item ID to award: %u", rare_harvested);
  309. }
  310. else {
  311. // all item entries were eliminated above, or none are assigned. Either way, shouldn't be here!
  312. LogWrite(GROUNDSPAWN__ERROR, 0, "GSpawn", "Groundspawn Entry for '%s' (%i) has no items!", GetName(), GetID());
  313. }
  314. // if an item was harvested, send updates to client, add item to inventory
  315. if (item_harvested) {
  316. char tmp[200] = { 0 };
  317. // set Normal item harvested
  318. master_item = master_item_list.GetItem(item_harvested);
  319. if (master_item) {
  320. // set details of Normal item
  321. item = new Item(master_item);
  322. // set how many of this item the player receives
  323. item->details.count = reward_total;
  324. // chat box update for normal item (todo: verify output text)
  325. client->Message(CHANNEL_HARVESTING, "You %s %i %s from the %s.", GetHarvestMessageName(true).c_str(), item->details.count, item->CreateItemLink(client->GetVersion(), true).c_str(), GetName());
  326. // add Normal item to player inventory
  327. bool itemDeleted = false;
  328. client->AddItem(item, &itemDeleted);
  329. if(!itemDeleted) {
  330. //Check if the player has a harvesting quest for this
  331. client->GetPlayer()->CheckQuestsHarvestUpdate(item, reward_total);
  332. // if this is a 10+rare, handle sepErately
  333. if (harvest_type == 6 && rare_item == 1) {
  334. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Item ID %u is Normal. Qty %i", item_harvested, item->details.count);
  335. // send Normal harvest message to client
  336. sprintf(tmp, "\\#64FFFFYou have %s:\12\\#C8FFFF%i %s", GetHarvestMessageName().c_str(), item->details.count, item->name.c_str());
  337. client->SendPopupMessage(10, tmp, "ui_harvested_normal", 2.25, 0xFF, 0xFF, 0xFF);
  338. client->GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_ITEMS_HARVESTED, item->details.count);
  339. // set Rare item harvested
  340. master_rare = master_item_list.GetItem(rare_harvested);
  341. if (master_rare) {
  342. // set details of Rare item
  343. item_rare = new Item(master_rare);
  344. // count of Rare is always 1
  345. item_rare->details.count = 1;
  346. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Item ID %u is RARE!", rare_harvested);
  347. // send Rare harvest message to client
  348. sprintf(tmp, "\\#FFFF6ERare item found!\12%s: \\#C8FFFF%i %s", GetHarvestMessageName().c_str(), item_rare->details.count, item_rare->name.c_str());
  349. client->Message(CHANNEL_HARVESTING, "You have found a rare item!");
  350. client->SendPopupMessage(11, tmp, "ui_harvested_rare", 2.25, 0xFF, 0xFF, 0xFF);
  351. client->GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_RARES_HARVESTED, item_rare->details.count);
  352. // chat box update for rare item (todo: verify output text)
  353. client->Message(CHANNEL_HARVESTING, "You %s %i %s from the %s.", GetHarvestMessageName(true).c_str(), item_rare->details.count, item->CreateItemLink(client->GetVersion(), true).c_str(), GetName());
  354. // add Rare item to player inventory
  355. client->AddItem(item_rare);
  356. //Check if the player has a harvesting quest for this
  357. client->GetPlayer()->CheckQuestsHarvestUpdate(item_rare, 1);
  358. }
  359. }
  360. else if (rare_item == 1) {
  361. // if harvest signaled rare or imbue type
  362. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Item ID %u is RARE! Qty: %i", item_harvested, item->details.count);
  363. // send Rare harvest message to client
  364. sprintf(tmp, "\\#FFFF6ERare item found!\12%s: \\#C8FFFF%i %s", GetHarvestMessageName().c_str(), item->details.count, item->name.c_str());
  365. client->Message(CHANNEL_HARVESTING, "You have found a rare item!");
  366. client->SendPopupMessage(11, tmp, "ui_harvested_rare", 2.25, 0xFF, 0xFF, 0xFF);
  367. client->GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_RARES_HARVESTED, item->details.count);
  368. }
  369. else {
  370. // send Normal harvest message to client
  371. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "Item ID %u is Normal. Qty %i", item_harvested, item->details.count);
  372. sprintf(tmp, "\\#64FFFFYou have %s:\12\\#C8FFFF%i %s", GetHarvestMessageName().c_str(), item->details.count, item->name.c_str());
  373. client->SendPopupMessage(10, tmp, "ui_harvested_normal", 2.25, 0xFF, 0xFF, 0xFF);
  374. client->GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_ITEMS_HARVESTED, item->details.count);
  375. }
  376. }
  377. }
  378. else {
  379. // error!
  380. LogWrite(GROUNDSPAWN__ERROR, 0, "GSpawn", "Error: Item ID Not Found - %u", item_harvested);
  381. client->Message(CHANNEL_COLOR_RED, "Error: Unable to find item id %u", item_harvested);
  382. }
  383. // decrement # of pulls on this node before it despawns
  384. number_harvests--;
  385. }
  386. else {
  387. // if no item harvested
  388. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "No item_harvested");
  389. client->Message(CHANNEL_HARVESTING, "You failed to %s anything from %s.", GetHarvestMessageName(true, true).c_str(), GetName());
  390. }
  391. }
  392. else {
  393. // if no harvest type
  394. LogWrite(GROUNDSPAWN__DEBUG, 3, "GSpawn", "No harvest_type");
  395. client->Message(CHANNEL_HARVESTING, "You failed to %s anything from %s.", GetHarvestMessageName(true, true).c_str(), GetName());
  396. }
  397. }
  398. } // cycle through num_attempts_per_harvest
  399. MHarvest.unlock();
  400. LogWrite(GROUNDSPAWN__DEBUG, 0, "GSpawn", "Process harvest complete for player '%s' (%u)", client->GetPlayer()->GetName(), client->GetPlayer()->GetID());
  401. }
  402. string GroundSpawn::GetHarvestMessageName(bool present_tense, bool failure){
  403. string ret = "";
  404. if((collection_skill == "Gathering" ||collection_skill == "Collecting") && !present_tense)
  405. ret = "gathered";
  406. else if(collection_skill == "Gathering" || collection_skill == "Collecting")
  407. ret = "gather";
  408. else if(collection_skill == "Mining" && !present_tense)
  409. ret = "mined";
  410. else if(collection_skill == "Mining")
  411. ret = "mine";
  412. else if (collection_skill == "Fishing" && !present_tense)
  413. ret = "fished";
  414. else if(collection_skill == "Fishing")
  415. ret = "fish";
  416. else if(collection_skill == "Trapping" && !present_tense && !failure)
  417. ret = "acquired";
  418. else if(collection_skill == "Trapping" && failure)
  419. ret = "trap";
  420. else if(collection_skill == "Trapping")
  421. ret = "acquire";
  422. else if(collection_skill == "Foresting" && !present_tense)
  423. ret = "forested";
  424. else if(collection_skill == "Foresting")
  425. ret = "forest";
  426. else if (collection_skill == "Collecting")
  427. ret = "collect";
  428. return ret;
  429. }
  430. string GroundSpawn::GetHarvestSpellType(){
  431. string ret = "";
  432. if(collection_skill == "Gathering" || collection_skill == "Collecting")
  433. ret = "gather";
  434. else if(collection_skill == "Mining")
  435. ret = "mine";
  436. else if(collection_skill == "Trapping")
  437. ret = "trap";
  438. else if(collection_skill == "Foresting")
  439. ret = "chop";
  440. else if(collection_skill == "Fishing")
  441. ret = "fish";
  442. return ret;
  443. }
  444. string GroundSpawn::GetHarvestSpellName() {
  445. string ret = "";
  446. if (collection_skill == "Collecting")
  447. ret = "Gathering";
  448. else
  449. ret = collection_skill;
  450. return ret;
  451. }
  452. void GroundSpawn::HandleUse(Client* client, string type){
  453. if(!client || type.length() == 0)
  454. return;
  455. //The following check disables the use of the groundspawn if spawn access is not granted
  456. if (client) {
  457. bool meets_quest_reqs = MeetsSpawnAccessRequirements(client->GetPlayer());
  458. if (!meets_quest_reqs && (GetQuestsRequiredOverride() & 2) == 0)
  459. return;
  460. else if (meets_quest_reqs && appearance.show_command_icon != 1)
  461. return;
  462. }
  463. MHarvestUse.lock();
  464. if (type == GetHarvestSpellType() && MeetsSpawnAccessRequirements(client->GetPlayer())) {
  465. Spell* spell = master_spell_list.GetSpellByName(GetHarvestSpellName().c_str());
  466. if (spell)
  467. client->GetCurrentZone()->ProcessSpell(spell, client->GetPlayer(), client->GetPlayer()->GetTarget(), true, true);
  468. }
  469. else if (appearance.show_command_icon == 1 && MeetsSpawnAccessRequirements(client->GetPlayer())) {
  470. EntityCommand* entity_command = FindEntityCommand(type);
  471. if (entity_command)
  472. client->GetCurrentZone()->ProcessEntityCommand(entity_command, client->GetPlayer(), client->GetPlayer()->GetTarget());
  473. }
  474. MHarvestUse.unlock();
  475. }