Skip to content

Commit

Permalink
Add support for un-implemented LRs
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Mar 24, 2024
1 parent 7ce157f commit 20407cd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion mod/Jailbreak.Debug/Subcommands/LastRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public LastRequest(IServiceProvider services, BasePlugin plugin) : base(services
this.plugin = plugin;
manager = services.GetRequiredService<ILastRequestManager>();
playerSelector = new LastRequestPlayerSelector(manager, true);
menuSelector = new LastRequestMenuSelector((type) => "css_debug lastrequest " + type);
menuSelector = new LastRequestMenuSelector(services.GetRequiredService<ILastRequestFactory>(),
(type) => "css_debug lastrequest " + type);
_messages = services.GetRequiredService<ILastRequestMessages>();
_generic = services.GetRequiredService<IGenericCommandNotifications>();
}
Expand Down
6 changes: 4 additions & 2 deletions mod/Jailbreak.LastRequest/LastRequestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ public class LastRequestCommand : IPluginBehavior
private BasePlugin plugin;
private ILastRequestMessages _messages;
private IGenericCommandNotifications _generic;
private ILastRequestFactory _factory;

// css_lr <player> <LRType>
public LastRequestCommand(ILastRequestManager manager, ILastRequestMessages messages,

Check warning on line 28 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'menuSelector' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 28 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'playerSelector' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 28 in mod/Jailbreak.LastRequest/LastRequestCommand.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'plugin' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
IGenericCommandNotifications generic)
IGenericCommandNotifications generic, ILastRequestFactory factory)
{
_lrManager = manager;
_messages = messages;
_generic = generic;
_factory = factory;
}

public void Start(BasePlugin plugin)
{
this.plugin = plugin;
playerSelector = new LastRequestPlayerSelector(_lrManager);
menuSelector = new LastRequestMenuSelector();
menuSelector = new LastRequestMenuSelector(_factory);
}


Expand Down
17 changes: 15 additions & 2 deletions mod/Jailbreak.LastRequest/LastRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,22 @@ public AbstractLastRequest CreateLastRequest(CCSPlayerController prisoner, CCSPl
LRType.NoScope => new NoScope(plugin, manager, prisoner, guard),
LRType.RockPaperScissors => new RockPaperScissors(plugin, manager, prisoner, guard),
LRType.Coinflip => new Coinflip(plugin, manager, prisoner, guard),
LRType.ShotForShot => new ShotForShot(plugin, manager, prisoner, guard),
LRType.MagForMag => new MagForMag(plugin, manager, prisoner, guard),
// LRType.ShotForShot => new ShotForShot(plugin, manager, prisoner, guard),
// LRType.MagForMag => new MagForMag(plugin, manager, prisoner, guard),
_ => throw new ArgumentException("Invalid last request type: " + type, nameof(type))
};
}

public bool IsValidType(LRType type)
{
return type switch
{
LRType.KnifeFight => true,
LRType.GunToss => true,
LRType.NoScope => true,
LRType.RockPaperScissors => true,
LRType.Coinflip => true,
_ => false
};
}
}
9 changes: 7 additions & 2 deletions mod/Jailbreak.LastRequest/LastRequestMenuSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ public class LastRequestMenuSelector
{
private readonly CenterHtmlMenu menu;
private Func<LRType, string> command;
private readonly ILastRequestFactory factory;

public LastRequestMenuSelector() : this((lr) => "css_lr " + ((int)lr))
public LastRequestMenuSelector(ILastRequestFactory factory) : this(factory, (lr) => "css_lr " + ((int)lr))
{
this.factory = factory;
}

public LastRequestMenuSelector(Func<LRType, string> command)
public LastRequestMenuSelector(ILastRequestFactory factory, Func<LRType, string> command)
{
this.factory = factory;
this.command = command;
menu = new CenterHtmlMenu("css_lr [LR] [Player]");
foreach (LRType lr in Enum.GetValues(typeof(LRType)))
{
if (!factory.IsValidType(lr))
continue;
menu.AddMenuOption(lr.ToFriendlyString(), (p, o) => OnSelectLR(p, lr));
}
}
Expand Down
3 changes: 3 additions & 0 deletions public/Jailbreak.Public/Mod/LastRequest/Enums/LRType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public static string ToFriendlyString(this LRType type)
LRType.KnifeFight => "Knife Fight",
LRType.NoScope => "No Scope",
LRType.Coinflip => "Coinflip",
LRType.ShotForShot => "Shot For Shot",
LRType.MagForMag => "Mag For Mag",
LRType.Race => "Race",
_ => "Unknown"
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace Jailbreak.Public.Mod.LastRequest;
public interface ILastRequestFactory : IPluginBehavior
{
AbstractLastRequest CreateLastRequest(CCSPlayerController prisoner, CCSPlayerController guard, LRType type);
bool IsValidType(LRType type);
}

0 comments on commit 20407cd

Please sign in to comment.