GroundSpawn.cpp 22 KB

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