Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Application/GunGames/GunGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// the final kill.
/// </remarks>
public readonly struct GunGame(
WeaponProgression weaponProgression,
ActiveWeaponProgression weaponProgression,
KillsRequiredPerLevel killsRequiredPerLevel)
{

Expand Down
2 changes: 1 addition & 1 deletion src/Application/GunGames/GunGameSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class GunGameSystem(
IWorldService worldService,
IDialogService dialogService,
FrozenDictionary<GunGameResult, IGunGameResultHandler> handlers,
WeaponProgression weaponProgression,
ActiveWeaponProgression weaponProgression,
GunGameSession gunGameSession,
GunGameReward gunGameReward) : ISystem, IGunGameMode
{
Expand Down
2 changes: 1 addition & 1 deletion src/Application/GunGames/GunGameWeaponEnforcer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CTF.Application.GunGames;
/// </summary>
public class GunGameWeaponEnforcer(
IGunGameMode gunGameMode,
WeaponProgression weaponProgression) : ISystem
ActiveWeaponProgression weaponProgression) : ISystem
{
[Event]
public void OnPlayerUpdate(Player player, TimePoint _)
Expand Down
2 changes: 1 addition & 1 deletion src/Application/GunGames/Results/PlayerLeveledDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
public class PlayerLeveledDown(
IWorldService worldService,
WeaponProgression weaponProgression) : IGunGameResultHandler
ActiveWeaponProgression weaponProgression) : IGunGameResultHandler
{
public GunGameResult Result => GunGameResult.LeveledDown;

Expand Down
2 changes: 1 addition & 1 deletion src/Application/GunGames/Results/PlayerLeveledUp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
public class PlayerLeveledUp(
IWorldService worldService,
WeaponProgression weaponProgression) : IGunGameResultHandler
ActiveWeaponProgression weaponProgression) : IGunGameResultHandler
{
public GunGameResult Result => GunGameResult.LeveledUp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
public class PlayerReachedFinalLevel(
IWorldService worldService,
WeaponProgression weaponProgression) : IGunGameResultHandler
ActiveWeaponProgression weaponProgression) : IGunGameResultHandler
{
public GunGameResult Result => GunGameResult.ReachedFinalLevel;
public void Handle(KillContext context)
Expand Down
8 changes: 4 additions & 4 deletions src/Application/GunGames/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static IServiceCollection AddGunGameServices(this IServiceCollection serv
services
.AddSingleton<GunGameReward>()
.AddSingleton<GunGameSession>()
.AddSingleton<WeaponProgression>()
.AddSingleton<ActiveWeaponProgression>()
.AddSingleton<IGunGameMode>(sp => sp.GetRequiredService<GunGameSystem>());

services
Expand All @@ -21,7 +21,7 @@ public static IServiceCollection AddGunGameServices(this IServiceCollection serv
.AddWeaponProgression<PowerfulWeaponProgression>()
.AddSingleton(sp =>
{
var progressions = sp.GetRequiredService<IEnumerable<WeaponProgressionBase>>();
var progressions = sp.GetRequiredService<IEnumerable<WeaponProgression>>();
return progressions.ToFrozenDictionary(w => w.Type);
});

Expand All @@ -40,9 +40,9 @@ public static IServiceCollection AddGunGameServices(this IServiceCollection serv
}

private static IServiceCollection AddWeaponProgression<T>(this IServiceCollection services)
where T : WeaponProgressionBase
where T : WeaponProgression
{
services.AddSingleton<WeaponProgressionBase, T>();
services.AddSingleton<WeaponProgression, T>();
return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace CTF.Application.GunGames.WeaponProgressions;

/// <summary>
/// Represents the active weapon progression for the current GunGame session.
/// </summary>
/// <remarks>
/// Consumers do not need to know which weapon progression is active.
/// This class always exposes the progression selected for the current session.
/// </remarks>
public class ActiveWeaponProgression(
GunGameSession gunGameSession,
FrozenDictionary<WeaponProgressionType, WeaponProgression> progressions)
{
private WeaponProgression Current
=> progressions[gunGameSession.WeaponProgressionType];

/// <inheritdoc cref="WeaponProgression.GetWeapon"/>
public IWeapon GetWeapon(WeaponLevel level)
=> Current.GetWeapon(level);

/// <inheritdoc cref="WeaponProgression.IsFinalLevel"/>
public bool IsFinalLevel(WeaponLevel level)
=> Current.IsFinalLevel(level);

/// <inheritdoc cref="WeaponProgression.MaxLevel"/>
public MaxWeaponLevel MaxLevel
=> Current.MaxLevel;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace CTF.Application.GunGames.WeaponProgressions.Definitions;

/// <summary>
/// Defines the default GunGame weapon progression,
/// Defines the classic GunGame weapon progression,
/// where players advance through increasingly challenging
/// weapons until reaching the final knife level.
/// </summary>
public class ClassicWeaponProgression : WeaponProgressionBase
public class ClassicWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Classic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression using only high-skill weapons.
/// </summary>
public class HardcoreWeaponProgression : WeaponProgressionBase
public class HardcoreWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Hardcore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression using only pistols.
/// </summary>
public class PistolsWeaponProgression : WeaponProgressionBase
public class PistolsWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Pistols;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression featuring the most powerful weapons in GTA.
/// </summary>
public class PowerfulWeaponProgression : WeaponProgressionBase
public class PowerfulWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Powerful;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// Players begin with the most difficult weapons and finish with the easiest,
/// before reaching the final knife level.
/// </summary>
public class ReverseClassicWeaponProgression : WeaponProgressionBase
public class ReverseClassicWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.ReverseClassic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression using only rifles.
/// </summary>
public class RiflesWeaponProgression : WeaponProgressionBase
public class RiflesWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Rifles;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression using only shotguns.
/// </summary>
public class ShotgunsWeaponProgression : WeaponProgressionBase
public class ShotgunsWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Shotguns;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Defines a GunGame weapon progression using only submachine guns.
/// </summary>
public class SmgsWeaponProgression : WeaponProgressionBase
public class SmgsWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.SMGs;

Expand Down
76 changes: 57 additions & 19 deletions src/Application/GunGames/WeaponProgressions/WeaponProgression.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,66 @@
namespace CTF.Application.GunGames.WeaponProgressions;

/// <summary>
/// Represents the weapon progression used by the current GunGame session.
/// Represents a weapon progression consisting of an ordered sequence of weapons.
/// </summary>
/// <remarks>
/// Consumers do not need to know which progression implementation is active.
/// The active progression is resolved automatically from the current GunGame session.
/// </remarks>
public class WeaponProgression(
GunGameSession gunGameSession,
FrozenDictionary<WeaponProgressionType, WeaponProgressionBase> progressions)
public abstract class WeaponProgression
{
private WeaponProgressionBase Current
=> progressions[gunGameSession.WeaponProgressionType];
private readonly List<IWeapon> _weapons = [];

/// <inheritdoc cref="WeaponProgressionBase.GetWeapon"/>
public IWeapon GetWeapon(WeaponLevel level)
=> Current.GetWeapon(level);
/// <summary>
/// Gets the type of weapon progression.
/// </summary>
public abstract WeaponProgressionType Type { get; }

protected WeaponProgression()
{
Define(_weapons);
if (_weapons.Count == 0)
throw new InvalidOperationException(
"A weapon progression must define at least one weapon.");
}

/// <summary>
/// Defines the weapon sequence for this progression.
/// Weapons must be added in ascending level order,
/// starting from the first weapon level.
/// </summary>
/// <param name="weapons">
/// The collection to populate with weapons in progression order.
/// </param>
protected abstract void Define(List<IWeapon> weapons);

/// <summary>
/// Gets the maximum weapon level defined by this progression.
/// </summary>
public MaxWeaponLevel MaxLevel
=> new(_weapons.Count);

/// <inheritdoc cref="WeaponProgressionBase.IsFinalLevel"/>
/// <summary>
/// Determines whether the specified weapon level is the final level
/// of this progression.
/// </summary>
/// <param name="level">
/// The weapon level to evaluate.
/// </param>
public bool IsFinalLevel(WeaponLevel level)
=> Current.IsFinalLevel(level);

/// <inheritdoc cref="WeaponProgressionBase.MaxLevel"/>
public MaxWeaponLevel MaxLevel
=> Current.MaxLevel;
=> level.Value == MaxLevel.Value;

/// <summary>
/// Gets the weapon associated with the specified weapon level.
/// </summary>
/// <param name="level">
/// The weapon level.
/// </param>
/// <returns>
/// The weapon assigned to the specified level.
/// </returns>
public IWeapon GetWeapon(WeaponLevel level)
{
int index = level.Value - 1;
if (index < 0 || index >= _weapons.Count)
throw new InvalidOperationException($"No weapon defined for level {level.Value}");

return _weapons[index];
}
}

This file was deleted.

8 changes: 4 additions & 4 deletions tests/Application.Tests/GunGames/ProcessKillTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public void Init()
KillsRequiredPerLevel = new KillsRequiredPerLevel(2)
};

var progressions = new Dictionary<WeaponProgressionType, WeaponProgressionBase>
var progressions = new Dictionary<WeaponProgressionType, WeaponProgression>
{
[WeaponProgressionType.Classic] = new TestWeaponProgression()
}.ToFrozenDictionary();

var weaponProgression = new WeaponProgression(session, progressions);
var weaponProgression = new ActiveWeaponProgression(session, progressions);
_gunGame = new GunGame(weaponProgression, session.KillsRequiredPerLevel);
_maxLevel = weaponProgression.MaxLevel;
}
Expand Down Expand Up @@ -170,12 +170,12 @@ public void ProcessKill_WhenPlayerAtFinalLevelKillsWithNonKnifeFinalWeapon_Shoul
KillsRequiredPerLevel = new KillsRequiredPerLevel(2)
};

var progressions = new Dictionary<WeaponProgressionType, WeaponProgressionBase>
var progressions = new Dictionary<WeaponProgressionType, WeaponProgression>
{
[WeaponProgressionType.Classic] = new NonKnifeFinalWeaponProgression()
}.ToFrozenDictionary();

var weaponProgression = new WeaponProgression(session, progressions);
var weaponProgression = new ActiveWeaponProgression(session, progressions);
var gunGame = new GunGame(weaponProgression, session.KillsRequiredPerLevel);
var killer = new PlayerProgression();
var victim = new PlayerProgression();
Expand Down
4 changes: 2 additions & 2 deletions tests/Application.Tests/GunGames/TestWeaponProgression.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Tests.GunGames;

public class TestWeaponProgression : WeaponProgressionBase
public class TestWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Classic;

Expand All @@ -16,7 +16,7 @@ protected override void Define(List<IWeapon> weapons)
}
}

public class NonKnifeFinalWeaponProgression : WeaponProgressionBase
public class NonKnifeFinalWeaponProgression : WeaponProgression
{
public override WeaponProgressionType Type => WeaponProgressionType.Classic;

Expand Down
Loading
Loading