Skip to content

Commit

Permalink
Add automatic zone generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 3, 2024
1 parent 8cc0763 commit 0399a69
Show file tree
Hide file tree
Showing 39 changed files with 387 additions and 200 deletions.
26 changes: 8 additions & 18 deletions lang/Jailbreak.English/Warden/OpenCommandNotifications.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Utils;

namespace Jailbreak.English.Warden;

Expand All @@ -16,22 +15,13 @@ public IView CannotOpenYet(int seconds) {
};
}

public IView OpenResult(Sensitivity? sensitivity) {
return sensitivity switch {
Sensitivity.NAME_CELL_DOOR or Sensitivity.NAME_CELL => new SimpleView {
WardenNotifications.PREFIX, "The warden opened the cell doors."
},
Sensitivity.TARGET_CELL_DOOR or Sensitivity.TARGET_CELL => new
SimpleView {
WardenNotifications.PREFIX,
"The warden attempted to open the cell door."
},
Sensitivity.ANY_WITH_TARGET => new SimpleView {
WardenNotifications.PREFIX, "Attempting to open cell coors..."
},
_ => new SimpleView {
WardenNotifications.PREFIX, "Could not open cell doors."
}
public IView CellsOpened
=> new SimpleView {
WardenNotifications.PREFIX, "The warden opened cells."
};

public IView OpeningFailed
=> new SimpleView {
WardenNotifications.PREFIX, "Failed to open the cells."
};
}
}
5 changes: 2 additions & 3 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public IView CurrentWarden(CCSPlayerController? player) {
new SimpleView { PREFIX, "There is no warden." };
}

public IView CannotWardenDuringWarmup => new SimpleView {
PREFIX, "You cannot warden during warmup."
};
public IView CannotWardenDuringWarmup
=> new SimpleView { PREFIX, "You cannot warden during warmup." };

public IView FireCommandSuccess(CCSPlayerController player) {
return new SimpleView {
Expand Down
4 changes: 3 additions & 1 deletion mod/Jailbreak.Debug/Subcommands/OpenCells.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.Public.Mod.Zones;
using Jailbreak.Public.Utils;
using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.Debug.Subcommands;

public class OpenCells(IServiceProvider services) : AbstractCommand(services) {
public override void OnCommand(CCSPlayerController? executor,
WrappedInfo info) {
MapUtil.OpenCells();
MapUtil.OpenCells(Services.GetRequiredService<IZoneManager>());
}
}
2 changes: 1 addition & 1 deletion mod/Jailbreak.Debug/Subcommands/Zone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2,
}

tpDestinations.Sort((a, b)
=> a.GetMinDistance(position) <= b.GetMinDistance(position) ? -1 : 1);
=> a.GetMinDistanceSquared(position) <= b.GetMinDistanceSquared(position) ? -1 : 1);
executor.PlayerPawn.Value.Teleport(tpDestinations.First()
.GetCenterPoint());

Expand Down
68 changes: 37 additions & 31 deletions mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Runtime.InteropServices.JavaScript;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Menu;
Expand All @@ -10,27 +9,27 @@
namespace Jailbreak.LastRequest.LastRequests;

public class BulletForBullet : TeleportingRequest {
private static readonly string[] GUNS = [
"weapon_deagle", "weapon_glock", "weapon_hkp2000", "weapon_tec9",
"weapon_cz75a"
];

private static readonly string[] GUN_NAMES = [
"Desert Eagle", "Glock 18", "USP-S", "Tec9", "CZ75"
];

private readonly ChatMenu chatMenu;
private string? CHOSEN_PISTOL;
private readonly bool magForMag;
private int? whosShot, magSize;
private bool magForMag = false;

private static readonly string[] GUNS = new string[] {
"weapon_deagle", "weapon_glock", "weapon_hkp2000", "weapon_tec9",
"weapon_cz75a", "weapon_revolver"
};

private static readonly string[] GUN_NAMES = new string[] {
"Desert Eagle", "Glock 18", "USP-S", "Tec9", "CZ75", "Revolver"
};

public BulletForBullet(BasePlugin plugin, ILastRequestManager manager,
CCSPlayerController prisoner, CCSPlayerController guard,
bool magForMag) : base(plugin, manager, prisoner, guard) {
chatMenu = new ChatMenu(magForMag ? "Mag for Mag" : "Shot for Shot");
foreach (var pistol in Tag.PISTOLS) {
this.magForMag = magForMag;
chatMenu = new ChatMenu(magForMag ? "Mag for Mag" : "Shot for Shot");
foreach (var pistol in GUNS)
chatMenu.AddMenuOption(pistol.GetFriendlyWeaponName(), OnSelect);
}
}

public override LRType Type => LRType.SHOT_FOR_SHOT;
Expand All @@ -45,21 +44,26 @@ private void OnSelect(CCSPlayerController player, ChatMenuOption option) {
+ CHOSEN_PISTOL.GetFriendlyWeaponName());
State = LRState.ACTIVE;

Prisoner.RemoveWeapons();
Guard.RemoveWeapons();
Prisoner.GiveNamedItem(CHOSEN_PISTOL);
Prisoner.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(0, 0);
Guard.GiveNamedItem(CHOSEN_PISTOL);
Guard.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(0, 0);

//steal the VData of the prisoners gun for mag size
magSize = magForMag ?
Prisoner.GetWeaponBase(CHOSEN_PISTOL)!.VData!.MaxClip1 :
1;
Server.NextFrame(() => {
magSize = magForMag ?
Prisoner.GetWeaponBase(CHOSEN_PISTOL)!.VData!.MaxClip1 :
1;
Prisoner.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(0, 0);
Guard.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(0, 0);
//steal the VData of the prisoners gun for mag size

var shooter = new Random().Next(2) == 0 ? Prisoner : Guard;
whosShot = shooter.Slot;
PrintToParticipants(shooter.PlayerName + " gets to shoot first");
var shooter = new Random().Next(2) == 0 ? Prisoner : Guard;
whosShot = shooter.Slot;
PrintToParticipants(shooter.PlayerName
+ $" gets to shoot first {magSize} {magForMag}");

shooter.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(magSize.Value, 0);
shooter.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(magSize.Value, 0);
});
}

