AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
EventProcessor Class Reference

#include "EventProcessor.h"

Public Member Functions

 EventProcessor ()=default
 
 ~EventProcessor ()
 
void Update (uint32 p_time)
 
void KillAllEvents (bool force)
 
void AddEvent (BasicEvent *Event, uint64 e_time, bool set_addtime=true)
 
void AddEvent (BasicEvent *Event, uint64 e_time, bool set_addtime, uint8 eventGroup)
 
template<typename T >
is_lambda_event< T > AddEvent (T &&event, Milliseconds e_time, bool set_addtime=true)
 
void AddEventAtOffset (BasicEvent *event, Milliseconds offset)
 
void AddEventAtOffset (BasicEvent *event, Milliseconds offset, Milliseconds offset2)
 
template<typename T >
is_lambda_event< T > AddEventAtOffset (T &&event, Milliseconds offset, uint8 eventGroup)
 
template<typename T >
is_lambda_event< T > AddEventAtOffset (T &&event, Milliseconds offset, Milliseconds offset2, uint8 eventGroup)
 
template<typename T >
is_lambda_event< T > AddEventAtOffset (T &&event, Milliseconds offset)
 
template<typename T >
is_lambda_event< T > AddEventAtOffset (T &&event, Milliseconds offset, Milliseconds offset2)
 
void ModifyEventTime (BasicEvent *event, Milliseconds newTime)
 
uint64 CalculateTime (uint64 t_offset) const
 
uint64 CalculateQueueTime (uint64 delay) const
 
void CancelEventGroup (uint8 group)
 

Protected Attributes

uint64 m_time {0}
 
EventList m_events
 
bool m_aborting
 

Detailed Description

Constructor & Destructor Documentation

◆ EventProcessor()

EventProcessor::EventProcessor ( )
default

◆ ~EventProcessor()

EventProcessor::~EventProcessor ( )
36{
37 KillAllEvents(true);
38}
void KillAllEvents(bool force)
Definition: EventProcessor.cpp:82

References KillAllEvents().

Member Function Documentation

◆ AddEvent() [1/3]

void EventProcessor::AddEvent ( BasicEvent Event,
uint64  e_time,
bool  set_addtime,
uint8  eventGroup 
)
137{
138 if (set_addtime)
139 Event->m_addTime = m_time;
140 Event->m_execTime = e_time;
141 Event->m_eventGroup = eventGroup;
142 m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event));
143}
Event
Definition: boss_prince_taldaram.cpp:68
EventList m_events
Definition: EventProcessor.h:128
uint64 m_time
Definition: EventProcessor.h:127

References m_events, and m_time.

◆ AddEvent() [2/3]

void EventProcessor::AddEvent ( BasicEvent Event,
uint64  e_time,
bool  set_addtime = true 
)
inline
104{ AddEvent(Event, e_time, set_addtime, 0); };
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.h:104

References AddEvent().

