diff --git a/server/gameserver/bag.cc b/server/gameserver/bag.cc index 00a71425..062d2d73 100644 --- a/server/gameserver/bag.cc +++ b/server/gameserver/bag.cc @@ -19,3 +19,9 @@ void Bag::Parse(const std::list& items) p->equip_meta = mt::Equip::GetById(p->equip_id); items_[p->equip_id] = p; } + +std::shared_ptr Bag::GetItemById(int equip_id) +{ + auto itr = items_.find(equip_id); + return itr != items_.end() ? itr->second : nullptr; +} diff --git a/server/gameserver/bag.h b/server/gameserver/bag.h index 1b3b265f..b7f6bb98 100644 --- a/server/gameserver/bag.h +++ b/server/gameserver/bag.h @@ -23,6 +23,7 @@ class Bag void UseItem(int equip_id); void PushBagInfo(); void Parse(const std::list& items); + std::shared_ptr GetItemById(int equip_id); private: Human* owner_ = nullptr; diff --git a/server/gameserver/pbutils.cc b/server/gameserver/pbutils.cc index ac3a4443..5a034fc6 100644 --- a/server/gameserver/pbutils.cc +++ b/server/gameserver/pbutils.cc @@ -2947,7 +2947,17 @@ void CustomBattle::NotifyState() void Bag::UseItem(int equip_id) { - + auto p = GetItemById(equip_id); + if (p && p->equip_num > 0 && p->GetCdTime(owner_) <= 0) { + --p->equip_num; + p->last_use_tick = owner_->room->GetFrameNo(); + cs::SMUpdateBag notify_msg; + auto pb_item = notify_msg.add_items(); + pb_item->set_equip_id(p->equip_id); + pb_item->set_equip_num(p->equip_num); + pb_item->set_use_cd(p->GetCdTime(owner_)); + owner_->SendNotifyMsg(notify_msg); + } } void Bag::PushBagInfo()