From 688d9d2ef0ed5afd4a8153ed92783a3bdf357b64 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Thu, 5 Sep 2024 21:04:55 -0500 Subject: [PATCH 1/3] BREAKING CHANGE: Use ICombo interface instead of IBenefit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change was introduced because “ICombo” is that the represents the set of benefits that a player can obtain. “IBenefit” is not a good name, because it represents a single benefit and what we really want is to represent a set of benefits (a combo). --- src/Application/Players/Combos/ComboSystem.cs | 18 +++++++++--------- src/Application/Players/Combos/IBenefit.cs | 8 -------- src/Application/Players/Combos/ICombo.cs | 12 ++++++++++++ .../Combos/ServiceCollectionExtensions.cs | 10 +++++----- .../{Benefits => Services}/GrenadesArmour.cs | 4 ++-- .../{Benefits => Services}/HealthArmour.cs | 4 ++-- .../{Benefits => Services}/MolotovArmour.cs | 4 ++-- .../SatchelChargesArmour.cs | 4 ++-- .../{Benefits => Services}/TearGasHealth.cs | 4 ++-- 9 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 src/Application/Players/Combos/IBenefit.cs create mode 100644 src/Application/Players/Combos/ICombo.cs rename src/Application/Players/Combos/{Benefits => Services}/GrenadesArmour.cs (78%) rename src/Application/Players/Combos/{Benefits => Services}/HealthArmour.cs (80%) rename src/Application/Players/Combos/{Benefits => Services}/MolotovArmour.cs (78%) rename src/Application/Players/Combos/{Benefits => Services}/SatchelChargesArmour.cs (80%) rename src/Application/Players/Combos/{Benefits => Services}/TearGasHealth.cs (78%) diff --git a/src/Application/Players/Combos/ComboSystem.cs b/src/Application/Players/Combos/ComboSystem.cs index acf7f9d7..e7ab1496 100644 --- a/src/Application/Players/Combos/ComboSystem.cs +++ b/src/Application/Players/Combos/ComboSystem.cs @@ -5,16 +5,16 @@ public class ComboSystem : ISystem private readonly IDialogService _dialogService; private readonly TablistDialog _tablistDialog; private readonly IWorldService _worldService; - private readonly IEnumerable _benefits; + private readonly IEnumerable _combos; public ComboSystem( IDialogService dialogService, IWorldService worldService, - IEnumerable benefits) + IEnumerable combos) { _dialogService = dialogService; _worldService = worldService; - _benefits = benefits; + _combos = combos; var columnHeaders = new[] { "Combo", @@ -26,8 +26,8 @@ public ComboSystem( button2: "Close", columnHeaders); - foreach (IBenefit benefit in benefits) - _tablistDialog.Add(benefit.Name, benefit.RequiredPoints.ToString()); + foreach (ICombo combo in combos) + _tablistDialog.Add(combo.Name, combo.RequiredPoints.ToString()); } [PlayerCommand("combos")] @@ -38,9 +38,9 @@ public async void ShowCombos(Player player) return; string selectedItemName = response.Item.Columns[0]; - IBenefit selectedBenefit = _benefits.First(benefit => benefit.Name == selectedItemName); + ICombo selectedCombo = _combos.First(combo => combo.Name == selectedItemName); PlayerStatsPerRound playerStats = player.GetInfo().StatsPerRound; - if(playerStats.HasInsufficientPoints(selectedBenefit.RequiredPoints)) + if(playerStats.HasInsufficientPoints(selectedCombo.RequiredPoints)) { player.SendClientMessage(Color.Red, Messages.InsufficientPoints); ShowCombos(player); @@ -50,10 +50,10 @@ public async void ShowCombos(Player player) var message = Smart.Format(Messages.RedeemedPoints, new { PlayerName = player.Name, - BenefitName = selectedBenefit.Name + ComboName = selectedCombo.Name }); _worldService.SendClientMessage(Color.Yellow, message); - selectedBenefit.Give(player); + selectedCombo.Give(player); ShowCombos(player); } } diff --git a/src/Application/Players/Combos/IBenefit.cs b/src/Application/Players/Combos/IBenefit.cs deleted file mode 100644 index e1a2b931..00000000 --- a/src/Application/Players/Combos/IBenefit.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CTF.Application.Players.Combos; - -public interface IBenefit -{ - string Name { get; } - int RequiredPoints { get; } - void Give(Player player); -} diff --git a/src/Application/Players/Combos/ICombo.cs b/src/Application/Players/Combos/ICombo.cs new file mode 100644 index 00000000..08d65cd2 --- /dev/null +++ b/src/Application/Players/Combos/ICombo.cs @@ -0,0 +1,12 @@ +namespace CTF.Application.Players.Combos; + +/// +/// Represents a combination of different advantages, such as health, armour, and weapons, +/// that a player can use to gain an advantage in the game. +/// +public interface ICombo +{ + string Name { get; } + int RequiredPoints { get; } + void Give(Player player); +} diff --git a/src/Application/Players/Combos/ServiceCollectionExtensions.cs b/src/Application/Players/Combos/ServiceCollectionExtensions.cs index b52114e9..49abfa6f 100644 --- a/src/Application/Players/Combos/ServiceCollectionExtensions.cs +++ b/src/Application/Players/Combos/ServiceCollectionExtensions.cs @@ -5,11 +5,11 @@ public static class ComboServicesExtensions public static IServiceCollection AddComboServices(this IServiceCollection services) { services - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton(); return services; } diff --git a/src/Application/Players/Combos/Benefits/GrenadesArmour.cs b/src/Application/Players/Combos/Services/GrenadesArmour.cs similarity index 78% rename from src/Application/Players/Combos/Benefits/GrenadesArmour.cs rename to src/Application/Players/Combos/Services/GrenadesArmour.cs index 2bd70c8e..d6a45a32 100644 --- a/src/Application/Players/Combos/Benefits/GrenadesArmour.cs +++ b/src/Application/Players/Combos/Services/GrenadesArmour.cs @@ -1,6 +1,6 @@ -namespace CTF.Application.Players.Combos.Benefits; +namespace CTF.Application.Players.Combos.Services; -public class GrenadesArmour : IBenefit +public class GrenadesArmour : ICombo { public string Name => "2 Grenades and 20 Armour"; public int RequiredPoints => 25; diff --git a/src/Application/Players/Combos/Benefits/HealthArmour.cs b/src/Application/Players/Combos/Services/HealthArmour.cs similarity index 80% rename from src/Application/Players/Combos/Benefits/HealthArmour.cs rename to src/Application/Players/Combos/Services/HealthArmour.cs index f5a08800..dd3b386e 100644 --- a/src/Application/Players/Combos/Benefits/HealthArmour.cs +++ b/src/Application/Players/Combos/Services/HealthArmour.cs @@ -1,6 +1,6 @@ -namespace CTF.Application.Players.Combos.Benefits; +namespace CTF.Application.Players.Combos.Services; -public class HealthArmour : IBenefit +public class HealthArmour : ICombo { public string Name => "100 Health, 100 Armour and FlameThrower"; public int RequiredPoints => 100; diff --git a/src/Application/Players/Combos/Benefits/MolotovArmour.cs b/src/Application/Players/Combos/Services/MolotovArmour.cs similarity index 78% rename from src/Application/Players/Combos/Benefits/MolotovArmour.cs rename to src/Application/Players/Combos/Services/MolotovArmour.cs index 994d1ca8..87a9b00b 100644 --- a/src/Application/Players/Combos/Benefits/MolotovArmour.cs +++ b/src/Application/Players/Combos/Services/MolotovArmour.cs @@ -1,6 +1,6 @@ -namespace CTF.Application.Players.Combos.Benefits; +namespace CTF.Application.Players.Combos.Services; -public class MolotovArmour : IBenefit +public class MolotovArmour : ICombo { public string Name => "2 Molotov cocktail and 20 Armour"; public int RequiredPoints => 25; diff --git a/src/Application/Players/Combos/Benefits/SatchelChargesArmour.cs b/src/Application/Players/Combos/Services/SatchelChargesArmour.cs similarity index 80% rename from src/Application/Players/Combos/Benefits/SatchelChargesArmour.cs rename to src/Application/Players/Combos/Services/SatchelChargesArmour.cs index f29788da..4b9897ff 100644 --- a/src/Application/Players/Combos/Benefits/SatchelChargesArmour.cs +++ b/src/Application/Players/Combos/Services/SatchelChargesArmour.cs @@ -1,6 +1,6 @@ -namespace CTF.Application.Players.Combos.Benefits; +namespace CTF.Application.Players.Combos.Services; -public class SatchelChargesArmour : IBenefit +public class SatchelChargesArmour : ICombo { public string Name => "4 Satchel charges and 30 Armour"; public int RequiredPoints => 40; diff --git a/src/Application/Players/Combos/Benefits/TearGasHealth.cs b/src/Application/Players/Combos/Services/TearGasHealth.cs similarity index 78% rename from src/Application/Players/Combos/Benefits/TearGasHealth.cs rename to src/Application/Players/Combos/Services/TearGasHealth.cs index ecdea187..84aa7898 100644 --- a/src/Application/Players/Combos/Benefits/TearGasHealth.cs +++ b/src/Application/Players/Combos/Services/TearGasHealth.cs @@ -1,6 +1,6 @@ -namespace CTF.Application.Players.Combos.Benefits; +namespace CTF.Application.Players.Combos.Services; -public class TearGasHealth : IBenefit +public class TearGasHealth : ICombo { public string Name => "20 Tear gas and 30 Health"; public int RequiredPoints => 20; From c81c5dfcc18b6fecd8cc7e859dcf7033f075a338 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Thu, 5 Sep 2024 21:16:04 -0500 Subject: [PATCH 2/3] chore: Update global usings --- src/Application/Usings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application/Usings.cs b/src/Application/Usings.cs index 3d4e2f4c..91f9c81d 100644 --- a/src/Application/Usings.cs +++ b/src/Application/Usings.cs @@ -22,7 +22,7 @@ global using CTF.Application.Players.Accounts; global using CTF.Application.Players.Ranks; global using CTF.Application.Players.Combos; -global using CTF.Application.Players.Combos.Benefits; +global using CTF.Application.Players.Combos.Services; global using CTF.Application.Players.Extensions; global using CTF.Application.Teams; global using CTF.Application.Teams.Flags; From 323b97d6d9d1689cb7e2b52fdfc876ea5d40aea8 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Thu, 5 Sep 2024 21:16:29 -0500 Subject: [PATCH 3/3] Update RedeemedPoints message --- src/Application/Common/Resources/Messages.Designer.cs | 2 +- src/Application/Common/Resources/Messages.resx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/Common/Resources/Messages.Designer.cs b/src/Application/Common/Resources/Messages.Designer.cs index f8dab0d5..d3ac5347 100644 --- a/src/Application/Common/Resources/Messages.Designer.cs +++ b/src/Application/Common/Resources/Messages.Designer.cs @@ -295,7 +295,7 @@ internal static string RankUpAward { } /// - /// Looks up a localized string similar to {PlayerName} redeemed their points for the benefit: {BenefitName}. + /// Looks up a localized string similar to {PlayerName} redeemed their points for the combo: {ComboName}. /// internal static string RedeemedPoints { get { diff --git a/src/Application/Common/Resources/Messages.resx b/src/Application/Common/Resources/Messages.resx index d9806340..bc9b0186 100644 --- a/src/Application/Common/Resources/Messages.resx +++ b/src/Application/Common/Resources/Messages.resx @@ -196,7 +196,7 @@ You have gained +100 points, +100 armour, and +100 health - {PlayerName} redeemed their points for the benefit: {BenefitName} + {PlayerName} redeemed their points for the combo: {ComboName} A spawn location can only be obtained for the alpha or beta team