Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_cast.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: cast_commandscript
8%Complete: 100
9Comment: All cast related commands
10Category: commandscripts
11EndScriptData */
12
13#include "Chat.h"
14#include "Creature.h"
15#include "Language.h"
16#include "Player.h"
17#include "ScriptMgr.h"
18
20{
21public:
22 cast_commandscript() : CommandScript("cast_commandscript") { }
23
24 std::vector<ChatCommand> GetCommands() const OVERRIDE
25 {
26 static std::vector<ChatCommand> castCommandTable =
27 {
34 };
35 static std::vector<ChatCommand> commandTable =
36 {
37 { "cast", rbac::RBAC_PERM_COMMAND_CAST, false, NULL, "", castCommandTable },
38 };
39 return commandTable;
40 }
41
42 static bool HandleCastCommand(ChatHandler* handler, char const* args)
43 {
44 if (!*args)
45 return false;
46
47 Unit* target = handler->getSelectedUnit();
48 if (!target)
49 {
51 handler->SetSentErrorMessage(true);
52 return false;
53 }
54
55 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
56 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
57 if (!spellId)
58 return false;
59
60 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
61 if (!spellInfo)
62 {
64 handler->SetSentErrorMessage(true);
65 return false;
66 }
67
68 if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
69 {
71 handler->SetSentErrorMessage(true);
72 return false;
73 }
74
75 char* triggeredStr = strtok(NULL, " ");
76 if (triggeredStr)
77 {
78 int l = strlen(triggeredStr);
79 if (strncmp(triggeredStr, "triggered", l) != 0)
80 return false;
81 }
82
83 bool triggered = (triggeredStr != NULL);
84
85 handler->GetSession()->GetPlayer()->CastSpell(target, spellId, triggered);
86
87 return true;
88 }
89
90 static bool HandleCastBackCommand(ChatHandler* handler, char const* args)
91 {
92 Creature* caster = handler->getSelectedCreature();
93 if (!caster)
94 {
96 handler->SetSentErrorMessage(true);
97 return false;
98 }
99
100 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
101 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
102 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
103 if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
104 {
106 handler->SetSentErrorMessage(true);
107 return false;
108 }
109
110 char* triggeredStr = strtok(NULL, " ");
111 if (triggeredStr)
112 {
113 int l = strlen(triggeredStr);
114 if (strncmp(triggeredStr, "triggered", l) != 0)
115 return false;
116 }
117
118 bool triggered = (triggeredStr != NULL);
119
120 caster->CastSpell(handler->GetSession()->GetPlayer(), spellId, triggered);
121
122 return true;
123 }
124
125 static bool HandleCastDistCommand(ChatHandler* handler, char const* args)
126 {
127 if (!*args)
128 return false;
129
130 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
131 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
132 if (!spellId)
133 return false;
134
135 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
136 if (!spellInfo)
137 {
139 handler->SetSentErrorMessage(true);
140 return false;
141 }
142
143 if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
144 {
146 handler->SetSentErrorMessage(true);
147 return false;
148 }
149
150 char* distStr = strtok(NULL, " ");
151
152 float dist = 0;
153
154 if (distStr)
155 sscanf(distStr, "%f", &dist);
156
157 char* triggeredStr = strtok(NULL, " ");
158 if (triggeredStr)
159 {
160 int l = strlen(triggeredStr);
161 if (strncmp(triggeredStr, "triggered", l) != 0)
162 return false;
163 }
164
165 bool triggered = (triggeredStr != NULL);
166
167 float x, y, z;
168 handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, dist);
169
170 handler->GetSession()->GetPlayer()->CastSpell(x, y, z, spellId, triggered);
171
172 return true;
173 }
174
175 static bool HandleCastSelfCommand(ChatHandler* handler, char const* args)
176 {
177 if (!*args)
178 return false;
179
180 Unit* target = handler->getSelectedUnit();
181 if (!target)
182 {
184 handler->SetSentErrorMessage(true);
185 return false;
186 }
187
188 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
189 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
190 if (!spellId)
191 return false;
192
193 SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
194 if (!spellInfo)
195 return false;
196
197 if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
198 {
200 handler->SetSentErrorMessage(true);
201 return false;
202 }
203
204 target->CastSpell(target, spellId, false);
205
206 return true;
207 }
208
209 static bool HandleCastTargetCommad(ChatHandler* handler, char const* args)
210 {
211 Creature* caster = handler->getSelectedCreature();
212 if (!caster)
213 {
215 handler->SetSentErrorMessage(true);
216 return false;
217 }
218
219 if (!caster->GetVictim())
220 {
222 handler->SetSentErrorMessage(true);
223 return false;
224 }
225
226 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
227 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
228 if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
229 {
231 handler->SetSentErrorMessage(true);
232 return false;
233 }
234
235 char* triggeredStr = strtok(NULL, " ");
236 if (triggeredStr)
237 {
238 int l = strlen(triggeredStr);
239 if (strncmp(triggeredStr, "triggered", l) != 0)
240 return false;
241 }
242
243 bool triggered = (triggeredStr != NULL);
244
245 caster->CastSpell(caster->GetVictim(), spellId, triggered);
246
247 return true;
248 }
249
250 static bool HandleCastDestCommand(ChatHandler* handler, char const* args)
251 {
252 Unit* caster = handler->getSelectedUnit();
253 if (!caster)
254 {
256 handler->SetSentErrorMessage(true);
257 return false;
258 }
259
260 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
261 uint32 spellId = handler->extractSpellIdFromLink((char*)args);
262 if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
263 {
265 handler->SetSentErrorMessage(true);
266 return false;
267 }
268
269 char* posX = strtok(NULL, " ");
270 char* posY = strtok(NULL, " ");
271 char* posZ = strtok(NULL, " ");
272
273 if (!posX || !posY || !posZ)
274 return false;
275
276 float x = float(atof(posX));
277 float y = float(atof(posY));
278 float z = float(atof(posZ));
279
280 char* triggeredStr = strtok(NULL, " ");
281 if (triggeredStr)
282 {
283 int l = strlen(triggeredStr);
284 if (strncmp(triggeredStr, "triggered", l) != 0)
285 return false;
286 }
287
288 bool triggered = (triggeredStr != NULL);
289
290 caster->CastSpell(x, y, z, spellId, triggered);
291
292 return true;
293 }
294};
295
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
@ LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
Definition Language.h:582
@ LANG_COMMAND_NOSPELLFOUND
Definition Language.h:425
@ LANG_SELECT_CHAR_OR_CREATURE
Definition Language.h:12
@ LANG_COMMAND_SPELL_BROKEN
Definition Language.h:468
#define sSpellMgr
Definition SpellMgr.h:744
Unit * getSelectedUnit()
Definition Chat.cpp:841
WorldSession * GetSession()
Definition Chat.h:43
Creature * getSelectedCreature()
Definition Chat.cpp:865
uint32 extractSpellIdFromLink(char *text)
Definition Chat.cpp:1042
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
CommandScript(const char *name)
static bool IsSpellValid(SpellInfo const *spellInfo, Player *player=NULL, bool msg=true)
Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book,...
Definition SpellMgr.cpp:319
Definition Unit.h:1367
void CastSpell(SpellCastTargets const &targets, SpellInfo const *spellInfo, CustomSpellValues const *value, TriggerCastFlags triggerFlags=TRIGGERED_NONE, Item *castItem=NULL, AuraEffect const *triggeredByAura=NULL, uint64 originalCaster=0)
Unit * GetVictim() const
Definition Unit.h:1468
void GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float angle=0) const
Definition Object.cpp:3070
Player * GetPlayer() const
static bool HandleCastDistCommand(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:125
static bool HandleCastTargetCommad(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:209
static bool HandleCastSelfCommand(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:175
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_cast.cpp:24
static bool HandleCastCommand(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:42
static bool HandleCastBackCommand(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:90
static bool HandleCastDestCommand(ChatHandler *handler, char const *args)
Definition cs_cast.cpp:250
void AddSC_cast_commandscript()
Definition cs_cast.cpp:296
@ RBAC_PERM_COMMAND_CAST_SELF
Definition RBAC.h:158
@ RBAC_PERM_COMMAND_CAST_DEST
Definition RBAC.h:160
@ RBAC_PERM_COMMAND_CAST
Definition RBAC.h:155
@ RBAC_PERM_COMMAND_CAST_TARGET
Definition RBAC.h:159
@ RBAC_PERM_COMMAND_CAST_BACK
Definition RBAC.h:156
@ RBAC_PERM_COMMAND_CAST_DIST
Definition RBAC.h:157