diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/scripts/Commands/cs_cast.cpp | 91 |
1 files changed, 34 insertions, 57 deletions
diff --git a/src/server/scripts/Commands/cs_cast.cpp b/src/server/scripts/Commands/cs_cast.cpp index dfd0bb36755..d5c7470a0ec 100644 --- a/src/server/scripts/Commands/cs_cast.cpp +++ b/src/server/scripts/Commands/cs_cast.cpp @@ -53,6 +53,25 @@ public: return commandTable; } + static bool CheckSpellExistsAndIsValid(ChatHandler* handler, uint32 spellId) + { + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); + if (!spellInfo) + { + handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); + handler->SetSentErrorMessage(true); + return false; + } + + if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer())) + { + handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId); + handler->SetSentErrorMessage(true); + return false; + } + return true; + } + static bool HandleCastCommand(ChatHandler* handler, char const* args) { if (!*args) @@ -71,20 +90,8 @@ public: if (!spellId) return false; - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); - if (!spellInfo) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } - - if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer())) - { - handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId); - handler->SetSentErrorMessage(true); - return false; - } char* triggeredStr = strtok(NULL, " "); if (triggeredStr) @@ -111,15 +118,13 @@ public: return false; } - // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellId = handler->extractSpellIdFromLink((char*)args); - if (!spellId || !sSpellMgr->GetSpellInfo(spellId)) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); + if (!spellId) + return false; + + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } char* triggeredStr = strtok(NULL, " "); if (triggeredStr) @@ -146,20 +151,8 @@ public: if (!spellId) return false; - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); - if (!spellInfo) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } - - if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer())) - { - handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId); - handler->SetSentErrorMessage(true); - return false; - } char* distStr = strtok(NULL, " "); @@ -192,28 +185,14 @@ public: return false; Unit* target = handler->getSelectedUnit(); - if (!target) - { - handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE); - handler->SetSentErrorMessage(true); - return false; - } // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellId = handler->extractSpellIdFromLink((char*)args); if (!spellId) return false; - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); - if (!spellInfo) - return false; - - if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer())) - { - handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId); - handler->SetSentErrorMessage(true); + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } target->CastSpell(target, spellId, false); @@ -239,12 +218,11 @@ public: // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellId = handler->extractSpellIdFromLink((char*)args); - if (!spellId || !sSpellMgr->GetSpellInfo(spellId)) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); + if (!spellId) + return false; + + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } char* triggeredStr = strtok(NULL, " "); if (triggeredStr) @@ -273,12 +251,11 @@ public: // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellId = handler->extractSpellIdFromLink((char*)args); - if (!spellId || !sSpellMgr->GetSpellInfo(spellId)) - { - handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); - handler->SetSentErrorMessage(true); + if (!spellId) + return false; + + if (!CheckSpellExistsAndIsValid(handler, spellId)) return false; - } char* posX = strtok(NULL, " "); char* posY = strtok(NULL, " "); |