aozhiwei 4694bfa9e4 1
2023-06-20 20:06:06 +08:00

123 lines
3.3 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,
kBulletKill,
kAttackTargetEvent,
kStartReloadEvent,
kEndReloadEvent,
kDownedEvent,
kUpdateEnergyShieldEvent,
kDestoryEnergyShieldEvent,
kCrazeModeEvent
};
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 BulletKill(IBullet* bullet, Creature* target);
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);
void Downed();
void StartReload();
void EndReload();
void UpdateEnergyShield(int value, int new_time);
void DestoryEnergyShield();
void EnterCrazeMode();
std::weak_ptr<EventHandlerPtr> AddListener(int event_id, a8::CommonCbProc cb);
void RemoveEventHandler(std::weak_ptr<EventHandlerPtr> handler_ptr);
void RemoveEventHandlers(std::vector<std::weak_ptr<EventHandlerPtr>> handlers);
void DispatchEvent(int event_id, const std::vector<std::any>& params);
bool HasCondBuff(int cond);
private:
void TraverseCondBuffs(int cond, std::function<void (Buff*, bool&)> func);
void TriggeCondBuffAll(int cond);
void TryAddBuffs(Buff* buff, int cond, const std::vector<int>& buffids,
std::shared_ptr<std::vector<float>> buff_vars = nullptr);
void AddBuffs(Buff* buff, int cond, const std::vector<int>& buffids,
std::shared_ptr<std::vector<float>> buff_vars = nullptr);
void RemoveBuffs(int cond, const std::vector<int>& buffids);
private:
Creature* owner_ = nullptr;
int kill_num_ = 0;
std::map<int, list_head> listeners_hash_;
};