Skip to content

Commit

Permalink
Update lifecycle and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Feb 20, 2024
1 parent 0b3485d commit 1df1bee
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
29 changes: 29 additions & 0 deletions lang/Jailbreak.English/LastRequest/LastRequestMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;

namespace Jailbreak.English.LastRequest;

Expand Down Expand Up @@ -37,4 +39,31 @@ public IView InvalidPlayerChoice(CCSPlayerController player, string reason)
reason
};
}

public IView InformLastRequest(AbstractLastRequest lr)
{
return new SimpleView()
{
lr.prisoner, "is", lr.type.ToFriendlyString(),
"against", lr.guard
};
}

public IView AnnounceLastRequest(AbstractLastRequest lr)
{
return new SimpleView()
{
lr.prisoner, "is", lr.type.ToFriendlyString(),
"against", lr.guard
};
}

public IView LastRequestDecided(AbstractLastRequest lr, LRResult result)
{
return new SimpleView()
{
lr.prisoner, "'s LR has been decided: ",
result == LRResult.PrisonerWin ? lr.prisoner : lr.guard
};
}
}
5 changes: 5 additions & 0 deletions mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public bool InitiateLastRequest(CCSPlayerController prisoner, CCSPlayerControlle
var lr = factory.CreateLastRequest(prisoner, guard, type);
lr.Setup();
ActiveLRs.Add(lr);

messages.InformLastRequest(lr).ToPlayerChat(prisoner);
messages.InformLastRequest(lr).ToPlayerChat(guard);
return true;
}
catch (ArgumentException e)
Expand All @@ -111,6 +114,8 @@ public bool InitiateLastRequest(CCSPlayerController prisoner, CCSPlayerControlle

public bool EndLastRequest(AbstractLastRequest lr, LRResult result)
{
if (result == LRResult.GuardWin || result == LRResult.PrisonerWin)
messages.LastRequestDecided(lr, result).ToAllChat();
lr.End(result);
ActiveLRs.Remove(lr);
return true;
Expand Down
22 changes: 6 additions & 16 deletions mod/Jailbreak.LastRequest/LastRequests/KnifeFight.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;

Expand All @@ -11,29 +12,19 @@ public class KnifeFight : AbstractLastRequest
public KnifeFight(BasePlugin plugin, CCSPlayerController prisoner, CCSPlayerController guard) : base(plugin,
prisoner, guard)
{
plugin.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
}

public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
if (@event.Userid.Slot != prisoner.Slot && @event.Userid.Slot != guard.Slot)
return HookResult.Continue;

if (@event.Userid.Slot == prisoner.Slot)
End(LRResult.GuardWin);
else
End(LRResult.PrisonerWin);
return HookResult.Continue;
}

public override void Setup()
{
Server.PrintToChatAll($"{prisoner.PlayerName} is knife fighting {guard.PlayerName}");
// Strip weapons, teleport T to CT
prisoner.RemoveWeapons();
guard.RemoveWeapons();
guard.Teleport(prisoner.Pawn.Value!.AbsOrigin!, prisoner.Pawn.Value.AbsRotation!, new Vector());
prisoner.Pawn.Value.MoveType = MoveType_t.MOVETYPE_NONE;
guard.Pawn.Value!.MoveType = MoveType_t.MOVETYPE_NONE;
this.state = LRState.Pending;

plugin.AddTimer(0.5f, () => guard.Pawn.Value.MoveType = MoveType_t.MOVETYPE_WALK);
plugin.AddTimer(0.8f, () => guard.Pawn.Value.MoveType = MoveType_t.MOVETYPE_WALK);
plugin.AddTimer(3, Execute);
}

Expand All @@ -48,7 +39,6 @@ public override void Execute()

public override void End(LRResult result)
{
Server.PrintToChatAll($"The knife fight ended!");
this.state = LRState.Completed;
}
}
5 changes: 5 additions & 0 deletions public/Jailbreak.Formatting/Views/ILastRequestMessages.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.Formatting.Base;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;

namespace Jailbreak.Formatting.Views;

Expand All @@ -9,4 +11,7 @@ public interface ILastRequestMessages
public IView LastRequestDisabled();
public IView InvalidLastRequest(string query);
public IView InvalidPlayerChoice(CCSPlayerController player, string reason);
public IView InformLastRequest(AbstractLastRequest lr);
public IView AnnounceLastRequest(AbstractLastRequest lr);
public IView LastRequestDecided(AbstractLastRequest lr, LRResult result);
}

0 comments on commit 1df1bee

Please sign in to comment.