Skip to content

Commit

Permalink
Mark everyone as rebel on last guard
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Nov 1, 2024
1 parent e1790d1 commit 85cf6d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
17 changes: 10 additions & 7 deletions mod/Jailbreak.LastGuard/LastGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.LastGuard;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Utils;
using Jailbreak.Validator;
using Microsoft.Extensions.DependencyInjection;
using MStatsShared;

namespace Jailbreak.LastGuard;

public class LastGuard(ILGLocale notifications, ILastRequestManager lrManager)
: ILastGuardService, IPluginBehavior {
public class LastGuard(ILGLocale notifications, ILastRequestManager lrManager,
IRebelService rebel) : ILastGuardService, IPluginBehavior {
public static readonly FakeConVar<bool> CV_ALWAYS_OVERRIDE_CT = new(
"css_jb_lg_apply_lower_hp",
"If true, the LG will be forced lower health if calculated");
Expand Down Expand Up @@ -66,7 +67,7 @@ public class LastGuard(ILGLocale notifications, ILastRequestManager lrManager)

private readonly Random rng = new();
private bool canStart;
private bool isLastGuard;
public bool IsLastGuardActive { get; private set; }
private List<CCSPlayerController> lastGuardPrisoners = [];

public void Start(BasePlugin basePlugin, bool hotreload) {
Expand All @@ -82,7 +83,7 @@ public void StartLastGuard(CCSPlayerController lastGuard) {

if (guardPlayerPawn == null || !guardPlayerPawn.IsValid) return;

isLastGuard = true;
IsLastGuardActive = true;

var stats = API.Gangs?.Services.GetService<IPlayerStatManager>();
if (stats != null) {
Expand Down Expand Up @@ -134,6 +135,8 @@ public void StartLastGuard(CCSPlayerController lastGuard) {
.ToAllCenter()
.ToAllChat();

foreach (var player in lastGuardPrisoners) rebel.MarkRebel(player);

if (string.IsNullOrEmpty(CV_LG_WEAPON.Value)) return;

foreach (var player in lastGuardPrisoners)
Expand Down Expand Up @@ -161,7 +164,7 @@ public HookResult OnPlayerDeathEvent(EventPlayerDeath @event,
if (player == null) return HookResult.Continue;
checkLastGuard(@event.Userid);

if (!isLastGuard) return HookResult.Continue;
if (!IsLastGuardActive) return HookResult.Continue;

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

Expand Down Expand Up @@ -204,7 +207,7 @@ private bool playerHasGun(CCSPlayerController player) {

private void checkLastGuard(CCSPlayerController? poi) {
if (poi == null) return;
if (isLastGuard) return;
if (IsLastGuardActive) return;
lastGuardPrisoners.Remove(poi);
if (poi.Team != CsTeam.CounterTerrorist) return;
var aliveCts = Utilities.GetPlayers()
Expand All @@ -223,7 +226,7 @@ private void checkLastGuard(CCSPlayerController? poi) {

[GameEventHandler]
public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) {
isLastGuard = false;
IsLastGuardActive = false;
return HookResult.Continue;
}

Expand Down
9 changes: 7 additions & 2 deletions mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
using Jailbreak.Public;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Damage;
using Jailbreak.Public.Mod.LastGuard;
using Jailbreak.Public.Mod.LastRequest;
using Jailbreak.Public.Mod.LastRequest.Enums;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Utils;
using Microsoft.Extensions.DependencyInjection;
using MStatsShared;

namespace Jailbreak.LastRequest;

public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
public class LastRequestManager(ILRLocale messages, IServiceProvider provider,
ILastGuardService lastGuard, IRebelService rebel)
: ILastRequestManager, IDamageBlocker {
public static readonly FakeConVar<int> CV_LR_BASE_TIME =
new("css_jb_lr_time_base",
Expand All @@ -49,7 +52,7 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider)
public void Start(BasePlugin basePlugin, bool hotreload) {
var stats = API.Gangs?.Services.GetService<IStatManager>();
if (stats == null) return;

stats.Stats.Add(new LRStat());
}

Expand Down Expand Up @@ -146,6 +149,8 @@ public void EnableLR(CCSPlayerController? died = null) {

if (player.Team != CsTeam.Terrorist) continue;
if (died != null && player.SteamID == died.SteamID) continue;

if (lastGuard.IsLastGuardActive) rebel.UnmarkRebel(player);
player.ExecuteClientCommandFromServer("css_lr");
}

Expand Down
2 changes: 2 additions & 0 deletions public/Jailbreak.Public/Mod/LastGuard/ILastGuardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface ILastGuardService {
void StartLastGuard(CCSPlayerController lastGuard);

public void DisableLastGuardForRound();

bool IsLastGuardActive { get; }
}

0 comments on commit 85cf6d5

Please sign in to comment.