This commit is contained in:
aozhiwei 2019-07-10 11:15:55 +08:00
parent bb4d2313e3
commit 49edba7957
6 changed files with 17 additions and 5 deletions

View File

@ -186,6 +186,7 @@ enum BuffTriggerType_e
enum BuffEffectType_e
{
BET_Begin = 0,
BET_ChgAttr = 1, //改变属性
BET_Vertigo = 2, //眩晕
BET_LastDmg = 3, //持续伤害
@ -193,6 +194,7 @@ enum BuffEffectType_e
BET_Invincible = 5, //无敌
BET_Hide = 6, //隐身
BET_Dcgr = 7, //电磁干扰
BET_End
};
enum SkillFunc_e

View File

@ -48,3 +48,8 @@ SkillFunc_e Str2SkillFunc(const std::string& func_str)
}
return Skill_FuncNone;
}
bool IsValidBuffEffect(int buff_effect)
{
return buff_effect > BET_Begin && buff_effect < BET_End;
}

View File

@ -23,3 +23,4 @@ class Global : public a8::Singleton<Global>
bool IsValidSlotId(int slot_id);
SkillFunc_e Str2SkillFunc(const std::string& func_str);
bool IsValidBuffEffect(int buff_effect);

View File

@ -1352,7 +1352,7 @@ void Human::AddBuff(MetaData::Buff* buff_meta)
//buff->skill_meta
buff->add_frameno = room->frame_no;
buff->xtimer_attacher.xtimer = &room->xtimer;
buff_effect_hash_[buff->meta->i->buff_id()] = buff;
buff_effect_[buff->meta->i->buff_effect()] = buff;
room->frame_event.AddBuff(this, buff);
{
room->xtimer.AddDeadLineTimerAndAttach(
@ -1374,7 +1374,9 @@ void Human::RemoveBuff(int buff_id)
{
for (auto itr = buff_list_.begin(); itr != buff_list_.end(); ++itr) {
if (itr->meta->i->buff_id() == buff_id) {
buff_effect_hash_.erase(itr->meta->i->buff_effect());
if (buff_effect_[itr->meta->i->buff_effect()] == &(*itr)) {
buff_effect_[itr->meta->i->buff_effect()] = nullptr;
}
buff_list_.erase(itr);
room->frame_event.RemoveBuff(this, buff_id);
break;
@ -1546,6 +1548,5 @@ Buff* Human::GetBuffById(int buff_id)
Buff* Human::GetBuffByEffectId(int effect_id)
{
auto itr = buff_effect_hash_.find(effect_id);
return itr != buff_effect_hash_.end() ? itr->second : nullptr;
return IsValidBuffEffect(effect_id) ? buff_effect_[effect_id] : nullptr;
}

View File

@ -250,7 +250,7 @@ private:
CircleCollider* self_collider_ = nullptr;
long long last_sync_gas_frameno = 0;
std::list<Buff> buff_list_;
std::map<int, Buff*> buff_effect_hash_;
std::array<Buff*, BET_End> buff_effect_ = {};
bool already_report_battle_ = false;
bool sent_game_end_ = false;

View File

@ -248,6 +248,9 @@ private:
}
for (auto& meta : buff_meta_list) {
if (!IsValidBuffEffect(meta.buff_effect())) {
abort();
}
MetaData::Buff& item = a8::FastAppend(buff_list);
item.i = &meta;
item.Init();