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
36 changes: 36 additions & 0 deletions src/Application/Players/Weapons/ActiveWeaponCatalog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace CTF.Application.Players.Weapons;

/// <summary>
/// Represents the active weapon catalog used by the server.
/// </summary>
/// <remarks>
/// Consumers do not need to know which weapon catalog is active.
/// This class always exposes the catalog selected by the current server configuration.
/// </remarks>
public class ActiveWeaponCatalog(
WeaponCatalogSettings settings,
FrozenDictionary<WeaponCatalogType, WeaponCatalog> catalogs)
{
private WeaponCatalog Current
=> catalogs[settings.Type];

/// <inheritdoc cref="WeaponCatalog.Count"/>
public int Count
=> Current.Count;

/// <inheritdoc cref="WeaponCatalog.GetAll"/>
public IReadOnlyList<IWeapon> GetAll()
=> Current.GetAll();

/// <inheritdoc cref="WeaponCatalog.Contains"/>
public bool Contains(IWeapon weapon)
=> Current.Contains(weapon);

/// <inheritdoc cref="WeaponCatalog.GetById"/>
public Result<IWeapon> GetById(Weapon id)
=> Current.GetById(id);

/// <inheritdoc cref="WeaponCatalog.GetByName"/>
public Result<IWeapon> GetByName(string weaponName)
=> Current.GetByName(weaponName);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Players.Weapons.Catalogs;

public class HeavyWeaponCatalog : WeaponCatalogBase
public class HeavyWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Heavy;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Players.Weapons.Catalogs;

public class MeleeWeaponCatalog : WeaponCatalogBase
public class MeleeWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Melee;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace CTF.Application.Players.Weapons.Catalogs;

/// <summary>
/// Provides a combination of walking and run weapons.
/// Defines a weapon catalog that combines the Walking and Run weapon catalogs.
/// </summary>
/// <remarks>
/// This catalog contains all weapons available from both categories.
/// </remarks>
public class MixedWeaponCatalog : WeaponCatalogBase
public class MixedWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Mixed;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Players.Weapons.Catalogs;

public class RifleOnlyWeaponCatalog : WeaponCatalogBase
public class RifleOnlyWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.RifleOnly;

Expand Down
4 changes: 2 additions & 2 deletions src/Application/Players/Weapons/Catalogs/RunWeaponCatalog.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace CTF.Application.Players.Weapons.Catalogs;

/// <summary>
/// Provides weapons that allow players to remain mobile while fighting.
/// Defines a weapon catalog that allows players to remain mobile while fighting.
/// </summary>
/// <remarks>
/// These weapons support the classic Run Weapons (RW) gameplay style,
/// where players can move quickly while attacking.
/// </remarks>
public class RunWeaponCatalog : WeaponCatalogBase
public class RunWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Run;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace CTF.Application.Players.Weapons.Catalogs;

/// <summary>
/// Provides weapons that restrict player mobility while fighting.
/// Defines a weapon catalog that restricts player mobility while fighting.
/// </summary>
/// <remarks>
/// Players can only walk while using most weapons in this catalog.
/// </remarks>
public class WalkingWeaponCatalog : WeaponCatalogBase
public class WalkingWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Walking;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Players.Weapons.Catalogs;

public class WarWeaponCatalog : WeaponCatalogBase
public class WarWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.War;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <remarks>
/// Derived classes define which weapons belong to a specific catalog.
/// </remarks>
public abstract class WeaponCatalogBase
public abstract class WeaponCatalog
{
private readonly List<IWeapon> _weapons =
[
Expand All @@ -18,7 +18,7 @@ public abstract class WeaponCatalogBase
/// Initializes the catalog with the weapons that are
/// always available to players.
/// </summary>
protected WeaponCatalogBase()
protected WeaponCatalog()
{
Define(_weapons);
}
Expand All @@ -29,7 +29,7 @@ protected WeaponCatalogBase()
public abstract WeaponCatalogType Type { get; }

/// <summary>
/// Populates the catalog with weapon definitions.
/// Defines the weapons that belong to this catalog.
/// </summary>
protected abstract void Define(List<IWeapon> weapons);

Expand All @@ -39,7 +39,7 @@ protected WeaponCatalogBase()
public int Count => _weapons.Count;

/// <summary>
/// Gets all weapons defined by the catalog.
/// Gets all weapons defined in this catalog.
/// </summary>
public IReadOnlyList<IWeapon> GetAll() => _weapons;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ public static IServiceCollection AddWeaponServices(this IServiceCollection servi
.AddWeaponCatalog<WarWeaponCatalog>()
.AddWeaponCatalog<HeavyWeaponCatalog>()
.AddWeaponCatalog<MeleeWeaponCatalog>()
.AddSingleton<WeaponCatalog>()
.AddSingleton<ActiveWeaponCatalog>()
.AddSingleton(sp =>
{
var catalogs = sp.GetRequiredService<IEnumerable<WeaponCatalogBase>>();
var catalogs = sp.GetRequiredService<IEnumerable<WeaponCatalog>>();
return catalogs.ToFrozenDictionary(w => w.Type);
});

return services;
}

private static IServiceCollection AddWeaponCatalog<T>(this IServiceCollection services)
where T : WeaponCatalogBase
where T : WeaponCatalog
{
services.AddSingleton<WeaponCatalogBase, T>();
services.AddSingleton<WeaponCatalog, T>();
return services;
}
}
41 changes: 0 additions & 41 deletions src/Application/Players/Weapons/WeaponCatalog.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Application/Players/Weapons/WeaponCatalogSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class WeaponCatalogSystem(
IEntityManager entityManager,
IDialogService dialogService,
IGunGameMode gunGameMode,
WeaponCatalog weaponCatalog,
ActiveWeaponCatalog weaponCatalog,
WeaponCatalogSettings weaponCatalogSettings) : ISystem
{
[PlayerCommand("weaponcatalog")]
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Players/Weapons/WeaponSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class WeaponSelectionSystem(
IDialogService dialogService,
IGunGameMode gunGameMode,
WeaponCatalog weaponCatalog) : ISystem
ActiveWeaponCatalog weaponCatalog) : ISystem
{
[Event]
public void OnPlayerConnect(Player player)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Tests.Players.Weapons;

public class TestWeaponCatalog : WeaponCatalogBase
public class TestWeaponCatalog : WeaponCatalog
{
public override WeaponCatalogType Type => WeaponCatalogType.Mixed;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CTF.Application.Tests.Players.Weapons;

public class WeaponCatalogBaseTests
public class WeaponCatalogTests
{
[Test]
public void GetById_WhenWeaponIdIsNotFound_ShouldReturnFailureResult()
Expand Down
Loading