104 lines
2.7 KiB
C++
104 lines
2.7 KiB
C++
#pragma once
|
|
|
|
|
|
struct EventHandlerPtr
|
|
{
|
|
struct EventHandler* data = nullptr;
|
|
};
|
|
|
|
struct EventHandler
|
|
{
|
|
a8::CommonCbProc cb;
|
|
list_head entry;
|
|
std::shared_ptr<EventHandlerPtr> ptr;
|
|
};
|
|
|
|
enum EventId_e
|
|
{
|
|
kNoneEvent = 0,
|
|
kShotEvent,
|
|
kReceiveDmgEvent,
|
|
kKillEvent,
|
|
kPreDieEvent,
|
|
kDieEvent,
|
|
kShieldDestoryEvent,
|
|
kFlyHookPullEvent,
|
|
kBulletHitEvent,
|
|
kBulletBlockEvent,
|
|
kYsRemoveEvent,
|
|
kStartRescueEvent,
|
|
kEndRescueEvent,
|
|
kStartSwitchWeaponBuffEvent,
|
|
kEndSwitchWeaponBuffEvent,
|
|
kFlyHookCreateEvent,
|
|
kFlyHookDestoryEvent,
|
|
kSkillBulletPreCreateEvent,
|
|
kUseSkillEvent,
|
|
kTriggerBulletHitBuffEvent,
|
|
kDmgOutEvent,
|
|
kHpChgEvent,
|
|
kRevive,
|
|
kAttacked,
|
|
kStartJump,
|
|
kEndJump,
|
|
kTakeonWeaponEvent
|
|
};
|
|
|
|
class Weapon;
|
|
class Creature;
|
|
class Skill;
|
|
class Buff;
|
|
class Bullet;
|
|
class Human;
|
|
class Trigger
|
|
{
|
|
public:
|
|
|
|
Trigger(Creature* owner) { owner_ = owner; };
|
|
void Init();
|
|
void UnInit();
|
|
Creature* GetOwner() { return owner_; };
|
|
void TakeonWeapon(Weapon* old_weapon, Weapon* new_weapon);
|
|
void Shot(const mt::Equip* weapon_meta);
|
|
void Kill(Creature* target, int weapon_id);
|
|
void UseItemAction(int slot_id);
|
|
void UseSkill(Skill* skill);
|
|
void HpChg();
|
|
void ReceiveDmg();
|
|
void PreDie(int killer_id, int weapon_id);
|
|
void Die(int killer_id, int weapon_id);
|
|
void ActiveBuff(const mt::Buff* buff_meta);
|
|
void DeactiveBuff(const mt::Buff* buff_meta);
|
|
void BulletHit(IBullet* bullet, Creature* target);
|
|
void ShieldDestory();
|
|
void StartRescue(Human* target);
|
|
void EndRescue(Human* target);
|
|
void YsBuffRemove(Buff* buff);
|
|
void SkillBulletPreCreate(int delay_time, const mt::Skill* skill_meta);
|
|
void FlyHookCreate(Bullet* bullet);
|
|
void FlyHookDestory();
|
|
void BulletHitBuff(Bullet* bullet);
|
|
void Attacked(Creature* sender);
|
|
void DmgOut(Creature* target, float dmg);
|
|
void BulletBlock(IBullet* bullet, const glm::vec3& pos);
|
|
void StartJump(Creature* sender);
|
|
void EndJump(Creature* sender);
|
|
|
|
std::weak_ptr<EventHandlerPtr> AddListener(int event_id, a8::CommonCbProc cb);
|
|
void RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler_ptr);
|
|
void DispatchEvent(int event_id, const std::vector<std::any>& params);
|
|
|
|
private:
|
|
void TraverseCondBuffs(int cond, std::function<void (Buff*, bool&)> func);
|
|
void TriggeCondBuffAll(int cond);
|
|
void TryAddBuffs(int cond, const std::vector<int>& buffids);
|
|
void AddBuffs(int cond, const std::vector<int>& buffids);
|
|
void RemoveBuffs(int cond, const std::vector<int>& buffids);
|
|
|
|
|
|
private:
|
|
Creature* owner_ = nullptr;
|
|
int kill_num_ = 0;
|
|
std::map<int, list_head> listeners_hash_;
|
|
};
|