GroundSpawn.cpp 21 KB

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