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
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 

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)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ cast_commandscript()

cast_commandscript::cast_commandscript ( )
inline
39: CommandScript("cast_commandscript") { }
Definition: ScriptMgr.h:850

Member Function Documentation

◆ CheckSpellCastResult()

static bool cast_commandscript::CheckSpellCastResult ( ChatHandler handler,
SpellCastResult  result 
)
inlinestatic
60 {
61 if (result != SPELL_CAST_OK)
62 {
64 return false;
65 }
66
67 return true;
68 }
@ LANG_CMD_CAST_ERROR_CODE
Definition: Language.h:1151
SpellCastResult
Definition: SharedDefines.h:920
@ SPELL_CAST_OK
Definition: SharedDefines.h:1110
static char const * ToTitle(Enum value)
Definition: SmartEnum.h:127
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60

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
71 {
72 if (!spell)
73 {
75 handler->SetSentErrorMessage(true);
76 return false;
77 }
78
79 if (!SpellMgr::IsSpellValid(spell))
80 {
81 handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
82 handler->SetSentErrorMessage(true);
83 return false;
84 }
85 return true;
86 }
@ LANG_COMMAND_NOSPELLFOUND
Definition: Language.h:460
@ LANG_COMMAND_SPELL_BROKEN
Definition: Language.h:503
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition: SpellMgr.cpp:442

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

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

◆ GetCommands()

ChatCommandTable cast_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

42 {
43 static ChatCommandTable castCommandTable =
44 {
45 { "back", HandleCastBackCommand, SEC_GAMEMASTER, Console::No },
46 { "dist", HandleCastDistCommand, SEC_GAMEMASTER, Console::No },
47 { "self", HandleCastSelfCommand, SEC_GAMEMASTER, Console::No },
48 { "target", HandleCastTargetCommad, SEC_GAMEMASTER, Console::No },
49 { "dest", HandleCastDestCommand, SEC_GAMEMASTER, Console::No },
50 { "", HandleCastCommand, SEC_GAMEMASTER, Console::No }
51 };
52 static ChatCommandTable commandTable =
53 {
54 { "cast", castCommandTable }
55 };
56 return commandTable;
57 }
@ SEC_GAMEMASTER
Definition: Common.h:68
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:50
static bool HandleCastDestCommand(ChatHandler *handler, SpellInfo const *spell, float x, float y, float z, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:232
static bool HandleCastSelfCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:173
static bool HandleCastBackCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:126
static bool HandleCastTargetCommad(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:199
static bool HandleCastDistCommand(ChatHandler *handler, SpellInfo const *spell, float dist, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:152
static bool HandleCastCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:100

References HandleCastBackCommand(), HandleCastCommand(), HandleCastDestCommand(), HandleCastDistCommand(), HandleCastSelfCommand(), HandleCastTargetCommad(), and SEC_GAMEMASTER.

◆ GetTriggerFlags()

static Optional< TriggerCastFlags > cast_commandscript::GetTriggerFlags ( Optional< std::string >  triggeredStr)
inlinestatic
89 {
90 if (triggeredStr)
91 {
92 if (StringStartsWith("triggered", *triggeredStr)) // check if "triggered" starts with *triggeredStr (e.g. "trig", "trigger", etc.)
94 else
95 return std::nullopt;
96 }
97 return TRIGGERED_NONE;
98 }
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition: Util.h:396
@ TRIGGERED_NONE
Definition: SpellDefines.h:131
@ TRIGGERED_FULL_DEBUG_MASK
Periodic aura tick wont be reset on override.
Definition: SpellDefines.h:151

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
127 {
128 Creature* caster = handler->getSelectedCreature();
129 if (!caster)
130 {
132 handler->SetSentErrorMessage(true);
133 return false;
134 }
135
136 if (!CheckSpellExistsAndIsValid(handler, spell))
137 return false;
138
139 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
140 if (!triggerFlags)
141 return false;
142
143 if (!CheckSpellCastResult(handler, caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags)))
144 {
145 handler->SetSentErrorMessage(true);
146 return false;
147 }
148
149 return true;
150 }
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
@ LANG_SELECT_CHAR_OR_CREATURE
Definition: Language.h:31
WorldSession * GetSession()
Definition: Chat.h:122
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
Creature * getSelectedCreature() const
Definition: Chat.cpp:337
Definition: Creature.h:46
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:1169
Player * GetPlayer() const
Definition: WorldSession.h:361
static bool CheckSpellExistsAndIsValid(ChatHandler *handler, SpellInfo const *spell)
Definition: cs_cast.cpp:70
static bool CheckSpellCastResult(ChatHandler *handler, SpellCastResult result)
Definition: cs_cast.cpp:59
static Optional< TriggerCastFlags > GetTriggerFlags(Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:88

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

Referenced by GetCommands().

◆ HandleCastCommand()

static bool cast_commandscript::HandleCastCommand ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
101 {
102 Unit* target = handler->getSelectedUnit();
103 if (!target)
104 {
106 handler->SetSentErrorMessage(true);
107 return false;
108 }
109
110 if (!CheckSpellExistsAndIsValid(handler, spell))
111 return false;
112
113 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
114 if (!triggerFlags)
115 return false;
116
117 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags)))
118 {
119 handler->SetSentErrorMessage(true);
120 return false;
121 }
122
123 return true;
124 }
Unit * getSelectedUnit() const
Definition: Chat.cpp:313
Definition: Unit.h:1290

