Skip to content

Commit 6f8734d

Browse files
authored
Merge pull request #367 from DevD4v3/feature/add-gungame-wins
Add GunGame wins as a persistent player statistic. Changes: * Added the GunGameWins statistic to PlayerInfo. * Persisted the statistic across all repository implementations (InMemory, MariaDB and SQLite). * Added UpdateGunGameWins to IPlayerRepository. * Updated SQL scripts and seed data. * Increment and update GunGame wins after a player completes the weapon progression. * Display GunGame wins in the /mystats command. * Added unit and integration tests.
2 parents c7a600b + 2f7f960 commit 6f8734d

20 files changed

Lines changed: 311 additions & 60 deletions

File tree

src/Application/GunGames/Results/PlayerLeveledDown.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void Handle(KillContext context)
2424
Level = victimProgression.WeaponLevel,
2525
Weapon = newWeapon.Name
2626
});
27+
2728
worldService.SendClientMessage(Color.Yellow, message);
2829
}
2930
}

src/Application/GunGames/Results/PlayerLeveledUp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void Handle(KillContext context)
2222
Level = killerProgression.WeaponLevel,
2323
Weapon = newWeapon.Name
2424
});
25+
2526
worldService.SendClientMessage(Color.Yellow, message);
2627
}
2728
}

src/Application/GunGames/Results/PlayerReachedFinalLevel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void Handle(KillContext context)
2020
Killer = context.Killer.Name,
2121
Weapon = newWeapon.Name
2222
});
23+
2324
worldService.SendClientMessage(Color.Yellow, message);
2425
}
2526
}

src/Application/GunGames/Results/PlayerScoredFinalKill.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
/// Handles the <see cref="GunGameResult.ScoredFinalKill"/> result.
55
/// </summary>
66
public class PlayerScoredFinalKill(
7-
IWorldService worldService) : IGunGameResultHandler
7+
IWorldService worldService,
8+
IPlayerRepository playerRepository) : IGunGameResultHandler
89
{
910
public GunGameResult Result => GunGameResult.ScoredFinalKill;
1011

1112
public void Handle(KillContext context)
1213
{
14+
PlayerInfo killerInfo = context.Killer.GetRequiredInfo();
15+
killerInfo.AddGunGameWins();
16+
playerRepository.UpdateGunGameWins(killerInfo);
17+
1318
var message = Smart.Format(GunGameMessages.PlayerScoredFinalKill, new
1419
{
1520
Killer = context.Killer.Name
1621
});
22+
1723
worldService.SendClientMessage(Color.Gold, message);
1824
}
1925
}

src/Application/Players/Accounts/IPlayerRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IPlayerRepository
1515
void UpdateDroppedFlags(PlayerInfo player);
1616
void UpdateReturnedFlags(PlayerInfo player);
1717
void UpdateHeadShots(PlayerInfo player);
18+
void UpdateGunGameWins(PlayerInfo player);
1819
void UpdateRole(PlayerInfo player);
1920
void UpdateSkin(PlayerInfo player);
2021
void UpdateRank(PlayerInfo player);

src/Application/Players/Accounts/PlayerInfo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public PlayerInfo() { }
5252
/// Indicates the number of shots that the player has made at the heads of other players.
5353
/// </summary>
5454
public int HeadShots { get; private set; }
55+
56+
/// <summary>
57+
/// Indicates the number of times the player has won a GunGame match.
58+
/// </summary>
59+
public int GunGameWins { get; private set; }
60+
5561
public RoleId RoleId { get; private set; } = RoleId.Basic;
5662
public int SkinId { get; private set; } = NoSkin;
5763
public RankId RankId { get; private set; } = RankId.Noob;
@@ -80,6 +86,7 @@ public PlayerInfo() { }
8086
public void AddDroppedFlags() => DroppedFlags++;
8187
public void AddReturnedFlags() => ReturnedFlags++;
8288
public void AddHeadShots() => HeadShots++;
89+
public void AddGunGameWins() => GunGameWins++;
8390

8491
public Result SetName(string value)
8592
{

src/Application/Players/Accounts/Statistics/PlayerStatsSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private static string GetPlayerContent(Player player)
116116
Dropped Flags: {playerInfo.DroppedFlags}
117117
Returned Flags: {playerInfo.ReturnedFlags}
118118
HeadShots: {playerInfo.HeadShots}
119+
GunGame Wins: {playerInfo.GunGameWins}
119120
Role: {playerInfo.RoleId}
120121
Rank: {playerInfo.RankId}
121122
Registration Date: {createdAt}

src/Persistence/Persistence.InMemory/FakePlayer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public FakePlayer(string name, string passwordHash)
2222
public int DroppedFlags { get; set; }
2323
public int ReturnedFlags { get; set; }
2424
public int HeadShots { get; set; }
25+
public int GunGameWins { get; set; }
2526
public int SkinId { get; set; } = NoSkin;
2627
public RoleId RoleId { get; set; } = RoleId.Basic;
2728
public RankId RankId { get; set; } = RankId.Noob;

src/Persistence/Persistence.InMemory/FakePlayerRepository.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ internal class FakePlayerRepository(
77
public void Create(PlayerInfo player)
88
{
99
var passwordHash = passwordHasher.HashPassword(player.Password);
10-
var fakePlayer = new FakePlayer(player.Name, passwordHash);
10+
var fakePlayer = new FakePlayer(player.Name, passwordHash)
11+
{
12+
TotalKills = player.TotalKills,
13+
TotalDeaths = player.TotalDeaths,
14+
MaxKillingSpree = player.MaxKillingSpree,
15+
BroughtFlags = player.BroughtFlags,
16+
CapturedFlags = player.CapturedFlags,
17+
DroppedFlags = player.DroppedFlags,
18+
ReturnedFlags = player.ReturnedFlags,
19+
HeadShots = player.HeadShots,
20+
GunGameWins = player.GunGameWins,
21+
SkinId = player.SkinId,
22+
RoleId = player.RoleId,
23+
RankId = player.RankId,
24+
CreatedAt = player.CreatedAt,
25+
LastConnection = player.LastConnection
26+
};
1127
players.Add(fakePlayer.Id, fakePlayer);
1228
// The Account ID is immutable and lacks a public setter; Reflection is used to modify it.
1329
player.SetValue(value: fakePlayer.Id, propertyName: nameof(PlayerInfo.AccountId));
@@ -47,6 +63,7 @@ public PlayerInfo GetOrDefault(string name)
4763
playerInfo.SetValue(value: fakePlayer.DroppedFlags, propertyName: nameof(PlayerInfo.DroppedFlags));
4864
playerInfo.SetValue(value: fakePlayer.ReturnedFlags, propertyName: nameof(PlayerInfo.ReturnedFlags));
4965
playerInfo.SetValue(value: fakePlayer.HeadShots, propertyName: nameof(PlayerInfo.HeadShots));
66+
playerInfo.SetValue(value: fakePlayer.GunGameWins, propertyName: nameof(PlayerInfo.GunGameWins));
5067
playerInfo.SetValue(value: fakePlayer.CreatedAt, propertyName: nameof(PlayerInfo.CreatedAt));
5168
playerInfo.SetValue(value: fakePlayer.LastConnection, propertyName: nameof(PlayerInfo.LastConnection));
5269
return playerInfo;
@@ -67,6 +84,9 @@ public void UpdateReturnedFlags(PlayerInfo player)
6784
public void UpdateHeadShots(PlayerInfo player)
6885
=> players[player.AccountId].HeadShots = player.HeadShots;
6986

87+
public void UpdateGunGameWins(PlayerInfo player)
88+
=> players[player.AccountId].GunGameWins = player.GunGameWins;
89+
7090
public void UpdateLastConnection(PlayerInfo player)
7191
=> players[player.AccountId].LastConnection = player.LastConnection;
7292

src/Persistence/Persistence.MariaDB/PlayerRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void Create(PlayerInfo player)
2323
command.Parameters.AddWithValue("@dropped_flags", player.DroppedFlags);
2424
command.Parameters.AddWithValue("@returned_flags", player.ReturnedFlags);
2525
command.Parameters.AddWithValue("@head_shots", player.HeadShots);
26+
command.Parameters.AddWithValue("@gungame_wins", player.GunGameWins);
2627
command.Parameters.AddWithValue("@role_id", player.RoleId.ToString());
2728
command.Parameters.AddWithValue("@skin_id", player.SkinId);
2829
command.Parameters.AddWithValue("@rank_id", player.RankId);
@@ -81,6 +82,7 @@ public PlayerInfo GetOrDefault(string name)
8182
playerInfo.SetValue(value: reader.GetInt32("dropped_flags"), propertyName: nameof(PlayerInfo.DroppedFlags));
8283
playerInfo.SetValue(value: reader.GetInt32("returned_flags"), propertyName: nameof(PlayerInfo.ReturnedFlags));
8384
playerInfo.SetValue(value: reader.GetInt32("head_shots"), propertyName: nameof(PlayerInfo.HeadShots));
85+
playerInfo.SetValue(value: reader.GetInt32("gungame_wins"), propertyName: nameof(PlayerInfo.GunGameWins));
8486
playerInfo.SetValue(value: reader.GetDateTime("created_at"), propertyName: nameof(PlayerInfo.CreatedAt));
8587
playerInfo.SetValue(value: reader.GetDateTime("last_connection"), propertyName: nameof(PlayerInfo.LastConnection));
8688
return playerInfo;
@@ -101,6 +103,9 @@ public void UpdateReturnedFlags(PlayerInfo player)
101103
public void UpdateHeadShots(PlayerInfo player)
102104
=> Update(player.AccountId, "head_shots", player.HeadShots);
103105

106+
public void UpdateGunGameWins(PlayerInfo player)
107+
=> Update(player.AccountId, "gungame_wins", player.GunGameWins);
108+
104109
public void UpdateLastConnection(PlayerInfo player)
105110
=> Update(player.AccountId, "last_connection", player.LastConnection);
106111

0 commit comments

Comments
 (0)