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)
8123 : BasicEvent()
8124{
8125 m_Spell = spell;
8126}
BasicEvent()=default
Spell * m_Spell
Definition: Spell.cpp:529

References m_Spell.

◆ ~SpellEvent()

SpellEvent::~SpellEvent ( )
8129{
8131 m_Spell->cancel();
8132
8133 if (m_Spell->IsDeletable())
8134 {
8135 delete m_Spell;
8136 }
8137 else
8138 {
8139 LOG_ERROR("spells", "~SpellEvent: {} {} tried to delete non-deletable spell {}. Was not deleted, causes memory leak.",
8140 (m_Spell->GetCaster()->IsPlayer() ? "Player" : "Creature"), m_Spell->GetCaster()->GetGUID().ToString(), m_Spell->m_spellInfo->Id);
8141 ABORT();
8142 }
8143}
#define ABORT
Definition: Errors.h:76
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
@ SPELL_STATE_FINISHED
Definition: Spell.h:229
bool IsPlayer() const
Definition: Object.h:200
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
std::string ToString() const
Definition: ObjectGuid.cpp:47
Unit * GetCaster() const
Definition: Spell.h:577
bool IsDeletable() const
Definition: Spell.h:562
uint32 getState() const
Definition: Spell.h:485
void cancel(bool bySelf=false)
Definition: Spell.cpp:3723
SpellInfo const *const m_spellInfo
Definition: Spell.h:523
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.

8209{
8210 // oops, the spell we try to do is aborted
8212 m_Spell->cancel();
8213}

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.

8146{
8147 // update spell if it is not finished
8149 m_Spell->update(p_time);
8150
8151 // check spell state to process
8152 switch (m_Spell->getState())
8153 {
8155 {
8156 // spell was finished, check deletable state
8157 if (m_Spell->IsDeletable())
8158 {
8159 // check, if we do have unfinished triggered spells
8160 return true; // spell is deletable, finish event
8161 }
8162 // event will be re-added automatically at the end of routine)
8163 }
8164 break;
8165
8167 {
8168 // first, check, if we have just started
8169 if (m_Spell->GetDelayStart() != 0)
8170 {
8171 {
8172 // run the spell handler and think about what we can do next
8173 uint64 t_offset = e_time - m_Spell->GetDelayStart();
8174 uint64 n_offset = m_Spell->handle_delayed(t_offset);
8175 if (n_offset)
8176 {
8177 // re-add us to the queue
8178 m_Spell->GetCaster()->m_Events.AddEvent(this, m_Spell->GetDelayStart() + n_offset, false);
8179 return false; // event not complete
8180 }
8181 // event complete
8182 // finish update event will be re-added automatically at the end of routine)
8183 }
8184 }
8185 else
8186 {
8187 // delaying had just started, record the moment
8188 m_Spell->SetDelayStart(e_time);
8189 // re-plan the event for the delay moment
8190 m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + m_Spell->GetDelayMoment(), false);
8191 return false; // event not complete
8192 }
8193 }
8194 break;
8195
8196 default:
8197 {
8198 // all other states
8199 // event will be re-added automatically at the end of routine)
8200 } break;
8201 }
8202
8203 // spell processing not complete, plan event on the next update interval
8204 m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + 1, false);
8205 return false; // event not complete
8206}
std::uint64_t uint64
Definition: Define.h:106
@ SPELL_STATE_DELAYED
Definition: Spell.h:231
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.h:103
EventProcessor m_Events
Definition: Object.h:642
void SetDelayStart(uint64 m_time)
Definition: Spell.h:567
uint64 handle_delayed(uint64 t_offset)
Definition: Spell.cpp:4180
void update(uint32 difftime)
Definition: Spell.cpp:4406
uint64 GetDelayStart() const
Definition: Spell.h:566
uint64 GetDelayMoment() const
Definition: Spell.h:568

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

◆ IsDeletable()

bool SpellEvent::IsDeletable ( ) const
virtual

Reimplemented from BasicEvent.

8216{
8217 return m_Spell->IsDeletable();
8218}

References Spell::IsDeletable(), and m_Spell.

Member Data Documentation

◆ m_Spell

Spell* SpellEvent::m_Spell
protected