Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d4463ca0b | |||
| 38dffee5f6 | |||
| 4d8a2a20e1 | |||
| 7a32675298 | |||
| e7f0ce052b | |||
| b49efcea0d | |||
| 6516b32fc6 |
@@ -108,3 +108,4 @@ local.properties
|
||||
# !modules/yourmodule
|
||||
#
|
||||
# ==================
|
||||
.claude
|
||||
@@ -0,0 +1,45 @@
|
||||
-- MySQL dump 10.13 Distrib 8.4.3, for Win64 (x86_64)
|
||||
--
|
||||
-- Host: localhost Database: acore_characters
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 8.4.3
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!50503 SET NAMES utf8mb4 */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `mod_gamemodes_characters`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `mod_gamemodes_characters`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `mod_gamemodes_characters` (
|
||||
`guid` int unsigned NOT NULL,
|
||||
`game_mode` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '0 = NORMAL, 1 = TRAITOR',
|
||||
PRIMARY KEY (`guid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Character Game Modes';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `mod_gamemodes_characters`
|
||||
--
|
||||
|
||||
LOCK TABLES `mod_gamemodes_characters` WRITE;
|
||||
/*!40000 ALTER TABLE `mod_gamemodes_characters` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `mod_gamemodes_characters` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
@@ -0,0 +1,86 @@
|
||||
local AIO = AIO or require("AIO")
|
||||
|
||||
local ADDON_NAME = "MoonWellClient"
|
||||
local HANDLER_NAME = "Init"
|
||||
local GAME_MODE_NORMAL = 0
|
||||
local GAME_MODE_TRAITOR = 1
|
||||
local PLAYER_EVENT_ON_LOGIN = 3
|
||||
local AIO_INIT_SEND_DELAY_MS = 1000
|
||||
|
||||
local MoonWellAIO = rawget(_G, "MoonWellAIO") or {}
|
||||
_G.MoonWellAIO = MoonWellAIO
|
||||
local PendingSyncEvents = {}
|
||||
|
||||
local function GetPlayerGameMode(player)
|
||||
if not player then
|
||||
return GAME_MODE_NORMAL
|
||||
end
|
||||
|
||||
local query = CharDBQuery(
|
||||
"SELECT game_mode FROM mod_gamemodes_characters WHERE guid = " .. player:GetGUIDLow() .. " LIMIT 1"
|
||||
)
|
||||
|
||||
if not query or query:IsNull(0) then
|
||||
return GAME_MODE_NORMAL
|
||||
end
|
||||
|
||||
local gameMode = query:GetUInt8(0)
|
||||
if gameMode == GAME_MODE_TRAITOR then
|
||||
return GAME_MODE_TRAITOR
|
||||
end
|
||||
|
||||
return GAME_MODE_NORMAL
|
||||
end
|
||||
|
||||
function MoonWellAIO.GetPlayerGameMode(player)
|
||||
return GetPlayerGameMode(player)
|
||||
end
|
||||
|
||||
function MoonWellAIO.SendPlayerGameMode(player)
|
||||
if not player then
|
||||
return GAME_MODE_NORMAL
|
||||
end
|
||||
|
||||
local gameMode = GetPlayerGameMode(player)
|
||||
AIO.Handle(player, ADDON_NAME, HANDLER_NAME, gameMode)
|
||||
return gameMode
|
||||
end
|
||||
|
||||
local function CancelPendingSync(playerGuidLow)
|
||||
local eventId = PendingSyncEvents[playerGuidLow]
|
||||
if eventId then
|
||||
RemoveEventById(eventId)
|
||||
PendingSyncEvents[playerGuidLow] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function MoonWellAIO.SchedulePlayerGameMode(player, delayMs)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
local playerGuidLow = player:GetGUIDLow()
|
||||
local playerGuid = player:GetGUID()
|
||||
|
||||
CancelPendingSync(playerGuidLow)
|
||||
|
||||
PendingSyncEvents[playerGuidLow] = CreateLuaEvent(function()
|
||||
PendingSyncEvents[playerGuidLow] = nil
|
||||
|
||||
local onlinePlayer = GetPlayerByGUID(playerGuid)
|
||||
if onlinePlayer then
|
||||
MoonWellAIO.SendPlayerGameMode(onlinePlayer)
|
||||
end
|
||||
end, delayMs or AIO_INIT_SEND_DELAY_MS, 1)
|
||||
end
|
||||
|
||||
-- Do not append MoonWellClient blocks directly into the AIO init packet:
|
||||
-- the client addon may register its handlers slightly later than AIO itself.
|
||||
AIO.AddOnInit(function(msg, player)
|
||||
MoonWellAIO.SchedulePlayerGameMode(player, AIO_INIT_SEND_DELAY_MS)
|
||||
return msg
|
||||
end)
|
||||
|
||||
RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, function(_, player)
|
||||
MoonWellAIO.SchedulePlayerGameMode(player, AIO_INIT_SEND_DELAY_MS)
|
||||
end)
|
||||
@@ -1207,6 +1207,9 @@ public:
|
||||
|
||||
void OnHeal(Unit* healer, Unit* receiver, uint32& gain) override
|
||||
{
|
||||
if (!healer)
|
||||
return;
|
||||
|
||||
if (healer->IsPlayer())
|
||||
sEluna->OnPlayerHeal(healer->ToPlayer(), receiver, gain);
|
||||
|
||||
@@ -1216,6 +1219,9 @@ public:
|
||||
|
||||
void OnDamage(Unit* attacker, Unit* receiver, uint32& damage) override
|
||||
{
|
||||
if (!attacker)
|
||||
return;
|
||||
|
||||
if (attacker->IsPlayer())
|
||||
sEluna->OnPlayerDamage(attacker->ToPlayer(), receiver, damage);
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Game Modes module configuration
|
||||
#
|
||||
|
||||
########################################
|
||||
# GameModes settings
|
||||
########################################
|
||||
|
||||
#
|
||||
# GameModes.Enable
|
||||
# Description: Enable game modes system
|
||||
# Default: 1 - (Enabled)
|
||||
# 0 - (Disabled)
|
||||
#
|
||||
|
||||
GameModes.Enable = 1
|
||||
|
||||
#
|
||||
# GameModes.Traitor.Enable
|
||||
# Description: Enable Traitor game mode
|
||||
# Default: 1 - (Enabled)
|
||||
# 0 - (Disabled)
|
||||
#
|
||||
|
||||
GameModes.Traitor.Enable = 1
|
||||
@@ -0,0 +1,6 @@
|
||||
DROP TABLE IF EXISTS `mod_gamemodes_characters`;
|
||||
CREATE TABLE `mod_gamemodes_characters` (
|
||||
`guid` INT UNSIGNED NOT NULL,
|
||||
`game_mode` TINYINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '0 = NORMAL, 1 = TRAITOR',
|
||||
PRIMARY KEY (`guid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef MOD_GAMEMODES_H
|
||||
#define MOD_GAMEMODES_H
|
||||
|
||||
#include "Player.h"
|
||||
#include <unordered_map>
|
||||
|
||||
enum GameMode : uint8
|
||||
{
|
||||
GAMEMODE_NORMAL = 0,
|
||||
GAMEMODE_TRAITOR = 1,
|
||||
GAMEMODE_MAX
|
||||
};
|
||||
|
||||
// Custom bit in SMSG_CHAR_ENUM character flags.
|
||||
// Chosen as a high unused bit so the packet layout stays unchanged.
|
||||
constexpr uint32 GAMEMODE_CHARACTER_FLAG_TRAITOR = 0x40000000;
|
||||
|
||||
class GameModeMgr
|
||||
{
|
||||
public:
|
||||
static GameModeMgr* Instance();
|
||||
|
||||
void LoadFromDB();
|
||||
void SaveGameMode(ObjectGuid::LowType guid, GameMode mode);
|
||||
void DeleteGameMode(ObjectGuid::LowType guid);
|
||||
|
||||
GameMode GetGameMode(ObjectGuid::LowType guid) const;
|
||||
bool HasGameMode(ObjectGuid::LowType guid, GameMode mode) const;
|
||||
|
||||
private:
|
||||
GameModeMgr() = default;
|
||||
std::unordered_map<ObjectGuid::LowType, GameMode> _gameModes;
|
||||
};
|
||||
|
||||
#define sGameModeMgr GameModeMgr::Instance()
|
||||
|
||||
#endif // MOD_GAMEMODES_H
|
||||
@@ -0,0 +1,6 @@
|
||||
void AddSC_TraitorMode();
|
||||
|
||||
void Addmod_gamemodesScripts()
|
||||
{
|
||||
AddSC_TraitorMode();
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
#include "TraitorMode.h"
|
||||
#include "GameModes.h"
|
||||
#include "Config.h"
|
||||
#include "DBCStores.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "ReputationMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
namespace TraitorMode
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void NormalizeFactionState(Player* player, FactionEntry const* factionEntry, bool visible, bool atWar)
|
||||
{
|
||||
if (!factionEntry || factionEntry->reputationListID < 0)
|
||||
return;
|
||||
|
||||
FactionState* factionState = const_cast<FactionState*>(player->GetReputationMgr().GetState(factionEntry));
|
||||
if (!factionState)
|
||||
return;
|
||||
|
||||
factionState->Flags &= ~(FACTION_FLAG_VISIBLE | FACTION_FLAG_HIDDEN | FACTION_FLAG_INVISIBLE_FORCED |
|
||||
FACTION_FLAG_PEACE_FORCED | FACTION_FLAG_INACTIVE);
|
||||
|
||||
if (visible)
|
||||
factionState->Flags |= FACTION_FLAG_VISIBLE;
|
||||
else
|
||||
factionState->Flags |= FACTION_FLAG_HIDDEN | FACTION_FLAG_INVISIBLE_FORCED;
|
||||
|
||||
if (atWar)
|
||||
factionState->Flags |= FACTION_FLAG_AT_WAR;
|
||||
else
|
||||
factionState->Flags &= ~FACTION_FLAG_AT_WAR;
|
||||
|
||||
factionState->needSend = true;
|
||||
factionState->needSave = true;
|
||||
}
|
||||
|
||||
void SetFactionStanding(Player* player, uint32 factionId, int32 targetDisplayed, bool visible, bool atWar)
|
||||
{
|
||||
FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId);
|
||||
if (!factionEntry)
|
||||
return;
|
||||
|
||||
// ReputationMgr::GetBaseReputation now always uses the player's actual race
|
||||
// mask, so SetOneFactionReputation is safe to call directly.
|
||||
player->GetReputationMgr().SetOneFactionReputation(factionEntry, static_cast<float>(targetDisplayed), false);
|
||||
NormalizeFactionState(player, factionEntry, visible, atWar);
|
||||
}
|
||||
|
||||
void NormalizeTraitorReputationStates(Player* player)
|
||||
{
|
||||
TeamId originalTeam = player->GetTeamId(true);
|
||||
uint32 const* newFactions = (originalTeam == TEAM_ALLIANCE)
|
||||
? HORDE_REPUTATION_FACTIONS
|
||||
: ALLIANCE_REPUTATION_FACTIONS;
|
||||
uint32 const* oldFactions = (originalTeam == TEAM_ALLIANCE)
|
||||
? ALLIANCE_REPUTATION_FACTIONS
|
||||
: HORDE_REPUTATION_FACTIONS;
|
||||
|
||||
auto normalizeFactionAndParent = [player](uint32 factionId, bool visible, bool atWar)
|
||||
{
|
||||
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId))
|
||||
{
|
||||
NormalizeFactionState(player, factionEntry, visible, atWar);
|
||||
|
||||
if (factionEntry->team)
|
||||
NormalizeFactionState(player, sFactionStore.LookupEntry(factionEntry->team), visible, false);
|
||||
}
|
||||
};
|
||||
|
||||
for (uint32 i = 0; i < FACTION_COUNT; ++i)
|
||||
{
|
||||
normalizeFactionAndParent(newFactions[i], true, false);
|
||||
normalizeFactionAndParent(oldFactions[i], false, true);
|
||||
}
|
||||
}
|
||||
|
||||
void SendFactionVisiblePacket(Player* player, FactionEntry const* factionEntry)
|
||||
{
|
||||
if (!factionEntry || factionEntry->reputationListID < 0)
|
||||
return;
|
||||
|
||||
WorldPacket data(SMSG_SET_FACTION_VISIBLE, 4);
|
||||
data << uint32(factionEntry->reputationListID);
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
|
||||
void SendTraitorFactionVisibility(Player* player)
|
||||
{
|
||||
TeamId originalTeam = player->GetTeamId(true);
|
||||
uint32 const* newFactions = (originalTeam == TEAM_ALLIANCE)
|
||||
? HORDE_REPUTATION_FACTIONS
|
||||
: ALLIANCE_REPUTATION_FACTIONS;
|
||||
auto sendFactionAndParent = [player](uint32 factionId)
|
||||
{
|
||||
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId))
|
||||
{
|
||||
SendFactionVisiblePacket(player, factionEntry);
|
||||
|
||||
if (factionEntry->team)
|
||||
SendFactionVisiblePacket(player, sFactionStore.LookupEntry(factionEntry->team));
|
||||
}
|
||||
};
|
||||
|
||||
for (uint32 i = 0; i < FACTION_COUNT; ++i)
|
||||
sendFactionAndParent(newFactions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyFactionSwap(Player* player)
|
||||
{
|
||||
TeamId originalTeam = player->GetTeamId(true);
|
||||
TeamId newTeam = (originalTeam == TEAM_ALLIANCE) ? TEAM_HORDE : TEAM_ALLIANCE;
|
||||
|
||||
player->setTeamId(newTeam);
|
||||
|
||||
// Derive faction template from the canonical race for the new team (same
|
||||
// logic as SetFactionForRace), so we never rely on hardcoded DBC IDs.
|
||||
uint8 representativeRace = (newTeam == TEAM_HORDE) ? HORDE_DEFAULT_RACE : ALLIANCE_DEFAULT_RACE;
|
||||
if (ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(representativeRace))
|
||||
player->SetFaction(rEntry->FactionID);
|
||||
|
||||
LOG_INFO("module", "mod-gamemodes: ApplyFactionSwap for {} (GUID: {}), original team = {}, new team = {}, factionTemplate = {}",
|
||||
player->GetName(), player->GetGUID().GetCounter(),
|
||||
(originalTeam == TEAM_ALLIANCE ? "Alliance" : "Horde"),
|
||||
(newTeam == TEAM_ALLIANCE ? "Alliance" : "Horde"),
|
||||
player->GetFaction());
|
||||
}
|
||||
|
||||
void InitTraitorReputations(Player* player)
|
||||
{
|
||||
TeamId originalTeam = player->GetTeamId(true);
|
||||
|
||||
// New faction reputations -> Neutral (standing = 0)
|
||||
const uint32* newFactions = (originalTeam == TEAM_ALLIANCE)
|
||||
? HORDE_REPUTATION_FACTIONS
|
||||
: ALLIANCE_REPUTATION_FACTIONS;
|
||||
|
||||
for (uint32 i = 0; i < FACTION_COUNT; ++i)
|
||||
SetFactionStanding(player, newFactions[i], 0, true, false);
|
||||
|
||||
// Old faction reputations -> Hostile (standing = -6000)
|
||||
const uint32* oldFactions = (originalTeam == TEAM_ALLIANCE)
|
||||
? ALLIANCE_REPUTATION_FACTIONS
|
||||
: HORDE_REPUTATION_FACTIONS;
|
||||
|
||||
for (uint32 i = 0; i < FACTION_COUNT; ++i)
|
||||
SetFactionStanding(player, oldFactions[i], -6000, false, true);
|
||||
|
||||
LOG_INFO("module", "mod-gamemodes: InitTraitorReputations for {} (GUID: {})",
|
||||
player->GetName(), player->GetGUID().GetCounter());
|
||||
}
|
||||
|
||||
void TeleportToNewFactionStart(Player* player)
|
||||
{
|
||||
TeamId originalTeam = player->GetTeamId(true);
|
||||
uint8 spawnRace = (originalTeam == TEAM_ALLIANCE)
|
||||
? HORDE_DEFAULT_RACE
|
||||
: ALLIANCE_DEFAULT_RACE;
|
||||
|
||||
PlayerInfo const* info = sObjectMgr->GetPlayerInfo(spawnRace, player->getClass());
|
||||
if (!info)
|
||||
{
|
||||
// Fallback: try warrior (class 1) for that race
|
||||
info = sObjectMgr->GetPlayerInfo(spawnRace, 1);
|
||||
}
|
||||
|
||||
if (!info)
|
||||
{
|
||||
LOG_ERROR("module", "mod-gamemodes: No spawn info for race {} class {}", spawnRace, player->getClass());
|
||||
return;
|
||||
}
|
||||
|
||||
player->TeleportTo(info->mapId, info->positionX, info->positionY, info->positionZ, info->orientation);
|
||||
|
||||
LOG_INFO("module", "mod-gamemodes: Teleported {} to faction start (map {}, {:.1f}, {:.1f}, {:.1f})",
|
||||
player->GetName(), info->mapId, info->positionX, info->positionY, info->positionZ);
|
||||
}
|
||||
}
|
||||
|
||||
class TraitorModePlayer : public PlayerScript
|
||||
{
|
||||
public:
|
||||
TraitorModePlayer() : PlayerScript("TraitorModePlayer",
|
||||
{PLAYERHOOK_ON_CREATE, PLAYERHOOK_ON_LOGIN, PLAYERHOOK_ON_REPUTATION_LOAD_FROM_DB, PLAYERHOOK_ON_UPDATE_FACTION}) {}
|
||||
|
||||
// OnPlayerCreate fires on a temporary Player object AFTER SaveToDB.
|
||||
// Changes to faction/reputation here are lost. We only save the game mode to DB.
|
||||
void OnPlayerCreate(Player* player) override
|
||||
{
|
||||
LOG_INFO("module", "mod-gamemodes: OnPlayerCreate for {} (GUID: {}), OutfitId = {}",
|
||||
player->GetName(), player->GetGUID().GetCounter(), player->GetOutfitId());
|
||||
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Enable", true))
|
||||
return;
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Traitor.Enable", true))
|
||||
return;
|
||||
|
||||
if (player->GetOutfitId() != GAMEMODE_TRAITOR)
|
||||
return;
|
||||
|
||||
sGameModeMgr->SaveGameMode(player->GetGUID().GetCounter(), GAMEMODE_TRAITOR);
|
||||
CharacterDatabase.Execute("UPDATE `characters` SET `cinematic` = 1 WHERE `guid` = {}", player->GetGUID().GetCounter());
|
||||
LOG_INFO("module", "mod-gamemodes: Saved TRAITOR mode for {} (GUID: {})",
|
||||
player->GetName(), player->GetGUID().GetCounter());
|
||||
}
|
||||
|
||||
// Reputation load completes before initial packets are sent to the client.
|
||||
// Traitor mode must rewrite faction/reputation state here, otherwise the client
|
||||
// builds the reputation window from the original race defaults.
|
||||
void OnPlayerReputationLoadFromDB(Player* player) override
|
||||
{
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Enable", true))
|
||||
return;
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Traitor.Enable", true))
|
||||
return;
|
||||
|
||||
if (!sGameModeMgr->HasGameMode(player->GetGUID().GetCounter(), GAMEMODE_TRAITOR))
|
||||
return;
|
||||
|
||||
TraitorMode::ApplyFactionSwap(player);
|
||||
|
||||
if (player->HasAtLoginFlag(AT_LOGIN_FIRST))
|
||||
TraitorMode::InitTraitorReputations(player);
|
||||
TraitorMode::NormalizeTraitorReputationStates(player);
|
||||
}
|
||||
|
||||
void OnPlayerLogin(Player* player) override
|
||||
{
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Enable", true))
|
||||
return;
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Traitor.Enable", true))
|
||||
return;
|
||||
|
||||
if (!sGameModeMgr->HasGameMode(player->GetGUID().GetCounter(), GAMEMODE_TRAITOR))
|
||||
return;
|
||||
|
||||
TraitorMode::ApplyFactionSwap(player);
|
||||
TraitorMode::NormalizeTraitorReputationStates(player);
|
||||
player->GetReputationMgr().SendInitialReputations();
|
||||
TraitorMode::SendTraitorFactionVisibility(player);
|
||||
player->SetPlayerFlag(PLAYER_FLAGS_TRAITOR);
|
||||
|
||||
if (player->HasAtLoginFlag(AT_LOGIN_FIRST))
|
||||
TraitorMode::TeleportToNewFactionStart(player);
|
||||
|
||||
LOG_INFO("module", "mod-gamemodes: OnPlayerLogin END for {} — TeamId = {}, FactionTemplate = {}, OriginalTeam = {}",
|
||||
player->GetName(),
|
||||
static_cast<uint32>(player->GetTeamId()),
|
||||
player->GetFaction(),
|
||||
static_cast<uint32>(player->GetTeamId(true)));
|
||||
}
|
||||
|
||||
// OnPlayerUpdateFaction fires every time SetFactionForRace is called
|
||||
// (login, race change, etc). Re-apply the swap so it's never lost.
|
||||
void OnPlayerUpdateFaction(Player* player) override
|
||||
{
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Enable", true))
|
||||
return;
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Traitor.Enable", true))
|
||||
return;
|
||||
|
||||
if (!sGameModeMgr->HasGameMode(player->GetGUID().GetCounter(), GAMEMODE_TRAITOR))
|
||||
return;
|
||||
|
||||
TraitorMode::ApplyFactionSwap(player);
|
||||
}
|
||||
};
|
||||
|
||||
class TraitorModeWorld : public WorldScript
|
||||
{
|
||||
public:
|
||||
TraitorModeWorld() : WorldScript("TraitorModeWorld",
|
||||
{WORLDHOOK_ON_LOAD_CUSTOM_DATABASE_TABLE}) {}
|
||||
|
||||
void OnLoadCustomDatabaseTable() override
|
||||
{
|
||||
sGameModeMgr->LoadFromDB();
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_TraitorMode()
|
||||
{
|
||||
new TraitorModePlayer();
|
||||
new TraitorModeWorld();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef MOD_GAMEMODES_TRAITOR_H
|
||||
#define MOD_GAMEMODES_TRAITOR_H
|
||||
|
||||
#include "Player.h"
|
||||
|
||||
namespace TraitorMode
|
||||
{
|
||||
// Reputation faction IDs: capital cities + PvP battleground factions
|
||||
constexpr uint32 ALLIANCE_REPUTATION_FACTIONS[] = {
|
||||
72, // Stormwind
|
||||
47, // Ironforge
|
||||
69, // Darnassus
|
||||
54, // Gnomeregan Exiles
|
||||
930, // Exodar
|
||||
890, // Silverwing Sentinels (WSG)
|
||||
730, // Stormpike Guard (AV)
|
||||
509, // League of Arathor (AB)
|
||||
};
|
||||
|
||||
constexpr uint32 HORDE_REPUTATION_FACTIONS[] = {
|
||||
76, // Orgrimmar
|
||||
81, // Thunder Bluff
|
||||
68, // Undercity
|
||||
530, // Darkspear Trolls
|
||||
911, // Silvermoon City
|
||||
889, // Warsong Outriders (WSG)
|
||||
729, // Frostwolf Clan (AV)
|
||||
510, // The Defilers (AB)
|
||||
};
|
||||
|
||||
constexpr uint32 FACTION_COUNT = 8;
|
||||
|
||||
// Default spawn points for each faction (race 2 = Orc for Horde, race 1 = Human for Alliance)
|
||||
constexpr uint8 HORDE_DEFAULT_RACE = 2; // Orc
|
||||
constexpr uint8 ALLIANCE_DEFAULT_RACE = 1; // Human
|
||||
|
||||
// Apply faction swap on login/faction update
|
||||
void ApplyFactionSwap(Player* player);
|
||||
|
||||
// Set new faction reputations to Neutral (standing 0)
|
||||
void InitTraitorReputations(Player* player);
|
||||
|
||||
// Teleport traitor to the opposite faction's starting zone
|
||||
void TeleportToNewFactionStart(Player* player);
|
||||
}
|
||||
|
||||
void AddSC_TraitorMode();
|
||||
|
||||
#endif // MOD_GAMEMODES_TRAITOR_H
|
||||
@@ -4772,7 +4772,10 @@ uint32 PlayerbotAI::AutoScaleActivity(uint32 mod)
|
||||
return static_cast<uint32>(mod * (1 - lagProgress));
|
||||
}
|
||||
|
||||
bool PlayerbotAI::IsOpposing(Player* player) { return IsOpposing(player->getRace(), bot->getRace()); }
|
||||
bool PlayerbotAI::IsOpposing(Player* player)
|
||||
{
|
||||
return player && bot && player->GetTeamId() != bot->GetTeamId();
|
||||
}
|
||||
|
||||
bool PlayerbotAI::IsOpposing(uint8 race1, uint8 race2)
|
||||
{
|
||||
|
||||
+40
-4
@@ -82,6 +82,9 @@ FORCE_PLAYERBOTS="${FORCE_PLAYERBOTS:-${ACORE_PLAYERBOTS_FORCE:-0}}"
|
||||
: "${ACORE_QUEST_PARTY_ENABLE:=1}"
|
||||
: "${ACORE_QUEST_PARTY_MESSAGE:=0}"
|
||||
|
||||
: "${ACORE_GAMEMODES_ENABLE:=1}"
|
||||
: "${ACORE_GAMEMODES_TRAITOR_ENABLE:=1}"
|
||||
|
||||
: "${ACORE_ELUNA_ENABLED:=true}"
|
||||
: "${ACORE_ELUNA_TRACEBACK:=false}"
|
||||
: "${ACORE_ELUNA_SCRIPT_PATH:=lua_scripts}"
|
||||
@@ -266,8 +269,9 @@ database_service_running() {
|
||||
docker compose ps --status running --services 2>/dev/null | grep -qx 'ac-database'
|
||||
}
|
||||
|
||||
import_world_sql_file() {
|
||||
import_sql_file() {
|
||||
local file_path="$1"
|
||||
local database="$2"
|
||||
|
||||
if [[ ! -f "$file_path" ]]; then
|
||||
log "skip missing ${file_path#$ROOT_DIR/}"
|
||||
@@ -275,13 +279,21 @@ import_world_sql_file() {
|
||||
fi
|
||||
|
||||
if (( DRY_RUN )); then
|
||||
log "would import ${file_path#$ROOT_DIR/} into acore_world"
|
||||
log "would import ${file_path#$ROOT_DIR/} into ${database}"
|
||||
return
|
||||
fi
|
||||
|
||||
docker compose exec -T ac-database bash -lc \
|
||||
"mysql --default-character-set=utf8mb4 -uroot -p\"\$MYSQL_ROOT_PASSWORD\" acore_world" < "$file_path"
|
||||
log "imported ${file_path#$ROOT_DIR/} into acore_world"
|
||||
"mysql --default-character-set=utf8mb4 -uroot -p\"\$MYSQL_ROOT_PASSWORD\" ${database}" < "$file_path"
|
||||
log "imported ${file_path#$ROOT_DIR/} into ${database}"
|
||||
}
|
||||
|
||||
import_world_sql_file() {
|
||||
import_sql_file "$1" "acore_world"
|
||||
}
|
||||
|
||||
import_characters_sql_file() {
|
||||
import_sql_file "$1" "acore_characters"
|
||||
}
|
||||
|
||||
import_local_lua_module_sql() {
|
||||
@@ -300,6 +312,15 @@ import_local_lua_module_sql() {
|
||||
import_world_sql_file "$start_zone_race_teleporters_sql"
|
||||
}
|
||||
|
||||
import_gamemodes_sql() {
|
||||
if ! database_service_running; then
|
||||
log "skip gamemodes SQL: ac-database is not running"
|
||||
return
|
||||
fi
|
||||
|
||||
import_characters_sql_file "$ROOT_DIR/modules/mod-gamemodes/data/sql/db-characters/base/mod_gamemodes_characters.sql"
|
||||
}
|
||||
|
||||
ensure_world_conf() {
|
||||
if [[ -f "$WORLD_CONF" ]]; then
|
||||
return
|
||||
@@ -339,6 +360,8 @@ sync_module_dists() {
|
||||
"$MODULES_ETC_DIR/mod_learnspells.conf.dist"
|
||||
sync_file "$ROOT_DIR/modules/mod-playerbots/conf/playerbots.conf.dist" \
|
||||
"$MODULES_ETC_DIR/playerbots.conf.dist"
|
||||
sync_file "$ROOT_DIR/modules/mod-gamemodes/conf/mod_gamemodes.conf.dist" \
|
||||
"$MODULES_ETC_DIR/mod_gamemodes.conf.dist"
|
||||
sync_file "$ROOT_DIR/modules/mod-quest-loot-party/conf/mod-quest-loot-party.conf.dist" \
|
||||
"$MODULES_ETC_DIR/mod-quest-loot-party.conf.dist"
|
||||
}
|
||||
@@ -482,6 +505,16 @@ playerbots_supported() {
|
||||
return 0
|
||||
}
|
||||
|
||||
write_gamemodes_conf() {
|
||||
write_file "$MODULES_ETC_DIR/mod_gamemodes.conf.dist" <<EOF
|
||||
[worldserver]
|
||||
|
||||
# Managed by ./setup-modules.sh
|
||||
GameModes.Enable = ${ACORE_GAMEMODES_ENABLE}
|
||||
GameModes.Traitor.Enable = ${ACORE_GAMEMODES_TRAITOR_ENABLE}
|
||||
EOF
|
||||
}
|
||||
|
||||
write_playerbots_conf() {
|
||||
if ! [[ -f "$ROOT_DIR/modules/mod-playerbots/conf/playerbots.conf.dist" ]]; then
|
||||
log "skip playerbots: module config source not found"
|
||||
@@ -570,6 +603,7 @@ cleanup_legacy_module_overrides() {
|
||||
"$MODULES_ETC_DIR/mod_eluna.conf"
|
||||
"$MODULES_ETC_DIR/mod_learnspells.conf"
|
||||
"$MODULES_ETC_DIR/mod-quest-loot-party.conf"
|
||||
"$MODULES_ETC_DIR/mod_gamemodes.conf"
|
||||
"$MODULES_ETC_DIR/playerbots.conf"
|
||||
)
|
||||
|
||||
@@ -626,8 +660,10 @@ main() {
|
||||
write_quest_loot_party_conf
|
||||
write_eluna_conf
|
||||
write_learnspells_conf
|
||||
write_gamemodes_conf
|
||||
write_playerbots_conf
|
||||
import_local_lua_module_sql
|
||||
import_gamemodes_sql
|
||||
|
||||
log "module bootstrap completed"
|
||||
}
|
||||
|
||||
@@ -41,14 +41,18 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(CHAR_SEL_BANINFO_LIST, "SELECT bandate, unbandate, bannedby, banreason FROM character_banned WHERE guid = ? ORDER BY unbandate", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_BANNED_NAME, "SELECT characters.name FROM characters, character_banned WHERE character_banned.guid = ? AND character_banned.guid = characters.guid", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_ENUM, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.skin, c.face, c.hairStyle, c.hairColor, c.facialStyle, c.level, c.zone, c.map, c.position_x, c.position_y, c.position_z, "
|
||||
"gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid, c.extra_flags "
|
||||
"gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, cb.guid, c.extra_flags, COALESCE(mgc.game_mode, 0) "
|
||||
"FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? LEFT JOIN guild_member AS gm ON c.guid = gm.guid "
|
||||
"LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? AND c.deleteInfos_Name IS NULL ORDER BY COALESCE(c.order, c.guid)", CONNECTION_ASYNC);
|
||||
"LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 "
|
||||
"LEFT JOIN mod_gamemodes_characters AS mgc ON c.guid = mgc.guid "
|
||||
"WHERE c.account = ? AND c.deleteInfos_Name IS NULL ORDER BY COALESCE(c.order, c.guid)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_ENUM_DECLINED_NAME, "SELECT c.guid, c.name, c.race, c.class, c.gender, c.skin, c.face, c.hairStyle, c.hairColor, c.facialStyle, c.level, c.zone, c.map, "
|
||||
"c.position_x, c.position_y, c.position_z, gm.guildid, c.playerFlags, c.at_login, cp.entry, cp.modelid, cp.level, c.equipmentCache, "
|
||||
"cb.guid, c.extra_flags, cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? "
|
||||
"cb.guid, c.extra_flags, COALESCE(mgc.game_mode, 0), cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? "
|
||||
"LEFT JOIN character_declinedname AS cd ON c.guid = cd.guid LEFT JOIN guild_member AS gm ON c.guid = gm.guid "
|
||||
"LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? AND c.deleteInfos_Name IS NULL ORDER BY COALESCE(c.order, c.guid)", CONNECTION_ASYNC);
|
||||
"LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 "
|
||||
"LEFT JOIN mod_gamemodes_characters AS mgc ON c.guid = mgc.guid "
|
||||
"WHERE c.account = ? AND c.deleteInfos_Name IS NULL ORDER BY COALESCE(c.order, c.guid)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_FREE_NAME, "SELECT guid, name, at_login FROM characters WHERE guid = ? AND account = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_CHAR_ZONE, "SELECT zone FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_NAME_DATA, "SELECT race, class, gender, level FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
@@ -66,12 +70,13 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(CHAR_INS_BATTLEGROUND_RANDOM, "INSERT INTO character_battleground_random (guid) VALUES (?)", CONNECTION_ASYNC);
|
||||
|
||||
// Start LoginQueryHolder content
|
||||
PrepareStatement(CHAR_SEL_CHARACTER, "SELECT guid, account, name, race, class, gender, level, xp, money, skin, face, hairStyle, hairColor, facialStyle, bankSlots, restState, playerFlags, "
|
||||
PrepareStatement(CHAR_SEL_CHARACTER, "SELECT characters.guid, account, name, race, class, gender, level, xp, money, skin, face, hairStyle, hairColor, facialStyle, bankSlots, restState, playerFlags, "
|
||||
"position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, "
|
||||
"resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, instance_mode_mask, "
|
||||
"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
||||
"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, "
|
||||
"knownTitles, actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date) FROM characters WHERE guid = ?", CONNECTION_ASYNC);
|
||||
"knownTitles, actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date), COALESCE(mgc.game_mode, 0) "
|
||||
"FROM characters LEFT JOIN mod_gamemodes_characters AS mgc ON characters.guid = mgc.guid WHERE characters.guid = ?", CONNECTION_ASYNC);
|
||||
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_AURAS, "SELECT casterGuid, itemGuid, spell, effectMask, recalculateMask, stackCount, amount0, amount1, amount2, "
|
||||
"base_amount0, base_amount1, base_amount2, maxDuration, remainTime, remainCharges FROM character_aura WHERE guid = ?", CONNECTION_ASYNC);
|
||||
@@ -109,6 +114,8 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_RANDOMBG, "SELECT guid FROM character_battleground_random WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_BANNED, "SELECT guid FROM character_banned WHERE guid = ? AND active = 1", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_CHARACTER_QUESTSTATUSREW, "SELECT quest FROM character_queststatus_rewarded WHERE guid = ? AND active = 1", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_REP_CHAR_GAME_MODE, "REPLACE INTO mod_gamemodes_characters (guid, game_mode) VALUES (?, ?)", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_DEL_CHAR_GAME_MODE, "DELETE FROM mod_gamemodes_characters WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_ACCOUNT_INSTANCELOCKTIMES, "SELECT instanceId, releaseTime FROM account_instance_times WHERE accountId = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_SEL_BREW_OF_THE_MONTH, "SELECT lastEventId FROM character_brew_of_the_month WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PrepareStatement(CHAR_REP_BREW_OF_THE_MONTH, "REPLACE INTO character_brew_of_the_month (guid, lastEventId) VALUES (?, ?)", CONNECTION_ASYNC);
|
||||
|
||||
@@ -97,6 +97,8 @@ enum CharacterDatabaseStatements : uint32
|
||||
CHAR_SEL_CHARACTER_RANDOMBG,
|
||||
CHAR_SEL_CHARACTER_BANNED,
|
||||
CHAR_SEL_CHARACTER_QUESTSTATUSREW,
|
||||
CHAR_REP_CHAR_GAME_MODE,
|
||||
CHAR_DEL_CHAR_GAME_MODE,
|
||||
CHAR_SEL_ACCOUNT_INSTANCELOCKTIMES,
|
||||
CHAR_SEL_MAILITEMS,
|
||||
CHAR_SEL_BREW_OF_THE_MONTH,
|
||||
|
||||
@@ -333,7 +333,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
|
||||
if (Player const* player = target->ToPlayer())
|
||||
if (player->GetDeathTimer() != 0)
|
||||
// flag set == must be same team, not set == different team
|
||||
return (player->GetTeamId() == source->GetTeamId()) == (player_dead.own_team_flag != 0);
|
||||
return (player->GetBgTeamId() == source->GetBgTeamId()) == (player_dead.own_team_flag != 0);
|
||||
return false;
|
||||
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA:
|
||||
return source->HasAuraEffect(aura.spell_id, aura.effect_idx);
|
||||
@@ -389,7 +389,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
|
||||
if (!bg)
|
||||
return false;
|
||||
|
||||
uint32 score = bg->GetTeamScore(source->GetTeamId() == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE);
|
||||
uint32 score = bg->GetTeamScore(source->GetBgTeamId() == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE);
|
||||
return score >= bg_loss_team_score.min_score && score <= bg_loss_team_score.max_score;
|
||||
}
|
||||
case ACHIEVEMENT_CRITERIA_DATA_TYPE_INSTANCE_SCRIPT:
|
||||
@@ -462,7 +462,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
|
||||
|
||||
uint32 winnnerScore = bg->GetTeamScore(winnerTeam);
|
||||
uint32 loserScore = bg->GetTeamScore(TeamId(!uint32(winnerTeam)));
|
||||
return source->GetTeamId() == winnerTeam && winnnerScore == teams_scores.winner_score && loserScore == teams_scores.loser_score;
|
||||
return source->GetBgTeamId() == winnerTeam && winnnerScore == teams_scores.winner_score && loserScore == teams_scores.loser_score;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@@ -635,7 +635,7 @@ void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQ
|
||||
|
||||
// title achievement rewards are retroactive
|
||||
if (AchievementReward const* reward = sAchievementMgr->GetAchievementReward(achievement))
|
||||
if (uint32 titleId = reward->titleId[Player::TeamIdForRace(GetPlayer()->getRace())])
|
||||
if (uint32 titleId = reward->titleId[uint8(GetPlayer()->GetTeamId())])
|
||||
if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(titleId))
|
||||
if (!GetPlayer()->HasTitle(titleEntry))
|
||||
GetPlayer()->SetTitle(titleEntry);
|
||||
@@ -2448,8 +2448,8 @@ bool AchievementMgr::CanUpdateCriteria(AchievementCriteriaEntry const* criteria,
|
||||
if (achievement->mapID != -1 && GetPlayer()->GetMapId() != uint32(achievement->mapID))
|
||||
return false;
|
||||
|
||||
if ((achievement->requiredFaction == ACHIEVEMENT_FACTION_HORDE && GetPlayer()->GetTeamId(true) != TEAM_HORDE) ||
|
||||
(achievement->requiredFaction == ACHIEVEMENT_FACTION_ALLIANCE && GetPlayer()->GetTeamId(true) != TEAM_ALLIANCE))
|
||||
if ((achievement->requiredFaction == ACHIEVEMENT_FACTION_HORDE && GetPlayer()->GetTeamId() != TEAM_HORDE) ||
|
||||
(achievement->requiredFaction == ACHIEVEMENT_FACTION_ALLIANCE && GetPlayer()->GetTeamId() != TEAM_ALLIANCE))
|
||||
return false;
|
||||
|
||||
for (uint32 i = 0; i < MAX_CRITERIA_REQUIREMENTS; ++i)
|
||||
|
||||
@@ -28,6 +28,16 @@ namespace
|
||||
{
|
||||
std::unordered_map<ObjectGuid, CharacterCacheEntry> _characterCacheStore;
|
||||
std::unordered_map<std::string, CharacterCacheEntry*> _characterCacheByNameStore;
|
||||
|
||||
TeamId GetEffectiveCharacterTeam(uint8 race, uint32 playerFlags, uint8 gameMode)
|
||||
{
|
||||
TeamId teamId = Player::TeamIdForRace(race);
|
||||
|
||||
if (Player::ResolveGameModeFromStorage(playerFlags, gameMode) == PLAYER_GAMEMODE_TRAITOR)
|
||||
return teamId == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
|
||||
|
||||
return teamId;
|
||||
}
|
||||
}
|
||||
|
||||
CharacterCache* CharacterCache::instance()
|
||||
@@ -62,7 +72,11 @@ void CharacterCache::LoadCharacterCacheStorage()
|
||||
_characterCacheStore.clear();
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT guid, name, account, race, gender, class, level FROM characters");
|
||||
QueryResult result = CharacterDatabase.Query(R"(
|
||||
SELECT c.guid, c.name, c.account, c.race, c.gender, c.class, c.level, c.playerFlags, COALESCE(mgc.game_mode, 0)
|
||||
FROM characters c
|
||||
LEFT JOIN mod_gamemodes_characters mgc ON mgc.guid = c.guid
|
||||
)");
|
||||
if (!result)
|
||||
{
|
||||
LOG_INFO("server.loading", "No character name data loaded, empty query!");
|
||||
@@ -73,7 +87,8 @@ void CharacterCache::LoadCharacterCacheStorage()
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>()) /*guid*/, fields[2].Get<uint32>() /*account*/, fields[1].Get<std::string>() /*name*/,
|
||||
fields[4].Get<uint8>() /*gender*/, fields[3].Get<uint8>() /*race*/, fields[5].Get<uint8>() /*class*/, fields[6].Get<uint8>() /*level*/);
|
||||
fields[4].Get<uint8>() /*gender*/, fields[3].Get<uint8>() /*race*/, fields[5].Get<uint8>() /*class*/, fields[6].Get<uint8>() /*level*/,
|
||||
fields[7].Get<uint32>() /*playerFlags*/, fields[8].Get<uint8>() /*gameMode*/);
|
||||
} while (result->NextRow());
|
||||
|
||||
QueryResult mailCountResult = CharacterDatabase.Query("SELECT receiver, COUNT(receiver) FROM mail GROUP BY receiver");
|
||||
@@ -92,7 +107,12 @@ void CharacterCache::LoadCharacterCacheStorage()
|
||||
|
||||
void CharacterCache::RefreshCacheEntry(uint32 lowGuid)
|
||||
{
|
||||
QueryResult result = CharacterDatabase.Query("SELECT guid, name, account, race, gender, class, level FROM characters WHERE guid = {}", lowGuid);
|
||||
QueryResult result = CharacterDatabase.Query(R"(
|
||||
SELECT c.guid, c.name, c.account, c.race, c.gender, c.class, c.level, c.playerFlags, COALESCE(mgc.game_mode, 0)
|
||||
FROM characters c
|
||||
LEFT JOIN mod_gamemodes_characters mgc ON mgc.guid = c.guid
|
||||
WHERE c.guid = {}
|
||||
)", lowGuid);
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
@@ -102,7 +122,9 @@ void CharacterCache::RefreshCacheEntry(uint32 lowGuid)
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
DeleteCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(lowGuid), fields[1].Get<std::string>());
|
||||
AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>()) /*guid*/, fields[2].Get<uint32>() /*account*/, fields[1].Get<std::string>() /*name*/, fields[4].Get<uint8>() /*gender*/, fields[3].Get<uint8>() /*race*/, fields[5].Get<uint8>() /*class*/, fields[6].Get<uint8>() /*level*/);
|
||||
AddCharacterCacheEntry(ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>()) /*guid*/, fields[2].Get<uint32>() /*account*/, fields[1].Get<std::string>() /*name*/,
|
||||
fields[4].Get<uint8>() /*gender*/, fields[3].Get<uint8>() /*race*/, fields[5].Get<uint8>() /*class*/, fields[6].Get<uint8>() /*level*/,
|
||||
fields[7].Get<uint32>() /*playerFlags*/, fields[8].Get<uint8>() /*gameMode*/);
|
||||
} while (result->NextRow());
|
||||
|
||||
QueryResult mailCountResult = CharacterDatabase.Query("SELECT receiver, COUNT(receiver) FROM mail WHERE receiver = {} GROUP BY receiver", lowGuid);
|
||||
@@ -119,16 +141,18 @@ void CharacterCache::RefreshCacheEntry(uint32 lowGuid)
|
||||
/*
|
||||
Modifying functions
|
||||
*/
|
||||
void CharacterCache::AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level)
|
||||
void CharacterCache::AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint32 playerFlags, uint8 gameMode)
|
||||
{
|
||||
CharacterCacheEntry& data = _characterCacheStore[guid];
|
||||
data.Guid = guid;
|
||||
data.Name = name;
|
||||
data.AccountId = accountId;
|
||||
data.PlayerFlags = playerFlags;
|
||||
data.Race = race;
|
||||
data.Sex = gender;
|
||||
data.Class = playerClass;
|
||||
data.Level = level;
|
||||
data.GameMode = gameMode;
|
||||
data.GuildId = 0; // Will be set in guild loading or guild setting
|
||||
for (uint8 i = 0; i < MAX_ARENA_SLOT; ++i)
|
||||
{
|
||||
@@ -145,7 +169,7 @@ void CharacterCache::DeleteCharacterCacheEntry(ObjectGuid const& guid, std::stri
|
||||
_characterCacheByNameStore.erase(name);
|
||||
}
|
||||
|
||||
void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender /*= {}*/, Optional<uint8> race /*= {}*/)
|
||||
void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender /*= {}*/, Optional<uint8> race /*= {}*/, Optional<uint32> playerFlags /*= {}*/, Optional<uint8> gameMode /*= {}*/)
|
||||
{
|
||||
auto itr = _characterCacheStore.find(guid);
|
||||
if (itr == _characterCacheStore.end())
|
||||
@@ -164,6 +188,16 @@ void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string con
|
||||
itr->second.Race = *race;
|
||||
}
|
||||
|
||||
if (playerFlags)
|
||||
{
|
||||
itr->second.PlayerFlags = *playerFlags;
|
||||
}
|
||||
|
||||
if (gameMode)
|
||||
{
|
||||
itr->second.GameMode = *gameMode;
|
||||
}
|
||||
|
||||
//WorldPackets::Misc::InvalidatePlayer packet(guid);
|
||||
//sWorld->SendGlobalMessage(packet.Write());
|
||||
|
||||
@@ -311,7 +345,7 @@ uint32 CharacterCache::GetCharacterTeamByGuid(ObjectGuid guid) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Player::TeamIdForRace(itr->second.Race);
|
||||
return GetEffectiveCharacterTeam(itr->second.Race, itr->second.PlayerFlags, itr->second.GameMode);
|
||||
}
|
||||
|
||||
uint32 CharacterCache::GetCharacterAccountIdByGuid(ObjectGuid guid) const
|
||||
|
||||
@@ -29,10 +29,12 @@ struct CharacterCacheEntry
|
||||
ObjectGuid Guid;
|
||||
std::string Name;
|
||||
uint32 AccountId;
|
||||
uint32 PlayerFlags = 0;
|
||||
uint8 Class;
|
||||
uint8 Race;
|
||||
uint8 Sex;
|
||||
uint8 Level;
|
||||
uint8 GameMode = 0;
|
||||
uint8 MailCount;
|
||||
ObjectGuid::LowType GuildId;
|
||||
std::array<uint32, MAX_ARENA_SLOT> ArenaTeamId;
|
||||
@@ -49,10 +51,10 @@ class AC_GAME_API CharacterCache
|
||||
void LoadCharacterCacheStorage();
|
||||
void RefreshCacheEntry(uint32 lowGuid);
|
||||
|
||||
void AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level);
|
||||
void AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint32 playerFlags = 0, uint8 gameMode = 0);
|
||||
void DeleteCharacterCacheEntry(ObjectGuid const& guid, std::string const& name);
|
||||
|
||||
void UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender = {}, Optional<uint8> race = {});
|
||||
void UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender = {}, Optional<uint8> race = {}, Optional<uint32> playerFlags = {}, Optional<uint8> gameMode = {});
|
||||
void UpdateCharacterLevel(ObjectGuid const& guid, uint8 level);
|
||||
void UpdateCharacterAccountId(ObjectGuid const& guid, uint32 accountId);
|
||||
void UpdateCharacterGuildId(ObjectGuid const& guid, ObjectGuid::LowType guildId);
|
||||
|
||||
@@ -430,7 +430,7 @@ namespace lfg
|
||||
{
|
||||
if (!itemRequirement->checkLeaderOnly || !group || group->GetLeaderGUID() == player->GetGUID())
|
||||
{
|
||||
if (itemRequirement->faction == TEAM_NEUTRAL || itemRequirement->faction == player->GetTeamId(true))
|
||||
if (itemRequirement->faction == TEAM_NEUTRAL || itemRequirement->faction == player->GetTeamId())
|
||||
{
|
||||
if (!player->HasItemCount(itemRequirement->id, 1))
|
||||
{
|
||||
@@ -446,7 +446,7 @@ namespace lfg
|
||||
{
|
||||
if (!questRequirement->checkLeaderOnly || !group || group->GetLeaderGUID() == player->GetGUID())
|
||||
{
|
||||
if (questRequirement->faction == TEAM_NEUTRAL || questRequirement->faction == player->GetTeamId(true))
|
||||
if (questRequirement->faction == TEAM_NEUTRAL || questRequirement->faction == player->GetTeamId())
|
||||
{
|
||||
if (!player->GetQuestRewardStatus(questRequirement->id))
|
||||
{
|
||||
@@ -468,7 +468,7 @@ namespace lfg
|
||||
{
|
||||
if (!achievementRequirement->checkLeaderOnly || !group || group->GetLeaderGUID() == player->GetGUID())
|
||||
{
|
||||
if (achievementRequirement->faction == TEAM_NEUTRAL || achievementRequirement->faction == player->GetTeamId(true))
|
||||
if (achievementRequirement->faction == TEAM_NEUTRAL || achievementRequirement->faction == player->GetTeamId())
|
||||
{
|
||||
if (!player->HasAchieved(achievementRequirement->id))
|
||||
{
|
||||
|
||||
@@ -147,6 +147,80 @@ enum CharacterCustomizeFlags
|
||||
CHAR_CUSTOMIZE_FLAG_RACE = 0x00100000 // name, gender, race, etc...
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr uint32 ALLIANCE_TRAITOR_REPUTATION_FACTIONS[] = { 72, 47, 69, 54, 930, 890, 730, 509 };
|
||||
constexpr uint32 HORDE_TRAITOR_REPUTATION_FACTIONS[] = { 76, 81, 68, 530, 911, 889, 729, 510 };
|
||||
constexpr uint32 TRAITOR_REPUTATION_FACTION_COUNT = 8;
|
||||
|
||||
bool IsGameModeEnabled(PlayerGameMode gameMode)
|
||||
{
|
||||
if (gameMode == PLAYER_GAMEMODE_NORMAL)
|
||||
return true;
|
||||
|
||||
if (!sConfigMgr->GetOption<bool>("GameModes.Enable", true))
|
||||
return false;
|
||||
|
||||
switch (gameMode)
|
||||
{
|
||||
case PLAYER_GAMEMODE_TRAITOR:
|
||||
return sConfigMgr->GetOption<bool>("GameModes.Traitor.Enable", true);
|
||||
case PLAYER_GAMEMODE_NORMAL:
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
TeamId GetOppositeTeamId(TeamId team)
|
||||
{
|
||||
switch (team)
|
||||
{
|
||||
case TEAM_ALLIANCE:
|
||||
return TEAM_HORDE;
|
||||
case TEAM_HORDE:
|
||||
return TEAM_ALLIANCE;
|
||||
default:
|
||||
return TEAM_NEUTRAL;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerGameMode NormalizeGameModeValue(uint8 gameMode)
|
||||
{
|
||||
return gameMode == PLAYER_GAMEMODE_TRAITOR ? PLAYER_GAMEMODE_TRAITOR : PLAYER_GAMEMODE_NORMAL;
|
||||
}
|
||||
|
||||
PlayerGameMode GameModeFromOutfitId(uint8 outfitId)
|
||||
{
|
||||
if (outfitId == 0)
|
||||
return PLAYER_GAMEMODE_NORMAL;
|
||||
|
||||
// We repurpose the create packet's outfit byte for game mode selection.
|
||||
// The stock client normally sends 0 here, so treat any non-zero custom value
|
||||
// as a request for the only create-time custom mode we currently support.
|
||||
PlayerGameMode gameMode = NormalizeGameModeValue(outfitId);
|
||||
|
||||
if (gameMode == PLAYER_GAMEMODE_NORMAL)
|
||||
gameMode = PLAYER_GAMEMODE_TRAITOR;
|
||||
|
||||
return IsGameModeEnabled(gameMode) ? gameMode : PLAYER_GAMEMODE_NORMAL;
|
||||
}
|
||||
|
||||
uint8 GetRepresentativeRaceForTeam(TeamId team)
|
||||
{
|
||||
return team == TEAM_HORDE ? RACE_ORC : RACE_HUMAN;
|
||||
}
|
||||
|
||||
PlayerInfo const* GetRepresentativePlayerInfoForTeam(TeamId team, uint8 classId)
|
||||
{
|
||||
uint8 representativeRace = GetRepresentativeRaceForTeam(team);
|
||||
|
||||
if (PlayerInfo const* info = sObjectMgr->GetPlayerInfo(representativeRace, classId))
|
||||
return info;
|
||||
|
||||
return sObjectMgr->GetPlayerInfo(representativeRace, CLASS_WARRIOR);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32 copseReclaimDelay[MAX_DEATH_COUNT] = { 30, 60, 120 };
|
||||
|
||||
// we can disable this warning for this since it only
|
||||
@@ -486,12 +560,13 @@ void Player::CleanupsBeforeDelete(bool finalCleanup)
|
||||
|
||||
bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo)
|
||||
{
|
||||
// FIXME: outfitId not used in player creating
|
||||
m_outfitId = createInfo->OutfitId;
|
||||
/// @todo: need more checks against packet modifications
|
||||
// should check that skin, face, hair* are valid via DBC per race/class
|
||||
// also do it in Player::BuildEnumData, Player::LoadFromDB
|
||||
|
||||
Object::_Create(guidlow, 0, HighGuid::Player);
|
||||
SetGameMode(GameModeFromOutfitId(m_outfitId));
|
||||
|
||||
m_name = createInfo->Name;
|
||||
|
||||
@@ -506,8 +581,6 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
|
||||
for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; i++)
|
||||
m_items[i] = nullptr;
|
||||
|
||||
Relocate(info->positionX, info->positionY, info->positionZ, info->orientation);
|
||||
|
||||
ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(createInfo->Class);
|
||||
if (!cEntry)
|
||||
{
|
||||
@@ -516,8 +589,6 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
SetMap(sMapMgr->CreateMap(info->mapId, this));
|
||||
|
||||
uint8 powertype = cEntry->powerType;
|
||||
|
||||
SetObjectScale(1.0f);
|
||||
@@ -525,8 +596,6 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
|
||||
m_realRace = createInfo->Race; // set real race flag
|
||||
m_race = createInfo->Race; // set real race flag
|
||||
|
||||
SetFactionForRace(createInfo->Race);
|
||||
|
||||
if (!IsValidGender(createInfo->Gender))
|
||||
{
|
||||
LOG_ERROR("entities.player", "Player::Create: Possible hacking-attempt: Account {} tried creating a character named '{}' with an invalid gender ({}) - refusing to do so",
|
||||
@@ -535,8 +604,14 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
|
||||
}
|
||||
|
||||
uint32 RaceClassGender = (createInfo->Race) | (createInfo->Class << 8) | (createInfo->Gender << 16);
|
||||
|
||||
SetUInt32Value(UNIT_FIELD_BYTES_0, (RaceClassGender | (powertype << 24)));
|
||||
|
||||
SetFactionForRace(createInfo->Race);
|
||||
|
||||
WorldLocation startPosition = GetStartPosition();
|
||||
Relocate(startPosition);
|
||||
SetMap(sMapMgr->CreateMap(startPosition.GetMapId(), this));
|
||||
|
||||
InitDisplayIds();
|
||||
if (sWorld->getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || sWorld->getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP)
|
||||
{
|
||||
@@ -1111,8 +1186,8 @@ bool Player::BuildEnumData(PreparedQueryResult result, WorldPacket* data)
|
||||
// characters.hairColor, characters.facialStyle, character.level, characters.zone, characters.map, characters.position_x, characters.position_y, characters.position_z,
|
||||
// 16 17 18 19 20 21 22 23
|
||||
// guild_member.guildid, characters.playerFlags, characters.at_login, character_pet.entry, character_pet.modelid, character_pet.level, characters.equipmentCache, character_banned.guid,
|
||||
// 24 25
|
||||
// characters.extra_flags, character_declinedname.genitive
|
||||
// 24 25 26
|
||||
// characters.extra_flags, mod_gamemodes_characters.game_mode, character_declinedname.genitive
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
@@ -1184,12 +1259,15 @@ bool Player::BuildEnumData(PreparedQueryResult result, WorldPacket* data)
|
||||
charFlags |= CHARACTER_FLAG_LOCKED_BY_BILLING;
|
||||
if (sWorld->getBoolConfig(CONFIG_DECLINED_NAMES_USED))
|
||||
{
|
||||
if (!fields[25].Get<std::string>().empty())
|
||||
if (!fields[26].Get<std::string>().empty())
|
||||
charFlags |= CHARACTER_FLAG_DECLINED;
|
||||
}
|
||||
else
|
||||
charFlags |= CHARACTER_FLAG_DECLINED;
|
||||
|
||||
if (fields[25].Get<uint8>() == 1 /* GAMEMODE_TRAITOR */)
|
||||
charFlags |= CHARACTER_FLAG_UNK31;
|
||||
|
||||
*data << uint32(charFlags); // character flags
|
||||
|
||||
// character customize flags
|
||||
@@ -4065,6 +4143,10 @@ void Player::DeleteFromDB(ObjectGuid::LowType lowGuid, uint32 accountId, bool up
|
||||
stmt->SetData(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_GAME_MODE);
|
||||
stmt->SetData(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_ACCOUNT_DATA);
|
||||
stmt->SetData(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
@@ -5850,17 +5932,46 @@ TeamId Player::TeamIdForRace(uint8 race)
|
||||
|
||||
void Player::SetFactionForRace(uint8 race)
|
||||
{
|
||||
m_team = TeamIdForRace(race);
|
||||
TeamId nativeTeam = TeamIdForRace(race);
|
||||
m_team = IsTraitor() ? GetOppositeTeamId(nativeTeam) : nativeTeam;
|
||||
|
||||
sScriptMgr->OnPlayerUpdateFaction(this);
|
||||
|
||||
if (GetTeamId(true) != GetTeamId())
|
||||
return;
|
||||
|
||||
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(race);
|
||||
uint8 factionRace = IsTraitor() ? GetRepresentativeRaceForTeam(m_team) : race;
|
||||
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(factionRace);
|
||||
SetFaction(rEntry ? rEntry->FactionID : 0);
|
||||
}
|
||||
|
||||
PlayerGameMode Player::ResolveGameModeFromStorage(uint32 playerFlags, uint8 gameMode)
|
||||
{
|
||||
PlayerGameMode resolvedGameMode = NormalizeGameModeValue(gameMode);
|
||||
|
||||
if (resolvedGameMode == PLAYER_GAMEMODE_NORMAL && (playerFlags & PLAYER_FLAGS_TRAITOR))
|
||||
resolvedGameMode = PLAYER_GAMEMODE_TRAITOR;
|
||||
|
||||
return IsGameModeEnabled(resolvedGameMode) ? resolvedGameMode : PLAYER_GAMEMODE_NORMAL;
|
||||
}
|
||||
|
||||
PlayerInfo const* Player::GetStartPlayerInfo() const
|
||||
{
|
||||
if (IsTraitor())
|
||||
return GetRepresentativePlayerInfoForTeam(GetTeamId(), getClass());
|
||||
|
||||
return sObjectMgr->GetPlayerInfo(getRace(true), getClass());
|
||||
}
|
||||
|
||||
void Player::SetGameMode(PlayerGameMode gameMode)
|
||||
{
|
||||
m_gameMode = NormalizeGameModeValue(static_cast<uint8>(gameMode));
|
||||
if (!IsGameModeEnabled(m_gameMode))
|
||||
m_gameMode = PLAYER_GAMEMODE_NORMAL;
|
||||
|
||||
if (m_gameMode == PLAYER_GAMEMODE_TRAITOR)
|
||||
SetPlayerFlag(PLAYER_FLAGS_TRAITOR);
|
||||
else
|
||||
RemovePlayerFlag(PLAYER_FLAGS_TRAITOR);
|
||||
}
|
||||
|
||||
ReputationRank Player::GetReputationRank(uint32 faction) const
|
||||
{
|
||||
FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction);
|
||||
@@ -5972,7 +6083,7 @@ void Player::RewardReputation(Unit* victim)
|
||||
ChampioningFaction = GetChampioningFaction();
|
||||
}
|
||||
|
||||
TeamId teamId = GetTeamId(true); // Always check player original reputation when rewarding
|
||||
TeamId teamId = GetTeamId();
|
||||
|
||||
if (Rep->RepFaction1 && (!Rep->TeamDependent || teamId == TEAM_ALLIANCE))
|
||||
{
|
||||
@@ -6086,6 +6197,78 @@ void Player::RewardReputation(Quest const* quest)
|
||||
}
|
||||
}
|
||||
|
||||
void Player::ApplyTraitorReputationState()
|
||||
{
|
||||
if (!IsTraitor())
|
||||
return;
|
||||
|
||||
auto normalizeFactionState = [this](FactionEntry const* factionEntry, bool visible, bool atWar)
|
||||
{
|
||||
if (!factionEntry || factionEntry->reputationListID < 0)
|
||||
return;
|
||||
|
||||
FactionState* factionState = const_cast<FactionState*>(GetReputationMgr().GetState(factionEntry));
|
||||
if (!factionState)
|
||||
return;
|
||||
|
||||
factionState->Flags &= ~(FACTION_FLAG_VISIBLE | FACTION_FLAG_HIDDEN | FACTION_FLAG_INVISIBLE_FORCED |
|
||||
FACTION_FLAG_PEACE_FORCED | FACTION_FLAG_INACTIVE);
|
||||
|
||||
if (visible)
|
||||
factionState->Flags |= FACTION_FLAG_VISIBLE;
|
||||
else
|
||||
factionState->Flags |= FACTION_FLAG_HIDDEN | FACTION_FLAG_INVISIBLE_FORCED;
|
||||
|
||||
if (atWar)
|
||||
factionState->Flags |= FACTION_FLAG_AT_WAR;
|
||||
else
|
||||
factionState->Flags &= ~FACTION_FLAG_AT_WAR;
|
||||
|
||||
factionState->needSend = true;
|
||||
factionState->needSave = true;
|
||||
};
|
||||
|
||||
auto setFactionStanding = [this, &normalizeFactionState](uint32 factionId, int32 targetDisplayed, bool visible, bool atWar)
|
||||
{
|
||||
FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId);
|
||||
if (!factionEntry)
|
||||
return;
|
||||
|
||||
GetReputationMgr().SetOneFactionReputation(factionEntry, static_cast<float>(targetDisplayed), false);
|
||||
normalizeFactionState(factionEntry, visible, atWar);
|
||||
};
|
||||
|
||||
auto normalizeFactionAndParent = [&normalizeFactionState](uint32 factionId, bool visible, bool atWar)
|
||||
{
|
||||
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId))
|
||||
{
|
||||
normalizeFactionState(factionEntry, visible, atWar);
|
||||
|
||||
if (factionEntry->team)
|
||||
normalizeFactionState(sFactionStore.LookupEntry(factionEntry->team), visible, false);
|
||||
}
|
||||
};
|
||||
|
||||
TeamId nativeTeam = GetTeamId(true);
|
||||
uint32 const* friendlyFactions = nativeTeam == TEAM_ALLIANCE ? HORDE_TRAITOR_REPUTATION_FACTIONS : ALLIANCE_TRAITOR_REPUTATION_FACTIONS;
|
||||
uint32 const* hostileFactions = nativeTeam == TEAM_ALLIANCE ? ALLIANCE_TRAITOR_REPUTATION_FACTIONS : HORDE_TRAITOR_REPUTATION_FACTIONS;
|
||||
|
||||
if (HasAtLoginFlag(AT_LOGIN_FIRST))
|
||||
{
|
||||
for (uint32 i = 0; i < TRAITOR_REPUTATION_FACTION_COUNT; ++i)
|
||||
setFactionStanding(friendlyFactions[i], 0, true, false);
|
||||
|
||||
for (uint32 i = 0; i < TRAITOR_REPUTATION_FACTION_COUNT; ++i)
|
||||
setFactionStanding(hostileFactions[i], -6000, false, true);
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < TRAITOR_REPUTATION_FACTION_COUNT; ++i)
|
||||
{
|
||||
normalizeFactionAndParent(friendlyFactions[i], true, false);
|
||||
normalizeFactionAndParent(hostileFactions[i], false, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::RewardExtraBonusTalentPoints(uint32 bonusTalentPoints)
|
||||
{
|
||||
if (bonusTalentPoints)
|
||||
@@ -10301,7 +10484,7 @@ bool Player::ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc
|
||||
// only one mount ID for both sides. Probably not good to use 315 in case DBC nodes
|
||||
// change but I couldn't find a suitable alternative. OK to use class because only DK
|
||||
// can use this taxi.
|
||||
uint32 mount_display_id = sObjectMgr->GetTaxiMountDisplayId(sourcenode, GetTeamId(true), npc == nullptr || (sourcenode == 315 && IsClass(CLASS_DEATH_KNIGHT, CLASS_CONTEXT_TAXI)));
|
||||
uint32 mount_display_id = sObjectMgr->GetTaxiMountDisplayId(sourcenode, GetTeamId(), npc == nullptr || (sourcenode == 315 && IsClass(CLASS_DEATH_KNIGHT, CLASS_CONTEXT_TAXI)));
|
||||
|
||||
// in spell case allow 0 model
|
||||
if ((mount_display_id == 0 && spellid == 0) || sourcepath == 0)
|
||||
@@ -10396,7 +10579,7 @@ void Player::ContinueTaxiFlight()
|
||||
|
||||
LOG_DEBUG("entities.unit", "WORLD: Restart character {} taxi flight", GetGUID().ToString());
|
||||
|
||||
uint32 mountDisplayId = sObjectMgr->GetTaxiMountDisplayId(sourceNode, GetTeamId(true), true);
|
||||
uint32 mountDisplayId = sObjectMgr->GetTaxiMountDisplayId(sourceNode, GetTeamId(), true);
|
||||
if (!mountDisplayId)
|
||||
return;
|
||||
|
||||
@@ -10675,7 +10858,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorguid, uint32 vendorslot, uin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsGameMaster() && ((pProto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && GetTeamId(true) == TEAM_ALLIANCE) || (pProto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && GetTeamId(true) == TEAM_HORDE)))
|
||||
if (!IsGameMaster() && ((pProto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && GetTeamId() == TEAM_ALLIANCE) || (pProto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && GetTeamId() == TEAM_HORDE)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -11338,7 +11521,7 @@ void Player::ReportedAfkBy(Player* reporter)
|
||||
|
||||
WorldLocation Player::GetStartPosition() const
|
||||
{
|
||||
PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(true), getClass());
|
||||
PlayerInfo const* info = GetStartPlayerInfo();
|
||||
uint32 mapId = info->mapId;
|
||||
if (IsClass(CLASS_DEATH_KNIGHT, CLASS_CONTEXT_INIT) && HasSpell(50977))
|
||||
return WorldLocation(0, 2352.0f, -5709.0f, 154.5f, 0.0f);
|
||||
@@ -14698,6 +14881,7 @@ void Player::_SaveEntryPoint(CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(7, m_entryPointData.taxiPath[1]);
|
||||
stmt->SetData(8, m_entryPointData.mountSpell);
|
||||
trans->Append(stmt);
|
||||
|
||||
}
|
||||
|
||||
void Player::DeleteEquipmentSet(uint64 setGuid)
|
||||
@@ -14765,6 +14949,25 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
uint8 index = 0;
|
||||
|
||||
auto finiteAlways = [](float f) { return std::isfinite(f) ? f : 0.0f; };
|
||||
PlayerGameMode persistedGameMode = GetGameMode();
|
||||
|
||||
// Character enum and login restore traitor mode from persisted storage, not from the
|
||||
// transient create packet. Re-derive the initial mode from the raw create byte before
|
||||
// the first save in case later create initialization has reset the in-memory state.
|
||||
if (create && persistedGameMode == PLAYER_GAMEMODE_NORMAL && m_outfitId != 0)
|
||||
{
|
||||
persistedGameMode = GameModeFromOutfitId(m_outfitId);
|
||||
|
||||
if (persistedGameMode != GetGameMode())
|
||||
{
|
||||
SetGameMode(persistedGameMode);
|
||||
SetFactionForRace(getRace(true));
|
||||
}
|
||||
}
|
||||
|
||||
uint32 playerFlagsForSave = GetPlayerFlags();
|
||||
if (create && persistedGameMode == PLAYER_GAMEMODE_TRAITOR)
|
||||
playerFlagsForSave |= PLAYER_FLAGS_TRAITOR;
|
||||
|
||||
if (create)
|
||||
{
|
||||
@@ -14787,7 +14990,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 0));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 2));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 3));
|
||||
stmt->SetData(index++, (uint32)GetPlayerFlags());
|
||||
stmt->SetData(index++, playerFlagsForSave);
|
||||
stmt->SetData(index++, (uint16)GetMapId());
|
||||
stmt->SetData(index++, (uint32)GetInstanceId());
|
||||
stmt->SetData(index++, (uint8(GetDungeonDifficulty()) | uint8(GetRaidDifficulty()) << 4));
|
||||
@@ -14905,7 +15108,7 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 0));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 2));
|
||||
stmt->SetData(index++, GetByteValue(PLAYER_BYTES_2, 3));
|
||||
stmt->SetData(index++, GetPlayerFlags());
|
||||
stmt->SetData(index++, playerFlagsForSave);
|
||||
|
||||
if (!IsBeingTeleported())
|
||||
{
|
||||
@@ -15033,6 +15236,20 @@ void Player::_SaveCharacter(bool create, CharacterDatabaseTransaction trans)
|
||||
}
|
||||
|
||||
trans->Append(stmt);
|
||||
|
||||
if (persistedGameMode == PLAYER_GAMEMODE_TRAITOR)
|
||||
{
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHAR_GAME_MODE);
|
||||
stmt->SetData(0, GetGUID().GetCounter());
|
||||
stmt->SetData(1, uint8(persistedGameMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_GAME_MODE);
|
||||
stmt->SetData(0, GetGUID().GetCounter());
|
||||
}
|
||||
|
||||
trans->Append(stmt);
|
||||
}
|
||||
|
||||
void Player::_LoadGlyphs(PreparedQueryResult result)
|
||||
|
||||
@@ -454,6 +454,13 @@ enum DrunkenState
|
||||
|
||||
#define MAX_DRUNKEN 4
|
||||
|
||||
enum PlayerGameMode : uint8
|
||||
{
|
||||
PLAYER_GAMEMODE_NORMAL = 0,
|
||||
PLAYER_GAMEMODE_TRAITOR = 1,
|
||||
PLAYER_GAMEMODE_MAX
|
||||
};
|
||||
|
||||
enum PlayerFlags : uint32
|
||||
{
|
||||
PLAYER_FLAGS_GROUP_LEADER = 0x00000001,
|
||||
@@ -486,7 +493,7 @@ enum PlayerFlags : uint32
|
||||
PLAYER_FLAGS_UNK27 = 0x08000000,
|
||||
PLAYER_FLAGS_UNK28 = 0x10000000,
|
||||
PLAYER_FLAGS_UNK29 = 0x20000000,
|
||||
PLAYER_FLAGS_UNK30 = 0x40000000,
|
||||
PLAYER_FLAGS_TRAITOR = 0x40000000, // mod-gamemodes: player is playing for the opposite faction
|
||||
PLAYER_FLAGS_UNK31 = 0x80000000,
|
||||
};
|
||||
|
||||
@@ -1156,7 +1163,7 @@ public:
|
||||
PlayerSocial* GetSocial() { return m_social; }
|
||||
|
||||
PlayerTaxi m_taxi;
|
||||
void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(getRace(), getClass(), GetLevel()); }
|
||||
void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(IsTraitor() ? (GetTeamId() == TEAM_ALLIANCE ? RACE_HUMAN : RACE_ORC) : getRace(), getClass(), GetLevel()); }
|
||||
bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, Creature* npc = nullptr, uint32 spellid = 1);
|
||||
bool ActivateTaxiPathTo(uint32 taxi_path_id, uint32 spellid = 1);
|
||||
void CleanupAfterTaxiFlight();
|
||||
@@ -2126,10 +2133,18 @@ public:
|
||||
void CheckAreaExploreAndOutdoor();
|
||||
|
||||
static TeamId TeamIdForRace(uint8 race);
|
||||
[[nodiscard]] static PlayerGameMode ResolveGameModeFromStorage(uint32 playerFlags, uint8 gameMode);
|
||||
[[nodiscard]] TeamId GetTeamId(bool original = false) const { return original ? TeamIdForRace(getRace(true)) : m_team; };
|
||||
[[nodiscard]] PlayerGameMode GetGameMode() const { return m_gameMode; }
|
||||
[[nodiscard]] bool HasGameMode(PlayerGameMode gameMode) const { return m_gameMode == gameMode; }
|
||||
[[nodiscard]] bool IsTraitor() const { return HasGameMode(PLAYER_GAMEMODE_TRAITOR); }
|
||||
[[nodiscard]] PlayerInfo const* GetStartPlayerInfo() const;
|
||||
void SetGameMode(PlayerGameMode gameMode);
|
||||
void SetFactionForRace(uint8 race);
|
||||
void setTeamId(TeamId teamid) { m_team = teamid; };
|
||||
|
||||
[[nodiscard]] uint8 GetOutfitId() const { return m_outfitId; }
|
||||
|
||||
void InitDisplayIds();
|
||||
|
||||
bool IsAtGroupRewardDistance(WorldObject const* pRewardSource) const;
|
||||
@@ -2148,6 +2163,7 @@ public:
|
||||
[[nodiscard]] ReputationRank GetReputationRank(uint32 faction_id) const;
|
||||
void RewardReputation(Unit* victim);
|
||||
void RewardReputation(Quest const* quest);
|
||||
void ApplyTraitorReputationState();
|
||||
|
||||
float CalculateReputationGain(ReputationSource source, uint32 creatureOrQuestLevel, float rep, int32 faction, bool noQuestBonus = false);
|
||||
|
||||
@@ -2823,6 +2839,8 @@ protected:
|
||||
ObjectGuid m_lootGuid;
|
||||
|
||||
TeamId m_team;
|
||||
PlayerGameMode m_gameMode{PLAYER_GAMEMODE_NORMAL};
|
||||
uint8 m_outfitId{0};
|
||||
uint32 m_nextSave; // pussywizard
|
||||
uint16 m_additionalSaveTimer; // pussywizard
|
||||
uint8 m_additionalSaveMask; // pussywizard
|
||||
|
||||
@@ -1106,8 +1106,18 @@ bool Player::SatisfyQuestRace(Quest const* qInfo, bool msg) const
|
||||
uint32 reqraces = qInfo->GetAllowableRaces();
|
||||
if (reqraces == 0)
|
||||
return true;
|
||||
|
||||
if ((reqraces & getRaceMask()) == 0)
|
||||
{
|
||||
// Allow faction-swapped characters to take quests restricted to their active faction,
|
||||
// while still respecting truly race-specific quests on the opposite side.
|
||||
if (GetTeamId() != GetTeamId(true))
|
||||
{
|
||||
uint32 currentFactionRaceMask = (GetTeamId() == TEAM_ALLIANCE) ? RACEMASK_ALLIANCE : RACEMASK_HORDE;
|
||||
if ((reqraces & currentFactionRaceMask) == reqraces)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
SendCanTakeQuestResponse(INVALIDREASON_QUEST_FAILED_WRONG_RACE);
|
||||
return false;
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#include "Util.h"
|
||||
#include "World.h"
|
||||
#include "WorldPacket.h"
|
||||
#include <cmath>
|
||||
|
||||
/// @todo: this import is not necessary for compilation and marked as unused by the IDE
|
||||
// however, for some reasons removing it would cause a damn linking issue
|
||||
@@ -2378,12 +2379,12 @@ InventoryResult Player::CanUseItem(ItemTemplate const* proto) const
|
||||
return EQUIP_ERR_ITEM_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (proto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && GetTeamId(true) != TEAM_HORDE)
|
||||
if (proto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && GetTeamId() != TEAM_HORDE)
|
||||
{
|
||||
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
|
||||
}
|
||||
|
||||
if (proto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && GetTeamId(true) != TEAM_ALLIANCE)
|
||||
if (proto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && GetTeamId() != TEAM_ALLIANCE)
|
||||
{
|
||||
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
|
||||
}
|
||||
@@ -5014,8 +5015,8 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
//"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
||||
// 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
||||
//"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, knownTitles,
|
||||
// 70 71 72 73 74
|
||||
//"actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date) FROM characters WHERE guid = '{}'", guid);
|
||||
// 70 71 72 73 74 75
|
||||
//"actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date), game_mode FROM characters WHERE guid = '{}'", guid);
|
||||
PreparedQueryResult result = holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_FROM);
|
||||
|
||||
if (!result)
|
||||
@@ -5093,6 +5094,8 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
|
||||
// load character creation date, relevant for achievements of type average
|
||||
SetCreationTime(fields[74].Get<Seconds>());
|
||||
PlayerGameMode storedGameMode = ResolveGameModeFromStorage(fields[16].Get<uint32>(), fields[75].Get<uint8>());
|
||||
SetGameMode(storedGameMode);
|
||||
|
||||
// load achievements before anything else to prevent multiple gains for the same achievement/criteria on every loading (as loading does call UpdateAchievementCriteria)
|
||||
m_achievementMgr->LoadFromDB(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_ACHIEVEMENTS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_CRITERIA_PROGRESS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_OFFLINE_ACHIEVEMENTS_UPDATES));
|
||||
@@ -5112,6 +5115,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
SetByteValue(PLAYER_BYTES_3, 0, fields[5].Get<uint8>());
|
||||
SetByteValue(PLAYER_BYTES_3, 1, fields[54].Get<uint8>());
|
||||
ReplaceAllPlayerFlags((PlayerFlags)fields[16].Get<uint32>());
|
||||
SetGameMode(storedGameMode);
|
||||
SetInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, fields[53].Get<uint32>());
|
||||
|
||||
SetUInt64Value(PLAYER_FIELD_KNOWN_CURRENCIES, fields[52].Get<uint64>());
|
||||
@@ -5149,12 +5153,22 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
|
||||
InitPrimaryProfessions(); // to max set before any spell loaded
|
||||
|
||||
bool isFirstLogin = (fields[38].Get<uint16>() & AT_LOGIN_FIRST) != 0;
|
||||
|
||||
// init saved position, and fix it later if problematic
|
||||
int32 transLowGUID = fields[35].Get<int32>();
|
||||
Relocate(fields[17].Get<float>(), fields[18].Get<float>(), fields[19].Get<float>(), fields[21].Get<float>());
|
||||
uint32 mapId = fields[20].Get<uint16>();
|
||||
uint32 instanceId = fields[63].Get<uint32>();
|
||||
|
||||
if (isFirstLogin && IsTraitor())
|
||||
{
|
||||
WorldLocation startPosition = GetStartPosition();
|
||||
Relocate(startPosition);
|
||||
mapId = startPosition.GetMapId();
|
||||
instanceId = 0;
|
||||
}
|
||||
|
||||
uint32 dungeonDiff = fields[43].Get<uint8>() & 0x0F;
|
||||
if (dungeonDiff >= MAX_DUNGEON_DIFFICULTY)
|
||||
dungeonDiff = DUNGEON_DIFFICULTY_NORMAL;
|
||||
@@ -5311,7 +5325,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
else if (!taxi_nodes.empty())
|
||||
{
|
||||
instanceId = 0;
|
||||
if (!m_taxi.LoadTaxiDestinationsFromString(taxi_nodes, GetTeamId(true)))
|
||||
if (!m_taxi.LoadTaxiDestinationsFromString(taxi_nodes, GetTeamId()))
|
||||
{
|
||||
// xinef: could no load valid data for taxi, relocate to homebind and clear
|
||||
m_taxi.ClearTaxiDestinations();
|
||||
@@ -5543,6 +5557,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
||||
|
||||
// must be before inventory (some items required reputation check)
|
||||
m_reputationMgr->LoadFromDB(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_REPUTATION));
|
||||
sScriptMgr->OnPlayerReputationLoadFromDB(this);
|
||||
|
||||
// xinef: load mails before inventory, so problematic items can be added to already loaded mails
|
||||
_LoadMail(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAILS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAIL_ITEMS));
|
||||
@@ -6850,7 +6865,7 @@ bool Player::Satisfy(DungeonProgressionRequirements const* ar, uint32 target_map
|
||||
missingItems = &missingLeaderItems;
|
||||
}
|
||||
|
||||
if (itemRequirement->faction == TEAM_NEUTRAL || itemRequirement->faction == checkPlayer->GetTeamId(true))
|
||||
if (itemRequirement->faction == TEAM_NEUTRAL || itemRequirement->faction == checkPlayer->GetTeamId())
|
||||
{
|
||||
if (!checkPlayer->HasItemCount(itemRequirement->id, 1))
|
||||
{
|
||||
@@ -6872,7 +6887,7 @@ bool Player::Satisfy(DungeonProgressionRequirements const* ar, uint32 target_map
|
||||
missingAchievements = &missingLeaderAchievements;
|
||||
}
|
||||
|
||||
if (achievementRequirement->faction == TEAM_NEUTRAL || achievementRequirement->faction == GetTeamId(true))
|
||||
if (achievementRequirement->faction == TEAM_NEUTRAL || achievementRequirement->faction == GetTeamId())
|
||||
{
|
||||
if (!checkPlayer || !checkPlayer->HasAchieved(achievementRequirement->id))
|
||||
{
|
||||
@@ -6894,7 +6909,7 @@ bool Player::Satisfy(DungeonProgressionRequirements const* ar, uint32 target_map
|
||||
missingQuests = &missingLeaderQuests;
|
||||
}
|
||||
|
||||
if (questRequirement->faction == TEAM_NEUTRAL || questRequirement->faction == checkPlayer->GetTeamId(true))
|
||||
if (questRequirement->faction == TEAM_NEUTRAL || questRequirement->faction == checkPlayer->GetTeamId())
|
||||
{
|
||||
if (!checkPlayer->GetQuestRewardStatus(questRequirement->id))
|
||||
{
|
||||
@@ -7081,8 +7096,9 @@ bool Player::CheckInstanceCount(uint32 instanceId) const
|
||||
|
||||
bool Player::_LoadHomeBind(PreparedQueryResult result)
|
||||
{
|
||||
PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(true), getClass());
|
||||
if (!info)
|
||||
PlayerInfo const* info = GetStartPlayerInfo();
|
||||
PlayerInfo const* nativeInfo = sObjectMgr->GetPlayerInfo(getRace(true), getClass());
|
||||
if (!info || !nativeInfo)
|
||||
{
|
||||
LOG_ERROR("entities.player", "Player (Name {}) has incorrect race/class pair. Can't be loaded.", GetName());
|
||||
return false;
|
||||
@@ -7114,6 +7130,25 @@ bool Player::_LoadHomeBind(PreparedQueryResult result)
|
||||
}
|
||||
}
|
||||
|
||||
if (ok && IsTraitor())
|
||||
{
|
||||
auto sameCoord = [](float left, float right) { return std::fabs(left - right) < 0.01f; };
|
||||
bool matchesNativeHomebind = m_homebindMapId == nativeInfo->mapId &&
|
||||
m_homebindAreaId == nativeInfo->areaId &&
|
||||
sameCoord(m_homebindX, nativeInfo->positionX) &&
|
||||
sameCoord(m_homebindY, nativeInfo->positionY) &&
|
||||
sameCoord(m_homebindZ, nativeInfo->positionZ);
|
||||
|
||||
bool matchesEffectiveHomebind = m_homebindMapId == info->mapId &&
|
||||
m_homebindAreaId == info->areaId &&
|
||||
sameCoord(m_homebindX, info->positionX) &&
|
||||
sameCoord(m_homebindY, info->positionY) &&
|
||||
sameCoord(m_homebindZ, info->positionZ);
|
||||
|
||||
if (matchesNativeHomebind && !matchesEffectiveHomebind)
|
||||
SetHomebind(WorldLocation(info->mapId, info->positionX, info->positionY, info->positionZ, 0.0f), info->areaId);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
m_homebindMapId = info->mapId;
|
||||
|
||||
@@ -1244,7 +1244,7 @@ void Player::UpdateArea(uint32 newArea)
|
||||
else
|
||||
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY);
|
||||
|
||||
uint32 const areaRestFlag = (GetTeamId(true) == TEAM_ALLIANCE)
|
||||
uint32 const areaRestFlag = (GetTeamId() == TEAM_ALLIANCE)
|
||||
? AREA_FLAG_REST_ZONE_ALLIANCE
|
||||
: AREA_FLAG_REST_ZONE_HORDE;
|
||||
if (area && area->flags & areaRestFlag)
|
||||
@@ -1305,12 +1305,12 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea, bool force)
|
||||
{
|
||||
case AREATEAM_ALLY:
|
||||
pvpInfo.IsInHostileArea =
|
||||
GetTeamId(true) != TEAM_ALLIANCE &&
|
||||
GetTeamId() != TEAM_ALLIANCE &&
|
||||
(sWorld->IsPvPRealm() || zone->flags & AREA_FLAG_CAPITAL);
|
||||
break;
|
||||
case AREATEAM_HORDE:
|
||||
pvpInfo.IsInHostileArea =
|
||||
GetTeamId(true) != TEAM_HORDE &&
|
||||
GetTeamId() != TEAM_HORDE &&
|
||||
(sWorld->IsPvPRealm() || zone->flags & AREA_FLAG_CAPITAL);
|
||||
break;
|
||||
case AREATEAM_NONE:
|
||||
|
||||
@@ -1483,7 +1483,7 @@ void Guild::HandleInviteMember(WorldSession* session, std::string const& name)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && pInvitee->GetTeamId(true) != player->GetTeamId(true))
|
||||
if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD) && pInvitee->GetTeamId() != player->GetTeamId())
|
||||
{
|
||||
SendCommandResult(session, GUILD_COMMAND_INVITE, ERR_GUILD_NOT_ALLIED, name);
|
||||
return;
|
||||
|
||||
@@ -548,7 +548,9 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((haveSameRace && skipCinematics == 1) || skipCinematics == 2)
|
||||
if (newChar->IsTraitor())
|
||||
newChar->setCinematic(1);
|
||||
else if ((haveSameRace && skipCinematics == 1) || skipCinematics == 2)
|
||||
newChar->setCinematic(1); // not show intro
|
||||
|
||||
newChar->SetAtLoginFlag(AT_LOGIN_FIRST); // First login
|
||||
@@ -558,6 +560,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
|
||||
|
||||
// Player created, save it now
|
||||
newChar->SaveToDB(characterTransaction, true, false);
|
||||
|
||||
createInfo->CharCount++;
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS_BY_REALM);
|
||||
@@ -579,7 +582,8 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
|
||||
{
|
||||
LOG_INFO("entities.player.character", "Account: {} (IP: {}) Create Character: {} {}", GetAccountId(), GetRemoteAddress(), newChar->GetName(), newChar->GetGUID().ToString());
|
||||
sScriptMgr->OnPlayerCreate(newChar.get());
|
||||
sCharacterCache->AddCharacterCacheEntry(newChar->GetGUID(), GetAccountId(), newChar->GetName(), newChar->getGender(), newChar->getRace(), newChar->getClass(), newChar->GetLevel());
|
||||
sCharacterCache->AddCharacterCacheEntry(newChar->GetGUID(), GetAccountId(), newChar->GetName(), newChar->getGender(), newChar->getRace(), newChar->getClass(), newChar->GetLevel(),
|
||||
newChar->GetUInt32Value(PLAYER_FLAGS), static_cast<uint8>(newChar->GetGameMode()));
|
||||
SendCharCreate(CHAR_CREATE_SUCCESS);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -446,12 +446,12 @@ bool LootItem::AllowedForPlayer(Player const* player, ObjectGuid source) const
|
||||
}
|
||||
|
||||
// not show loot for not own team
|
||||
if (pProto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && player->GetTeamId(true) != TEAM_HORDE)
|
||||
if (pProto->HasFlag2(ITEM_FLAG2_FACTION_HORDE) && player->GetTeamId() != TEAM_HORDE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pProto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && player->GetTeamId(true) != TEAM_ALLIANCE)
|
||||
if (pProto->HasFlag2(ITEM_FLAG2_FACTION_ALLIANCE) && player->GetTeamId() != TEAM_ALLIANCE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,20 @@ const int32 ReputationMgr::PointsInRank[MAX_REPUTATION_RANK] = {36000, 3000, 300
|
||||
const int32 ReputationMgr::Reputation_Cap = 42999;
|
||||
const int32 ReputationMgr::Reputation_Bottom = -42000;
|
||||
|
||||
namespace
|
||||
{
|
||||
uint32 GetEffectiveReputationRaceMask(Player const* player)
|
||||
{
|
||||
// Always use the player's actual race mask so the server BaseRep calculation
|
||||
// matches what the client computes (client always uses the original race, not
|
||||
// the current team). This is correct for both the race-change service (where
|
||||
// getRace() already reflects the new race) and for game modes like Traitor
|
||||
// that swap team without changing race (where the original race mask is the
|
||||
// right baseline for reputation display and incremental gain alike).
|
||||
return player->getRaceMask();
|
||||
}
|
||||
}
|
||||
|
||||
ReputationRank ReputationMgr::ReputationToRank(int32 standing)
|
||||
{
|
||||
int32 limit = Reputation_Cap + 1;
|
||||
@@ -93,7 +107,7 @@ int32 ReputationMgr::GetBaseReputation(FactionEntry const* factionEntry) const
|
||||
if (!factionEntry)
|
||||
return 0;
|
||||
|
||||
uint32 raceMask = _player->getRaceMask();
|
||||
uint32 raceMask = GetEffectiveReputationRaceMask(_player);
|
||||
uint32 classMask = _player->getClassMask();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -147,7 +161,7 @@ uint32 ReputationMgr::GetDefaultStateFlags(FactionEntry const* factionEntry) con
|
||||
if (!factionEntry)
|
||||
return 0;
|
||||
|
||||
uint32 raceMask = _player->getRaceMask();
|
||||
uint32 raceMask = GetEffectiveReputationRaceMask(_player);
|
||||
uint32 classMask = _player->getClassMask();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
@@ -464,10 +478,18 @@ void ReputationMgr::SetVisible(FactionTemplateEntry const* factionTemplateEntry)
|
||||
return;
|
||||
|
||||
if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplateEntry->faction))
|
||||
{
|
||||
if (_player->GetTeamId() != _player->GetTeamId(true))
|
||||
{
|
||||
SetVisible(factionEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
// Never show factions of the opposing team
|
||||
if (!(factionEntry->BaseRepRaceMask[1] & _player->getRaceMask() && factionEntry->BaseRepValue[1] == Reputation_Bottom))
|
||||
SetVisible(factionEntry);
|
||||
}
|
||||
}
|
||||
|
||||
void ReputationMgr::SetVisible(FactionEntry const* factionEntry)
|
||||
{
|
||||
|
||||
@@ -215,6 +215,11 @@ void ScriptMgr::OnPlayerLoadFromDB(Player* player)
|
||||
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_LOAD_FROM_DB, script->OnPlayerLoadFromDB(player));
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerReputationLoadFromDB(Player* player)
|
||||
{
|
||||
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_REPUTATION_LOAD_FROM_DB, script->OnPlayerReputationLoadFromDB(player));
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerBeforeLogout(Player* player)
|
||||
{
|
||||
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_BEFORE_LOGOUT, script->OnPlayerBeforeLogout(player));
|
||||
|
||||
@@ -67,6 +67,7 @@ enum PlayerHook
|
||||
PLAYERHOOK_ON_TEXT_EMOTE,
|
||||
PLAYERHOOK_ON_SPELL_CAST,
|
||||
PLAYERHOOK_ON_LOAD_FROM_DB,
|
||||
PLAYERHOOK_ON_REPUTATION_LOAD_FROM_DB,
|
||||
PLAYERHOOK_ON_LOGIN,
|
||||
PLAYERHOOK_ON_BEFORE_LOGOUT,
|
||||
PLAYERHOOK_ON_LOGOUT,
|
||||
@@ -320,6 +321,7 @@ public:
|
||||
|
||||
// Called during data loading
|
||||
virtual void OnPlayerLoadFromDB(Player* /*player*/) { };
|
||||
virtual void OnPlayerReputationLoadFromDB(Player* /*player*/) { };
|
||||
|
||||
// Called when a player logs in.
|
||||
virtual void OnPlayerLogin(Player* /*player*/) { }
|
||||
|
||||
@@ -346,6 +346,7 @@ public: /* PlayerScript */
|
||||
void OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck);
|
||||
void OnPlayerLogin(Player* player);
|
||||
void OnPlayerLoadFromDB(Player* player);
|
||||
void OnPlayerReputationLoadFromDB(Player* player);
|
||||
void OnPlayerBeforeLogout(Player* player);
|
||||
void OnPlayerLogout(Player* player);
|
||||
void OnPlayerCreate(Player* player);
|
||||
|
||||
@@ -111,12 +111,14 @@ public:
|
||||
{
|
||||
if (sCharacterCache->HasCharacterCacheEntry(cPlayer->GetGUID()))
|
||||
{
|
||||
sCharacterCache->UpdateCharacterData(cPlayer->GetGUID(), cPlayer->GetName(), cPlayer->getGender(), cPlayer->getRace());
|
||||
sCharacterCache->UpdateCharacterData(cPlayer->GetGUID(), cPlayer->GetName(), cPlayer->getGender(), cPlayer->getRace(),
|
||||
cPlayer->GetUInt32Value(PLAYER_FLAGS), static_cast<uint8>(cPlayer->GetGameMode()));
|
||||
}
|
||||
else
|
||||
{
|
||||
sCharacterCache->AddCharacterCacheEntry(cPlayer->GetGUID(), cPlayer->GetSession()->GetAccountId(), cPlayer->GetName(),
|
||||
cPlayer->getGender(), cPlayer->getRace(), cPlayer->getClass(), cPlayer->GetLevel());
|
||||
cPlayer->getGender(), cPlayer->getRace(), cPlayer->getClass(), cPlayer->GetLevel(),
|
||||
cPlayer->GetUInt32Value(PLAYER_FLAGS), static_cast<uint8>(cPlayer->GetGameMode()));
|
||||
}
|
||||
|
||||
sCharacterCache->UpdateCharacterAccountId(cPlayer->GetGUID(), cPlayer->GetSession()->GetAccountId());
|
||||
|
||||
Reference in New Issue
Block a user