Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:edgegamers/Jailbreak into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 31, 2024
2 parents 1b68788 + e183a5a commit 54a60d6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
20 changes: 20 additions & 0 deletions lang/Jailbreak.English/Warden/WardenCmdOpenLocale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ public IView CellsOpened
WardenLocale.PREFIX, ChatColors.Grey + "Cells were auto-opened."
};

public IView CellsOpenedWithPrisoners(int prisoners) {
return new SimpleView {
WardenLocale.PREFIX,
"Detected",
prisoners,
ChatColors.Green + "prisoner" + (prisoners == 1 ? "" : "s")
+ " still in cells, opening..."
};
}

public IView CellsOpenedSnitchPrisoners(int prisoners) {
return new SimpleView {
WardenLocale.PREFIX,
"Detected",
prisoners,
ChatColors.Green + "prisoner" + (prisoners == 1 ? "" : "s")
+ " still in cells..."
};
}

public IView OpeningFailed
=> new SimpleView { WardenLocale.PREFIX, "Failed to open the cells." };
}
55 changes: 50 additions & 5 deletions mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Jailbreak.Public.Mod.Warden;
using Jailbreak.Public.Mod.Zones;
using Jailbreak.Public.Utils;
using Jailbreak.Zones;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MStatsShared;
Expand Down Expand Up @@ -58,6 +59,11 @@ public class WardenBehavior(ILogger<WardenBehavior> logger,
new("css_jb_warden_opencells_delay",
"Delay in seconds to auto-open cells at, -1 to disable", 60);

public static readonly FakeConVar<bool> CV_WARDEN_AUTO_SNITCH =
new("css_jb_warden_auto_snitch",
"True to broadcast how many prisoners were in cells when they auto-open",
true);

public static readonly FakeConVar<int> CV_WARDEN_HEALTH =
new("css_jb_warden_hp", "HP for the warden", 125, ConVarFlags.FCVAR_NONE,
new RangeValidator<int>(1, 200));
Expand Down Expand Up @@ -409,18 +415,57 @@ public HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info) {

openCellsTimer?.Kill();
openCellsTimer = parent.AddTimer(CV_WARDEN_AUTO_OPEN_CELLS.Value, () => {
if (openCmd.OpenedCells) return;
var zone = provider.GetService<IZoneManager>();
if (zone != null)
MapUtil.OpenCells(zone);
var cellZone = getCellZone();

var prisoners = PlayerUtil.FromTeam(CsTeam.Terrorist)
.Count(p => p.Pawn.Value != null && p.Pawn.Value.AbsOrigin != null
&& cellZone.IsInsideZone(p.Pawn.Value?.AbsOrigin!));

if (openCmd.OpenedCells) {
if (CV_WARDEN_AUTO_SNITCH.Value && prisoners > 0)
cmdLocale.CellsOpenedSnitchPrisoners(prisoners);
return;
}

var zoneMgr = provider.GetService<IZoneManager>();
// Regardless of if we actually _detect_ prisoners in cells,
// we should still open them (for convenience)
if (zoneMgr != null)
MapUtil.OpenCells(zoneMgr);
else
MapUtil.OpenCells();
cmdLocale.CellsOpened.ToAllChat();

// Only if we detect prisoners in cells (i.e. presumably
// cells haven't been opened yet) should we send the message

if (prisoners == 0) return;

if (CV_WARDEN_AUTO_SNITCH.Value) {
cmdLocale.CellsOpenedWithPrisoners(prisoners);
} else { cmdLocale.CellsOpened.ToAllChat(); }
});

return HookResult.Continue;
}

private IZone getCellZone() {
var manager = provider.GetService<IZoneManager>();
if (manager != null) {
var zones = manager.GetZones(Server.MapName, ZoneType.CELL)
.GetAwaiter()
.GetResult();
if (zones.Count > 0) return new MultiZoneWrapper(zones);
}

var bounds = new DistanceZone(
Utilities
.FindAllEntitiesByDesignerName<SpawnPoint>("info_player_terrorist")
.Where(s => s.AbsOrigin != null)
.Select(s => s.AbsOrigin!)
.ToList(), DistanceZone.WIDTH_CELL);
return bounds;
}

[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect ev,
GameEventInfo info) {
Expand Down
1 change: 1 addition & 0 deletions mod/Jailbreak.Warden/Jailbreak.Warden.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj"/>
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj"/>
<ProjectReference Include="..\Jailbreak.Zones\Jailbreak.Zones.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions public/Jailbreak.Formatting/Views/Warden/IWardenCmdOpenLocale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,19 @@ public interface IWardenCmdOpenLocale {
/// <returns></returns>
public IView CellsOpenedBy(CCSPlayerController? player);

/// <summary>
/// Cells were opened with prisoners still inside.
/// </summary>
/// <param name="prisoners"></param>
/// <returns></returns>
public IView CellsOpenedWithPrisoners(int prisoners);

/// <summary>
/// Cells were already opened, but there are still prisoners inside.
/// </summary>
/// <param name="prisoners"></param>
/// <returns></returns>
public IView CellsOpenedSnitchPrisoners(int prisoners);

public IView CannotOpenYet(int seconds);
}

0 comments on commit 54a60d6

Please sign in to comment.