Skip to content

Commit

Permalink
Add factory, enhance ALR, add empty knifefight example
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Feb 11, 2024
1 parent 3c53366 commit dfe24dd
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 10 deletions.
17 changes: 17 additions & 0 deletions lang/Jailbreak.English/LastRequest/LastRequestMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Views;

namespace Jailbreak.English.LastRequest;

public class LastRequestMessages : ILastRequestMessages
{
public IView LastRequestEnabled() => new SimpleView()
{
{ "Last Request has been enabled." }
};

public IView LastRequestDisabled() => new SimpleView()
{
{ "Last Request has been disabled." }
};
}
1 change: 1 addition & 0 deletions mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj" />
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions mod/Jailbreak.LastRequest/LastRequestConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Jailbreak.LastRequest;

public class LastRequestConfig
{
public int PrisonersToActiveLR { get; set; } = 2;
}
15 changes: 15 additions & 0 deletions mod/Jailbreak.LastRequest/LastRequestExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.LastRequest;
using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.LastRequest;

public static class LastRequestExtension
{
public static void AddJailbreakLastRequest(this IServiceCollection collection)
{
collection.AddConfig<LastRequestConfig>("lastrequest");

collection.AddPluginBehavior<ILastRequestManager, LastRequestManager>();
}
}
25 changes: 25 additions & 0 deletions mod/Jailbreak.LastRequest/LastRequestFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.LastRequest.LastRequests;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;

namespace Jailbreak.LastRequest;

public class LastRequestFactory : ILastRequestFactory
{
private BasePlugin plugin;

public LastRequestFactory(BasePlugin plugin)
{
this.plugin = plugin;
}

public AbstractLastRequest CreateLastRequest(CCSPlayerController prisoner, CCSPlayerController guard, LRType type)
{
return type switch
{
LRType.KnifeFight => new KnifeFight(plugin, prisoner, guard),
_ => throw new ArgumentException("Invalid last request type: " + type, nameof(type))
};
}
}
39 changes: 38 additions & 1 deletion mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.LastRequest;

namespace Jailbreak.LastRequest;

public class LastRequestManager : IPluginBehavior, ILastRequestManager
{
private BasePlugin _parent;
private LastRequestConfig config;
private ILastRequestMessages messages;

public LastRequestManager(LastRequestConfig config, ILastRequestMessages messages)
{
this.config = config;
this.messages = messages;
}

public void Start(BasePlugin parent)
{
_parent = parent;
_parent.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
}

[GameEventHandler(HookMode.Post)]
public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsReal())
return HookResult.Continue;

if (player.GetTeam() != CsTeam.Terrorist)
return HookResult.Continue;

int remainingPrisoners = Utilities.GetPlayers().Count(CountsToLR);
if (remainingPrisoners > config.PrisonersToActiveLR)
return HookResult.Continue;

IsLREnabled = true;
messages.LastRequestEnabled().ToAllChat();
return HookResult.Continue;
}

private bool CountsToLR(CCSPlayerController player)
{
if (!player.IsReal())
return false;
if (!player.PawnIsAlive)
return false;
return player.GetTeam() == CsTeam.Terrorist;
}

public bool IsLREnabled { get; set; }
public IList<AbstractLastRequest> ActiveLRs { get; } = new List<AbstractLastRequest>();

Expand Down
28 changes: 28 additions & 0 deletions mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;

namespace Jailbreak.LastRequest.LastRequests;

public class KnifeFight : AbstractLastRequest
{
public KnifeFight(BasePlugin plugin, CCSPlayerController prisoner, CCSPlayerController guard) : base(plugin,
prisoner, guard)
{
}

public override void Setup()
{
// Strip weapons, teleport T to CT
}

public override void Execute()
{
// Give knives
}

public override void End(LRResult result)
{
// Slay the loser
}
}
9 changes: 9 additions & 0 deletions public/Jailbreak.Formatting/Views/ILastRequestMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Jailbreak.Formatting.Base;

namespace Jailbreak.Formatting.Views;

public interface ILastRequestMessages
{
public IView LastRequestEnabled();
public IView LastRequestDisabled();
}
27 changes: 18 additions & 9 deletions public/Jailbreak.Public/Mod/LastRequest/AbstractLastRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ namespace Jailbreak.Public.Mod.LastRequest;

public abstract class AbstractLastRequest
{
protected CCSPlayerController prisoner, guard;
protected LRType type;
protected LRState state;

protected DateTimeOffset startTime;

public abstract void Setup();
public abstract void Execute();
public abstract void End(LRResult result);
public CCSPlayerController prisoner { get; protected set; }
public CCSPlayerController guard { get; protected set; }
public LRType type { get; protected set; }
public LRState state { get; protected set; }
protected BasePlugin plugin;
protected DateTimeOffset startTime;

protected AbstractLastRequest(BasePlugin plugin, CCSPlayerController prisoner, CCSPlayerController guard)
{
this.plugin = plugin;
this.prisoner = prisoner;
this.guard = guard;
}


public abstract void Setup();
public abstract void Execute();
public abstract void End(LRResult result);
}

0 comments on commit dfe24dd

Please sign in to comment.