Referenced by Unit::_ApplyAura(), Unit::_ExitVehicle(), npc_q24545_wretched_ghoul::npc_q24545_wretched_ghoulAI::Activate(), BattlegroundQueue::AddEvent(), AddEvent(), AddEventAtOffset(), Spell::AddUnitTarget(), spell_sindragosa_ice_tomb::spell_sindragosa_ice_tomb_AuraScript::AfterApply(), Creature::CallAssistance(), Unit::CastDelayedSpellWithPeriodicAmount(), boss_the_lich_king::boss_the_lich_kingAI::DamageTaken(), boss_baltharus_the_warborn::boss_baltharus_the_warbornAI::DoAction(), boss_prince_keleseth_icc::boss_prince_kelesethAI::DoAction(), boss_prince_taldaram_icc::boss_prince_taldaramAI::DoAction(), boss_prince_valanar_icc::boss_prince_valanarAI::DoAction(), boss_sindragosa::boss_sindragosaAI::DoAction(), npc_spinestalker::npc_spinestalkerAI::DoAction(), npc_rimefang::npc_rimefangAI::DoAction(), npc_green_dragon_combat_trigger::npc_green_dragon_combat_triggerAI::DoAction(), SpellEvent::Execute(), BattleExperienceEvent::Execute(), UtherBatteredHiltEvent::Execute(), TriggerWickedSpirit::Execute(), lapseTeleport::Execute(), PartyTimeEmoteEvent::Execute(), npc_xt002_boombot::npc_xt002_boombotAI::Explode(), Creature::ForcedDespawn(), WorldSession::HandleAuctionListOwnerItems(), spell_item_party_time::HandleEffectApply(), spell_alar_flame_quills::spell_alar_flame_quills_AuraScript::HandlePeriodic(), npc_pet_mage_mirror_image::InitializeAI(), npc_swarm_scarab::npc_swarm_scarabAI::JustDied(), npc_nerubian_burrower::npc_nerubian_burrowerAI::JustDied(), npc_gunship::npc_gunshipAI::JustDied(), npc_xt002_boombot::npc_xt002_boombotAI::JustDied(), npc_q24545_wretched_ghoul::npc_q24545_wretched_ghoulAI::JustDied(), boss_kiljaeden::boss_kiljaedenAI::JustSummoned(), boss_baltharus_the_warborn::boss_baltharus_the_warbornAI::JustSummoned(), boss_drakkari_colossus::boss_drakkari_colossusAI::JustSummoned(), boss_prince_valanar_icc::boss_prince_valanarAI::JustSummoned(), boss_sindragosa::boss_sindragosaAI::JustSummoned(), boss_the_lich_king::boss_the_lich_kingAI::JustSummoned(), boss_valithria_dreamwalker::boss_valithria_dreamwalkerAI::JustSummoned(), npc_risen_archmage::npc_risen_archmageAI::JustSummoned(), boss_algalon_the_observer::boss_algalon_the_observerAI::JustSummoned(), Creature::ModifyThreatPercentTemp(), boss_essence_of_suffering::boss_essence_of_sufferingAI::MovementInform(), boss_essence_of_desire::boss_essence_of_desireAI::MovementInform(), gunship_npc_AI::MovementInform(), npc_gunship_boarding_addAI::MovementInform(), spell_halion_twilight_realm::spell_halion_twilight_realm_AuraScript::OnApply(), instance_icecrown_citadel::instance_icecrown_citadel_InstanceMapScript::OnCreatureCreate(), spell_halion_leave_twilight_realm::spell_halion_leave_twilight_realm_AuraScript::OnRemove(), instance_icecrown_citadel::instance_icecrown_citadel_InstanceMapScript::OnUnitDeath(), npc_hyldsmeet_protodrake::npc_hyldsmeet_protodrakeAI::PassengerBoarded(), Spell::prepare(), boss_runemaster_molgeim::boss_runemaster_molgeimAI::Reset(), npc_gunship_boarding_addAI::SetData(), npc_highlord_darion_mograine::npc_highlord_darion_mograineAI::SummonedCreatureDies(), TempSummon::UnSummon(), Totem::UnSummon(), spell_illidari_council_deadly_strike::spell_illidari_council_deadly_strike_AuraScript::Update(), Update(), boss_felmyst::boss_felmystAI::UpdateAI(), and boss_anomalus::boss_anomalusAI::UpdateAI().

◆ AddEvent() [3/3]

template<typename T >
is_lambda_event< T > EventProcessor::AddEvent ( T &&  event,
Milliseconds  e_time,
bool  set_addtime = true 
)
inline
107{ AddEvent(new LambdaBasicEvent<T>(std::move(event)), e_time, set_addtime); }
Definition: EventProcessor.h:76

References AddEvent().

Referenced by AddEvent().

◆ AddEventAtOffset() [1/6]

◆ AddEventAtOffset() [2/6]

void EventProcessor::AddEventAtOffset ( BasicEvent event,
Milliseconds  offset,
Milliseconds  offset2 
)
inline
109{ AddEvent(event, CalculateTime(randtime(offset, offset2).count()), true, false); }
Milliseconds randtime(Milliseconds min, Milliseconds max)
Definition: Random.cpp:64

References AddEvent(), CalculateTime(), and randtime().

◆ AddEventAtOffset() [3/6]

template<typename T >
is_lambda_event< T > EventProcessor::AddEventAtOffset ( T &&  event,
Milliseconds  offset 
)
inline
115{ AddEventAtOffset(new LambdaBasicEvent<T>(std::move(event)), offset); }
void AddEventAtOffset(BasicEvent *event, Milliseconds offset)
Definition: EventProcessor.h:108

References AddEventAtOffset().

Referenced by AddEventAtOffset().

◆ AddEventAtOffset() [4/6]

template<typename T >
is_lambda_event< T > EventProcessor::AddEventAtOffset ( T &&  event,
Milliseconds  offset,
Milliseconds  offset2 
)
inline
117{ AddEventAtOffset(new LambdaBasicEvent<T>(std::move(event)), offset, offset2); }

References AddEventAtOffset().

Referenced by AddEventAtOffset().

