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

Member Function Documentation

◆ CheckSpellCastResult()

static bool cast_commandscript::CheckSpellCastResult ( ChatHandler handler,
SpellCastResult  result 
)
inlinestatic
59 {
60 if (result != SPELL_CAST_OK)
61 {
63 return false;
64 }
65
66 return true;
67 }
@ LANG_CMD_CAST_ERROR_CODE
Definition: Language.h:1160
SpellCastResult
Definition: SharedDefines.h:948
@ SPELL_CAST_OK
Definition: SharedDefines.h:1138
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
70 {
71 if (!spell)
72 {
74 return false;
75 }
76
77 if (!SpellMgr::IsSpellValid(spell))
78 {
80 return false;
81 }
82 return true;
83 }
@ LANG_COMMAND_NOSPELLFOUND
Definition: Language.h:460
@ LANG_COMMAND_SPELL_BROKEN
Definition: Language.h:503
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition: SpellMgr.cpp:442

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.

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

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

◆ GetTriggerFlags()

static Optional< TriggerCastFlags > cast_commandscript::GetTriggerFlags ( Optional< std::string >  triggeredStr)
inlinestatic
86 {
87 if (triggeredStr)
88 {
89 if (StringStartsWith("triggered", *triggeredStr)) // check if "triggered" starts with *triggeredStr (e.g. "trig", "trigger", etc.)
91 else
92 return std::nullopt;
93 }
94 return TRIGGERED_NONE;
95 }
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition: Util.h:401
@ 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
123 {
124 Creature* caster = handler->getSelectedCreature();
125 if (!caster)
126 {
128 return false;
129 }
130
131 if (!CheckSpellExistsAndIsValid(handler, spell))
132 return false;
133
134 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
135 if (!triggerFlags)
136 return false;
137
138 if (!CheckSpellCastResult(handler, caster->CastSpell(handler->GetSession()->GetPlayer(), spell->Id, *triggerFlags)))
139 {
140 handler->SetSentErrorMessage(true);
141 return false;
142 }
143
144 return true;
145 }
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:139
void SetSentErrorMessage(bool val)
Definition: Chat.h:135
Creature * getSelectedCreature() const
Definition: Chat.cpp:346
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:364
static bool CheckSpellExistsAndIsValid(ChatHandler *handler, SpellInfo const *spell)
Definition: cs_cast.cpp:69
static bool CheckSpellCastResult(ChatHandler *handler, SpellCastResult result)
Definition: cs_cast.cpp:58
static Optional< TriggerCastFlags > GetTriggerFlags(Optional< std::string > triggeredStr)
Definition: cs_cast.cpp:85

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
98 {
99 Unit* target = handler->getSelectedUnit();
100 if (!target)
101 {
103 return false;
104 }
105
106 if (!CheckSpellExistsAndIsValid(handler, spell))
107 return false;
108
109 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
110 if (!triggerFlags)
111 return false;
112
113 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(target, spell->Id, *triggerFlags)))
114 {
115 handler->SetSentErrorMessage(true);
116 return false;
117 }
118
119 return true;
120 }
Unit * getSelectedUnit() const
Definition: Chat.cpp:322
Definition: Unit.h:1302

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
225 {
226 Unit* caster = handler->getSelectedUnit();
227 if (!caster)
228 {
230 return false;
231 }
232
233 if (!CheckSpellExistsAndIsValid(handler, spell))
234 return false;
235
236 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
237 if (!triggerFlags)
238 return false;
239
240 if (!CheckSpellCastResult(handler, caster->CastSpell(x, y, z, spell->Id, *triggerFlags)))
241 {
242 handler->SetSentErrorMessage(true);
243 return false;
244 }
245
246 return true;
247 }

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
148 {
149 if (!CheckSpellExistsAndIsValid(handler, spell))
150 return false;
151
152 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
153 if (!triggerFlags)
154 return false;
155
156 float x, y, z;
157 handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
158
159 if (!CheckSpellCastResult(handler, handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spell->Id, *triggerFlags)))
160 {
161 handler->SetSentErrorMessage(true);
162 return false;
163 }
164
165 return true;
166 }
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:2687

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

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
194 {
195 Creature* caster = handler->getSelectedCreature();
196 if (!caster)
197 {
199 return false;
200 }
201
202 if (!caster->GetVictim())
203 {
205 return false;
206 }
207
208 if (!CheckSpellExistsAndIsValid(handler, spell))
209 return false;
210
211 Optional<TriggerCastFlags> triggerFlags = GetTriggerFlags(triggeredStr);
212 if (!triggerFlags)
213 return false;
214
215 if (!CheckSpellCastResult(handler, caster->CastSpell(caster->GetVictim(), spell->Id, *triggerFlags)))
216 {
217 handler->SetSentErrorMessage(true);
218 return false;
219 }
220
221 return true;
222 }
@ LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
Definition: Language.h:620
Unit * GetVictim() const
Definition: Unit.h:1398

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().