feat(Core/Player): Implement player specific settings (#9483)

This commit is contained in:
Skjalf
2021-12-26 08:39:15 -03:00
committed by GitHub
parent d2950b21b9
commit 58302e4196
19 changed files with 381 additions and 8 deletions

View File

@@ -0,0 +1,81 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Chat.h"
#include "Player.h"
#include "PlayerSettings.h"
#include "ScriptMgr.h"
using namespace Acore::ChatCommands;
class player_settings_commandscript : public CommandScript
{
public:
player_settings_commandscript() : CommandScript("player_settings_commandscript") {}
ChatCommandTable GetCommands() const override
{
static ChatCommandTable playerSettingsCommandTable =
{
{ "announcer", HandleSettingsAnnouncerFlags, SEC_MODERATOR, Console::No },
};
static ChatCommandTable commandTable =
{
{ "settings", playerSettingsCommandTable },
};
return commandTable;
}
static bool HandleSettingsAnnouncerFlags(ChatHandler* handler, std::string type, bool on)
{
Player* player = handler->GetPlayer();
PlayerSetting setting;
setting = player->GetPlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS);
if (type == "bg")
{
on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_BG_QUEUE) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_BG_QUEUE);
player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
}
else if (type == "arena")
{
on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE);
player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
}
else if (type == "autobroadcast")
{
if (player->getLevel() < sWorld->getIntConfig(CONFIG_AUTOBROADCAST_MIN_LEVEL_DISABLE))
{
handler->SetSentErrorMessage(true);
handler->PSendSysMessage(LANG_CMD_AUTOBROADCAST_LVL_ERROR, sWorld->getIntConfig(CONFIG_AUTOBROADCAST_MIN_LEVEL_DISABLE));
}
on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST);
player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
}
handler->SetSentErrorMessage(false);
handler->PSendSysMessage(on ? LANG_CMD_SETTINGS_ANNOUNCER_ON : LANG_CMD_SETTINGS_ANNOUNCER_OFF, type);
return true;
}
};
void AddSC_player_settings_commandscript()
{
new player_settings_commandscript();
}

View File

@@ -61,6 +61,7 @@ void AddSC_titles_commandscript();
void AddSC_wp_commandscript();
void AddSC_cache_commandscript();
void AddSC_item_commandscript();
void AddSC_player_settings_commandscript();
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
@@ -111,4 +112,5 @@ void AddCommandsScripts()
AddSC_wp_commandscript();
AddSC_cache_commandscript();
AddSC_item_commandscript();
AddSC_player_settings_commandscript();
}