From f3a2f9715591c24c4f6bff637abf4a3e92440ac1 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 9 Feb 2025 22:25:43 -0500 Subject: [PATCH] [Bug Fix] Fix Item Discovery (#4663) * [Bug Fix] Fix Item Discovery for Pickups, Evolving, Fishing, and Forage * Push * Caching * Update tradeskills.cpp * Update task_client_state.cpp --- zone/client.cpp | 51 ++++++++++++++++++++++++++++------ zone/client.h | 4 ++- zone/client_evolving_items.cpp | 6 ++++ zone/client_packet.cpp | 45 ++---------------------------- zone/corpse.cpp | 17 ++---------- zone/forage.cpp | 4 +++ zone/object.cpp | 16 +---------- zone/task_client_state.cpp | 1 + zone/tradeskills.cpp | 1 + zone/zone.h | 2 ++ 10 files changed, 66 insertions(+), 81 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 5470d716b..af7fceccc 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -4785,18 +4785,32 @@ bool Client::ChangePetName(std::string new_name) return true; } -bool Client::IsDiscovered(uint32 item_id) { - const auto& l = DiscoveredItemsRepository::GetWhere( - database, - fmt::format( - "item_id = {}", +bool Client::IsDiscovered(uint32 item_id) +{ + if ( + std::find( + zone->discovered_items.begin(), + zone->discovered_items.end(), item_id - ) - ); - if (l.empty()) { + ) != zone->discovered_items.end() + ) { + return true; + } + + if ( + DiscoveredItemsRepository::GetWhere( + database, + fmt::format( + "`item_id` = {} LIMIT 1", + item_id + ) + ).empty() + ) { return false; } + zone->discovered_items.emplace_back(item_id); + return true; } @@ -13562,3 +13576,24 @@ void Client::SendMerchantEnd() EQApplicationPacket empty(OP_ShopEndConfirm); QueuePacket(&empty); } + +void Client::CheckItemDiscoverability(uint32 item_id) +{ + if (!RuleB(Character, EnableDiscoveredItems) || IsDiscovered(item_id)) { + return; + } + + if (GetGM()) { + const std::string& item_link = database.CreateItemLink(item_id); + Message( + Chat::White, + fmt::format( + "Your GM flag prevents {} from being added to discovered items.", + item_link + ).c_str() + ); + return; + } + + DiscoverItem(item_id); +} diff --git a/zone/client.h b/zone/client.h index 848e66931..046da9052 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1830,6 +1830,8 @@ public: void SendMerchantEnd(); + void CheckItemDiscoverability(uint32 item_id); + Raid *p_raid_instance; inline uint32 GetPotionBeltItemIcon(uint8 slot_id) @@ -1845,7 +1847,7 @@ public: { return EQ::ValueWithin(slot_id, 0, EQ::profile::POTION_BELT_SIZE - 1) ? m_pp.potionbelt.Items[slot_id].ID : 0; }; - + inline std::string GetPotionBeltItemName(uint8 slot_id) { return EQ::ValueWithin( diff --git a/zone/client_evolving_items.cpp b/zone/client_evolving_items.cpp index f94667797..a22623534 100644 --- a/zone/client_evolving_items.cpp +++ b/zone/client_evolving_items.cpp @@ -260,6 +260,12 @@ bool Client::DoEvolveCheckProgression(const EQ::ItemInstance &inst) std::unique_ptr const new_inst(database.CreateItem(new_item_id)); + if (!new_inst) { + return false; + } + + CheckItemDiscoverability(new_inst->GetID()); + PlayerEvent::EvolveItem e{}; RemoveItemBySerialNumber(inst.GetSerialNumber()); diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 571e74288..a0a62d6b6 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -2148,20 +2148,7 @@ void Client::Handle_OP_AdventureMerchantPurchase(const EQApplicationPacket *app) if (item->MaxCharges != 0) charges = item->MaxCharges; - if (RuleB(Character, EnableDiscoveredItems) && !IsDiscovered(item->ID)) { - if (!GetGM()) { - DiscoverItem(item->ID); - } else { - const std::string& item_link = database.CreateItemLink(item->ID); - Message( - Chat::White, - fmt::format( - "Your GM flag prevents {} from being added to discovered items.", - item_link - ).c_str() - ); - } - } + CheckItemDiscoverability(item->ID); EQ::ItemInstance *inst = database.CreateItem(item, charges); if (!AutoPutLootInInventory(*inst, true, true)) @@ -2708,20 +2695,7 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app) RecordPlayerEventLog(PlayerEvent::MERCHANT_PURCHASE, e); } - if (RuleB(Character, EnableDiscoveredItems) && !IsDiscovered(item->ID)) { - if (!GetGM()) { - DiscoverItem(item->ID); - } else { - const std::string& item_link = database.CreateItemLink(item->ID); - Message( - Chat::White, - fmt::format( - "Your GM flag prevents {} from being added to discovered items.", - item_link - ).c_str() - ); - } - } + CheckItemDiscoverability(item->ID); EQ::ItemInstance *inst = database.CreateItem(item, charges); if (!AutoPutLootInInventory(*inst, true, true)) @@ -14200,20 +14174,7 @@ void Client::Handle_OP_ShopPlayerBuy(const EQApplicationPacket *app) parse->EventPlayer(EVENT_MERCHANT_BUY, this, export_string, 0); } - if (RuleB(Character, EnableDiscoveredItems) && !IsDiscovered(item_id)) { - if (!GetGM()) { - DiscoverItem(item_id); - } else { - const std::string& item_link = database.CreateItemLink(item_id); - Message( - Chat::White, - fmt::format( - "Your GM flag prevents {} from being added to discovered items.", - item_link - ).c_str() - ); - } - } + CheckItemDiscoverability(item_id); safe_delete(inst); safe_delete(outapp); diff --git a/zone/corpse.cpp b/zone/corpse.cpp index 387813b32..8b634b8a2 100644 --- a/zone/corpse.cpp +++ b/zone/corpse.cpp @@ -1623,21 +1623,8 @@ void Corpse::LootCorpseItem(Client *c, const EQApplicationPacket *app) // safe to ACK now c->QueuePacket(app); - if (!IsPlayerCorpse()) { - if (RuleB(Character, EnableDiscoveredItems) && c && !c->IsDiscovered(inst->GetItem()->ID)) { - if (!c->GetGM()) { - c->DiscoverItem(inst->GetItem()->ID); - } else { - const std::string& item_link = database.CreateItemLink(inst->GetItem()->ID); - c->Message( - Chat::White, - fmt::format( - "Your GM flag prevents {} from being added to discovered items.", - item_link - ).c_str() - ); - } - } + if (!IsPlayerCorpse() && c) { + c->CheckItemDiscoverability(inst->GetID()); } if (zone->adv_data) { diff --git a/zone/forage.cpp b/zone/forage.cpp index a6ad1b648..9ae61133e 100644 --- a/zone/forage.cpp +++ b/zone/forage.cpp @@ -393,6 +393,8 @@ void Client::GoFish(bool guarantee, bool use_bait) RecordPlayerEventLog(PlayerEvent::FISH_SUCCESS, e); } + CheckItemDiscoverability(inst->GetID()); + if (parse->PlayerHasQuestSub(EVENT_FISH_SUCCESS)) { std::vector args = {inst}; parse->EventPlayer(EVENT_FISH_SUCCESS, this, "", inst->GetID(), &args); @@ -531,6 +533,8 @@ void Client::ForageItem(bool guarantee) { RecordPlayerEventLog(PlayerEvent::FORAGE_SUCCESS, e); } + CheckItemDiscoverability(inst->GetID()); + if (parse->PlayerHasQuestSub(EVENT_FORAGE_SUCCESS)) { std::vector args = { inst }; parse->EventPlayer(EVENT_FORAGE_SUCCESS, this, "", inst->GetID(), &args); diff --git a/zone/object.cpp b/zone/object.cpp index af4993dbe..252c7c04b 100644 --- a/zone/object.cpp +++ b/zone/object.cpp @@ -643,21 +643,7 @@ bool Object::HandleClick(Client* sender, const ClickObject_Struct* click_object) sender->PutItemInInventory(EQ::invslot::slotCursor, *m_inst, false); sender->SendItemPacket(EQ::invslot::slotCursor, m_inst, ItemPacketTrade); - // Could be an undiscovered ground_spawn - if (m_ground_spawn && RuleB(Character, EnableDiscoveredItems) && !sender->IsDiscovered(item->ID)) { - if (!sender->GetGM()) { - sender->DiscoverItem(item->ID); - } else { - const std::string& item_link = database.CreateItemLink(item->ID); - sender->Message( - Chat::White, - fmt::format( - "Your GM flag prevents {} from being added to discovered items.", - item_link - ).c_str() - ); - } - } + sender->CheckItemDiscoverability(m_inst->GetID()); if (cursor_delete) { // delete the item if it's a duplicate lore. We have to do this because the client expects the item packet sender->DeleteItemInInventory(EQ::invslot::slotCursor, 1, true); diff --git a/zone/task_client_state.cpp b/zone/task_client_state.cpp index 0dfa3d8a6..7fa49a180 100644 --- a/zone/task_client_state.cpp +++ b/zone/task_client_state.cpp @@ -1026,6 +1026,7 @@ void ClientTaskState::RewardTask(Client *c, const TaskInformation *ti, ClientTas if (item_id > 0) { std::unique_ptr inst(database.CreateItem(item_id, charges)); if (inst && inst->GetItem()) { + c->CheckItemDiscoverability(item_id); bool stacked = c->TryStacking(inst.get()); if (!stacked) { int16_t slot = c->GetInv().FindFreeSlot(inst->IsClassBag(), true, inst->GetItem()->Size); diff --git a/zone/tradeskills.cpp b/zone/tradeskills.cpp index 1181a5f9d..9f7670264 100644 --- a/zone/tradeskills.cpp +++ b/zone/tradeskills.cpp @@ -1149,6 +1149,7 @@ bool Client::TradeskillExecute(DBTradeskillRecipe_Struct *spec) { item = database.GetItem(itr->first); if (item) { + CheckItemDiscoverability(itr->first); SummonItem(itr->first, itr->second); if (GetGroup()) { entity_list.MessageGroup(this, true, Chat::Skills, "%s has successfully fashioned %s!", GetName(), item->Name); diff --git a/zone/zone.h b/zone/zone.h index 1d46a0415..2d8a33b60 100755 --- a/zone/zone.h +++ b/zone/zone.h @@ -241,6 +241,8 @@ public: std::unordered_map exp_modifiers; + std::vector discovered_items; + time_t weather_timer; Timer spawn2_timer; Timer hot_reload_timer;