This commit is contained in:
aozhiwei 2023-07-21 19:20:28 +08:00
commit 55a14af63e
9 changed files with 95 additions and 7 deletions

View File

@ -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
});
}

View File

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

View File

@ -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<long long, const mt::NpcStandard*> hero_lv_hash_;
};
}

View File

@ -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;
}
}
}
}

View File

@ -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_;
};

View File

@ -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__;
};
};

View File

@ -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;
}

View File

@ -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();
}
}
}

View File

@ -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