diff --git a/server/gameserver/mt/NpcStandard.cc b/server/gameserver/mt/NpcStandard.cc index 8b3ba5c6..95a65dbd 100644 --- a/server/gameserver/mt/NpcStandard.cc +++ b/server/gameserver/mt/NpcStandard.cc @@ -4,7 +4,25 @@ IMPL_TABLE(mt::NpcStandard) +std::map mt::NpcStandard::hero_lv_hash_; + namespace mt { + void NpcStandard::Init() + { + hero_lv_hash_[a8::MakeInt64(hero_id(), level())] = this; + } + + void NpcStandard::StaticPostInit() + { + + } + + const mt::NpcStandard* NpcStandard::GetByHeroAndLv(int hero_id, int lv) + { + auto itr = hero_lv_hash_.find(a8::MakeInt64(hero_id, lv)); + return itr != hero_lv_hash_.end() ? itr->second : nullptr; + } + } diff --git a/server/gameserver/mt/NpcStandard.h b/server/gameserver/mt/NpcStandard.h index d80d289d..9020207a 100644 --- a/server/gameserver/mt/NpcStandard.h +++ b/server/gameserver/mt/NpcStandard.h @@ -10,7 +10,12 @@ namespace mt "npcStandard@npcStandard.json", "id") public: + void Init(); + static void StaticPostInit(); + const mt::NpcStandard* GetByHeroAndLv(int hero_id, int lv); + private: + static std::map hero_lv_hash_; }; } diff --git a/server/gameserver/mtb/NpcStandard.h b/server/gameserver/mtb/NpcStandard.h index 91728c9a..7040e285 100644 --- a/server/gameserver/mtb/NpcStandard.h +++ b/server/gameserver/mtb/NpcStandard.h @@ -16,6 +16,7 @@ namespace mtb int damage() const { return damage_; }; int defence() const { return defence_; }; int hero_id() const { return hero_id_; }; + int level() const { return level_; }; bool has_id() const { return __flags__.test(0);}; bool has_quality() const { return __flags__.test(1);};