References Unit::CastSpell(), CheckSpellCastResult(), CheckSpellExistsAndIsValid(), WorldSession::GetPlayer(), ChatHandler::getSelectedUnit(), ChatHandler::GetSession(), GetTriggerFlags(), SpellInfo::Id, LANG_SELECT_CHAR_OR_CREATURE, ChatHandler::SendSysMessage(), 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
233 {
234 Unit* caster = handler->getSelectedUnit();
235 if (!caster)
236 {
238 handler->SetSentErrorMessage(true);
239 return false;
240 }
241
242 if (!CheckSpellExistsAndIsValid(handler, spell))
243 return false;
244
245 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
246 if (!triggerFlags)
247 return false;
248
249 if (!CheckSpellCastResult(handler, caster->CastSpell(x, y, z, spell->Id, *triggerFlags)))
250 {
251 handler->SetSentErrorMessage(true);
252 return false;
253 }
254
255 return true;
256 }

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

Referenced by GetCommands().

◆ HandleCastDistCommand()

static bool cast_commandscript::HandleCastDistCommand ( ChatHandler handler,
SpellInfo const *  spell,
float  dist,
Optional< std::string >  triggeredStr 
)
inlinestatic
153 {
154 if (!CheckSpellExistsAndIsValid(handler, spell))
155 return false;
156
157 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
158 if (!triggerFlags)
159 return false;
160
161 float x, y, z;
162 handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
163
164 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags)))
165 {
166 handler->SetSentErrorMessage(true);
167 return false;
168 }
169
170 return true;
171 }
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:2662

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
174 {
175 Unit* target = handler->getSelectedUnit();
176 if (!target)
177 {
179 handler->SetSentErrorMessage(true);
180 return false;
181 }
182
183 if (!CheckSpellExistsAndIsValid(handler, spell))
184 return false;
185
186 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
187 if (!triggerFlags)
188 return false;
189
190 if (!CheckSpellCastResult(handler, target->CastSpell(target, spell->Id, *triggerFlags)))
191 {
192 handler->SetSentErrorMessage(true);
193 return false;
194 }
195
196 return true;
197 }

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

Referenced by GetCommands().

◆ HandleCastTargetCommad()

static bool cast_commandscript::HandleCastTargetCommad ( ChatHandler handler,
SpellInfo const *  spell,
Optional< std::string >  triggeredStr 
)
inlinestatic
200 {
201 Creature* caster = handler->getSelectedCreature();
202 if (!caster)
203 {
205 handler->SetSentErrorMessage(true);
206 return false;
207 }
208
209 if (!caster->GetVictim())
210 {
212 handler->SetSentErrorMessage(true);
213 return false;
214 }
215
216 if (!CheckSpellExistsAndIsValid(handler, spell))
217 return false;
218
219 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
220 if (!triggerFlags)
221 return false;
222
223 if (!CheckSpellCastResult(handler, caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags)))
224 {
225 handler->SetSentErrorMessage(true);
226 return false;
227 }
228
229 return true;
230 }
@ LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
Definition: Language.h:620
Unit * GetVictim() const
Definition: Unit.h:1386

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

Referenced by GetCommands().