From 3d530d582d2fa61602205900325df017000a3f03 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Fri, 27 Sep 2024 13:16:55 -0500 Subject: [PATCH 1/4] feat: Get the name of the player who captured the flag --- src/Application/Teams/Flags/Flag.cs | 8 ++++ .../Teams/Flags/FlagTests.cs | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/Application/Teams/Flags/Flag.cs b/src/Application/Teams/Flags/Flag.cs index 2e60d4f7..5c16f709 100644 --- a/src/Application/Teams/Flags/Flag.cs +++ b/src/Application/Teams/Flags/Flag.cs @@ -20,6 +20,14 @@ public class Flag /// public bool IsCaptured() => Carrier is not null; + /// + /// Gets the name of the player who captured the flag. + /// + /// + /// If the flag is not captured, returns None. + /// + public string CarrierName => IsCaptured() ? Carrier.Name : "None"; + /// /// Sets the player who holds the flag. /// diff --git a/tests/Application.Tests/Teams/Flags/FlagTests.cs b/tests/Application.Tests/Teams/Flags/FlagTests.cs index be5db459..cfccc6f6 100644 --- a/tests/Application.Tests/Teams/Flags/FlagTests.cs +++ b/tests/Application.Tests/Teams/Flags/FlagTests.cs @@ -42,6 +42,48 @@ public void IsCaptured_WhenFlagIsNotCapturedByPlayer_ShouldReturnsFalse() actual.Should().BeFalse(); } + [Test] + public void CarrierName_WhenFlagIsCaptured_ShouldReturnsCarrierName() + { + // Arrange + var flag = new Flag + { + Model = FlagModel.Blue, + Icon = FlagIcon.Blue, + Name = "Blue", + ColorHex = Color.Blue + }; + var expectedCarrierName = "Bob"; + var fakeCarrier = new FakePlayer(id: 1, expectedCarrierName); + flag.SetCarrier(fakeCarrier); + + // Act + string actual = flag.CarrierName; + + // Assert + actual.Should().Be(expectedCarrierName); + } + + [Test] + public void CarrierName_WhenFlagIsNotCaptured_ShouldReturnsNone() + { + // Arrange + var flag = new Flag + { + Model = FlagModel.Blue, + Icon = FlagIcon.Blue, + Name = "Blue", + ColorHex = Color.Blue + }; + var expectedCarrierName = "None"; + + // Act + string actual = flag.CarrierName; + + // Assert + actual.Should().Be(expectedCarrierName); + } + [Test] public void SetCarrier_WhenArgumentIsNull_ShouldThrowArgumentNullException() { From f1874bc97e48adee3e85e58250fe0aebcc7e4376 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Fri, 27 Sep 2024 13:17:40 -0500 Subject: [PATCH 2/4] cleanup: Remove TeamSystem.cs file --- src/Application/Teams/Systems/TeamSystem.cs | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/Application/Teams/Systems/TeamSystem.cs diff --git a/src/Application/Teams/Systems/TeamSystem.cs b/src/Application/Teams/Systems/TeamSystem.cs deleted file mode 100644 index 77ab115f..00000000 --- a/src/Application/Teams/Systems/TeamSystem.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CTF.Application.Teams.Systems; - -public class TeamSystem(TeamTextDrawRenderer teamTextDrawRenderer) : ISystem -{ - [Event] - public void OnPlayerSpawn(Player player) - { - teamTextDrawRenderer.Show(player); - } -} From 6621b208212c13cb8253c307b59157371c691a9f Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Fri, 27 Sep 2024 13:18:53 -0500 Subject: [PATCH 3/4] feat: Allow players to view statistics of both teams (Alpha and Beta) --- .../Teams/Systems/TeamStatsSystem.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Application/Teams/Systems/TeamStatsSystem.cs diff --git a/src/Application/Teams/Systems/TeamStatsSystem.cs b/src/Application/Teams/Systems/TeamStatsSystem.cs new file mode 100644 index 00000000..4f499bcd --- /dev/null +++ b/src/Application/Teams/Systems/TeamStatsSystem.cs @@ -0,0 +1,37 @@ +namespace CTF.Application.Teams.Systems; + +public class TeamStatsSystem( + IDialogService dialogService, + TeamTextDrawRenderer teamTextDrawRenderer) : ISystem +{ + [Event] + public void OnPlayerSpawn(Player player) + { + teamTextDrawRenderer.Show(player); + } + + [PlayerCommand("tstats")] + public void ShowStats(Player player) + { + Team alphaTeam = Team.Alpha; + Team betaTeam = Team.Beta; + var content = + $""" + {alphaTeam.ColorHex}>>> Alpha Team: + Members: {alphaTeam.Members.Count} + Score: {alphaTeam.StatsPerRound.Score} + Kills: {alphaTeam.StatsPerRound.Kills} + Deaths: {alphaTeam.StatsPerRound.Deaths} + Flag captured by: {alphaTeam.Flag.CarrierName} + + {betaTeam.ColorHex}>>> Beta Team: + Members: {betaTeam.Members.Count} + Score: {betaTeam.StatsPerRound.Score} + Kills: {betaTeam.StatsPerRound.Kills} + Deaths: {betaTeam.StatsPerRound.Deaths} + Flag captured by: {betaTeam.Flag.CarrierName} + """; + var dialog = new MessageDialog("Team Stats", content, "Close"); + dialogService.ShowAsync(player, dialog); + } +} From bd26cb45809c30514e6013675e3d3f3c2af27682 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Fri, 27 Sep 2024 13:24:48 -0500 Subject: [PATCH 4/4] feat: Update kills and deaths of a team --- src/Application/Teams/Systems/TeamStatsSystem.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Application/Teams/Systems/TeamStatsSystem.cs b/src/Application/Teams/Systems/TeamStatsSystem.cs index 4f499bcd..a28527df 100644 --- a/src/Application/Teams/Systems/TeamStatsSystem.cs +++ b/src/Application/Teams/Systems/TeamStatsSystem.cs @@ -10,6 +10,19 @@ public void OnPlayerSpawn(Player player) teamTextDrawRenderer.Show(player); } + [Event] + public void OnPlayerDeath(Player deadPlayer, Player killer, Weapon reason) + { + PlayerInfo deadPlayerInfo = deadPlayer.GetInfo(); + deadPlayerInfo.Team.StatsPerRound.AddDeaths(); + + if (killer.IsInvalidPlayer()) + return; + + PlayerInfo killerInfo = killer.GetInfo(); + killerInfo.Team.StatsPerRound.AddKills(); + } + [PlayerCommand("tstats")] public void ShowStats(Player player) {