This commit is contained in:
aozhiwei 2023-03-17 13:12:04 +08:00
parent 395a2a1a88
commit a722f25f52
12 changed files with 74 additions and 58 deletions

View File

@ -6,6 +6,13 @@
#include "mt/Buff.h" #include "mt/Buff.h"
/*
*/
void CondAddBuff::Activate() void CondAddBuff::Activate()
{ {
} }

View File

@ -2,6 +2,15 @@
#include "buff.h" #include "buff.h"
#if 0
A8_DECLARE_CLASS_ENUM(CondAddBuff_e, int,
kBulletHit = 11,
kBulletKill = 12,
kBulletEnd = 13,
kEnd
);
#endif
class CondAddBuff : public Buff class CondAddBuff : public Buff
{ {
public: public:

View File

@ -12,17 +12,17 @@
void EventAddBuff::Activate() void EventAddBuff::Activate()
{ {
if (!IsValidCondBuff(meta->_int_buff_param1)) { if (!IsValidEventBuff(meta->_int_buff_param1)) {
A8_ABORT(); A8_ABORT();
} }
list_add_tail(&cond_entry, &owner->cond_buffs_[meta->_int_buff_param1]); list_add_tail(&cond_entry, &owner->cond_buffs_[meta->_int_buff_param1]);
switch (meta->_int_buff_param1) { switch (meta->_int_buff_param1) {
case kCondBuffDisengageBattle: case kEventBuffDisengageBattle:
{ {
ProcDisengageBattle(); ProcDisengageBattle();
} }
break; break;
case kCondBuffLimitTimeKillTarget: case kEventBuffLimitTimeKillTarget:
{ {
ProcLimitTimeSkillTarget(); ProcLimitTimeSkillTarget();
} }

View File

@ -331,26 +331,26 @@ enum ExplosionHit_e
kExplosionHitEatDmg = 4, kExplosionHitEatDmg = 4,
}; };
enum CondAddBuff_e enum EventAddBuff_e
{ {
kCondBuffUpdateWeaponId = 1, kEventBuffUpdateWeaponId = 1,
kCondBuffUpdateWeaponSlot = 2, kEventBuffUpdateWeaponSlot = 2,
kCondBuffUpdateWeaponType = 3, kEventBuffUpdateWeaponType = 3,
kCondBuffShotWeaponId = 4, kEventBuffShotWeaponId = 4,
kCondBuffShotWeaponSlot = 5, kEventBuffShotWeaponSlot = 5,
kCondBuffShotWeaponType = 6, kEventBuffShotWeaponType = 6,
kCondBuffKillTarget = 7, kEventBuffKillTarget = 7,
kCondBuffDid = 8, kEventBuffDid = 8,
kCondBuffUpdateBuffId = 9, kEventBuffUpdateBuffId = 9,
kCondBuffUpdateBuffEffect = 10, kEventBuffUpdateBuffEffect = 10,
kCondBuffHp = 11, kEventBuffHp = 11,
kCondBuffDown = 12, kEventBuffDown = 12,
kCondBuffReceiveDmg = 13, kEventBuffReceiveDmg = 13,
kCondBuffUseSkill = 14, kEventBuffUseSkill = 14,
kCondBuffEatDrug = 15, kEventBuffEatDrug = 15,
kCondBuffDisengageBattle = 16, kEventBuffDisengageBattle = 16,
kCondBuffLimitTimeKillTarget = 17, kEventBuffLimitTimeKillTarget = 17,
kCondBuffEnd kEventBuffEnd
}; };
enum WeaponOpt_e enum WeaponOpt_e

View File

@ -390,7 +390,7 @@ private:
int buff_uniid_ = 1000; int buff_uniid_ = 1000;
std::array<list_head, kBET_End> buff_effect_ = {}; std::array<list_head, kBET_End> buff_effect_ = {};
std::array<list_head, kBET_End> depend_effect_ = {}; std::array<list_head, kBET_End> depend_effect_ = {};
std::array<list_head, kCondBuffEnd> cond_buffs_ = {}; std::array<list_head, kEventBuffEnd> cond_buffs_ = {};
std::list<std::shared_ptr<Buff>> buff_list_; std::list<std::shared_ptr<Buff>> buff_list_;
std::map<int, std::shared_ptr<Effect>> effect_hash_; std::map<int, std::shared_ptr<Effect>> effect_hash_;
std::list<std::tuple<int, Hero*>> slave_heros_; std::list<std::tuple<int, Hero*>> slave_heros_;

View File

@ -23,9 +23,9 @@ bool IsValidHumanAttr(int attr_type)
return attr_type > kHAT_Begin && attr_type < kHAT_End; return attr_type > kHAT_Begin && attr_type < kHAT_End;
} }
bool IsValidCondBuff(int cond) bool IsValidEventBuff(int event)
{ {
return cond >= 0 && cond < kCondBuffEnd; return event >= 0 && event < kEventBuffEnd;
} }
bool IsValidWeaponOpt(int opt) bool IsValidWeaponOpt(int opt)

View File

@ -21,7 +21,7 @@ class Global : public a8::Singleton<Global>
bool IsValidSlotId(int slot_id); bool IsValidSlotId(int slot_id);
bool IsValidBuffEffect(int buff_effect); bool IsValidBuffEffect(int buff_effect);
bool IsValidHumanAttr(int attr_type); bool IsValidHumanAttr(int attr_type);
bool IsValidCondBuff(int cond); bool IsValidEventBuff(int event);
bool IsValidWeaponOpt(int opt); bool IsValidWeaponOpt(int opt);
bool IsValidBuffOpt(int opt); bool IsValidBuffOpt(int opt);
float GetAttrAbsFromXObject(std::shared_ptr<a8::XObject> obj, int attr_id); float GetAttrAbsFromXObject(std::shared_ptr<a8::XObject> obj, int attr_id);

View File

@ -246,7 +246,7 @@ namespace mt
} }
} }
if (buff_effect() == kBET_EventAdd) { if (buff_effect() == kBET_EventAdd) {
if (!IsValidCondBuff(_int_buff_param1)) { if (!IsValidEventBuff(_int_buff_param1)) {
A8_ABORT(); A8_ABORT();
} }
} }
@ -323,15 +323,15 @@ namespace mt
return _immune_buffeffect.find(buff_effect) != _immune_buffeffect.end(); return _immune_buffeffect.find(buff_effect) != _immune_buffeffect.end();
} }
bool Buff::Match(CondAddBuff_e cond, int val) const bool Buff::Match(EventAddBuff_e event, int val) const
{ {
switch (cond) { switch (event) {
case kCondBuffUpdateBuffId: case kEventBuffUpdateBuffId:
{ {
return val == buff_id(); return val == buff_id();
} }
break; break;
case kCondBuffUpdateBuffEffect: case kEventBuffUpdateBuffEffect:
{ {
return val == buff_effect(); return val == buff_effect();
} }

View File

@ -26,7 +26,7 @@ namespace mt
void Init2(); void Init2();
bool EffectCanStack() const; bool EffectCanStack() const;
bool IsImmuneBuffEffect(int buff_effect) const; bool IsImmuneBuffEffect(int buff_effect) const;
bool Match(CondAddBuff_e cond, int val) const; bool Match(EventAddBuff_e cond, int val) const;
float _buff_param1 = 0.0f; float _buff_param1 = 0.0f;
float _buff_param2 = 0.0f; float _buff_param2 = 0.0f;

View File

@ -242,23 +242,23 @@ namespace mt
return weapon_idx; return weapon_idx;
} }
bool Equip::Match(CondAddBuff_e cond, int val, int val2) const bool Equip::Match(EventAddBuff_e event, int val, int val2) const
{ {
switch (cond) { switch (event) {
case kCondBuffUpdateWeaponId: case kEventBuffUpdateWeaponId:
case kCondBuffShotWeaponId: case kEventBuffShotWeaponId:
{ {
return val == id(); return val == id();
} }
break; break;
case kCondBuffUpdateWeaponSlot: case kEventBuffUpdateWeaponSlot:
case kCondBuffShotWeaponSlot: case kEventBuffShotWeaponSlot:
{ {
return val == _inventory_slot(); return val == _inventory_slot();
} }
break; break;
case kCondBuffUpdateWeaponType: case kEventBuffUpdateWeaponType:
case kCondBuffShotWeaponType: case kEventBuffShotWeaponType:
{ {
return val == equip_subtype() && return val == equip_subtype() &&
(val2 == 0 || val2 == equip_type()); (val2 == 0 || val2 == equip_type());

View File

@ -38,7 +38,7 @@ namespace mt
void Init1(); void Init1();
void Init2(); void Init2();
int GetWeaponIdx() const; int GetWeaponIdx() const;
bool Match(CondAddBuff_e cond, int val, int val2) const; bool Match(EventAddBuff_e event, int val, int val2) const;
static const Equip* GetByIdBySlotId(int slot_id); static const Equip* GetByIdBySlotId(int slot_id);
private: private:

View File

@ -40,12 +40,12 @@ void Trigger::TakeonWeapon(Weapon* old_weapon, Weapon* new_weapon)
{ {
const mt::Equip* weapon_meta = old_weapon ? old_weapon->meta : nullptr; const mt::Equip* weapon_meta = old_weapon ? old_weapon->meta : nullptr;
if (weapon_meta) { if (weapon_meta) {
for (int cond = kCondBuffUpdateWeaponId; cond <= kCondBuffUpdateWeaponType; cond++) { for (int cond = kEventBuffUpdateWeaponId; cond <= kEventBuffUpdateWeaponType; cond++) {
TraverseCondBuffs TraverseCondBuffs
(cond, (cond,
[this, cond, weapon_meta] (Buff* buff, bool& stop) [this, cond, weapon_meta] (Buff* buff, bool& stop)
{ {
if (weapon_meta->Match((CondAddBuff_e)cond, if (weapon_meta->Match((EventAddBuff_e)cond,
buff->meta->_int_buff_param3, buff->meta->_int_buff_param3,
buff->meta->_int_buff_param5)) { buff->meta->_int_buff_param5)) {
switch (buff->meta->_int_buff_param2) { switch (buff->meta->_int_buff_param2) {
@ -68,12 +68,12 @@ void Trigger::TakeonWeapon(Weapon* old_weapon, Weapon* new_weapon)
{ {
const mt::Equip* weapon_meta = new_weapon ? new_weapon->meta : nullptr; const mt::Equip* weapon_meta = new_weapon ? new_weapon->meta : nullptr;
if (weapon_meta) { if (weapon_meta) {
for (int cond = kCondBuffUpdateWeaponId; cond <= kCondBuffUpdateWeaponType; cond++) { for (int cond = kEventBuffUpdateWeaponId; cond <= kEventBuffUpdateWeaponType; cond++) {
TraverseCondBuffs TraverseCondBuffs
(cond, (cond,
[this, cond, weapon_meta] (Buff* buff, bool& stop) [this, cond, weapon_meta] (Buff* buff, bool& stop)
{ {
if (weapon_meta->Match((CondAddBuff_e)cond, if (weapon_meta->Match((EventAddBuff_e)cond,
buff->meta->_int_buff_param3, buff->meta->_int_buff_param3,
buff->meta->_int_buff_param5)) { buff->meta->_int_buff_param5)) {
switch (buff->meta->_int_buff_param2) { switch (buff->meta->_int_buff_param2) {
@ -102,12 +102,12 @@ void Trigger::TakeonWeapon(Weapon* old_weapon, Weapon* new_weapon)
void Trigger::Shot(const mt::Equip* weapon_meta) void Trigger::Shot(const mt::Equip* weapon_meta)
{ {
for (int cond = kCondBuffShotWeaponId; cond <= kCondBuffShotWeaponType; ++cond) { for (int cond = kEventBuffShotWeaponId; cond <= kEventBuffShotWeaponType; ++cond) {
TraverseCondBuffs TraverseCondBuffs
(cond, (cond,
[this, cond, weapon_meta] (Buff* buff, bool& stop) [this, cond, weapon_meta] (Buff* buff, bool& stop)
{ {
if (weapon_meta->Match((CondAddBuff_e)cond, if (weapon_meta->Match((EventAddBuff_e)cond,
buff->meta->_int_buff_param2, buff->meta->_int_buff_param2,
buff->meta->_int_buff_param5)) { buff->meta->_int_buff_param5)) {
AddBuffs(buff->meta->_int_buff_param1, buff->meta->_buff_param4_int_list); AddBuffs(buff->meta->_int_buff_param1, buff->meta->_buff_param4_int_list);
@ -149,7 +149,7 @@ void Trigger::Kill(Creature* target, int weapon_id)
} }
++kill_num_; ++kill_num_;
TraverseCondBuffs TraverseCondBuffs
(kCondBuffKillTarget, (kEventBuffKillTarget,
[this] (Buff* buff, bool& stop) [this] (Buff* buff, bool& stop)
{ {
if (buff->meta->_int_buff_param2 > 0 && (kill_num_ % buff->meta->_int_buff_param2) == 0) { if (buff->meta->_int_buff_param2 > 0 && (kill_num_ % buff->meta->_int_buff_param2) == 0) {
@ -162,7 +162,7 @@ void Trigger::Kill(Creature* target, int weapon_id)
void Trigger::UseItemAction(int slot_id) void Trigger::UseItemAction(int slot_id)
{ {
TraverseCondBuffs TraverseCondBuffs
(kCondBuffEatDrug, (kEventBuffEatDrug,
[this, slot_id] (Buff* buff, bool& stop) [this, slot_id] (Buff* buff, bool& stop)
{ {
if (buff->meta->_buff_param2_int_set.find(slot_id) != buff->meta->_buff_param2_int_set.end()) { if (buff->meta->_buff_param2_int_set.find(slot_id) != buff->meta->_buff_param2_int_set.end()) {
@ -174,7 +174,7 @@ void Trigger::UseItemAction(int slot_id)
void Trigger::UseSkill(Skill* skill) void Trigger::UseSkill(Skill* skill)
{ {
TraverseCondBuffs TraverseCondBuffs
(kCondBuffUseSkill, (kEventBuffUseSkill,
[this, skill] (Buff* buff, bool& stop) [this, skill] (Buff* buff, bool& stop)
{ {
if (buff->meta->_int_buff_param2 == skill->meta->skill_id()) { if (buff->meta->_int_buff_param2 == skill->meta->skill_id()) {
@ -187,7 +187,7 @@ void Trigger::UseSkill(Skill* skill)
void Trigger::HpChg() void Trigger::HpChg()
{ {
TraverseCondBuffs TraverseCondBuffs
(kCondBuffHp, (kEventBuffHp,
[this] (Buff* buff, bool& stop) [this] (Buff* buff, bool& stop)
{ {
bool match = false; bool match = false;
@ -230,7 +230,7 @@ void Trigger::HpChg()
void Trigger::ReceiveDmg() void Trigger::ReceiveDmg()
{ {
TriggeCondBuffAll(kCondBuffReceiveDmg); TriggeCondBuffAll(kEventBuffReceiveDmg);
DispatchEvent(kReceiveDmgEvent, {}); DispatchEvent(kReceiveDmgEvent, {});
} }
@ -255,13 +255,13 @@ void Trigger::Die(int killer_id, int weapon_id)
owner_->RemoveBuffByUniId(buff_uniid); owner_->RemoveBuffByUniId(buff_uniid);
} }
} }
TriggeCondBuffAll(kCondBuffDid); TriggeCondBuffAll(kEventBuffDid);
DispatchEvent(kDieEvent, {killer_id, weapon_id}); DispatchEvent(kDieEvent, {killer_id, weapon_id});
} }
void Trigger::TraverseCondBuffs(int cond, std::function<void (Buff*, bool&)> func) void Trigger::TraverseCondBuffs(int cond, std::function<void (Buff*, bool&)> func)
{ {
if (!IsValidCondBuff(cond)) { if (!IsValidEventBuff(cond)) {
A8_ABORT(); A8_ABORT();
} }
if (!owner_->room->BattleStarted()) { if (!owner_->room->BattleStarted()) {
@ -315,12 +315,12 @@ void Trigger::TriggeCondBuffAll(int cond)
void Trigger::ActiveBuff(const mt::Buff* buff_meta) void Trigger::ActiveBuff(const mt::Buff* buff_meta)
{ {
for (int cond = kCondBuffUpdateBuffId; cond <= kCondBuffUpdateBuffEffect; ++cond) { for (int cond = kEventBuffUpdateBuffId; cond <= kEventBuffUpdateBuffEffect; ++cond) {
TraverseCondBuffs TraverseCondBuffs
(cond, (cond,
[this, cond, buff_meta] (Buff* buff, bool& stop) [this, cond, buff_meta] (Buff* buff, bool& stop)
{ {
if (buff_meta->Match((CondAddBuff_e)cond, buff->meta->_int_buff_param3)) { if (buff_meta->Match((EventAddBuff_e)cond, buff->meta->_int_buff_param3)) {
switch (buff->meta->_int_buff_param2) { switch (buff->meta->_int_buff_param2) {
case kBuffOptActive: case kBuffOptActive:
{ {
@ -344,12 +344,12 @@ void Trigger::ActiveBuff(const mt::Buff* buff_meta)
void Trigger::DeactiveBuff(const mt::Buff* buff_meta) void Trigger::DeactiveBuff(const mt::Buff* buff_meta)
{ {
for (int cond = kCondBuffUpdateBuffId; cond <= kCondBuffUpdateBuffEffect; ++cond) { for (int cond = kEventBuffUpdateBuffId; cond <= kEventBuffUpdateBuffEffect; ++cond) {
TraverseCondBuffs TraverseCondBuffs
(cond, (cond,
[this, cond, buff_meta] (Buff* buff, bool& stop) [this, cond, buff_meta] (Buff* buff, bool& stop)
{ {
if (buff_meta->Match((CondAddBuff_e)cond, buff->meta->_int_buff_param3)) { if (buff_meta->Match((EventAddBuff_e)cond, buff->meta->_int_buff_param3)) {
switch (buff->meta->_int_buff_param2) { switch (buff->meta->_int_buff_param2) {
case kBuffOptDeactive: case kBuffOptDeactive:
case kBuffOptKeep: case kBuffOptKeep: