Small BattlegroundScore refactoring
This commit is contained in:
+23
-5
@@ -95,6 +95,23 @@ namespace Game.Arenas
|
||||
CheckWinConditions();
|
||||
}
|
||||
|
||||
public override void BuildPvPLogDataPacket(out PVPLogData pvpLogData)
|
||||
{
|
||||
base.BuildPvPLogDataPacket(out pvpLogData);
|
||||
|
||||
if (isRated())
|
||||
{
|
||||
pvpLogData.Ratings.HasValue = true;
|
||||
|
||||
for (byte i = 0; i < SharedConst.BGTeamsCount; ++i)
|
||||
{
|
||||
pvpLogData.Ratings.Value.Postmatch[i] = _arenaTeamScores[i].PostMatchRating;
|
||||
pvpLogData.Ratings.Value.Prematch[i] = _arenaTeamScores[i].PreMatchRating;
|
||||
pvpLogData.Ratings.Value.PrematchMMR[i] = _arenaTeamScores[i].PreMatchMMR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket)
|
||||
{
|
||||
if (isRated() && GetStatus() == BattlegroundStatus.InProgress)
|
||||
@@ -177,8 +194,8 @@ namespace Game.Arenas
|
||||
byte winnerTeam = (byte)(winner == Team.Alliance ? BattlegroundTeamId.Alliance : BattlegroundTeamId.Horde);
|
||||
byte loserTeam = (byte)(winner == Team.Alliance ? BattlegroundTeamId.Horde : BattlegroundTeamId.Alliance);
|
||||
|
||||
_arenaTeamScores[winnerTeam].Assign((int)winnerTeamRating, (int)(winnerTeamRating + winnerChange), winnerMatchmakerRating);
|
||||
_arenaTeamScores[loserTeam].Assign((int)loserTeamRating, (int)(loserTeamRating + loserChange), loserMatchmakerRating);
|
||||
_arenaTeamScores[winnerTeam].Assign(winnerTeamRating, (uint)(winnerTeamRating + winnerChange), winnerMatchmakerRating, GetArenaMatchmakerRating(winner));
|
||||
_arenaTeamScores[loserTeam].Assign(loserTeamRating, (uint)(loserTeamRating + loserChange), loserMatchmakerRating, GetArenaMatchmakerRating(GetOtherTeam(winner)));
|
||||
|
||||
Log.outDebug(LogFilter.Arena, "Arena match Type: {0} for Team1Id: {1} - Team2Id: {2} ended. WinnerTeamId: {3}. Winner rating: +{4}, Loser rating: {5}",
|
||||
GetArenaType(), GetArenaTeamIdByIndex(TeamId.Alliance), GetArenaTeamIdByIndex(TeamId.Horde), winnerArenaTeam.GetId(), winnerChange, loserChange);
|
||||
@@ -200,9 +217,8 @@ namespace Game.Arenas
|
||||
// Deduct 16 points from each teams arena-rating if there are no winners after 45+2 minutes
|
||||
else
|
||||
{
|
||||
_arenaTeamScores[(int)BattlegroundTeamId.Alliance].Assign((int)winnerTeamRating, (int)(winnerTeamRating + SharedConst.ArenaTimeLimitPointsLoss), winnerMatchmakerRating);
|
||||
_arenaTeamScores[(int)BattlegroundTeamId.Horde].Assign((int)loserTeamRating, (int)(loserTeamRating + SharedConst.ArenaTimeLimitPointsLoss), loserMatchmakerRating);
|
||||
|
||||
_arenaTeamScores[(int)BattlegroundTeamId.Alliance].Assign(winnerTeamRating, (uint)(winnerTeamRating + SharedConst.ArenaTimeLimitPointsLoss), winnerMatchmakerRating, GetArenaMatchmakerRating(Team.Alliance));
|
||||
_arenaTeamScores[(int)BattlegroundTeamId.Horde].Assign(loserTeamRating, (uint)(loserTeamRating + SharedConst.ArenaTimeLimitPointsLoss), loserMatchmakerRating, GetArenaMatchmakerRating(Team.Horde));
|
||||
|
||||
winnerArenaTeam.FinishGame(SharedConst.ArenaTimeLimitPointsLoss);
|
||||
loserArenaTeam.FinishGame(SharedConst.ArenaTimeLimitPointsLoss);
|
||||
@@ -283,6 +299,8 @@ namespace Game.Arenas
|
||||
// end Battleground
|
||||
base.EndBattleground(winner);
|
||||
}
|
||||
|
||||
public ArenaTeamScore[] _arenaTeamScores = new ArenaTeamScore[SharedConst.BGTeamsCount];
|
||||
}
|
||||
|
||||
struct ArenaWorldStates
|
||||
|
||||
+31
-16
@@ -19,6 +19,7 @@ using Framework.Constants;
|
||||
using Game.BattleGrounds;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
using Game.Network.Packets;
|
||||
|
||||
namespace Game.Arenas
|
||||
{
|
||||
@@ -29,33 +30,47 @@ namespace Game.Arenas
|
||||
TeamId = (int)(team == Team.Alliance ? BattlegroundTeamId.Alliance : BattlegroundTeamId.Horde);
|
||||
}
|
||||
|
||||
public override void BuildObjectivesBlock(List<int> stats) { }
|
||||
void BuildPvPLogPlayerDataPacket(PVPLogData.PlayerData playerData)
|
||||
{
|
||||
if (PreMatchRating != 0)
|
||||
playerData.PreMatchRating.Set(PreMatchRating);
|
||||
|
||||
if (PostMatchRating != PreMatchRating)
|
||||
playerData.RatingChange.Set((int)(PostMatchRating - PreMatchRating));
|
||||
|
||||
if (PreMatchMMR != 0)
|
||||
playerData.PreMatchMMR.Set(PreMatchMMR);
|
||||
|
||||
if (PostMatchMMR != PreMatchMMR)
|
||||
playerData.MmrChange.Set((int)(PostMatchMMR - PreMatchMMR));
|
||||
}
|
||||
|
||||
// For Logging purpose
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("Damage done: {0}, Healing done: {1}, Killing blows: {2}", DamageDone, HealingDone, KillingBlows);
|
||||
return $"Damage done: {DamageDone} Healing done: {HealingDone} Killing blows: {KillingBlows} PreMatchRating: {PreMatchRating} " +
|
||||
$"PreMatchMMR: {PreMatchMMR} PostMatchRating: {PostMatchRating} PostMatchMMR: {PostMatchMMR}";
|
||||
}
|
||||
|
||||
uint PreMatchRating;
|
||||
uint PreMatchMMR;
|
||||
uint PostMatchRating;
|
||||
uint PostMatchMMR;
|
||||
}
|
||||
|
||||
public class ArenaTeamScore
|
||||
{
|
||||
void Reset()
|
||||
public void Assign(uint preMatchRating, uint postMatchRating, uint preMatchMMR, uint postMatchMMR)
|
||||
{
|
||||
OldRating = 0;
|
||||
NewRating = 0;
|
||||
MatchmakerRating = 0;
|
||||
PreMatchRating = preMatchRating;
|
||||
PostMatchRating = postMatchRating;
|
||||
PreMatchMMR = preMatchMMR;
|
||||
PostMatchMMR = postMatchMMR;
|
||||
}
|
||||
|
||||
public void Assign(int oldRating, int newRating, uint matchMakerRating)
|
||||
{
|
||||
OldRating = oldRating;
|
||||
NewRating = newRating;
|
||||
MatchmakerRating = matchMakerRating;
|
||||
}
|
||||
|
||||
public int OldRating;
|
||||
public int NewRating;
|
||||
public uint MatchmakerRating;
|
||||
public uint PreMatchRating;
|
||||
public uint PostMatchRating;
|
||||
public uint PreMatchMMR;
|
||||
public uint PostMatchMMR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +515,13 @@ namespace Game.BattleGrounds
|
||||
return player;
|
||||
}
|
||||
|
||||
public void SetTeamStartLoc(int teamIndex, Position pos)
|
||||
public BattlegroundMap GetBgMap()
|
||||
{
|
||||
Contract.Assert(m_Map);
|
||||
return m_Map;
|
||||
}
|
||||
|
||||
public void SetTeamStartPosition(int teamIndex, Position pos)
|
||||
{
|
||||
Contract.Assert(teamIndex < TeamId.Neutral);
|
||||
StartPosition[teamIndex] = pos;
|
||||
@@ -1196,7 +1202,7 @@ namespace Game.BattleGrounds
|
||||
return GetPlayersSize() < GetMaxPlayers();
|
||||
}
|
||||
|
||||
public void BuildPvPLogDataPacket(out PVPLogData pvpLogData)
|
||||
public virtual void BuildPvPLogDataPacket(out PVPLogData pvpLogData)
|
||||
{
|
||||
pvpLogData = new PVPLogData();
|
||||
|
||||
@@ -1205,57 +1211,25 @@ namespace Game.BattleGrounds
|
||||
|
||||
foreach (var score in PlayerScores)
|
||||
{
|
||||
PVPLogData.PlayerData playerData = new PVPLogData.PlayerData();
|
||||
PVPLogData.PlayerData playerData;
|
||||
|
||||
playerData.PlayerGUID = score.Value.PlayerGuid;
|
||||
playerData.Kills = score.Value.KillingBlows;
|
||||
playerData.Faction = (byte)score.Value.TeamId;
|
||||
if (score.Value.HonorableKills != 0 || score.Value.Deaths != 0 || score.Value.BonusHonor != 0)
|
||||
{
|
||||
playerData.Honor.HasValue = true;
|
||||
PVPLogData.HonorData honorData = playerData.Honor.Value;
|
||||
honorData.HonorKills = score.Value.HonorableKills;
|
||||
honorData.Deaths = score.Value.Deaths;
|
||||
honorData.ContributionPoints = score.Value.BonusHonor;
|
||||
}
|
||||
|
||||
playerData.DamageDone = score.Value.DamageDone;
|
||||
playerData.HealingDone = score.Value.HealingDone;
|
||||
score.Value.BuildObjectivesBlock(playerData.Stats);
|
||||
score.Value.BuildPvPLogPlayerDataPacket(out playerData);
|
||||
|
||||
Player player = Global.ObjAccessor.GetPlayer(GetBgMap(), playerData.PlayerGUID);
|
||||
if (player)
|
||||
{
|
||||
playerData.IsInWorld = true;
|
||||
playerData.PrimaryTalentTree = (int)player.GetUInt32Value(PlayerFields.CurrentSpecId);
|
||||
playerData.PrimaryTalentTreeNameIndex = 0;
|
||||
playerData.PlayerRace = player.GetRace();
|
||||
playerData.Prestige = player.GetPrestigeLevel();
|
||||
}
|
||||
|
||||
//if (isRated())
|
||||
//{
|
||||
// playerData.PreMatchRating;
|
||||
// playerData.RatingChange;
|
||||
// playerData.PreMatchMMR;
|
||||
// playerData.MmrChange;
|
||||
//}
|
||||
|
||||
pvpLogData.Players.Add(playerData);
|
||||
}
|
||||
|
||||
if (isRated())
|
||||
{
|
||||
pvpLogData.Ratings.HasValue = true;
|
||||
PVPLogData.RatingData ratingData = pvpLogData.Ratings.Value;
|
||||
for (byte i = 0; i < SharedConst.BGTeamsCount; ++i)
|
||||
{
|
||||
ratingData.Postmatch[i] = _arenaTeamScores[i].NewRating;
|
||||
ratingData.Prematch[i] = _arenaTeamScores[i].OldRating;
|
||||
ratingData.PrematchMMR[i] = (int)_arenaTeamScores[i].MatchmakerRating;
|
||||
}
|
||||
}
|
||||
|
||||
pvpLogData.PlayerCount[0] = (sbyte)GetPlayersCountByTeam(Team.Horde);
|
||||
pvpLogData.PlayerCount[1] = (sbyte)GetPlayersCountByTeam(Team.Alliance);
|
||||
pvpLogData.PlayerCount[(int)BattlegroundTeamId.Horde] = (sbyte)GetPlayersCountByTeam(Team.Horde);
|
||||
pvpLogData.PlayerCount[(int)BattlegroundTeamId.Alliance] = (sbyte)GetPlayersCountByTeam(Team.Alliance);
|
||||
}
|
||||
|
||||
public virtual bool UpdatePlayerScore(Player player, ScoreType type, uint value, bool doAddHonor = true)
|
||||
@@ -1907,7 +1881,6 @@ namespace Game.BattleGrounds
|
||||
public uint GetMapId() { return m_MapId; }
|
||||
|
||||
public void SetBgMap(BattlegroundMap map) { m_Map = map; }
|
||||
public BattlegroundMap GetBgMap() { return m_Map; }
|
||||
BattlegroundMap FindBgMap() { return m_Map; }
|
||||
|
||||
public Position GetTeamStartPosition(int teamIndex)
|
||||
@@ -2007,8 +1980,6 @@ namespace Game.BattleGrounds
|
||||
public BGHonorMode m_HonorMode;
|
||||
public uint[] m_TeamScores = new uint[SharedConst.BGTeamsCount];
|
||||
|
||||
public ArenaTeamScore[] _arenaTeamScores = new ArenaTeamScore[SharedConst.BGTeamsCount];
|
||||
|
||||
protected Dictionary<int, ObjectGuid> BgObjects = new Dictionary<int, ObjectGuid>();
|
||||
protected Dictionary<int, ObjectGuid> BgCreatures = new Dictionary<int, ObjectGuid>();
|
||||
|
||||
|
||||
@@ -374,8 +374,8 @@ namespace Game.BattleGrounds
|
||||
bg.SetMaxPlayersPerTeam(bgTemplate.MaxPlayersPerTeam);
|
||||
bg.SetMinPlayers(bgTemplate.MinPlayersPerTeam * 2);
|
||||
bg.SetMaxPlayers(bgTemplate.MaxPlayersPerTeam * 2);
|
||||
bg.SetTeamStartLoc(TeamId.Alliance, bgTemplate.StartLocation[TeamId.Alliance]);
|
||||
bg.SetTeamStartLoc(TeamId.Horde, bgTemplate.StartLocation[TeamId.Horde]);
|
||||
bg.SetTeamStartPosition(TeamId.Alliance, bgTemplate.StartLocation[TeamId.Alliance]);
|
||||
bg.SetTeamStartPosition(TeamId.Horde, bgTemplate.StartLocation[TeamId.Horde]);
|
||||
bg.SetStartMaxDist(bgTemplate.StartMaxDist);
|
||||
bg.SetLevelRange(bgTemplate.MinLevel, bgTemplate.MaxLevel);
|
||||
bg.SetScriptId(bgTemplate.scriptId);
|
||||
|
||||
@@ -19,6 +19,7 @@ using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Game.Network.Packets;
|
||||
|
||||
namespace Game.BattleGrounds
|
||||
{
|
||||
@@ -27,7 +28,7 @@ namespace Game.BattleGrounds
|
||||
public BattlegroundScore(ObjectGuid playerGuid, Team team)
|
||||
{
|
||||
PlayerGuid = playerGuid;
|
||||
TeamId = team == Team.Alliance ? 1 : 0;
|
||||
TeamId = (int)(team == Team.Alliance ? BattlegroundTeamId.Alliance : BattlegroundTeamId.Horde);
|
||||
}
|
||||
|
||||
public virtual void UpdateScore(ScoreType type, uint value)
|
||||
@@ -58,7 +59,23 @@ namespace Game.BattleGrounds
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void BuildObjectivesBlock(List<int> stats) { }
|
||||
public virtual void BuildPvPLogPlayerDataPacket(out PVPLogData.PlayerData playerData)
|
||||
{
|
||||
playerData = new PVPLogData.PlayerData();
|
||||
playerData.PlayerGUID = PlayerGuid;
|
||||
playerData.Kills = KillingBlows;
|
||||
playerData.Faction = (byte)TeamId;
|
||||
if (HonorableKills != 0 || Deaths != 0 || BonusHonor != 0)
|
||||
{
|
||||
playerData.Honor.HasValue = true;
|
||||
playerData.Honor.Value.HonorKills = HonorableKills;
|
||||
playerData.Honor.Value.Deaths = Deaths;
|
||||
playerData.Honor.Value.ContributionPoints = BonusHonor;
|
||||
}
|
||||
|
||||
playerData.DamageDone = DamageDone;
|
||||
playerData.HealingDone = HealingDone;
|
||||
}
|
||||
|
||||
public virtual uint GetAttr1() { return 0; }
|
||||
public virtual uint GetAttr2() { return 0; }
|
||||
|
||||
@@ -863,10 +863,12 @@ namespace Game.BattleGrounds
|
||||
}
|
||||
}
|
||||
|
||||
public override void BuildObjectivesBlock(List<int> stats)
|
||||
public override void BuildPvPLogPlayerDataPacket(out PVPLogData.PlayerData playerData)
|
||||
{
|
||||
stats.Add((int)BasesAssaulted);
|
||||
stats.Add((int)BasesDefended);
|
||||
base.BuildPvPLogPlayerDataPacket(out playerData);
|
||||
|
||||
playerData.Stats.Add(BasesAssaulted);
|
||||
playerData.Stats.Add(BasesDefended);
|
||||
}
|
||||
|
||||
public override uint GetAttr1() { return BasesAssaulted; }
|
||||
|
||||
@@ -1021,9 +1021,12 @@ namespace Game.BattleGrounds
|
||||
break;
|
||||
}
|
||||
}
|
||||
public override void BuildObjectivesBlock(List<int> stats)
|
||||
|
||||
public override void BuildPvPLogPlayerDataPacket(out PVPLogData.PlayerData playerData)
|
||||
{
|
||||
stats.Add((int)FlagCaptures);
|
||||
base.BuildPvPLogPlayerDataPacket(out playerData);
|
||||
|
||||
playerData.Stats.Add(FlagCaptures);
|
||||
}
|
||||
|
||||
public override uint GetAttr1() { return FlagCaptures; }
|
||||
|
||||
@@ -982,10 +982,12 @@ namespace Game.BattleGrounds
|
||||
}
|
||||
}
|
||||
|
||||
public override void BuildObjectivesBlock(List<int> stats)
|
||||
public override void BuildPvPLogPlayerDataPacket(out PVPLogData.PlayerData playerData)
|
||||
{
|
||||
stats.Add((int)FlagCaptures);
|
||||
stats.Add((int)FlagReturns);
|
||||
base.BuildPvPLogPlayerDataPacket(out playerData);
|
||||
|
||||
playerData.Stats.Add(FlagCaptures);
|
||||
playerData.Stats.Add(FlagReturns);
|
||||
}
|
||||
|
||||
public override uint GetAttr1() { return FlagCaptures; }
|
||||
|
||||
@@ -108,18 +108,18 @@ namespace Game.Network.Packets
|
||||
public void Write(WorldPacket data)
|
||||
{
|
||||
foreach (var id in Prematch)
|
||||
data.WriteInt32(id);
|
||||
data.WriteUInt32(id);
|
||||
|
||||
foreach (var id in Postmatch)
|
||||
data.WriteInt32(id);
|
||||
data.WriteUInt32(id);
|
||||
|
||||
foreach (var id in PrematchMMR)
|
||||
data.WriteInt32(id);
|
||||
data.WriteUInt32(id);
|
||||
}
|
||||
|
||||
public int[] Prematch = new int[2];
|
||||
public int[] Postmatch = new int[2];
|
||||
public int[] PrematchMMR = new int[2];
|
||||
public uint[] Prematch = new uint[2];
|
||||
public uint[] Postmatch = new uint[2];
|
||||
public uint[] PrematchMMR = new uint[2];
|
||||
}
|
||||
|
||||
public struct HonorData
|
||||
@@ -149,7 +149,7 @@ namespace Game.Network.Packets
|
||||
data.WriteInt32(PrimaryTalentTreeNameIndex);
|
||||
data.WriteInt32(PlayerRace);
|
||||
if (!Stats.Empty())
|
||||
Stats.ForEach(id => data.WriteInt32(id));
|
||||
Stats.ForEach(id => data.WriteUInt32(id));
|
||||
|
||||
data.WriteBit(Faction);
|
||||
data.WriteBit(IsInWorld);
|
||||
@@ -187,7 +187,7 @@ namespace Game.Network.Packets
|
||||
public Optional<int> RatingChange;
|
||||
public Optional<uint> PreMatchMMR;
|
||||
public Optional<int> MmrChange;
|
||||
public List<int> Stats = new List<int>();
|
||||
public List<uint> Stats = new List<uint>();
|
||||
public int PrimaryTalentTree;
|
||||
public int PrimaryTalentTreeNameIndex; // controls which name field from ChrSpecialization.dbc will be sent to lua
|
||||
public Race PlayerRace;
|
||||
|
||||
Reference in New Issue
Block a user