TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SpellEvent Class Reference

#include <Spell.h>

Public Member Functions

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

Protected Attributes

Spellm_Spell
 

Additional Inherited Members

- Public Attributes inherited from BasicEvent
bool to_Abort
 
uint64 m_addTime
 
uint64 m_execTime
 

Constructor & Destructor Documentation

SpellEvent::SpellEvent ( Spell spell)
6719  : BasicEvent()
6720 {
6721  m_Spell = spell;
6722 }
BasicEvent()
Definition: EventProcessor.h:31
Spell * m_Spell
Definition: Spell.h:915
SpellEvent::~SpellEvent ( )
virtual
6725 {
6727  m_Spell->cancel();
6728 
6729  if (m_Spell->IsDeletable())
6730  {
6731  delete m_Spell;
6732  }
6733  else
6734  {
6735  TC_LOG_ERROR("spells", "~SpellEvent: %s %s tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
6736  (m_Spell->GetCaster()->GetTypeId() == TYPEID_PLAYER ? "Player" : "Creature"), m_Spell->GetCaster()->GetGUID().ToString().c_str(), m_Spell->m_spellInfo->Id);
6737  ABORT();
6738  }
6739 }
SpellInfo const *const m_spellInfo
Definition: Spell.h:547
uint32 Id
Definition: SpellInfo.h:329
Unit * GetCaster() const
Definition: Spell.h:612
uint32 getState() const
Definition: Spell.h:509
TypeID GetTypeId() const
Definition: Object.h:113
ObjectGuid const & GetGUID() const
Definition: Object.h:105
bool IsDeletable() const
Definition: Spell.h:600
Definition: ObjectGuid.h:33
#define ABORT
Definition: Errors.h:56
void cancel()
Definition: Spell.cpp:3061
Spell * m_Spell
Definition: Spell.h:915
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: Spell.h:279
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

Member Function Documentation

void SpellEvent::Abort ( uint64  e_time)
overridevirtual

Reimplemented from BasicEvent.

6829 {
6830  // oops, the spell we try to do is aborted
6832  m_Spell->cancel();
6833 }
uint32 getState() const
Definition: Spell.h:509
void cancel()
Definition: Spell.cpp:3061
Spell * m_Spell
Definition: Spell.h:915
Definition: Spell.h:279

+ Here is the call graph for this function:

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

Reimplemented from BasicEvent.

6742 {
6743  // update spell if it is not finished
6745  m_Spell->update(p_time);
6746 
6747  // check spell state to process
6748  switch (m_Spell->getState())
6749  {
6750  case SPELL_STATE_FINISHED:
6751  {
6752  // spell was finished, check deletable state
6753  if (m_Spell->IsDeletable())
6754  {
6755  // check, if we do have unfinished triggered spells
6756  return true; // spell is deletable, finish event
6757  }
6758  // event will be re-added automatically at the end of routine)
6759  } break;
6760 
6761  case SPELL_STATE_DELAYED:
6762  {
6763  // first, check, if we have just started
6764  if (m_Spell->GetDelayStart() != 0)
6765  {
6766  // no, we aren't, do the typical update
6767  // check, if we have channeled spell on our hands
6768  /*
6769  if (m_Spell->m_spellInfo->IsChanneled())
6770  {
6771  // evented channeled spell is processed separately, cast once after delay, and not destroyed till finish
6772  // check, if we have casting anything else except this channeled spell and autorepeat
6773  if (m_Spell->GetCaster()->IsNonMeleeSpellCast(false, true, true))
6774  {
6775  // another non-melee non-delayed spell is cast now, abort
6776  m_Spell->cancel();
6777  }
6778  else
6779  {
6780  // Set last not triggered spell for apply spellmods
6781  ((Player*)m_Spell->GetCaster())->SetSpellModTakingSpell(m_Spell, true);
6782  // do the action (pass spell to channeling state)
6783  m_Spell->handle_immediate();
6784 
6785  // And remove after effect handling
6786  ((Player*)m_Spell->GetCaster())->SetSpellModTakingSpell(m_Spell, false);
6787  }
6788  // event will be re-added automatically at the end of routine)
6789  }
6790  else
6791  */
6792  {
6793  // run the spell handler and think about what we can do next
6794  uint64 t_offset = e_time - m_Spell->GetDelayStart();
6795  uint64 n_offset = m_Spell->handle_delayed(t_offset);
6796  if (n_offset)
6797  {
6798  // re-add us to the queue
6799  m_Spell->GetCaster()->m_Events.AddEvent(this, m_Spell->GetDelayStart() + n_offset, false);
6800  return false; // event not complete
6801  }
6802  // event complete
6803  // finish update event will be re-added automatically at the end of routine)
6804  }
6805  }
6806  else
6807  {
6808  // delaying had just started, record the moment
6809  m_Spell->SetDelayStart(e_time);
6810  // re-plan the event for the delay moment
6811  m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + m_Spell->GetDelayMoment(), false);
6812  return false; // event not complete
6813  }
6814  } break;
6815 
6816  default:
6817  {
6818  // all other states
6819  // event will be re-added automatically at the end of routine)
6820  } break;
6821  }
6822 
6823  // spell processing not complete, plan event on the next update interval
6824  m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + 1, false);
6825  return false; // event not complete
6826 }
EventProcessor m_Events
Definition: Unit.h:1948
Definition: Spell.h:281
Unit * GetCaster() const
Definition: Spell.h:612
uint32 getState() const
Definition: Spell.h:509
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
Definition: EventProcessor.cpp:88
uint64 GetDelayMoment() const
Definition: Spell.h:606
uint64 handle_delayed(uint64 t_offset)
Definition: Spell.cpp:3392
uint64_t uint64
Definition: Define.h:149
uint64 GetDelayStart() const
Definition: Spell.h:604
void update(uint32 difftime)
Definition: Spell.cpp:3540
void SetDelayStart(uint64 m_time)
Definition: Spell.h:605
bool IsDeletable() const
Definition: Spell.h:600
Spell * m_Spell
Definition: Spell.h:915
Definition: Spell.h:279

+ Here is the call graph for this function:

bool SpellEvent::IsDeletable ( ) const
overridevirtual

Reimplemented from BasicEvent.

6836 {
6837  return m_Spell->IsDeletable();
6838 }
bool IsDeletable() const
Definition: Spell.h:600
Spell * m_Spell
Definition: Spell.h:915

+ Here is the call graph for this function:

Member Data Documentation

Spell* SpellEvent::m_Spell
protected

The documentation for this class was generated from the following files: