AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
cast_commandscript Class Reference
Inheritance diagram for cast_commandscript:
CommandScript ScriptObject

Public Member Functions

 cast_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool CheckSpellCastResult (ChatHandler *handler, SpellCastResult result)
 
static bool CheckSpellExistsAndIsValid (ChatHandler *handler, SpellInfo const *spell)
 
static Optional< TriggerCastFlagsGetTriggerFlags (Optional< std::string > triggeredStr)
 
static bool HandleCastCommand (ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
 
static bool HandleCastBackCommand (ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
 
static bool HandleCastDistCommand (ChatHandler *handler, SpellInfo const *spell, float dist, Optional< std::string > triggeredStr)
 
static bool HandleCastSelfCommand (ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
 
static bool HandleCastTargetCommad (ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
 
static bool HandleCastDestCommand (ChatHandler *handler, SpellInfo const *spell, float x, float y, float z, Optional< std::string > triggeredStr)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ cast_commandscript()

cast_commandscript::cast_commandscript ( )
inline
32: CommandScript("cast_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ CheckSpellCastResult()

static bool cast_commandscript::CheckSpellCastResult ( ChatHandler handler,
SpellCastResult  result 
)
inlinestatic
53 {
54 if (result != SPELL_CAST_OK)
55 {
57 return false;
58 }
59
60 return true;
61 }
@ LANG_CMD_CAST_ERROR_CODE
Definition Language.h:1159
SpellCastResult
Definition SharedDefines.h:936
@ SPELL_CAST_OK
Definition SharedDefines.h:1126
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
static char const * ToTitle(Enum value)
Definition SmartEnum.h:126

References LANG_CMD_CAST_ERROR_CODE, ChatHandler::PSendSysMessage(), SPELL_CAST_OK, and EnumUtils::ToTitle().

Referenced by HandleCastBackCommand(), HandleCastCommand(), HandleCastDestCommand(), HandleCastDistCommand(), HandleCastSelfCommand(), and HandleCastTargetCommad().

◆ CheckSpellExistsAndIsValid()

static bool cast_commandscript::CheckSpellExistsAndIsValid ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
64 {
65 if (!spell)
66 {
68 return false;
69 }
70
71 if (!SpellMgr::IsSpellValid(spell))
72 {
74 return false;
75 }
76 return true;
77 }
@ LANG_COMMAND_NOSPELLFOUND
Definition Language.h:486
@ LANG_COMMAND_SPELL_BROKEN
Definition Language.h:529
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition SpellMgr.cpp:488

References SpellInfo::Id, SpellMgr::IsSpellValid(), LANG_COMMAND_NOSPELLFOUND, LANG_COMMAND_SPELL_BROKEN, and ChatHandler::SendErrorMessage().

Referenced by HandleCastBackCommand(), HandleCastCommand(), HandleCastDestCommand(), HandleCastDistCommand(), HandleCastSelfCommand(), and HandleCastTargetCommad().

◆ GetCommands()

ChatCommandTable cast_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

35 {
36 static ChatCommandTable castCommandTable =
37 {
44 };
45 static ChatCommandTable commandTable =
46 {
47 { "cast", castCommandTable }
48 };
49 return commandTable;
50 }
static bool HandleCastDestCommand(ChatHandler *handler, SpellInfo const *spell, float x, float y, float z, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:218
static bool HandleCastSelfCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:162
static bool HandleCastBackCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:116
static bool HandleCastTargetCommad(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:187
static bool HandleCastDistCommand(ChatHandler *handler, SpellInfo const *spell, float dist, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:141
static bool HandleCastCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:91
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_CAST_SELF
Definition RBAC.h:167
@ RBAC_PERM_COMMAND_CAST_DEST
Definition RBAC.h:169
@ RBAC_PERM_COMMAND_CAST
Definition RBAC.h:164
@ RBAC_PERM_COMMAND_CAST_TARGET
Definition RBAC.h:168
@ RBAC_PERM_COMMAND_CAST_BACK
Definition RBAC.h:165
@ RBAC_PERM_COMMAND_CAST_DIST
Definition RBAC.h:166

References HandleCastBackCommand(), HandleCastCommand(), HandleCastDestCommand(), HandleCastDistCommand(), HandleCastSelfCommand(), HandleCastTargetCommad(), rbac::RBAC_PERM_COMMAND_CAST, rbac::RBAC_PERM_COMMAND_CAST_BACK, rbac::RBAC_PERM_COMMAND_CAST_DEST, rbac::RBAC_PERM_COMMAND_CAST_DIST, rbac::RBAC_PERM_COMMAND_CAST_SELF, and rbac::RBAC_PERM_COMMAND_CAST_TARGET.

◆ GetTriggerFlags()

static Optional< TriggerCastFlags > cast_commandscript::GetTriggerFlags ( Optional< std::string >  triggeredStr)
inlinestatic
80 {
81 if (triggeredStr)
82 {
83 if (StringStartsWith("triggered", *triggeredStr)) // check if "triggered" starts with *triggeredStr (e.g. "trig", "trigger", etc.)
85 else
86 return std::nullopt;
87 }
88 return TRIGGERED_NONE;
89 }
@ TRIGGERED_NONE
Definition SpellDefines.h:133
@ TRIGGERED_FULL_DEBUG_MASK
Ignore spell effects - used for ritual portals.
Definition SpellDefines.h:154
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition Util.h:392

References StringStartsWith(), TRIGGERED_FULL_DEBUG_MASK, and TRIGGERED_NONE.

Referenced by HandleCastBackCommand(), HandleCastCommand(), HandleCastDestCommand(), HandleCastDistCommand(), HandleCastSelfCommand(), and HandleCastTargetCommad().

◆ HandleCastBackCommand()

static bool cast_commandscript::HandleCastBackCommand ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
117 {
118 Creature* caster = handler->getSelectedCreature();
119 if (!caster)
120 {
122 return false;
123 }
124
125 if (!CheckSpellExistsAndIsValid(handler, spell))
126 return false;
127
128 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
129 if (!triggerFlags)
130 return false;
131
132 if (!CheckSpellCastResult(handler, caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags)))
133 {
134 handler->SetSentErrorMessage(true);
135 return false;
136 }
137
138 return true;
139 }
@ LANG_SELECT_CHAR_OR_CREATURE
Definition Language.h:31
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
WorldSession * GetSession()
Definition Chat.h:242
void SetSentErrorMessage(bool val)
Definition Chat.h:238
Creature * getSelectedCreature() const
Definition Chat.cpp:418
Definition Creature.h:47
SpellCastResult CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=nullptr, AuraEffect const *triggeredByAura=nullptr, ObjectGuid originalCaster=ObjectGuid::Empty)
Definition Unit.cpp:1375
Player * GetPlayer() const
Definition WorldSession.h:454
static bool CheckSpellExistsAndIsValid(ChatHandler *handler, SpellInfo const *spell)
Definition cs_cast.cpp:63
static bool CheckSpellCastResult(ChatHandler *handler, SpellCastResult result)
Definition cs_cast.cpp:52
static Optional< TriggerCastFlags > GetTriggerFlags(Optional< std::string > triggeredStr)
Definition cs_cast.cpp:79

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), GetTriggerFlags(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleCastCommand()

static bool cast_commandscript::HandleCastCommand ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
92 {
93 Unit* target = handler->getSelectedUnit();
94 if (!target)
95 {
97 return false;
98 }
99
100 if (!CheckSpellExistsAndIsValid(handler, spell))
101 return false;
102
103 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
104 if (!triggerFlags)
105 return false;
106
107 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags)))
108 {
109 handler->SetSentErrorMessage(true);
110 return false;
111 }
112
113 return true;
114 }
Unit * getSelectedUnit() const
Definition Chat.cpp:394
Definition Unit.h:664

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), WorldSession::GetPlayer(), ChatHandler::getSelectedUnit(), ChatHandler::GetSession(), GetTriggerFlags(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleCastDestCommand()

static bool cast_commandscript::HandleCastDestCommand ( ChatHandler handler,
SpellInfo const *  spell,
float  x,
float  y,
float  z,
Optional< std::string >  triggeredStr 
)
inlinestatic
219 {
220 Unit* caster = handler->getSelectedUnit();
221 if (!caster)
222 {
224 return false;
225 }
226
227 if (!CheckSpellExistsAndIsValid(handler, spell))
228 return false;
229
230 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
231 if (!triggerFlags)
232 return false;
233
234 if (!CheckSpellCastResult(handler, caster->CastSpell(x, y, z, spell->Id, *triggerFlags)))
235 {
236 handler->SetSentErrorMessage(true);
237 return false;
238 }
239
240 return true;
241 }

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), ChatHandler::getSelectedUnit(), GetTriggerFlags(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleCastDistCommand()

static bool cast_commandscript::HandleCastDistCommand ( ChatHandler handler,
SpellInfo const *  spell,
float  dist,
Optional< std::string >  triggeredStr 
)
inlinestatic
142 {
143 if (!CheckSpellExistsAndIsValid(handler, spell))
144 return false;
145
146 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
147 if (!triggerFlags)
148 return false;
149
150 float x, y, z;
151 handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
152
153 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags)))
154 {
155 handler->SetSentErrorMessage(true);
156 return false;
157 }
158
159 return true;
160 }
bool GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0, WorldObject const *forWho=nullptr, bool force=false) const
Definition Object.cpp:2765

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), WorldObject::GetClosePoint(), WorldSession::GetPlayer(), ChatHandler::GetSession(), GetTriggerFlags(), SpellInfo::Id, and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleCastSelfCommand()

static bool cast_commandscript::HandleCastSelfCommand ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
163 {
164 Unit* target = handler->getSelectedUnit();
165 if (!target)
166 {
168 return false;
169 }
170
171 if (!CheckSpellExistsAndIsValid(handler, spell))
172 return false;
173
174 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
175 if (!triggerFlags)
176 return false;
177
178 if (!CheckSpellCastResult(handler, target->CastSpell(target, spell->Id, *triggerFlags)))
179 {
180 handler->SetSentErrorMessage(true);
181 return false;
182 }
183
184 return true;
185 }

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), ChatHandler::getSelectedUnit(), GetTriggerFlags(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleCastTargetCommad()

static bool cast_commandscript::HandleCastTargetCommad ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
188 {
189 Creature* caster = handler->getSelectedCreature();
190 if (!caster)
191 {
193 return false;
194 }
195
196 if (!caster->GetVictim())
197 {
199 return false;
200 }
201
202 if (!CheckSpellExistsAndIsValid(handler, spell))
203 return false;
204
205 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
206 if (!triggerFlags)
207 return false;
208
209 if (!CheckSpellCastResult(handler, caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags)))
210 {
211 handler->SetSentErrorMessage(true);
212 return false;
213 }
214
215 return true;
216 }
@ LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
Definition Language.h:646
Unit * GetVictim() const
Definition Unit.h:903

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), ChatHandler::getSelectedCreature(), GetTriggerFlags(), Unit::GetVictim(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, LANG_SELECTED_TARGET_NOT_HAVE_VICTIM, ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().


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