This commit is contained in:
aozhiwei 2023-07-21 16:05:23 +08:00
parent dcffc2f37d
commit 17b79ff66c
3 changed files with 24 additions and 0 deletions

View File

@ -4,7 +4,25 @@
IMPL_TABLE(mt::NpcStandard) IMPL_TABLE(mt::NpcStandard)
std::map<long long, const mt::NpcStandard*> mt::NpcStandard::hero_lv_hash_;
namespace mt 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;
}
} }

View File

@ -10,7 +10,12 @@ namespace mt
"npcStandard@npcStandard.json", "npcStandard@npcStandard.json",
"id") "id")
public: public:
void Init();
static void StaticPostInit();
const mt::NpcStandard* GetByHeroAndLv(int hero_id, int lv);
private:
static std::map<long long, const mt::NpcStandard*> hero_lv_hash_;
}; };
} }

View File

@ -16,6 +16,7 @@ namespace mtb
int damage() const { return damage_; }; int damage() const { return damage_; };
int defence() const { return defence_; }; int defence() const { return defence_; };
int hero_id() const { return hero_id_; }; int hero_id() const { return hero_id_; };
int level() const { return level_; };
bool has_id() const { return __flags__.test(0);}; bool has_id() const { return __flags__.test(0);};
bool has_quality() const { return __flags__.test(1);}; bool has_quality() const { return __flags__.test(1);};