mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-27 07:36:23 +00:00
feat(Core/Player): Implement player specific settings (#9483)
This commit is contained in:
@@ -4168,6 +4168,10 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
|
||||
stmt->setUInt32(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SETTINGS);
|
||||
stmt->setUInt32(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
|
||||
Corpse::DeleteFromDB(playerGuid, trans);
|
||||
|
||||
sScriptMgr->OnDeleteFromDB(trans, lowGuid);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "ObjectMgr.h"
|
||||
#include "Optional.h"
|
||||
#include "PetDefines.h"
|
||||
#include "PlayerSettings.h"
|
||||
#include "PlayerTaxi.h"
|
||||
#include "QuestDef.h"
|
||||
#include "SpellMgr.h"
|
||||
@@ -875,6 +876,7 @@ enum PlayerLoginQueryIndex
|
||||
PLAYER_LOGIN_QUERY_LOAD_MONTHLY_QUEST_STATUS = 32,
|
||||
PLAYER_LOGIN_QUERY_LOAD_BREW_OF_THE_MONTH = 34,
|
||||
PLAYER_LOGIN_QUERY_LOAD_CORPSE_LOCATION = 35,
|
||||
PLAYER_LOGIN_QUERY_LOAD_CHARACTER_SETTINGS = 36,
|
||||
MAX_PLAYER_LOGIN_QUERY
|
||||
};
|
||||
|
||||
@@ -2598,6 +2600,10 @@ public:
|
||||
|
||||
std::string GetPlayerName();
|
||||
|
||||
// Settings
|
||||
[[nodiscard]] PlayerSetting GetPlayerSetting(std::string source, uint8 index);
|
||||
void UpdatePlayerSetting(std::string source, uint8 index, uint32 value);
|
||||
|
||||
protected:
|
||||
// Gamemaster whisper whitelist
|
||||
WhisperListContainer WhisperList;
|
||||
@@ -2680,6 +2686,7 @@ public:
|
||||
void _LoadTalents(PreparedQueryResult result);
|
||||
void _LoadInstanceTimeRestrictions(PreparedQueryResult result);
|
||||
void _LoadBrewOfTheMonth(PreparedQueryResult result);
|
||||
void _LoadCharacterSettings(PreparedQueryResult result);
|
||||
|
||||
/*********************************************************/
|
||||
/*** SAVE SYSTEM ***/
|
||||
@@ -2703,6 +2710,7 @@ public:
|
||||
void _SaveStats(CharacterDatabaseTransaction trans);
|
||||
void _SaveCharacter(bool create, CharacterDatabaseTransaction trans);
|
||||
void _SaveInstanceTimeRestrictions(CharacterDatabaseTransaction trans);
|
||||
void _SavePlayerSettings(CharacterDatabaseTransaction trans);
|
||||
|
||||
/*********************************************************/
|
||||
/*** ENVIRONMENTAL SYSTEM ***/
|
||||
@@ -2955,6 +2963,8 @@ private:
|
||||
WorldLocation _corpseLocation;
|
||||
|
||||
Optional<float> _farSightDistance = { };
|
||||
|
||||
PlayerSettingMap m_charSettingsMap;
|
||||
};
|
||||
|
||||
void AddItemsSetItem(Player* player, Item* item);
|
||||
|
||||
128
src/server/game/Entities/Player/PlayerSettings.cpp
Normal file
128
src/server/game/Entities/Player/PlayerSettings.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 "Tokenize.h"
|
||||
#include "StringConvert.h"
|
||||
#include "Player.h"
|
||||
|
||||
/*********************************************************/
|
||||
/*** PLAYER SETTINGS SYSTEM ***/
|
||||
/*********************************************************/
|
||||
|
||||
void Player::_LoadCharacterSettings(PreparedQueryResult result)
|
||||
{
|
||||
m_charSettingsMap.clear();
|
||||
|
||||
if (!sWorld->getBoolConfig(CONFIG_PLAYER_SETTINGS_ENABLED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string source = fields[0].GetString();;
|
||||
std::string data = fields[1].GetString();
|
||||
|
||||
std::vector<std::string_view> tokens = Acore::Tokenize(data, ' ', true);
|
||||
|
||||
PlayerSettingVector setting;
|
||||
setting.resize(tokens.size());
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
for (auto token : tokens)
|
||||
{
|
||||
PlayerSetting set;
|
||||
set.value = Acore::StringTo<uint32>(token).value();
|
||||
setting[++count] = set;
|
||||
}
|
||||
|
||||
m_charSettingsMap[source] = setting;
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
}
|
||||
|
||||
PlayerSetting Player::GetPlayerSetting(std::string source, uint8 index)
|
||||
{
|
||||
auto itr = m_charSettingsMap.find(source);
|
||||
|
||||
if (itr == m_charSettingsMap.end())
|
||||
{
|
||||
// Settings not found, this will initialize a new entry.
|
||||
UpdatePlayerSetting(source, index, 0);
|
||||
return GetPlayerSetting(source, index);
|
||||
}
|
||||
|
||||
return itr->second[index];
|
||||
}
|
||||
|
||||
void Player::_SavePlayerSettings(CharacterDatabaseTransaction trans)
|
||||
{
|
||||
if (!sWorld->getBoolConfig(CONFIG_PLAYER_SETTINGS_ENABLED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto itr : m_charSettingsMap)
|
||||
{
|
||||
std::ostringstream data;
|
||||
|
||||
for (auto setting : itr.second)
|
||||
{
|
||||
data << setting.value << ' ';
|
||||
}
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHAR_SETTINGS);
|
||||
stmt->setUInt32(0, GetGUID().GetCounter());
|
||||
stmt->setString(1, itr.first);
|
||||
stmt->setString(2, data.str());
|
||||
trans->Append(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::UpdatePlayerSetting(std::string source, uint8 index, uint32 value)
|
||||
{
|
||||
auto itr = m_charSettingsMap.find(source);
|
||||
|
||||
if (itr == m_charSettingsMap.end())
|
||||
{
|
||||
// Settings not found, initialize a new entry.
|
||||
uint8 size = index ? index : index + 1;
|
||||
|
||||
PlayerSettingVector setting;
|
||||
setting.resize(size);
|
||||
|
||||
for (uint32 itr = 0; itr <= index; ++itr)
|
||||
{
|
||||
PlayerSetting set;
|
||||
set.value = itr == index ? value : 0;
|
||||
|
||||
setting[itr] = set;
|
||||
}
|
||||
|
||||
m_charSettingsMap[source] = setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
itr->second[index].value = value;
|
||||
}
|
||||
}
|
||||
51
src/server/game/Entities/Player/PlayerSettings.h
Normal file
51
src/server/game/Entities/Player/PlayerSettings.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _PLAYER_SETTINGS_H
|
||||
#define _PLAYER_SETTINGS_H
|
||||
|
||||
class Player;
|
||||
|
||||
const std::string AzerothcorePSSource = "ac_default";
|
||||
|
||||
enum CharacterSettingIndexes : uint8
|
||||
{
|
||||
SETTING_ANNOUNCER_FLAGS,
|
||||
MAX_CHAR_SETTINGS
|
||||
};
|
||||
|
||||
enum AnnouncerFlags : uint8
|
||||
{
|
||||
ANNOUNCER_FLAG_DISABLE_BG_QUEUE = 1,
|
||||
ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE = 2,
|
||||
ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST = 4
|
||||
};
|
||||
|
||||
struct PlayerSetting
|
||||
{
|
||||
uint32 value;
|
||||
|
||||
[[nodiscard]] bool HasFlag(uint32 flag) { return (value & flag) != 0; }
|
||||
[[nodiscard]] bool IsEnabled(uint32 equals = 1) { return value == equals; }
|
||||
void AddFlag(uint32 flag) { value = value | flag; }
|
||||
void RemoveFlag(uint32 flag) { value = value &~ flag; }
|
||||
};
|
||||
|
||||
typedef std::vector<PlayerSetting> PlayerSettingVector;
|
||||
typedef std::map<std::string, PlayerSettingVector> PlayerSettingMap;
|
||||
|
||||
#endif
|
||||
@@ -5622,6 +5622,8 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
|
||||
_LoadBrewOfTheMonth(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_BREW_OF_THE_MONTH));
|
||||
|
||||
_LoadCharacterSettings(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_CHARACTER_SETTINGS));
|
||||
|
||||
// Players are immune to taunt
|
||||
ApplySpellImmune(0, IMMUNITY_STATE, SPELL_AURA_MOD_TAUNT, true);
|
||||
ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_ATTACK_ME, true);
|
||||
@@ -7166,6 +7168,7 @@ void Player::SaveToDB(CharacterDatabaseTransaction trans, bool create, bool logo
|
||||
GetSession()->SaveTutorialsData(trans); // changed only while character in game
|
||||
_SaveGlyphs(trans);
|
||||
_SaveInstanceTimeRestrictions(trans);
|
||||
_SavePlayerSettings(trans);
|
||||
|
||||
// check if stats should only be saved on logout
|
||||
// save stats can be out of transaction
|
||||
|
||||
Reference in New Issue
Block a user