TrinityCore
SummonList Class Reference

#include <ScriptedCreature.h>

Public Types

typedef GuidList StorageType
 
typedef StorageType::iterator iterator
 
typedef StorageType::const_iterator const_iterator
 
typedef StorageType::size_type size_type
 
typedef StorageType::value_type value_type
 

Public Member Functions

 SummonList (Creature *creature)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
iterator erase (iterator i)
 
bool empty () const
 
size_type size () const
 
void clear ()
 
void Summon (Creature const *summon)
 
void Despawn (Creature const *summon)
 
void DespawnEntry (uint32 entry)
 
void DespawnAll ()
 
template<typename T >
void DespawnIf (T const &predicate)
 
template<class Predicate >
void DoAction (int32 info, Predicate &&predicate, uint16 max=0)
 
void DoZoneInCombat (uint32 entry=0)
 
void RemoveNotExisting ()
 
bool HasEntry (uint32 entry) const
 

Private Member Functions

void DoActionImpl (int32 action, StorageType const &summons)
 

Private Attributes

Creature_me
 
StorageType _storage
 

Member Typedef Documentation

◆ const_iterator

typedef StorageType::const_iterator SummonList::const_iterator

◆ iterator

typedef StorageType::iterator SummonList::iterator

◆ size_type

typedef StorageType::size_type SummonList::size_type

◆ StorageType

◆ value_type

typedef StorageType::value_type SummonList::value_type

Constructor & Destructor Documentation

◆ SummonList()

SummonList::SummonList ( Creature creature)
inlineexplicit
40 : _me(creature) { }
Creature * _me
Definition: ScriptedCreature.h:113

Member Function Documentation

◆ begin() [1/2]

iterator SummonList::begin ( )
inline
46  {
47  return _storage.begin();
48  }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the caller graph for this function:

◆ begin() [2/2]

const_iterator SummonList::begin ( ) const
inline
51  {
52  return _storage.begin();
53  }
StorageType _storage
Definition: ScriptedCreature.h:114

◆ clear()

void SummonList::clear ( )
inline
82  {
83  _storage.clear();
84  }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the caller graph for this function:

◆ Despawn()

void SummonList::Despawn ( Creature const *  summon)
41 {
42  _storage.remove(summon->GetGUID());
43 }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DespawnAll()

void SummonList::DespawnAll ( )
77 {
78  while (!_storage.empty())
79  {
80  Creature* summon = ObjectAccessor::GetCreature(*_me, _storage.front());
81  _storage.pop_front();
82  if (summon)
83  summon->DespawnOrUnsummon();
84  }
85 }
Definition: Creature.h:69
StorageType _storage
Definition: ScriptedCreature.h:114
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
Creature * _me
Definition: ScriptedCreature.h:113
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2307
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DespawnEntry()

void SummonList::DespawnEntry ( uint32  entry)
60 {
61  for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
62  {
64  if (!summon)
65  i = _storage.erase(i);
66  else if (summon->GetEntry() == entry)
67  {
68  i = _storage.erase(i);
69  summon->DespawnOrUnsummon();
70  }
71  else
72  ++i;
73  }
74 }
Definition: Creature.h:69
StorageType _storage
Definition: ScriptedCreature.h:114
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
uint32 GetEntry() const
Definition: Object.h:158
Creature * _me
Definition: ScriptedCreature.h:113
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
Definition: Creature.cpp:2307
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DespawnIf()

template<typename T >
void SummonList::DespawnIf ( T const &  predicate)
inline
93  {
94  _storage.remove_if(predicate);
95  }
StorageType _storage
Definition: ScriptedCreature.h:114

◆ DoAction()

template<class Predicate >
void SummonList::DoAction ( int32  info,
Predicate &&  predicate,
uint16  max = 0 
)
inline
99  {
100  // We need to use a copy of SummonList here, otherwise original SummonList would be modified
101  StorageType listCopy = _storage;
102  Trinity::Containers::RandomResize<StorageType, Predicate>(listCopy, std::forward<Predicate>(predicate), max);
103  DoActionImpl(info, listCopy);
104  }
GuidList StorageType
Definition: ScriptedCreature.h:34
StorageType _storage
Definition: ScriptedCreature.h:114
void DoActionImpl(int32 action, StorageType const &summons)
Definition: ScriptedCreature.cpp:110
+ Here is the caller graph for this function:

