From 23124ca3da76e3e5e1cee000b023acff2d6c8f69 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 15 Oct 2024 14:40:15 +0800 Subject: [PATCH] 1 --- server/gameserver/bag.cc | 13 ++++++++++++- server/gameserver/bag.h | 3 ++- server/gameserver/pbutils.cc | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/gameserver/bag.cc b/server/gameserver/bag.cc index 809cae58..dea26f69 100644 --- a/server/gameserver/bag.cc +++ b/server/gameserver/bag.cc @@ -42,8 +42,19 @@ void Bag::Parse(const std::list>& items) } } -std::shared_ptr Bag::GetItemById(int equip_id) +std::shared_ptr Bag::GetItemByEquipId(int equip_id) { auto itr = items_.find(equip_id); return itr != items_.end() ? itr->second : nullptr; } + +std::shared_ptr Bag::GetItemByItemId(int item_id) +{ + for (auto pair : items_) { + auto item = pair.second; + if (item->item_meta && item->item_meta->id() == item_id) { + return item; + } + } + return nullptr; +} diff --git a/server/gameserver/bag.h b/server/gameserver/bag.h index 5020031e..60e4f847 100644 --- a/server/gameserver/bag.h +++ b/server/gameserver/bag.h @@ -27,7 +27,8 @@ class Bag void UseItem(int equip_id); void PushBagInfo(); void Parse(const std::list>& items); - std::shared_ptr GetItemById(int equip_id); + std::shared_ptr GetItemByEquipId(int equip_id); + std::shared_ptr GetItemByItemId(int item_id); void UpdateItemNum(int item_id, int item_num); private: diff --git a/server/gameserver/pbutils.cc b/server/gameserver/pbutils.cc index 07dff54a..71df24f8 100644 --- a/server/gameserver/pbutils.cc +++ b/server/gameserver/pbutils.cc @@ -2948,7 +2948,7 @@ void CustomBattle::NotifyState() void Bag::UseItem(int equip_id) { - auto p = GetItemById(equip_id); + auto p = GetItemByEquipId(equip_id); if (p && p->equip_num > 0 && p->GetCdTime(owner_) <= 0 && p->equip_meta && p->potion_meta) { --p->equip_num; p->last_use_tick = owner_->room->GetFrameNo(); @@ -2978,6 +2978,7 @@ void Bag::UseItem(int equip_id) p->potion_meta->buff(), p->potion_meta->duration() * 1000); } + owner_->GetNetData()->UseItem(p->item_meta->id()); cs::SMUpdateBag notify_msg; auto pb_item = notify_msg.add_items(); @@ -3020,7 +3021,7 @@ void Bag::InternalPushBagInfo() void Bag::UpdateItemNum(int item_id, int item_num) { - auto p = GetItemById(item_id); + auto p = GetItemByItemId(item_id); if (p) { p->equip_num = item_num; cs::SMUpdateBag notify_msg;