[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
This commit is contained in:
Alex King 2025-02-09 22:25:43 -05:00 committed by GitHub
parent 9e07d90664
commit f3a2f97155
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 66 additions and 81 deletions

View File

@ -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);
}

View File

@ -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(

View File

@ -260,6 +260,12 @@ bool Client::DoEvolveCheckProgression(const EQ::ItemInstance &inst)
std::unique_ptr<EQ::ItemInstance> const new_inst(database.CreateItem(new_item_id));
if (!new_inst) {
return false;
}
CheckItemDiscoverability(new_inst->GetID());
PlayerEvent::EvolveItem e{};
RemoveItemBySerialNumber(inst.GetSerialNumber());

View File

@ -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);

View File

@ -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) {

View File

@ -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<std::any> 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<std::any> args = { inst };
parse->EventPlayer(EVENT_FORAGE_SUCCESS, this, "", inst->GetID(), &args);

View File

@ -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);

View File

@ -1026,6 +1026,7 @@ void ClientTaskState::RewardTask(Client *c, const TaskInformation *ti, ClientTas
if (item_id > 0) {
std::unique_ptr<EQ::ItemInstance> 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);

View File

@ -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);

View File

@ -241,6 +241,8 @@ public:
std::unordered_map<uint32, EXPModifier> exp_modifiers;
std::vector<uint32> discovered_items;
time_t weather_timer;
Timer spawn2_timer;
Timer hot_reload_timer;