GroundSpawn.cpp 22 KB

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