mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-31 09:33:47 +00:00
refactor(Scripts/Commands): convert cs_reset to new system (#17546)
Update cs_reset.cpp
This commit is contained in:
committed by
GitHub
parent
ec724cda89
commit
332ff49c13
@@ -30,10 +30,6 @@ EndScriptData */
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
#if AC_COMPILER == AC_COMPILER_GNU
|
|
||||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace Acore::ChatCommands;
|
using namespace Acore::ChatCommands;
|
||||||
|
|
||||||
class reset_commandscript : public CommandScript
|
class reset_commandscript : public CommandScript
|
||||||
@@ -45,48 +41,53 @@ public:
|
|||||||
{
|
{
|
||||||
static ChatCommandTable resetCommandTable =
|
static ChatCommandTable resetCommandTable =
|
||||||
{
|
{
|
||||||
{ "achievements", SEC_CONSOLE, true, &HandleResetAchievementsCommand, "" },
|
{ "achievements", HandleResetAchievementsCommand, SEC_CONSOLE, Console::Yes },
|
||||||
{ "honor", SEC_ADMINISTRATOR, true, &HandleResetHonorCommand, "" },
|
{ "honor", HandleResetHonorCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "level", SEC_ADMINISTRATOR, true, &HandleResetLevelCommand, "" },
|
{ "level", HandleResetLevelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "spells", SEC_ADMINISTRATOR, true, &HandleResetSpellsCommand, "" },
|
{ "spells", HandleResetSpellsCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "stats", SEC_ADMINISTRATOR, true, &HandleResetStatsCommand, "" },
|
{ "stats", HandleResetStatsCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "talents", SEC_ADMINISTRATOR, true, &HandleResetTalentsCommand, "" },
|
{ "talents", HandleResetTalentsCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "all", SEC_CONSOLE, true, &HandleResetAllCommand, "" }
|
{ "all", HandleResetAllCommand, SEC_CONSOLE, Console::Yes }
|
||||||
};
|
};
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
{ "reset", SEC_ADMINISTRATOR, true, nullptr, "", resetCommandTable }
|
{ "reset", resetCommandTable }
|
||||||
};
|
};
|
||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetAchievementsCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetAchievementsCommand(ChatHandler*, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
if (!target)
|
||||||
ObjectGuid targetGuid;
|
{
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid))
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (target)
|
Player* playerTarget = target->GetConnectedPlayer();
|
||||||
target->ResetAchievements();
|
|
||||||
|
if (playerTarget)
|
||||||
|
playerTarget->ResetAchievements();
|
||||||
else
|
else
|
||||||
AchievementMgr::DeleteFromDB(targetGuid.GetCounter());
|
AchievementMgr::DeleteFromDB(target->GetGUID().GetCounter());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetHonorCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetHonorCommand(ChatHandler*, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
if (!target)
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target))
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
target->SetHonorPoints(0);
|
Player* playerTarget = target->GetConnectedPlayer();
|
||||||
target->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
|
|
||||||
target->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 0);
|
playerTarget->SetHonorPoints(0);
|
||||||
target->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
|
playerTarget->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
|
||||||
target->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
|
playerTarget->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, 0);
|
||||||
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
|
playerTarget->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
|
||||||
|
playerTarget->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
|
||||||
|
playerTarget->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -123,156 +124,145 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetLevelCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetLevelCommand(ChatHandler*, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
if (!target)
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target))
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player* playerTarget = target->GetConnectedPlayer();
|
||||||
|
|
||||||
|
if (!HandleResetStatsOrLevelHelper(playerTarget))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!HandleResetStatsOrLevelHelper(target))
|
uint8 oldLevel = playerTarget->GetLevel();
|
||||||
return false;
|
|
||||||
|
|
||||||
uint8 oldLevel = target->GetLevel();
|
|
||||||
|
|
||||||
// set starting level
|
// set starting level
|
||||||
uint32 startLevel = target->getClass() != CLASS_DEATH_KNIGHT
|
uint32 startLevel = playerTarget->getClass() != CLASS_DEATH_KNIGHT
|
||||||
? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
|
? sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL)
|
||||||
: sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
|
: sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
|
||||||
|
|
||||||
target->_ApplyAllLevelScaleItemMods(false);
|
playerTarget->_ApplyAllLevelScaleItemMods(false);
|
||||||
target->SetLevel(startLevel);
|
playerTarget->SetLevel(startLevel);
|
||||||
target->InitRunes();
|
playerTarget->InitRunes();
|
||||||
target->InitStatsForLevel(true);
|
playerTarget->InitStatsForLevel(true);
|
||||||
target->InitTaxiNodesForLevel();
|
playerTarget->InitTaxiNodesForLevel();
|
||||||
target->InitGlyphsForLevel();
|
playerTarget->InitGlyphsForLevel();
|
||||||
target->InitTalentForLevel();
|
playerTarget->InitTalentForLevel();
|
||||||
target->SetUInt32Value(PLAYER_XP, 0);
|
playerTarget->SetUInt32Value(PLAYER_XP, 0);
|
||||||
|
|
||||||
target->_ApplyAllLevelScaleItemMods(true);
|
playerTarget->_ApplyAllLevelScaleItemMods(true);
|
||||||
|
|
||||||
// reset level for pet
|
// reset level for pet
|
||||||
if (Pet* pet = target->GetPet())
|
if (Pet* pet = playerTarget->GetPet())
|
||||||
pet->SynchronizeLevelWithOwner();
|
pet->SynchronizeLevelWithOwner();
|
||||||
|
|
||||||
sScriptMgr->OnPlayerLevelChanged(target, oldLevel);
|
sScriptMgr->OnPlayerLevelChanged(playerTarget, oldLevel);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetSpellsCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetSpellsCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
if (!target)
|
||||||
ObjectGuid targetGuid;
|
{
|
||||||
std::string targetName;
|
target = PlayerIdentifier::FromTargetOrSelf(handler);
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
|
}
|
||||||
|
|
||||||
|
if (!target)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player* playerTarget = target->GetConnectedPlayer();
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
target->resetSpells(/* bool myClassOnly */);
|
playerTarget->resetSpells(/* bool myClassOnly */);
|
||||||
|
|
||||||
ChatHandler(target->GetSession()).SendSysMessage(LANG_RESET_SPELLS);
|
ChatHandler(playerTarget->GetSession()).SendSysMessage(LANG_RESET_SPELLS);
|
||||||
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
|
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != playerTarget)
|
||||||
handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(target).c_str());
|
handler->PSendSysMessage(LANG_RESET_SPELLS_ONLINE, handler->GetNameLink(playerTarget).c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
||||||
stmt->SetData(0, uint16(AT_LOGIN_RESET_SPELLS));
|
stmt->SetData(0, uint16(AT_LOGIN_RESET_SPELLS));
|
||||||
stmt->SetData(1, targetGuid.GetCounter());
|
stmt->SetData(1, playerTarget->GetGUID().GetCounter());
|
||||||
CharacterDatabase.Execute(stmt);
|
CharacterDatabase.Execute(stmt);
|
||||||
|
|
||||||
handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, targetName.c_str());
|
handler->PSendSysMessage(LANG_RESET_SPELLS_OFFLINE, target->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetStatsCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetStatsCommand(ChatHandler*, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
if (!target)
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target))
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player* playerTarget = target->GetConnectedPlayer();
|
||||||
|
|
||||||
|
if (!HandleResetStatsOrLevelHelper(playerTarget))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!HandleResetStatsOrLevelHelper(target))
|
playerTarget->InitRunes();
|
||||||
return false;
|
playerTarget->InitStatsForLevel(true);
|
||||||
|
playerTarget->InitTaxiNodesForLevel();
|
||||||
target->InitRunes();
|
playerTarget->InitGlyphsForLevel();
|
||||||
target->InitStatsForLevel(true);
|
playerTarget->InitTalentForLevel();
|
||||||
target->InitTaxiNodesForLevel();
|
|
||||||
target->InitGlyphsForLevel();
|
|
||||||
target->InitTalentForLevel();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetTalentsCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetTalentsCommand(ChatHandler* handler, Optional<PlayerIdentifier> target)
|
||||||
{
|
{
|
||||||
Player* target;
|
Player* targetPlayer = nullptr;
|
||||||
ObjectGuid targetGuid;
|
|
||||||
std::string targetName;
|
if (target)
|
||||||
if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName))
|
{
|
||||||
|
targetPlayer = target->GetConnectedPlayer();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Try reset talents as Hunter Pet
|
|
||||||
Creature* creature = handler->getSelectedCreature();
|
|
||||||
if (!*args && creature && creature->IsPet())
|
|
||||||
{
|
|
||||||
Unit* owner = creature->GetOwner();
|
|
||||||
if (owner && owner->GetTypeId() == TYPEID_PLAYER && creature->ToPet()->IsPermanentPetFor(owner->ToPlayer()))
|
|
||||||
{
|
|
||||||
creature->ToPet()->resetTalents();
|
|
||||||
owner->ToPlayer()->SendTalentsInfoData(true);
|
|
||||||
|
|
||||||
ChatHandler(owner->ToPlayer()->GetSession()).SendSysMessage(LANG_RESET_PET_TALENTS);
|
|
||||||
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != owner->ToPlayer())
|
|
||||||
handler->PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE, handler->GetNameLink(owner->ToPlayer()).c_str());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target)
|
if (targetPlayer)
|
||||||
{
|
{
|
||||||
target->resetTalents(true);
|
targetPlayer->resetTalents(true);
|
||||||
target->SendTalentsInfoData(false);
|
targetPlayer->SendTalentsInfoData(false);
|
||||||
ChatHandler(target->GetSession()).SendSysMessage(LANG_RESET_TALENTS);
|
ChatHandler(targetPlayer->GetSession()).SendSysMessage(LANG_RESET_TALENTS);
|
||||||
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != target)
|
if (!handler->GetSession() || handler->GetSession()->GetPlayer() != targetPlayer)
|
||||||
handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(target).c_str());
|
handler->PSendSysMessage(LANG_RESET_TALENTS_ONLINE, handler->GetNameLink(targetPlayer).c_str());
|
||||||
|
|
||||||
Pet* pet = target->GetPet();
|
Pet* pet = targetPlayer->GetPet();
|
||||||
Pet::resetTalentsForAllPetsOf(target, pet);
|
Pet::resetTalentsForAllPetsOf(targetPlayer, pet);
|
||||||
if (pet)
|
if (pet)
|
||||||
target->SendTalentsInfoData(true);
|
targetPlayer->SendTalentsInfoData(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (targetGuid)
|
else
|
||||||
{
|
{
|
||||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG);
|
||||||
stmt->SetData(0, uint16(AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS));
|
stmt->SetData(0, uint16(AT_LOGIN_RESET_TALENTS | AT_LOGIN_RESET_PET_TALENTS));
|
||||||
stmt->SetData(1, targetGuid.GetCounter());
|
stmt->SetData(1, target->GetGUID().GetCounter());
|
||||||
CharacterDatabase.Execute(stmt);
|
CharacterDatabase.Execute(stmt);
|
||||||
|
|
||||||
std::string nameLink = handler->playerLink(targetName);
|
std::string nameLink = handler->playerLink(target->GetName());
|
||||||
handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
|
handler->PSendSysMessage(LANG_RESET_TALENTS_OFFLINE, nameLink.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handler->SendSysMessage(LANG_NO_CHAR_SELECTED);
|
|
||||||
handler->SetSentErrorMessage(true);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleResetAllCommand(ChatHandler* handler, char const* args)
|
static bool HandleResetAllCommand(ChatHandler* handler, std::string_view caseName)
|
||||||
{
|
{
|
||||||
if (!*args)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::string caseName = args;
|
|
||||||
|
|
||||||
AtLoginFlags atLogin;
|
AtLoginFlags atLogin;
|
||||||
|
|
||||||
// Command specially created as single command to prevent using short case names
|
// Command specially created as single command to prevent using short case names
|
||||||
@@ -292,7 +282,7 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
handler->PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE, args);
|
handler->PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE, caseName);
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -303,7 +293,7 @@ public:
|
|||||||
|
|
||||||
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
std::shared_lock<std::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
|
||||||
HashMapHolder<Player>::MapType const& plist = ObjectAccessor::GetPlayers();
|
HashMapHolder<Player>::MapType const& plist = ObjectAccessor::GetPlayers();
|
||||||
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
|
for (auto itr = plist.begin(); itr != plist.end(); ++itr)
|
||||||
itr->second->SetAtLoginFlag(atLogin);
|
itr->second->SetAtLoginFlag(atLogin);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user