public override void Setup() {
Expand Down Expand Up @@ -95,7 +99,7 @@ public override void Execute() {
LRResult.GUARD_WIN :
LRResult.PRISONER_WIN;
if (Guard.Health == Prisoner.Health) {
var active = whosShot == Prisoner.Slot ? Guard : Prisoner;
var active = whosShot == Prisoner.Slot ? Prisoner : Guard;
PrintToParticipants("Even health, since " + active.PlayerName
+ " had the shot, they lose.");
result = whosShot == Prisoner.Slot ?
Expand All @@ -111,7 +115,7 @@ public override void Execute() {
}

private void timeout() {
if (CHOSEN_PISTOL == String.Empty)
if (CHOSEN_PISTOL == string.Empty)
Manager.EndLastRequest(this, LRResult.TIMED_OUT);
}

Expand All @@ -132,12 +136,14 @@ private HookResult OnPlayerShoot(EventBulletImpact @event,
return HookResult.Handled;
}

if (player.GetWeaponBase(CHOSEN_PISTOL).Clip1 != 0)
return HookResult.Continue;
var bullets = player.GetWeaponBase(CHOSEN_PISTOL!)?.Clip1 ?? 1;
if (bullets > 1) return HookResult.Continue;

var opponent = player.Slot == Prisoner.Slot ? Guard : Prisoner;
opponent.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(magSize.Value, 0);
whosShot = opponent.Slot;
Server.NextFrame(() => {
var opponent = player.Slot == Prisoner.Slot ? Guard : Prisoner;
whosShot = opponent.Slot;
opponent.GetWeaponBase(CHOSEN_PISTOL!).SetAmmo(magSize.Value, 0);
});
return HookResult.Continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public virtual IView ArmoryReminder


override protected IZone GetZone() {
var manager = provider.GetRequiredService<IZoneManager>();
var manager = provider.GetRequiredService<IZoneManager>();
var zones = manager.GetZones(ZoneType.ARMORY).GetAwaiter().GetResult();
if (zones.Count > 0) return new MultiZoneWrapper(zones);

Expand Down
2 changes: 1 addition & 1 deletion mod/Jailbreak.SpecialDay/SpecialDays/CellRestrictedDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public virtual IView CellReminder
new SimpleView { SpecialDayMessages.PREFIX, "Stay in cells!" };

override protected IZone GetZone() {
var manager = provider.GetRequiredService<IZoneManager>();
var manager = provider.GetRequiredService<IZoneManager>();
var zones = manager.GetZones(ZoneType.CELL).GetAwaiter().GetResult();
if (zones.Count > 0) return new MultiZoneWrapper(zones);

Expand Down
11 changes: 5 additions & 6 deletions mod/Jailbreak.SpecialDay/SpecialDays/HideAndSeekDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,27 @@ public class HideAndSeekDay(BasePlugin plugin, IServiceProvider provider)
public ISpecialDayInstanceMessages Messages => new HNSDayMessages();

public override void Setup() {
Timers[5] += () => msg.DamageWarning(5).ToTeamChat(CsTeam.CounterTerrorist);
Timers[10] += () => {
foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist)) {
ct.SetSpeed(1.5f);
EnableDamage(ct);
}

((ISpecialDayMessageProvider)this).Messages.BeginsIn(25).ToAllChat();
msg.DamageWarning(15).ToTeamChat(CsTeam.CounterTerrorist);

Messages.BeginsIn(35).ToAllChat();
};
Timers[25] += () => {
foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist)) {
ct.SetSpeed(1.25f);
EnableDamage(ct);
}

Messages.BeginsIn(10).ToAllChat();
};
Timers[30] += () => {
foreach (var ct in PlayerUtil.FromTeam(CsTeam.CounterTerrorist))
ct.SetSpeed(1.1f);
Messages.BeginsIn(15).ToAllChat();
};
Timers[35] += Execute;
Timers[45] += Execute;

base.Setup();

Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.SpecialDay/SpecialDays/InfectionDay.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Extensions;
Expand Down Expand Up @@ -114,7 +113,8 @@ public HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) {
return HookResult.Continue;
}

public override HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) {
override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
var result = base.OnEnd(@event, info);
plugin.DeregisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
plugin.DeregisterEventHandler<EventPlayerSpawn>(OnRespawn);
Expand Down
6 changes: 2 additions & 4 deletions mod/Jailbreak.SpecialDay/SpecialDays/OneInTheChamberDay.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Views;
using Jailbreak.Public.Extensions;
Expand Down Expand Up @@ -53,7 +50,8 @@ private HookResult
return HookResult.Continue;
}

public override HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) {
override protected HookResult
OnEnd(EventRoundEnd @event, GameEventInfo info) {
plugin.DeregisterEventHandler<EventPlayerHurt>(OnPlayerDamage);
plugin.DeregisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
return base.OnEnd(@event, info);
Expand Down
Loading

0 comments on commit 0399a69

Please sign in to comment.