summaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands/PlayerCommand.cpp
diff options
context:
space:
mode:
authorIntelligentQuantum <IntelligentQuantum@ProtonMail.Com>2021-11-12 15:33:38 +0330
committerGitHub <noreply@github.com>2021-11-12 13:03:38 +0100
commit4a69d1fc071e67d6eff46a57016261620bbbb5c5 (patch)
tree63446fc4f28b547e5f7406f57462bb5ff815ba56 /src/server/scripts/Commands/PlayerCommand.cpp
parentb1f038336dbe146190702743990b6b17864eeded (diff)
refactor(Scripts/Commands): convert cs_learn & cs_player to new system (#9050)
Diffstat (limited to 'src/server/scripts/Commands/PlayerCommand.cpp')
-rw-r--r--src/server/scripts/Commands/PlayerCommand.cpp56
1 files changed, 15 insertions, 41 deletions
diff --git a/src/server/scripts/Commands/PlayerCommand.cpp b/src/server/scripts/Commands/PlayerCommand.cpp
index 3cf4aa2c40..d842f92810 100644
--- a/src/server/scripts/Commands/PlayerCommand.cpp
+++ b/src/server/scripts/Commands/PlayerCommand.cpp
@@ -15,46 +15,22 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "SpellInfo.h"
#include "PlayerCommand.h"
#include "Language.h"
-bool Acore::PlayerCommand::HandleLearnSpellCommand(ChatHandler* handler, Player* targetPlayer, uint32 spell, char const* all)
+bool Acore::PlayerCommand::HandleLearnSpellCommand(ChatHandler* handler, Player* targetPlayer, SpellInfo const* spell, Optional<EXACT_SEQUENCE("all")> allRanks)
{
- if (!spell)
- return false;
-
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell);
- if (!spellInfo)
+ if (!SpellMgr::IsSpellValid(spell))
{
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
+ handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
handler->SetSentErrorMessage(true);
return false;
}
- if (!SpellMgr::IsSpellValid(spellInfo))
+ if (!allRanks && targetPlayer->HasSpell(spell->Id))
{
- handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell);
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- if (handler->GetSession())
- {
- SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell);
- uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell);
- if (handler->GetSession() && handler->GetSession()->GetSecurity() < SEC_ADMINISTRATOR && (bounds.first != bounds.second || spellDifficultyId))
- {
- handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell);
- handler->SetSentErrorMessage(true);
- return false;
- }
- }
-
- bool allRanks = all ? (strncmp(all, "all", 3) == 0) : false;
-
- if (!allRanks && targetPlayer->HasSpell(spell))
- {
- if (handler->GetSession() && targetPlayer == handler->GetSession()->GetPlayer())
+ if (targetPlayer == handler->GetPlayer())
handler->SendSysMessage(LANG_YOU_KNOWN_SPELL);
else
handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str());
@@ -62,25 +38,23 @@ bool Acore::PlayerCommand::HandleLearnSpellCommand(ChatHandler* handler, Player*
return false;
}
+ targetPlayer->learnSpell(spell->Id, false);
if (allRanks)
- targetPlayer->learnSpellHighRank(spell);
- else
- targetPlayer->learnSpell(spell);
+ {
+ uint32 spellId = spell->Id;
+ while ((spellId = sSpellMgr->GetNextSpellInChain(spellId)))
+ targetPlayer->learnSpell(spellId, false);
+ }
- uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell);
- if (GetTalentSpellCost(firstSpell))
+ if (GetTalentSpellCost(spell->GetFirstRankSpell()->Id))
targetPlayer->SendTalentsInfoData(false);
return true;
}
-bool Acore::PlayerCommand::HandleUnlearnSpellCommand(ChatHandler* handler, Player* target, uint32 spellId, char const* allStr)
+bool Acore::PlayerCommand::HandleUnlearnSpellCommand(ChatHandler* handler, Player* target, SpellInfo const* spell, Optional<EXACT_SEQUENCE("all")> allRanks)
{
- if (!spellId)
- return false;
-
- bool allRanks = allStr ? (strncmp(allStr, "all", 3) == 0) : false;
-
+ uint32 spellId = spell->Id;
if (allRanks)
spellId = sSpellMgr->GetFirstSpellInChain (spellId);