◆ DoActionImpl()

void SummonList::DoActionImpl ( int32  action,
StorageType const &  summons 
)
private
111 {
112  for (ObjectGuid const& guid : summons)
113  {
114  Creature* summon = ObjectAccessor::GetCreature(*_me, guid);
115  if (summon && summon->IsAIEnabled())
116  summon->AI()->DoAction(action);
117  }
118 }
Definition: Creature.h:69
CreatureAI * AI() const
Definition: Creature.h:178
virtual void DoAction(int32)
Definition: UnitAI.h:156
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
bool IsAIEnabled() const
Definition: Unit.h:776
Creature * _me
Definition: ScriptedCreature.h:113
Definition: ObjectGuid.h:258
+ Here is the call graph for this function:

◆ DoZoneInCombat()

void SummonList::DoZoneInCombat ( uint32  entry = 0)
46 {
47  for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
48  {
50  ++i;
51  if (summon && summon->IsAIEnabled()
52  && (!entry || summon->GetEntry() == entry))
53  {
54  summon->AI()->DoZoneInCombat(nullptr);
55  }
56  }
57 }
void DoZoneInCombat(Creature *creature=nullptr)
Definition: CreatureAI.cpp:79
Definition: Creature.h:69
CreatureAI * AI() const
Definition: Creature.h:178
StorageType _storage
Definition: ScriptedCreature.h:114
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
uint32 GetEntry() const
Definition: Object.h:158
bool IsAIEnabled() const
Definition: Unit.h:776
Creature * _me
Definition: ScriptedCreature.h:113
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

bool SummonList::empty ( ) const
inline
71  {
72  return _storage.empty();
73  }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the caller graph for this function:

◆ end() [1/2]

iterator SummonList::end ( )
inline
56  {
57  return _storage.end();
58  }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the caller graph for this function:

◆ end() [2/2]

const_iterator SummonList::end ( ) const
inline
61  {
62  return _storage.end();
63  }
StorageType _storage
Definition: ScriptedCreature.h:114

◆ erase()

iterator SummonList::erase ( iterator  i)
inline
66  {
67  return _storage.erase(i);
68  }
StorageType _storage
Definition: ScriptedCreature.h:114

◆ HasEntry()

bool SummonList::HasEntry ( uint32  entry) const
99 {
100  for (ObjectGuid const& guid : _storage)
101  {
102  Creature* summon = ObjectAccessor::GetCreature(*_me, guid);
103  if (summon && summon->GetEntry() == entry)
104  return true;
105  }
106 
107  return false;
108 }
Definition: Creature.h:69
StorageType _storage
Definition: ScriptedCreature.h:114
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
uint32 GetEntry() const
Definition: Object.h:158
Creature * _me
Definition: ScriptedCreature.h:113
Definition: ObjectGuid.h:258
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveNotExisting()

void SummonList::RemoveNotExisting ( )
88 {
89  for (StorageType::iterator i = _storage.begin(); i != _storage.end();)
90  {
92  ++i;
93  else
94  i = _storage.erase(i);
95  }
96 }
StorageType _storage
Definition: ScriptedCreature.h:114
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:217
Creature * _me
Definition: ScriptedCreature.h:113
+ Here is the call graph for this function:

◆ size()

size_type SummonList::size ( ) const
inline
76  {
77  return _storage.size();
78  }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the caller graph for this function:

◆ Summon()

void SummonList::Summon ( Creature const *  summon)
36 {
37  _storage.push_back(summon->GetGUID());
38 }
StorageType _storage
Definition: ScriptedCreature.h:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _me

Creature* SummonList::_me
private

◆ _storage

StorageType SummonList::_storage
private

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