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
31: CommandScript("cast_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ CheckSpellCastResult()

static bool cast_commandscript::CheckSpellCastResult ( ChatHandler handler,
SpellCastResult  result 
)
inlinestatic
52 {
53 if (result != SPELL_CAST_OK)
54 {
56 return false;
57 }
58
59 return true;
60 }
@ LANG_CMD_CAST_ERROR_CODE
Definition Language.h:1145
SpellCastResult
Definition SharedDefines.h:948
@ SPELL_CAST_OK
Definition SharedDefines.h:1138
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
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
63 {
64 if (!spell)
65 {
67 return false;
68 }
69
70 if (!SpellMgr::IsSpellValid(spell))
71 {
73 return false;
74 }
75 return true;
76 }
@ LANG_COMMAND_NOSPELLFOUND
Definition Language.h:478
@ LANG_COMMAND_SPELL_BROKEN
Definition Language.h:521
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition SpellMgr.cpp:441

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.

34 {
35 static ChatCommandTable castCommandTable =
36 {
37 { "back", HandleCastBackCommand, SEC_GAMEMASTER, Console::No },
38 { "dist", HandleCastDistCommand, SEC_GAMEMASTER, Console::No },
39 { "self", HandleCastSelfCommand, SEC_GAMEMASTER, Console::No },
40 { "target", HandleCastTargetCommad, SEC_GAMEMASTER, Console::No },
41 { "dest", HandleCastDestCommand, SEC_GAMEMASTER, Console::No },
42 { "", HandleCastCommand, SEC_GAMEMASTER, Console::No }
43 };
44 static ChatCommandTable commandTable =
45 {
46 { "cast", castCommandTable }
47 };
48 return commandTable;
49 }
@ SEC_GAMEMASTER
Definition Common.h:59
static bool HandleCastDestCommand(ChatHandler *handler, SpellInfo const *spell, float x, float y, float z, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:217
static bool HandleCastSelfCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:161
static bool HandleCastBackCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:115
static bool HandleCastTargetCommad(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:186
static bool HandleCastDistCommand(ChatHandler *handler, SpellInfo const *spell, float dist, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:140
static bool HandleCastCommand(ChatHandler *handler, SpellInfo const *spell, Optional< std::string > triggeredStr)
Definition cs_cast.cpp:90
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

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

◆ GetTriggerFlags()

static Optional< TriggerCastFlags > cast_commandscript::GetTriggerFlags ( Optional< std::string >  triggeredStr)
inlinestatic
79 {
80 if (triggeredStr)
81 {
82 if (StringStartsWith("triggered", *triggeredStr)) // check if "triggered" starts with *triggeredStr (e.g. "trig", "trigger", etc.)
84 else
85 return std::nullopt;
86 }
87 return TRIGGERED_NONE;
88 }
@ 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:401

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
116 {
117 Creature* caster = handler->getSelectedCreature();
118 if (!caster)
119 {
121 return false;
122 }
123
124 if (!CheckSpellExistsAndIsValid(handler, spell))
125 return false;
126
127 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
128 if (!triggerFlags)
129 return false;
130
131 if (!CheckSpellCastResult(handler, caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags)))
132 {
133 handler->SetSentErrorMessage(true);
134 return false;
135 }
136
137 return true;
138 }
@ 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:410
Definition Creature.h:43
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:1179
Player * GetPlayer() const
Definition WorldSession.h:376
static bool CheckSpellExistsAndIsValid(ChatHandler *handler, SpellInfo const *spell)
Definition cs_cast.cpp:62
static bool CheckSpellCastResult(ChatHandler *handler, SpellCastResult result)
Definition cs_cast.cpp:51
static Optional< TriggerCastFlags > GetTriggerFlags(Optional< std::string > triggeredStr)
Definition cs_cast.cpp:78

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
91 {
92 Unit* target = handler->getSelectedUnit();
93 if (!target)
94 {
96 return false;
97 }
98
99 if (!CheckSpellExistsAndIsValid(handler, spell))
100 return false;
101
102 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
103 if (!triggerFlags)
104 return false;
105
106 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags)))
107 {
108 handler->SetSentErrorMessage(true);
109 return false;
110 }
111
112 return true;
113 }
Unit * getSelectedUnit() const
Definition Chat.cpp:386
Definition Unit.h:620

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
218 {
219 Unit* caster = handler->getSelectedUnit();
220 if (!caster)
221 {
223 return false;
224 }
225
226 if (!CheckSpellExistsAndIsValid(handler, spell))
227 return false;
228
229 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
230 if (!triggerFlags)
231 return false;
232
233 if (!CheckSpellCastResult(handler, caster->CastSpell(x, y, z, spell->Id, *triggerFlags)))
234 {
235 handler->SetSentErrorMessage(true);
236 return false;
237 }
238
239 return true;
240 }

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
141 {
142 if (!CheckSpellExistsAndIsValid(handler, spell))
143 return false;
144
145 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
146 if (!triggerFlags)
147 return false;
148
149 float x, y, z;
150 handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
151
152 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags)))
153 {
154 handler->SetSentErrorMessage(true);
155 return false;
156 }
157
158 return true;
159 }
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:2712

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
162 {
163 Unit* target = handler->getSelectedUnit();
164 if (!target)
165 {
167 return false;
168 }
169
170 if (!CheckSpellExistsAndIsValid(handler, spell))
171 return false;
172
173 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
174 if (!triggerFlags)
175 return false;
176
177 if (!CheckSpellCastResult(handler, target->CastSpell(target, spell->Id, *triggerFlags)))
178 {
179 handler->SetSentErrorMessage(true);
180 return false;
181 }
182
183 return true;
184 }

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
187 {
188 Creature* caster = handler->getSelectedCreature();
189 if (!caster)
190 {
192 return false;
193 }
194
195 if (!caster->GetVictim())
196 {
198 return false;
199 }
200
201 if (!CheckSpellExistsAndIsValid(handler, spell))
202 return false;
203
204 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
205 if (!triggerFlags)
206 return false;
207
208 if (!CheckSpellCastResult(handler, caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags)))
209 {
210 handler->SetSentErrorMessage(true);
211 return false;
212 }
213
214 return true;
215 }
@ LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
Definition Language.h:638
Unit * GetVictim() const
Definition Unit.h:846

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: