AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SpellEvent Class Reference
Inheritance diagram for SpellEvent:
BasicEvent

Public Member Functions

 SpellEvent (Spell *spell)
 
 ~SpellEvent ()
 
bool Execute (uint64 e_time, uint32 p_time)
 
void Abort (uint64 e_time)
 
bool IsDeletable () const
 
- Public Member Functions inherited from BasicEvent
 BasicEvent ()=default
 
virtual ~BasicEvent ()=default
 
virtual bool Execute (uint64, uint32)
 
virtual bool IsDeletable () const
 
virtual void Abort (uint64)
 
void ScheduleAbort ()
 

Protected Attributes

Spellm_Spell
 

Detailed Description

Constructor & Destructor Documentation

◆ SpellEvent()

SpellEvent::SpellEvent ( Spell spell)
8110 : BasicEvent()
8111{
8112 m_Spell = spell;
8113}
BasicEvent()=default
Spell * m_Spell
Definition: Spell.cpp:530

References m_Spell.

◆ ~SpellEvent()

SpellEvent::~SpellEvent ( )
8116{
8118 m_Spell->cancel();
8119
8120 if (m_Spell->IsDeletable())
8121 {
8122 delete m_Spell;
8123 }
8124 else
8125 {
8126 LOG_ERROR("spells", "~SpellEvent: {} {} tried to delete non-deletable spell {}. Was not deleted, causes memory leak.",
8127 (m_Spell->GetCaster()->IsPlayer() ? "Player" : "Creature"), m_Spell->GetCaster()->GetGUID().ToString(), m_Spell->m_spellInfo->Id);
8128 ABORT();
8129 }
8130}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
#define ABORT
Definition: Errors.h:76
@ SPELL_STATE_FINISHED
Definition: Spell.h:226
bool IsPlayer() const
Definition: Object.h:197
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
std::string ToString() const
Definition: ObjectGuid.cpp:47
Unit * GetCaster() const
Definition: Spell.h:573
bool IsDeletable() const
Definition: Spell.h:558
uint32 getState() const
Definition: Spell.h:482
void cancel(bool bySelf=false)
Definition: Spell.cpp:3712
SpellInfo const *const m_spellInfo
Definition: Spell.h:520
uint32 Id
Definition: SpellInfo.h:320

References ABORT, Spell::cancel(), Spell::GetCaster(), Object::GetGUID(), Spell::getState(), SpellInfo::Id, Spell::IsDeletable(), Object::IsPlayer(), LOG_ERROR, m_Spell, Spell::m_spellInfo, SPELL_STATE_FINISHED, and ObjectGuid::ToString().

Member Function Documentation

◆ Abort()

void SpellEvent::Abort ( uint64  e_time)
virtual

Reimplemented from BasicEvent.

8196{
8197 // oops, the spell we try to do is aborted
8199 m_Spell->cancel();
8200}

References Spell::cancel(), Spell::getState(), m_Spell, and SPELL_STATE_FINISHED.

◆ Execute()

bool SpellEvent::Execute ( uint64  e_time,
uint32  p_time 
)
virtual

Reimplemented from BasicEvent.

8133{
8134 // update spell if it is not finished
8136 m_Spell->update(p_time);
8137
8138 // check spell state to process
8139 switch (m_Spell->getState())
8140 {
8142 {
8143 // spell was finished, check deletable state
8144 if (m_Spell->IsDeletable())
8145 {
8146 // check, if we do have unfinished triggered spells
8147 return true; // spell is deletable, finish event
8148 }
8149 // event will be re-added automatically at the end of routine)
8150 }
8151 break;
8152
8154 {
8155 // first, check, if we have just started
8156 if (m_Spell->GetDelayStart() != 0)
8157 {
8158 {
8159 // run the spell handler and think about what we can do next
8160 uint64 t_offset = e_time - m_Spell->GetDelayStart();
8161 uint64 n_offset = m_Spell->handle_delayed(t_offset);
8162 if (n_offset)
8163 {
8164 // re-add us to the queue
8165 m_Spell->GetCaster()->m_Events.AddEvent(this, m_Spell->GetDelayStart() + n_offset, false);
8166 return false; // event not complete
8167 }
8168 // event complete
8169 // finish update event will be re-added automatically at the end of routine)
8170 }
8171 }
8172 else
8173 {
8174 // delaying had just started, record the moment
8175 m_Spell->SetDelayStart(e_time);
8176 // re-plan the event for the delay moment
8177 m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + m_Spell->GetDelayMoment(), false);
8178 return false; // event not complete
8179 }
8180 }
8181 break;
8182
8183 default:
8184 {
8185 // all other states
8186 // event will be re-added automatically at the end of routine)
8187 } break;
8188 }
8189
8190 // spell processing not complete, plan event on the next update interval
8191 m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + 1, false);
8192 return false; // event not complete
8193}
std::uint64_t uint64
Definition: Define.h:106
@ SPELL_STATE_DELAYED
Definition: Spell.h:228
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.h:103
EventProcessor m_Events
Definition: Unit.h:1792
void SetDelayStart(uint64 m_time)
Definition: Spell.h:563
uint64 handle_delayed(uint64 t_offset)
Definition: Spell.cpp:4167
void update(uint32 difftime)
Definition: Spell.cpp:4393
uint64 GetDelayStart() const
Definition: Spell.h:562
uint64 GetDelayMoment() const
Definition: Spell.h:564

References EventProcessor::AddEvent(), Spell::GetCaster(), Spell::GetDelayMoment(), Spell::GetDelayStart(), Spell::getState(), Spell::handle_delayed(), Spell::IsDeletable(), Unit::m_Events, m_Spell, Spell::SetDelayStart(), SPELL_STATE_DELAYED, SPELL_STATE_FINISHED, and Spell::update().

◆ IsDeletable()

bool SpellEvent::IsDeletable ( ) const
virtual

Reimplemented from BasicEvent.

8203{
8204 return m_Spell->IsDeletable();
8205}

References Spell::IsDeletable(), and m_Spell.

Member Data Documentation

◆ m_Spell

Spell* SpellEvent::m_Spell
protected