◆ AddEventAtOffset() [5/6]

template<typename T >
is_lambda_event< T > EventProcessor::AddEventAtOffset ( T &&  event,
Milliseconds  offset,
Milliseconds  offset2,
uint8  eventGroup 
)
inline
113{ AddEvent(new LambdaBasicEvent<T>(std::move(event)), CalculateTime(randtime(offset, offset2).count()), true, eventGroup); };

References AddEvent(), CalculateTime(), and randtime().

◆ AddEventAtOffset() [6/6]

template<typename T >
is_lambda_event< T > EventProcessor::AddEventAtOffset ( T &&  event,
Milliseconds  offset,
uint8  eventGroup 
)
inline
111{ AddEvent(new LambdaBasicEvent<T>(std::move(event)), CalculateTime(offset.count()), true, eventGroup); };

References AddEvent(), and CalculateTime().

◆ CalculateQueueTime()

uint64 EventProcessor::CalculateQueueTime ( uint64  delay) const
165{
166 return CalculateTime(delay - (m_time % delay));
167}

References CalculateTime(), and m_time.

Referenced by Unit::CastDelayedSpellWithPeriodicAmount().

◆ CalculateTime()

uint64 EventProcessor::CalculateTime ( uint64  t_offset) const
160{
161 return (m_time + t_offset);
162}

References m_time.

Referenced by Unit::_ApplyAura(), Unit::_ExitVehicle(), npc_q24545_wretched_ghoul::npc_q24545_wretched_ghoulAI::Activate(), BattlegroundQueue::AddEvent(), AddEventAtOffset(), Spell::AddUnitTarget(), CalculateQueueTime(), Creature::CallAssistance(), boss_the_lich_king::boss_the_lich_kingAI::DamageTaken(), boss_baltharus_the_warborn::boss_baltharus_the_warbornAI::DoAction(), boss_prince_keleseth_icc::boss_prince_kelesethAI::DoAction(), boss_prince_taldaram_icc::boss_prince_taldaramAI::DoAction(), boss_prince_valanar_icc::boss_prince_valanarAI::DoAction(), boss_sindragosa::boss_sindragosaAI::DoAction(), npc_spinestalker::npc_spinestalkerAI::DoAction(), npc_rimefang::npc_rimefangAI::DoAction(), npc_green_dragon_combat_trigger::npc_green_dragon_combat_triggerAI::DoAction(), UtherBatteredHiltEvent::Execute(), TriggerWickedSpirit::Execute(), lapseTeleport::Execute(), PartyTimeEmoteEvent::Execute(), npc_xt002_boombot::npc_xt002_boombotAI::Explode(), Creature::ForcedDespawn(), WorldSession::HandleAuctionListOwnerItems(), spell_item_party_time::HandleEffectApply(), npc_pet_mage_mirror_image::InitializeAI(), npc_swarm_scarab::npc_swarm_scarabAI::JustDied(), npc_nerubian_burrower::npc_nerubian_burrowerAI::JustDied(), npc_gunship::npc_gunshipAI::JustDied(), npc_xt002_boombot::npc_xt002_boombotAI::JustDied(), npc_q24545_wretched_ghoul::npc_q24545_wretched_ghoulAI::JustDied(), boss_kiljaeden::boss_kiljaedenAI::JustSummoned(), boss_baltharus_the_warborn::boss_baltharus_the_warbornAI::JustSummoned(), boss_drakkari_colossus::boss_drakkari_colossusAI::JustSummoned(), boss_prince_valanar_icc::boss_prince_valanarAI::JustSummoned(), boss_sindragosa::boss_sindragosaAI::JustSummoned(), boss_the_lich_king::boss_the_lich_kingAI::JustSummoned(), boss_valithria_dreamwalker::boss_valithria_dreamwalkerAI::JustSummoned(), npc_risen_archmage::npc_risen_archmageAI::JustSummoned(), boss_algalon_the_observer::boss_algalon_the_observerAI::JustSummoned(), Creature::ModifyThreatPercentTemp(), boss_essence_of_suffering::boss_essence_of_sufferingAI::MovementInform(), boss_essence_of_desire::boss_essence_of_desireAI::MovementInform(), gunship_npc_AI::MovementInform(), npc_gunship_boarding_addAI::MovementInform(), instance_icecrown_citadel::instance_icecrown_citadel_InstanceMapScript::OnCreatureCreate(), instance_icecrown_citadel::instance_icecrown_citadel_InstanceMapScript::OnUnitDeath(), npc_hyldsmeet_protodrake::npc_hyldsmeet_protodrakeAI::PassengerBoarded(), Spell::prepare(), boss_runemaster_molgeim::boss_runemaster_molgeimAI::Reset(), npc_gunship_boarding_addAI::SetData(), boss_the_beast::boss_thebeastAI::SetData(), npc_highlord_darion_mograine::npc_highlord_darion_mograineAI::SummonedCreatureDies(), TempSummon::UnSummon(), Totem::UnSummon(), Update(), boss_felmyst::boss_felmystAI::UpdateAI(), and boss_anomalus::boss_anomalusAI::UpdateAI().

