wip
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#include "GameModes.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
|
||||
GameModeMgr* GameModeMgr::Instance()
|
||||
{
|
||||
static GameModeMgr instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void GameModeMgr::LoadFromDB()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
_gameModes.clear();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT `guid`, `game_mode` FROM `mod_gamemodes_characters`");
|
||||
if (!result)
|
||||
{
|
||||
LOG_INFO("module", ">> Loaded 0 character game modes. Table `mod_gamemodes_characters` is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
ObjectGuid::LowType guid = fields[0].Get<uint32>();
|
||||
uint8 mode = fields[1].Get<uint8>();
|
||||
|
||||
if (mode >= GAMEMODE_MAX)
|
||||
{
|
||||
LOG_ERROR("module", "mod-gamemodes: Invalid game mode {} for character {}, skipping.", mode, guid);
|
||||
continue;
|
||||
}
|
||||
|
||||
_gameModes[guid] = static_cast<GameMode>(mode);
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("module", ">> Loaded {} character game modes in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void GameModeMgr::SaveGameMode(ObjectGuid::LowType guid, GameMode mode)
|
||||
{
|
||||
_gameModes[guid] = mode;
|
||||
|
||||
CharacterDatabase.Execute("REPLACE INTO `mod_gamemodes_characters` (`guid`, `game_mode`) VALUES ({}, {})",
|
||||
guid, static_cast<uint8>(mode));
|
||||
}
|
||||
|
||||
void GameModeMgr::DeleteGameMode(ObjectGuid::LowType guid)
|
||||
{
|
||||
_gameModes.erase(guid);
|
||||
|
||||
CharacterDatabase.Execute("DELETE FROM `mod_gamemodes_characters` WHERE `guid` = {}", guid);
|
||||
}
|
||||
|
||||
GameMode GameModeMgr::GetGameMode(ObjectGuid::LowType guid) const
|
||||
{
|
||||
auto it = _gameModes.find(guid);
|
||||
if (it != _gameModes.end())
|
||||
return it->second;
|
||||
return GAMEMODE_NORMAL;
|
||||
}
|
||||
|
||||
bool GameModeMgr::HasGameMode(ObjectGuid::LowType guid, GameMode mode) const
|
||||
{
|
||||
return GetGameMode(guid) == mode;
|
||||
}
|
||||
Reference in New Issue
Block a user