From 912bd0593a1629b31732e3edd2bb8a36b2deb257 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Jul 2019 15:11:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=81=BC=E7=83=A7buff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/constant.h | 18 +++++++++- server/gameserver/global.cc | 5 +++ server/gameserver/global.h | 1 + server/gameserver/human.cc | 67 +++++++++++++++++++++++++++++++++-- server/gameserver/human.h | 10 +++++- server/gameserver/metadata.cc | 3 ++ server/gameserver/metadata.h | 4 +++ 7 files changed, 103 insertions(+), 5 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 0f6be62..2b5aa25 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -189,11 +189,13 @@ enum BuffEffectType_e BET_Begin = 0, BET_ChgAttr = 1, //改变属性 BET_Vertigo = 2, //眩晕 - BET_LastDmg = 3, //持续伤害 + BET_Unuse = 3, // BET_LastBurn = 4, //持续灼烧 BET_Invincible = 5, //无敌 BET_Hide = 6, //隐身 BET_Dcgr = 7, //电磁干扰 + BET_ReleaseDcgr = 8, //释放电磁干扰 + BET_ReleaseFireBomb = 9, //释放燃烧弹 BET_End }; @@ -206,6 +208,20 @@ enum SkillFunc_e Skill_FuncEnd }; +enum HumanAttrType_e +{ + HAT_Begin = 0, + HAT_Hp = 1, + HAT_HPRecover = 2, + HAT_Atk = 3, + HAT_Def = 4, + HAT_Speed = 5, + HAT_ShotRange = 6, + HAT_ShotSpeed = 7, + HAT_ReloadSpeed = 8, + HAT_End +}; + const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_ROOT_FMT = "/data/logs/%s"; diff --git a/server/gameserver/global.cc b/server/gameserver/global.cc index 68c87c4..2c75692 100755 --- a/server/gameserver/global.cc +++ b/server/gameserver/global.cc @@ -53,3 +53,8 @@ bool IsValidBuffEffect(int buff_effect) { return buff_effect > BET_Begin && buff_effect < BET_End; } + +bool IsValidHumanAttr(int attr_type) +{ + return attr_type > HAT_Begin && attr_type < HAT_End; +} diff --git a/server/gameserver/global.h b/server/gameserver/global.h index 45694b4..08e6d15 100755 --- a/server/gameserver/global.h +++ b/server/gameserver/global.h @@ -24,3 +24,4 @@ class Global : public a8::Singleton bool IsValidSlotId(int slot_id); SkillFunc_e Str2SkillFunc(const std::string& func_str); bool IsValidBuffEffect(int buff_effect); +bool IsValidHumanAttr(int attr_type); diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index b1a2e2b..0b2f2d9 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -66,19 +66,22 @@ void Human::Initialize() float Human::GetSpeed() { + float speed = 0.0f; if (downed) { - return meta->i->move_speed3() + ability.speed; + speed = meta->i->move_speed3() + ability.speed; } else { + speed = meta->i->move_speed() + ability.speed; if (shot_hold) { if (curr_weapon->weapon_idx == GUN_SLOT1 || curr_weapon->weapon_idx == GUN_SLOT2) { if (action_type != AT_Reload) { - return meta->i->shot_speed(); + speed = meta->i->shot_speed(); } } } - return meta->i->move_speed() + ability.speed; } + speed = (speed + buff_attr_abs_[HAT_Speed]) * (1 + buff_attr_rate_[HAT_Speed]); + return std::min(speed, 1.0f); } float Human::GetSpeed4() @@ -581,6 +584,9 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i } } } + last_attacker_id = killer_id; + last_attacker_name = killer_name; + last_attacker_weapon_id = weapon_id; SyncAroundPlayers(); } @@ -1368,6 +1374,7 @@ void Human::AddBuff(MetaData::Buff* buff_meta) &buff->xtimer_attacher.timer_list_ ); } + ProcBuffEffect(buff); } void Human::RemoveBuff(int buff_id) @@ -1389,6 +1396,60 @@ bool Human::HasBuffEffect(int buff_effect_id) return GetBuffByEffectId(buff_effect_id) != nullptr; } +void Human::RecalcBuffAttr() +{ + buff_attr_abs_ = {}; + buff_attr_rate_ = {}; + for (auto& buff : buff_list_) { + if (buff.meta->i->buff_effect() == BET_ChgAttr) { + int attr_type = (int)buff.meta->param1; + int calc_type = (int)buff.meta->param2; + if (IsValidHumanAttr(attr_type)) { + if (calc_type == 1) { + buff_attr_abs_[attr_type] += buff.meta->param3; + } else if (calc_type == 2) { + buff_attr_rate_[attr_type] += buff.meta->param3; + } + } + } + } +} + +void Human::ProcBuffEffect(Buff* buff) +{ + switch (buff->meta->i->buff_effect()) { + case BET_ChgAttr: + { + RecalcBuffAttr(); + } + break; + case BET_LastBurn: + { + room->xtimer.AddRepeatTimerAndAttach( + SERVER_FRAME_RATE, + a8::XParams() + .SetSender(this) + .SetParam1(buff), + [] (const a8::XParams& param) + { + Human* hum = (Human*)param.sender.GetUserData(); + Buff* buff = (Buff*)param.param1.GetUserData(); + if (!hum->dead) { + hum->DecHP(buff->meta->param1, + hum->last_attacker_id, + hum->last_attacker_name, + hum->last_attacker_weapon_id); + } + }, + &buff->xtimer_attacher.timer_list_ + ); + } + break; + default: + break; + } +} + void Human::_UpdateMove(int speed) { for (int i = 0; i < speed; ++i) { diff --git a/server/gameserver/human.h b/server/gameserver/human.h index a353915..ed3c24c 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -50,6 +50,9 @@ class Human : public Entity MetaData::Tank* skin_jlf_meta = nullptr; HumanAbility ability; int born_point = 0; + int last_attacker_id = 0; + std::string last_attacker_name; + int last_attacker_weapon_id = 0; a8::Vec2 move_dir; a8::Vec2 attack_dir; @@ -202,6 +205,9 @@ class Human : public Entity void AddBuff(MetaData::Buff* buff_meta); void RemoveBuff(int buff_id); bool HasBuffEffect(int buff_effect_id); + Buff* GetBuffByEffectId(int effect_id); + void RecalcBuffAttr(); + void ProcBuffEffect(Buff* buff); protected: void _UpdateMove(int speed); @@ -212,7 +218,6 @@ private: void Revive(); void SelectSkillTargets(const a8::Vec2& target_pos, std::set& target_list); Buff* GetBuffById(int buff_id); - Buff* GetBuffByEffectId(int effect_id); protected: long long last_shot_frameno_ = 0; @@ -253,6 +258,9 @@ private: std::list buff_list_; std::array buff_effect_ = {}; + std::array buff_attr_abs_ = {}; + std::array buff_attr_rate_ = {}; + bool already_report_battle_ = false; bool sent_game_end_ = false; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 02f8bb3..9f0b346 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -414,6 +414,9 @@ namespace MetaData void Buff::Init() { + param1 = a8::XValue(i->buff_param1()).GetDouble(); + param2 = a8::XValue(i->buff_param2()).GetDouble(); + param3 = a8::XValue(i->buff_param3()).GetDouble(); } bool Buff::EffectCanStack() diff --git a/server/gameserver/metadata.h b/server/gameserver/metadata.h index a7d6e24..02b8dad 100755 --- a/server/gameserver/metadata.h +++ b/server/gameserver/metadata.h @@ -132,6 +132,10 @@ namespace MetaData void Init(); bool EffectCanStack(); + + float param1 = 0.0f; + float param2 = 0.0f; + float param3 = 0.0f; }; struct SkillPhase