◆ CancelEventGroup()

void EventProcessor::CancelEventGroup ( uint8  group)
115{
116 for (auto itr = m_events.begin(); itr != m_events.end();)
117 {
118 if (itr->second->m_eventGroup != group)
119 {
120 ++itr;
121 continue;
122 }
123
124 // Abort events which weren't aborted already
125 if (!itr->second->IsAborted())
126 {
127 itr->second->SetAborted();
128 itr->second->Abort(m_time);
129 }
130
131 delete itr->second;
132 itr = m_events.erase(itr);
133 }
134}

References m_events, and m_time.

Referenced by boss_murmur::CastSupressionOOC(), boss_murmur::JustEngagedWith(), and boss_hydross_the_unstable::JustEngagedWith().

◆ KillAllEvents()

void EventProcessor::KillAllEvents ( bool  force)
83{
84 // first, abort all existing events
85 for (auto itr = m_events.begin(); itr != m_events.end();)
86 {
87 // Abort events which weren't aborted already
88 if (!itr->second->IsAborted())
89 {
90 itr->second->SetAborted();
91 itr->second->Abort(m_time);
92 }
93
94 // Skip non-deletable events when we are
95 // not forcing the event cancellation.
96 if (!force && !itr->second->IsDeletable())
97 {
98 ++itr;
99 continue;
100 }
101
102 delete itr->second;
103
104 if (force)
105 ++itr; // Clear the whole container when forcing
106 else
107 itr = m_events.erase(itr);
108 }
109
110 if (force)
111 m_events.clear();
112}

References m_events, and m_time.

Referenced by Unit::CleanupBeforeRemoveFromMap(), npc_q24545_wretched_ghoul::npc_q24545_wretched_ghoulAI::DoAction(), at_cthun_stomach_exit::OnTrigger(), NPCStaveQuestAI::ResetState(), Battleground::~Battleground(), BattlegroundQueue::~BattlegroundQueue(), and ~EventProcessor().

◆ ModifyEventTime()

void EventProcessor::ModifyEventTime ( BasicEvent event,
Milliseconds  newTime 
)
146{
147 for (auto itr = m_events.begin(); itr != m_events.end(); ++itr)
148 {
149 if (itr->second != event)
150 continue;
151
152 event->m_execTime = newTime.count();
153 m_events.erase(itr);
154 m_events.insert(std::pair<uint64, BasicEvent*>(newTime.count(), event));
155 break;
156 }
157}

References m_events.

Referenced by Spell::RecalculateDelayMomentForDst().

◆ Update()

void EventProcessor::Update ( uint32  p_time)
41{
42 // update time
43 m_time += p_time;
44
45 // main event loop
46 EventList::iterator i;
47 while (((i = m_events.begin()) != m_events.end()) && i->first <= m_time)
48 {
49 // get and remove event from queue
50 BasicEvent* event = i->second;
51 m_events.erase(i);
52
53 if (event->IsRunning())
54 {
55 if (event->Execute(m_time, p_time))
56 {
57 // completely destroy event if it is not re-added
58 delete event;
59 }
60 continue;
61 }
62
63 if (event->IsAbortScheduled())
64 {
65 event->Abort(m_time);
66 // Mark the event as aborted
67 event->SetAborted();
68 }
69
70 if (event->IsDeletable())
71 {
72 delete event;
73 continue;
74 }
75
76 // Reschedule non deletable events to be checked at
77 // the next update tick
78 AddEvent(event, CalculateTime(1), false, 0);
79 }
80}
Definition: EventProcessor.h:31

References AddEvent(), CalculateTime(), m_events, and m_time.

Referenced by Battleground::_ProcessResurrect(), Unit::Update(), and BattlegroundQueue::UpdateEvents().

Member Data Documentation

◆ m_aborting

bool EventProcessor::m_aborting
protected

◆ m_events

EventList EventProcessor::m_events
protected

◆ m_time

uint64 EventProcessor::m_time {0}
protected