1
This commit is contained in:
parent
01b4b98c4c
commit
503eb03fff
@ -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";
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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<void (Buff*, bool&)> func)
|
||||
@ -76,3 +133,122 @@ void Trigger::TraverseCondBuffs(int cond, std::function<void (Buff*, bool&)> 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;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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<void (Buff*, bool&)> func);
|
||||
void TriggeCondBuffAll(int cond);
|
||||
void AddBuff(int cond, int buff_id);
|
||||
|
||||
private:
|
||||
Creature* owner_ = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user