GroundSpawn.cpp 23 KB

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