From 503eb03fffe8ed036e710f536902175d3dc14ee8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 28 Jun 2021 12:21:23 +0000 Subject: [PATCH] 1 --- server/gameserver/constant.h | 33 +++++-- server/gameserver/global.cc | 10 ++ server/gameserver/global.h | 2 + server/gameserver/human.cc | 3 + server/gameserver/trigger.cc | 184 ++++++++++++++++++++++++++++++++++- server/gameserver/trigger.h | 9 ++ 6 files changed, 230 insertions(+), 11 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index a2e59e6..1ec7ebe 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -377,21 +377,40 @@ enum ExplosionHit_e enum CondAddBuff_e { - kCondBuffTakeonWeaponId = 1, - kCondBuffTakeonWeaponSlot = 2, - kCondBuffTakeonWeaponType = 3, + kCondBuffUpdateWeaponId = 1, + kCondBuffUpdateWeaponSlot = 2, + kCondBuffUpdateWeaponType = 3, kCondBuffShotWeaponId = 4, kCondBuffShotWeaponSlot = 5, kCondBuffShotWeaponType = 6, kCondBuffKillTarget = 7, kCondBuffDid = 8, - kCondBuffActiveBuff = 9, - kCondBuffHp = 10, - kCondBuffDown = 11, - kCondBuffReceiveDmg = 12, + kCondBuffUpdateBuffId = 9, + kCondBuffUpdateBuffEffect = 10, + kCondBuffHp = 11, + kCondBuffDown = 12, + kCondBuffReceiveDmg = 13, + kCondBuffUseSkill = 14, + kCondBuffEatDrug = 15, kCondBuffEnd }; +enum WeaponOpt_e +{ + kWeaponOptTakeon = 0, + kWeaponOptTakeoff = 1, + kWeaponOptKeep = 2, + kWeaponOptEnd +}; + +enum BuffOpt_e +{ + kBuffOptActive = 0, + kBuffOptDeactive = 1, + kBuffOptKeep = 2, + kBuffOptEnd +}; + 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 48471a1..461701e 100755 --- a/server/gameserver/global.cc +++ b/server/gameserver/global.cc @@ -51,3 +51,13 @@ bool IsValidCondBuff(int cond) { return cond >= 0 && cond < kCondBuffEnd; } + +bool IsValidWeaponOpt(int opt) +{ + return opt >= 0 && opt < kWeaponOptEnd; +} + +bool IsValidBuffOpt(int opt) +{ + return opt >= 0 && opt < kBuffOptEnd; +} diff --git a/server/gameserver/global.h b/server/gameserver/global.h index 799488d..ce88ffc 100755 --- a/server/gameserver/global.h +++ b/server/gameserver/global.h @@ -25,3 +25,5 @@ bool IsValidSlotId(int slot_id); bool IsValidBuffEffect(int buff_effect); bool IsValidHumanAttr(int attr_type); bool IsValidCondBuff(int cond); +bool IsValidWeaponOpt(int opt); +bool IsValidBuffOpt(int opt); diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index c10a494..3d728af 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -3013,6 +3013,7 @@ void Human::ProcUseItemAction() { AddHp(item_meta->i->heal()); DecInventory(item_meta->i->_inventory_slot(), 1); + GetTrigger()->UseItemAction(action_item_id); } break; case IS_PAIN_KILLER: @@ -3054,6 +3055,7 @@ void Human::ProcUseItemAction() } DecInventory(item_meta->i->_inventory_slot(), 1); need_sync_active_player = true; + GetTrigger()->UseItemAction(action_item_id); } break; case IS_SHEN_BAO: @@ -3071,6 +3073,7 @@ void Human::ProcUseItemAction() } DecInventory(item_meta->i->_inventory_slot(), 1); need_sync_active_player = true; + GetTrigger()->UseItemAction(action_item_id); } break; default: diff --git a/server/gameserver/trigger.cc b/server/gameserver/trigger.cc index 9d43f40..cf993d6 100644 --- a/server/gameserver/trigger.cc +++ b/server/gameserver/trigger.cc @@ -4,6 +4,8 @@ #include "trigger.h" #include "creature.h" +#include "metamgr.h" +#include "skill.h" void Trigger::Init() { @@ -21,21 +23,76 @@ void Trigger::TakeonWeapon(Weapon* old_weapon, Weapon* new_weapon) void Trigger::Shot(MetaData::Equip* weapon_meta) { - + { + TraverseCondBuffs + (kCondBuffShotWeaponId, + [this, weapon_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == weapon_meta->i->id()) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); + } + { + TraverseCondBuffs + (kCondBuffShotWeaponSlot, + [this, weapon_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == weapon_meta->i->_inventory_slot()) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); + } + { + TraverseCondBuffs + (kCondBuffShotWeaponType, + [this, weapon_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == weapon_meta->i->equip_subtype()) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); + } } void Trigger::Kill(Creature* target) { - + { + TraverseCondBuffs + (kCondBuffKillTarget, + [this] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 >= 1) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); + } } void Trigger::UseItemAction(int slot_id) { + { + TraverseCondBuffs + (kCondBuffEatDrug, + [this, slot_id] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == slot_id) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); + } } void Trigger::UseSkill(Skill* skill) { - + TraverseCondBuffs + (kCondBuffUseSkill, + [this, skill] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == skill->meta->i->skill_id()) { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + }); } void Trigger::HpChg(float old_hp, float new_hp) @@ -45,7 +102,7 @@ void Trigger::HpChg(float old_hp, float new_hp) void Trigger::Die() { - + TriggeCondBuffAll(kCondBuffDid); } void Trigger::TraverseCondBuffs(int cond, std::function func) @@ -76,3 +133,122 @@ void Trigger::TraverseCondBuffs(int cond, std::function fun } } } + +void Trigger::TriggeCondBuffAll(int cond) +{ + TraverseCondBuffs + (cond, + [this, cond] (Buff* buff, bool& stop) + { + AddBuff(cond, buff->meta->int_param4); + }); +} + +void Trigger::AddBuff(int cond, int buff_id) +{ +#ifdef DEBUG + owner_->MustBeAddBuff(owner_, buff_id); +#else + owner_->TryBeAddBuff(owner_, buff_id); +#endif +} + +void Trigger::ActiveBuff(MetaData::Buff* buff_meta) +{ + { + TraverseCondBuffs + (kCondBuffUpdateBuffId, + [this, buff_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == buff_meta->i->buff_id()) { + switch (buff->meta->int_param3) { + case kBuffOptActive: + case kBuffOptKeep: + { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + break; + default: + { + } + break; + } + } + }); + } + { + TraverseCondBuffs + (kCondBuffUpdateBuffEffect, + [this, buff_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == buff_meta->i->buff_effect()) { + switch (buff->meta->int_param3) { + case kBuffOptActive: + case kBuffOptKeep: + { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + break; + default: + { + } + break; + } + } + }); + } +} + +void Trigger::DeactiveBuff(MetaData::Buff* buff_meta) +{ + { + TraverseCondBuffs + (kCondBuffUpdateBuffId, + [this, buff_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == buff_meta->i->buff_id()) { + switch (buff->meta->int_param3) { + case kBuffOptDeactive: + { + owner_->RemoveBuffById(buff->meta->int_param4); + } + break; + case kBuffOptKeep: + { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + break; + default: + { + } + break; + } + } + }); + } + { + TraverseCondBuffs + (kCondBuffUpdateBuffEffect, + [this, buff_meta] (Buff* buff, bool& stop) + { + if (buff->meta->int_param2 == buff_meta->i->buff_effect()) { + switch (buff->meta->int_param3) { + case kBuffOptDeactive: + { + owner_->RemoveBuffById(buff->meta->int_param4); + } + break; + case kBuffOptKeep: + { + AddBuff(buff->meta->int_param1, buff->meta->int_param4); + } + break; + default: + { + } + break; + } + } + }); + } +} diff --git a/server/gameserver/trigger.h b/server/gameserver/trigger.h index 86e3f0c..6ba094e 100644 --- a/server/gameserver/trigger.h +++ b/server/gameserver/trigger.h @@ -1,5 +1,10 @@ #pragma once +namespace MetaData +{ + struct Buff; +}; + class Weapon; class Creature; class Skill; @@ -19,9 +24,13 @@ public: void UseSkill(Skill* skill); void HpChg(float old_hp, float new_hp); void Die(); + void ActiveBuff(MetaData::Buff* buff_meta); + void DeactiveBuff(MetaData::Buff* buff_meta); private: void TraverseCondBuffs(int cond, std::function func); + void TriggeCondBuffAll(int cond); + void AddBuff(int cond, int buff_id); private: Creature* owner_ = nullptr;