Skip to content

Commit

Permalink
Merge pull request #58 from MrDave1999/breaking-change
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Use ICombo interface instead of IBenefit
  • Loading branch information
MrDave1999 authored Sep 6, 2024
2 parents 615ddf1 + 323b97d commit 81b6442
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<value>You have gained +100 points, +100 armour, and +100 health</value>
</data>
<data name="RedeemedPoints" xml:space="preserve">
<value>{PlayerName} redeemed their points for the benefit: {BenefitName}</value>
<value>{PlayerName} redeemed their points for the combo: {ComboName}</value>
</data>
<data name="SpawnLocationFailure" xml:space="preserve">
<value>A spawn location can only be obtained for the alpha or beta team</value>
Expand Down
18 changes: 9 additions & 9 deletions src/Application/Players/Combos/ComboSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ public class ComboSystem : ISystem
private readonly IDialogService _dialogService;
private readonly TablistDialog _tablistDialog;
private readonly IWorldService _worldService;
private readonly IEnumerable<IBenefit> _benefits;
private readonly IEnumerable<ICombo> _combos;

public ComboSystem(
IDialogService dialogService,
IWorldService worldService,
IEnumerable<IBenefit> benefits)
IEnumerable<ICombo> combos)
{
_dialogService = dialogService;
_worldService = worldService;
_benefits = benefits;
_combos = combos;
var columnHeaders = new[]
{
"Combo",
Expand All @@ -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")]
Expand All @@ -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);
Expand All @@ -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);
}
}
8 changes: 0 additions & 8 deletions src/Application/Players/Combos/IBenefit.cs

This file was deleted.

12 changes: 12 additions & 0 deletions src/Application/Players/Combos/ICombo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace CTF.Application.Players.Combos;

/// <summary>
/// Represents a combination of different advantages, such as health, armour, and weapons,
/// that a player can use to gain an advantage in the game.
/// </summary>
public interface ICombo
{
string Name { get; }
int RequiredPoints { get; }
void Give(Player player);
}
10 changes: 5 additions & 5 deletions src/Application/Players/Combos/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public static class ComboServicesExtensions
public static IServiceCollection AddComboServices(this IServiceCollection services)
{
services
.AddSingleton<IBenefit, HealthArmour>()
.AddSingleton<IBenefit, GrenadesArmour>()
.AddSingleton<IBenefit, MolotovArmour>()
.AddSingleton<IBenefit, SatchelChargesArmour>()
.AddSingleton<IBenefit, TearGasHealth>();
.AddSingleton<ICombo, HealthArmour>()
.AddSingleton<ICombo, GrenadesArmour>()
.AddSingleton<ICombo, MolotovArmour>()
.AddSingleton<ICombo, SatchelChargesArmour>()
.AddSingleton<ICombo, TearGasHealth>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 81b6442

Please sign in to comment.