diff --git a/server/gameserver/mt/Hero.cc b/server/gameserver/mt/Hero.cc index aaabbf90..32322fa0 100644 --- a/server/gameserver/mt/Hero.cc +++ b/server/gameserver/mt/Hero.cc @@ -5,6 +5,7 @@ #include "mt/MetaMgr.h" #include "mt/Hero.h" #include "mt/Equip.h" +#include "mt/NpcStandard.h" IMPL_TABLE(mt::Hero) @@ -162,6 +163,15 @@ namespace mt abort(); } } + #if 0 + if (hero->default_weapon()) { + for (int i = 1; i <= 15; ++i) { + if (!mt::NpcStandard::GetByHeroAndLv(hero->id(), i)) { + abort(); + } + } + } + #endif }); } diff --git a/server/gameserver/mt/NpcStandard.cc b/server/gameserver/mt/NpcStandard.cc index 8b3ba5c6..227838e6 100644 --- a/server/gameserver/mt/NpcStandard.cc +++ b/server/gameserver/mt/NpcStandard.cc @@ -4,7 +4,28 @@ IMPL_TABLE(mt::NpcStandard) +std::map mt::NpcStandard::hero_lv_hash_; + namespace mt { + void NpcStandard::Init1() + { + if (GetByHeroAndLv(hero_id(), level())) { + abort(); + } + 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..8a312e9f 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 Init1(); + static void StaticPostInit(); + static const mt::NpcStandard* GetByHeroAndLv(int hero_id, int lv); + private: + static std::map hero_lv_hash_; }; } diff --git a/server/gameserver/mt/Param.cc b/server/gameserver/mt/Param.cc index 4facb680..b354b05a 100644 --- a/server/gameserver/mt/Param.cc +++ b/server/gameserver/mt/Param.cc @@ -353,4 +353,30 @@ namespace mt return s_.rank_mode_confs.at(s_.rank_mode_confs.size() - 1).get(); } + int Param::RandHeroLv(int room_type) + { + switch (room_type) { + case RoomType_OldBrid1: + { + return a8::RandEx(1, 1); + break; + } + case RoomType_OldBrid2: + { + return a8::RandEx(2, 10); + break; + } + case RoomType_OldBrid3: + { + return a8::RandEx(11, 15); + break; + } + default: + { + return a8::RandEx(1, 5); + break; + } + } + } + } diff --git a/server/gameserver/mt/Param.h b/server/gameserver/mt/Param.h index 50c2365d..149099bb 100644 --- a/server/gameserver/mt/Param.h +++ b/server/gameserver/mt/Param.h @@ -144,7 +144,7 @@ namespace mt static int GetStarNum(int rank); static const RankMatchConf* GetRankModeConfByElo(int elo); static const RankMatchConf* GetRankModeConfByRoomType(int room_type); - + static int RandHeroLv(int room_type); private: static S s_; }; diff --git a/server/gameserver/mtb/NpcStandard.h b/server/gameserver/mtb/NpcStandard.h index db7dcd6f..7040e285 100644 --- a/server/gameserver/mtb/NpcStandard.h +++ b/server/gameserver/mtb/NpcStandard.h @@ -15,12 +15,16 @@ namespace mtb int hp() const { return hp_; }; 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);}; bool has_hp() const { return __flags__.test(2);}; bool has_damage() const { return __flags__.test(3);}; bool has_defence() const { return __flags__.test(4);}; + bool has_hero_id() const { return __flags__.test(5);}; + bool has_level() const { return __flags__.test(6);}; protected: @@ -29,9 +33,11 @@ namespace mtb int hp_ = 0; int damage_ = 0; int defence_ = 0; + int hero_id_ = 0; + int level_ = 0; public: - std::bitset<5> __flags__; + std::bitset<7> __flags__; }; }; diff --git a/server/gameserver/mtb/mtb.all.cc b/server/gameserver/mtb/mtb.all.cc index 3ac66485..09c3ff8f 100644 --- a/server/gameserver/mtb/mtb.all.cc +++ b/server/gameserver/mtb/mtb.all.cc @@ -441,12 +441,14 @@ namespace mtb { a8::reflect::Class* meta_class = nullptr; if (!meta_class) { - meta_class = new a8::reflect::Class("NpcStandard", 5, 0); + meta_class = new a8::reflect::Class("NpcStandard", 7, 0); meta_class->SetSimpleField(0, "id", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, id_)); meta_class->SetSimpleField(1, "quality", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, quality_)); meta_class->SetSimpleField(2, "hp", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, hp_)); meta_class->SetSimpleField(3, "damage", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, damage_)); meta_class->SetSimpleField(4, "defence", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, defence_)); + meta_class->SetSimpleField(5, "hero_id", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, hero_id_)); + meta_class->SetSimpleField(6, "level", a8::reflect::ET_INT32, my_offsetof2(NpcStandard, level_)); } return meta_class; } diff --git a/server/gameserver/netdata.cc b/server/gameserver/netdata.cc index db2dd4e3..ea4ec79e 100644 --- a/server/gameserver/netdata.cc +++ b/server/gameserver/netdata.cc @@ -146,15 +146,31 @@ private: const mt::NpcStandard* standard_meta = mt::NpcStandard::GetById (c->room->pve_instance->gemini_lv()); if (standard_meta) { - hp_ = standard_meta->hp() * hero_meta->hp_ratio() * - c->room->pve_instance->GetHpMul(c->room->GetHumanNum()); - atk_ = standard_meta->damage() * hero_meta->damage_ratio(); - def_ = standard_meta->defence() * hero_meta->defence_ratio(); + hp_ = standard_meta->hp(); + atk_ = standard_meta->damage(); + def_ = standard_meta->defence(); } else { #ifdef DEBUG abort(); #endif } + } else { + const mt::NpcStandard* standard_meta = nullptr; + auto match_conf = c->room->GetRankMatchConf(); + if (match_conf) { + standard_meta = mt::NpcStandard::GetByHeroAndLv + (hero_meta->id(), + a8::RandEx(match_conf->hero_min_lv, match_conf->hero_max_lv)); + } else { + standard_meta = mt::NpcStandard::GetByHeroAndLv + (hero_meta->id(), + mt::Param::RandHeroLv(c->room->GetRoomType())); + } + if (standard_meta) { + hp_ = standard_meta->hp(); + atk_ = standard_meta->damage(); + def_ = standard_meta->defence(); + } } } diff --git a/server/tools/protobuild/mt.proto b/server/tools/protobuild/mt.proto index fc7f5dc5..6f9578bb 100755 --- a/server/tools/protobuild/mt.proto +++ b/server/tools/protobuild/mt.proto @@ -363,6 +363,8 @@ message NpcStandard optional int32 hp = 3; optional int32 damage = 4; optional int32 defence = 5; + optional int32 hero_id = 6; + optional int32 level = 7; } message Buff