diff --git a/server/gameserver/mt/Equip.cc b/server/gameserver/mt/Equip.cc index 3b5e1664..205ce97f 100644 --- a/server/gameserver/mt/Equip.cc +++ b/server/gameserver/mt/Equip.cc @@ -4,6 +4,7 @@ #include "mt/Buff.h" IMPL_TABLE(mt::Equip) +std::map mt::Equip::slot_hash_; namespace mt { @@ -187,6 +188,14 @@ namespace mt #endif } } + if (inventory_slot().empty()) { + _inventory_slot_ = -1; + } else { + _inventory_slot_ = a8::XValue(inventory_slot()); + } + if (_inventory_slot() > -1) { + slot_hash_[_inventory_slot()] = this; + } } int Equip::GetWeaponIdx() const @@ -232,5 +241,10 @@ namespace mt } } + const Equip* Equip::GetByIdBySlotId(int slot_id) + { + auto itr = slot_hash_.find(slot_id); + return itr != slot_hash_.end() ? itr->second : nullptr; + } } diff --git a/server/gameserver/mt/Equip.h b/server/gameserver/mt/Equip.h index c44a28c3..ed25ae38 100644 --- a/server/gameserver/mt/Equip.h +++ b/server/gameserver/mt/Equip.h @@ -34,8 +34,10 @@ namespace mt void Init2(); int GetWeaponIdx() const; bool Match(CondAddBuff_e cond, int val, int val2) const; - static const Equip* GetByIdBySlotId(int slot_id) {}; + static const Equip* GetByIdBySlotId(int slot_id); - }; + private: + static std::map slot_hash_; + }; }