refactor(Scripts/Commands): convert cs_learn & cs_player to new system (#9050)

This commit is contained in:
IntelligentQuantum
2021-11-12 15:33:38 +03:30
committed by GitHub
parent b1f038336d
commit 4a69d1fc07
4 changed files with 79 additions and 188 deletions

View File

@@ -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);