Core/Misc: Moved CharacterInfo out of world to separate class
Port From (https://github.com/TrinityCore/TrinityCore/commit/ad4e63bae145ae49b584ab2fc621660430cec0d3)
This commit is contained in:
@@ -206,7 +206,7 @@ namespace Game.Entities
|
||||
public bool IsExpired(long t)
|
||||
{
|
||||
// Deleted character
|
||||
if (Global.WorldMgr.GetCharacterInfo(GetOwnerGUID()) == null)
|
||||
if (!Global.CharacterCacheStorage.HasCharacterCacheEntry(GetOwnerGUID()))
|
||||
return true;
|
||||
|
||||
if (m_type == CorpseType.Bones)
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Game.Entities
|
||||
m_corpseRemoveTime = Time.UnixTime;
|
||||
setDeathState(DeathState.Dead);
|
||||
RemoveAllAuras();
|
||||
UpdateObjectVisibility();
|
||||
DestroyForNearbyPlayers(); // old UpdateObjectVisibility()
|
||||
loot.clear();
|
||||
uint respawnDelay = m_respawnDelay;
|
||||
if (IsAIEnabled)
|
||||
|
||||
@@ -784,7 +784,7 @@ namespace Game.Entities
|
||||
if (!m_spawnedByDefault)
|
||||
{
|
||||
m_respawnTime = 0;
|
||||
UpdateObjectVisibility();
|
||||
DestroyForNearbyPlayers(); // old UpdateObjectVisibility()
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -794,8 +794,7 @@ namespace Game.Entities
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.SaveRespawnTimeImmediately))
|
||||
SaveRespawnTime();
|
||||
|
||||
UpdateObjectVisibility();
|
||||
|
||||
DestroyForNearbyPlayers(); // old UpdateObjectVisibility()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ using Framework.Constants;
|
||||
using Framework.Database;
|
||||
using Game.Arenas;
|
||||
using Game.BattleGrounds;
|
||||
using Game.Cache;
|
||||
using Game.DataStorage;
|
||||
using Game.Garrisons;
|
||||
using Game.Groups;
|
||||
@@ -630,6 +631,13 @@ namespace Game.Entities
|
||||
_currencyStorage.Add(currencyID, cur);
|
||||
} while (result.NextRow());
|
||||
}
|
||||
void LoadActions(SQLResult result)
|
||||
{
|
||||
if (!result.IsEmpty())
|
||||
_LoadActions(result);
|
||||
|
||||
SendActionButtons(1);
|
||||
}
|
||||
void _LoadActions(SQLResult result)
|
||||
{
|
||||
m_actionButtons.Clear();
|
||||
@@ -2333,7 +2341,7 @@ namespace Game.Entities
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
string name;
|
||||
ObjectManager.GetPlayerNameByGUID(guid, out name);
|
||||
Global.CharacterCacheStorage.GetCharacterNameByGuid(guid, out name);
|
||||
Log.outError(LogFilter.Player, "Player {0} {1} not found in table `characters`, can't load. ", name, guid.ToString());
|
||||
return false;
|
||||
}
|
||||
@@ -3462,26 +3470,6 @@ namespace Game.Entities
|
||||
DB.Characters.Execute(stmt);
|
||||
}
|
||||
|
||||
public static uint GetGuildIdFromDB(ObjectGuid guid)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_MEMBER);
|
||||
stmt.AddValue(0, guid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
return result.Read<uint>(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
public static byte GetRankFromDB(ObjectGuid guid)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUILD_MEMBER);
|
||||
stmt.AddValue(0, guid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
if (!result.IsEmpty())
|
||||
return result.Read<byte>(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
public static uint GetZoneIdFromDB(ObjectGuid guid)
|
||||
{
|
||||
ulong guidLow = guid.GetCounter();
|
||||
@@ -3527,17 +3515,6 @@ namespace Game.Entities
|
||||
|
||||
return zone;
|
||||
}
|
||||
public static uint GetLevelFromDB(ObjectGuid guid)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHAR_LEVEL);
|
||||
stmt.AddValue(0, guid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
return 0;
|
||||
|
||||
return result.Read<byte>(0);
|
||||
}
|
||||
public static void RemovePetitionsAndSigns(ObjectGuid guid)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION_SIG_BY_GUID);
|
||||
@@ -3582,18 +3559,21 @@ namespace Game.Entities
|
||||
// Convert guid to low GUID for CharacterNameData, but also other methods on success
|
||||
ulong guid = playerGuid.GetCounter();
|
||||
CharDeleteMethod charDelete_method = (CharDeleteMethod)WorldConfig.GetIntValue(WorldCfg.ChardeleteMethod);
|
||||
CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(playerGuid);
|
||||
string name = "<Unknown>";
|
||||
if (characterInfo != null)
|
||||
name = characterInfo.Name;
|
||||
|
||||
CharacterInfo characterInfo;
|
||||
if (deleteFinally)
|
||||
charDelete_method = CharDeleteMethod.Remove;
|
||||
else if ((characterInfo = Global.WorldMgr.GetCharacterInfo(playerGuid)) != null) // To avoid a Select, we select loaded data. If it doesn't exist, return.
|
||||
else if (characterInfo != null) // To avoid a Select, we select loaded data. If it doesn't exist, return.
|
||||
{
|
||||
// Define the required variables
|
||||
uint charDeleteMinLvl;
|
||||
|
||||
if (characterInfo.ClassID == Class.Deathknight)
|
||||
if (characterInfo.ClassId == Class.Deathknight)
|
||||
charDeleteMinLvl = WorldConfig.GetUIntValue(WorldCfg.ChardeleteDeathKnightMinLevel);
|
||||
else if (characterInfo.ClassID == Class.DemonHunter)
|
||||
else if (characterInfo.ClassId == Class.DemonHunter)
|
||||
charDeleteMinLvl = WorldConfig.GetUIntValue(WorldCfg.ChardeleteDemonHunterMinLevel);
|
||||
else
|
||||
charDeleteMinLvl = WorldConfig.GetUIntValue(WorldCfg.ChardeleteMinLevel);
|
||||
@@ -3605,7 +3585,7 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
SQLTransaction trans = new SQLTransaction();
|
||||
uint guildId = GetGuildIdFromDB(playerGuid);
|
||||
ulong guildId = Global.CharacterCacheStorage.GetCharacterGuildIdByGuid(playerGuid);
|
||||
if (guildId != 0)
|
||||
{
|
||||
Guild guild = Global.GuildMgr.GetGuildById(guildId);
|
||||
@@ -3714,7 +3694,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(0, mail_id);
|
||||
trans.Append(stmt);
|
||||
|
||||
uint pl_account = ObjectManager.GetPlayerAccountIdByGUID(ObjectGuid.Create(HighGuid.Player, guid));
|
||||
uint pl_account = Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(ObjectGuid.Create(HighGuid.Player, guid));
|
||||
|
||||
draft.AddMoney(money).SendReturnToSender(pl_account, guid, sender, trans);
|
||||
}
|
||||
@@ -3955,7 +3935,7 @@ namespace Game.Entities
|
||||
|
||||
Garrison.DeleteFromDB(guid, trans);
|
||||
|
||||
Global.WorldMgr.DeleteCharacterInfo(playerGuid);
|
||||
Global.CharacterCacheStorage.DeleteCharacterCacheEntry(playerGuid, name);
|
||||
break;
|
||||
}
|
||||
// The character gets unlinked from the account, the name gets freed up and appears as deleted ingame
|
||||
@@ -3965,7 +3945,7 @@ namespace Game.Entities
|
||||
stmt.AddValue(0, guid);
|
||||
trans.Append(stmt);
|
||||
|
||||
Global.WorldMgr.UpdateCharacterInfoDeleted(playerGuid, true);
|
||||
Global.CharacterCacheStorage.UpdateCharacterInfoDeleted(playerGuid, true);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -20,6 +20,7 @@ using Framework.Database;
|
||||
using Game.Arenas;
|
||||
using Game.BattleFields;
|
||||
using Game.BattleGrounds;
|
||||
using Game.Cache;
|
||||
using Game.DataStorage;
|
||||
using Game.Network.Packets;
|
||||
using Game.PvP;
|
||||
@@ -887,31 +888,15 @@ namespace Game.Entities
|
||||
SetArenaTeamInfoField(slot, ArenaTeamInfoType.Type, type);
|
||||
}
|
||||
|
||||
public static uint GetArenaTeamIdFromDB(ObjectGuid guid, byte type)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_ARENA_TEAM_ID_BY_PLAYER_GUID);
|
||||
stmt.AddValue(0, guid.GetCounter());
|
||||
stmt.AddValue(1, type);
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
return 0;
|
||||
|
||||
return result.Read<uint>(0);
|
||||
}
|
||||
|
||||
public static void LeaveAllArenaTeams(ObjectGuid guid)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PLAYER_ARENA_TEAMS);
|
||||
stmt.AddValue(0, guid.GetCounter());
|
||||
SQLResult result = DB.Characters.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(guid);
|
||||
if (characterInfo == null)
|
||||
return;
|
||||
|
||||
do
|
||||
for (byte i = 0; i < SharedConst.MaxArenaSlot; ++i)
|
||||
{
|
||||
uint arenaTeamId = result.Read<uint>(0);
|
||||
uint arenaTeamId = characterInfo.ArenaTeamId[i];
|
||||
if (arenaTeamId != 0)
|
||||
{
|
||||
ArenaTeam arenaTeam = Global.ArenaTeamMgr.GetArenaTeamById(arenaTeamId);
|
||||
@@ -919,7 +904,6 @@ namespace Game.Entities
|
||||
arenaTeam.DelMember(guid, true);
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
public uint GetArenaTeamId(byte slot) { return 0; }
|
||||
public uint GetArenaPersonalRating(byte slot) { return m_activePlayerData.PvpInfo[slot].Rating; }
|
||||
|
||||
@@ -1626,12 +1626,12 @@ namespace Game.Entities
|
||||
if (!qInfo.IsSeasonal() || m_seasonalquests.Empty())
|
||||
return true;
|
||||
|
||||
ushort eventId = Global.GameEventMgr.GetEventIdForQuest(qInfo);
|
||||
if (!m_seasonalquests.ContainsKey(eventId) || m_seasonalquests[eventId].Empty())
|
||||
var list = m_seasonalquests.LookupByKey(qInfo.GetEventIdForQuest());
|
||||
if (list == null || list.Empty())
|
||||
return true;
|
||||
|
||||
// if not found in cooldown list
|
||||
return !m_seasonalquests[eventId].Contains(qInfo.Id);
|
||||
return !list.Contains(qInfo.Id);
|
||||
}
|
||||
|
||||
public bool SatisfyQuestMonth(Quest qInfo, bool msg)
|
||||
@@ -1719,13 +1719,7 @@ namespace Game.Entities
|
||||
if (qInfo != null)
|
||||
{
|
||||
if (qInfo.IsSeasonal() && !qInfo.IsRepeatable())
|
||||
{
|
||||
ushort eventId = Global.GameEventMgr.GetEventIdForQuest(qInfo);
|
||||
if (m_seasonalquests.ContainsKey(eventId))
|
||||
return m_seasonalquests[eventId].Contains(quest_id);
|
||||
|
||||
return false;
|
||||
}
|
||||
return !SatisfyQuestSeasonal(qInfo, false);
|
||||
|
||||
// for repeatable quests: rewarded field is set after first reward only to prevent getting XP more than once
|
||||
if (!qInfo.IsRepeatable())
|
||||
@@ -1748,12 +1742,9 @@ namespace Game.Entities
|
||||
if (quest != null)
|
||||
{
|
||||
if (quest.IsSeasonal() && !quest.IsRepeatable())
|
||||
{
|
||||
ushort eventId = Global.GameEventMgr.GetEventIdForQuest(quest);
|
||||
if (!m_seasonalquests.ContainsKey(eventId) || !m_seasonalquests[eventId].Contains(questId))
|
||||
return QuestStatus.None;
|
||||
}
|
||||
if (!quest.IsRepeatable() && m_RewardedQuests.Contains(questId))
|
||||
return SatisfyQuestSeasonal(quest, false) ? QuestStatus.None : QuestStatus.Rewarded;
|
||||
|
||||
if (!quest.IsRepeatable() && IsQuestRewarded(questId))
|
||||
return QuestStatus.Rewarded;
|
||||
}
|
||||
}
|
||||
@@ -3049,7 +3040,7 @@ namespace Game.Entities
|
||||
if (quest == null)
|
||||
return;
|
||||
|
||||
m_seasonalquests.Add(Global.GameEventMgr.GetEventIdForQuest(quest), quest_id);
|
||||
m_seasonalquests.Add(quest.GetEventIdForQuest(), quest_id);
|
||||
m_SeasonalQuestChanged = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -381,9 +381,15 @@ namespace Game.Entities
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_CHARACTER_ACTIONS_SPEC);
|
||||
stmt.AddValue(0, GetGUID().GetCounter());
|
||||
stmt.AddValue(1, GetActiveTalentGroup());
|
||||
_LoadActions(DB.Characters.Query(stmt));
|
||||
|
||||
SendActionButtons(1);
|
||||
WorldSession mySess = GetSession();
|
||||
mySess.GetQueryProcessor().AddQuery(DB.Characters.AsyncQuery(stmt).WithCallback(result =>
|
||||
{
|
||||
// in case player logs out before db response (player would be deleted in that case)
|
||||
Player thisPlayer = mySess.GetPlayer();
|
||||
if (thisPlayer != null)
|
||||
thisPlayer.LoadActions(result);
|
||||
}));
|
||||
|
||||
UpdateDisplayPower();
|
||||
PowerType pw = GetPowerType();
|
||||
|
||||
@@ -791,7 +791,7 @@ namespace Game.Entities
|
||||
{
|
||||
base.DestroyForPlayer(target);
|
||||
|
||||
for (byte i = 0; i < InventorySlots.BagEnd; ++i)
|
||||
for (byte i = 0; i < EquipmentSlot.End; ++i)
|
||||
{
|
||||
if (m_items[i] == null)
|
||||
continue;
|
||||
@@ -5279,6 +5279,8 @@ namespace Game.Entities
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.GuildGUID), ObjectGuid.Empty);
|
||||
RemovePlayerFlag(PlayerFlags.GuildLevelEnabled);
|
||||
}
|
||||
|
||||
Global.CharacterCacheStorage.UpdateCharacterGuildId(GetGUID(), guildId);
|
||||
}
|
||||
public void SetGuildRank(byte rankId) { SetUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.GuildRankID), rankId); }
|
||||
public uint GetGuildRank() { return m_playerData.GuildRankID; }
|
||||
|
||||
@@ -986,10 +986,7 @@ namespace Game.Entities
|
||||
// Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings
|
||||
HitChance += (int)(modHitChance * 100.0f);
|
||||
|
||||
if (HitChance < 100)
|
||||
HitChance = 100;
|
||||
else if (HitChance > 10000)
|
||||
HitChance = 10000;
|
||||
MathFunctions.RoundToInterval(ref HitChance, 0, 10000);
|
||||
|
||||
int tmp = 10000 - HitChance;
|
||||
|
||||
|
||||
@@ -2073,7 +2073,8 @@ namespace Game.Entities
|
||||
{
|
||||
if (player.GetGroup())
|
||||
player.SetGroupUpdateFlag(GroupUpdateFlags.Level);
|
||||
Global.WorldMgr.UpdateCharacterInfoLevel(ToPlayer().GetGUID(), (byte)lvl);
|
||||
|
||||
Global.CharacterCacheStorage.UpdateCharacterLevel(ToPlayer().GetGUID(), (byte)lvl);
|
||||
}
|
||||
}
|
||||
public uint getLevel() { return m_unitData.Level; }
|
||||
|
||||
Reference in New Issue
Block a user