Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/new l rs #259

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lang/Jailbreak.English/SpecialDay/InfectionDayMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Jailbreak.English.SpecialDay;

public class InfectionDayMessages() : TeamDayMessages("Infection",
"CTs are infected and try to infect Ts!",
"Ts can scavenge for guns, but CTs can only use pistols!") {
"Ts can scavenge for any guns, but CTs can only use pistols!") {
public override IView SpecialDayEnd() {
var winner = PlayerUtil.GetAlive().FirstOrDefault()?.Team
?? CsTeam.Spectator;
Expand Down Expand Up @@ -42,4 +42,15 @@ public IView InfectedWarning(CCSPlayerController player) {
$"was {ChatColors.DarkRed}infected{ChatColors.Default}! {ChatColors.Red}Watch out!"
};
}

public IView DamageWarning(int seconds) {
return new SimpleView {
SpecialDayMessages.PREFIX,
"Damage will be enabled for the",
CsTeam.Terrorist,
"team in",
seconds,
"seconds."
};
}
}
28 changes: 25 additions & 3 deletions lang/Jailbreak.English/Warden/OpenCommandNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,31 @@ namespace Jailbreak.English.Warden;

public class OpenCommandNotifications : IOpenCommandMessages,
ILanguage<Formatting.Languages.English> {
public IView OpenResult(Sensitivity sensitivity) {
return new SimpleView { "foobar" };
public IView CannotOpenYet(int seconds) {
return new SimpleView {
WardenNotifications.PREFIX,
"You must wait",
seconds,
"seconds before opening the cells."
};
}

public IView OpenedCells => new SimpleView { "The warden opened the cells." };
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."
}
};
}
}
20 changes: 11 additions & 9 deletions mod/Jailbreak.LastRequest/LastRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ namespace Jailbreak.LastRequest;

public class LastRequestFactory(ILastRequestManager manager,
IServiceProvider services) : ILastRequestFactory {
private BasePlugin? plugin;
private BasePlugin plugin = null!;

public void Start(BasePlugin basePlugin) { plugin = basePlugin; }

public AbstractLastRequest CreateLastRequest(CCSPlayerController prisoner,
CCSPlayerController guard, LRType type) {
return type switch {
LRType.KNIFE_FIGHT => new KnifeFight(plugin!, manager, prisoner, guard),
LRType.GUN_TOSS => new GunToss(plugin!, manager, prisoner, guard),
LRType.NO_SCOPE => new NoScope(plugin!, manager, prisoner, guard),
LRType.SHOT_FOR_SHOT => new ShotForShot(plugin!, manager, prisoner, guard),
LRType.ROCK_PAPER_SCISSORS => new RockPaperScissors(plugin!, manager,
LRType.KNIFE_FIGHT => new KnifeFight(plugin, manager, prisoner, guard),
LRType.GUN_TOSS => new GunToss(plugin, manager, prisoner, guard),
LRType.NO_SCOPE => new NoScope(plugin, manager, prisoner, guard),
LRType.SHOT_FOR_SHOT => new BulletForBullet(plugin, manager, prisoner,
guard, false),
LRType.ROCK_PAPER_SCISSORS => new RockPaperScissors(plugin, manager,
prisoner, guard),
LRType.COINFLIP => new Coinflip(plugin!, manager, prisoner, guard),
LRType.RACE => new Race(plugin!, manager, prisoner, guard,
LRType.COINFLIP => new Coinflip(plugin, manager, prisoner, guard),
LRType.RACE => new Race(plugin, manager, prisoner, guard,
services.GetRequiredService<IRaceLRMessages>()),
LRType.MAG_FOR_MAG => new MagForMag(plugin!, manager, prisoner, guard),
LRType.MAG_FOR_MAG => new BulletForBullet(plugin, manager, prisoner,
guard, true),
_ => throw new ArgumentException("Invalid last request type: " + type,
nameof(type))
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.InteropServices.JavaScript;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Timers;
Expand All @@ -7,62 +9,80 @@

namespace Jailbreak.LastRequest.LastRequests;

public class MagForMag : WeaponizedRequest {
public class BulletForBullet : TeleportingRequest {
private readonly ChatMenu chatMenu;
private string? CHOSEN_PISTOL;
private int MAGAZINE_SIZE;
private CCSPlayerController? whosShot;
public MagForMag(BasePlugin plugin, ILastRequestManager manager,
CCSPlayerController prisoner, CCSPlayerController guard) :
base(plugin, manager, prisoner, guard) {
chatMenu = new ChatMenu("Shot For Shot");
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) {
chatMenu.AddMenuOption(pistol.GetFriendlyWeaponName(), OnSelect);
}
}

public override LRType Type => LRType.SHOT_FOR_SHOT;

private void OnSelect(CCSPlayerController player, ChatMenuOption option) {
if (player.Slot != Prisoner.Slot) return;
MenuManager.CloseActiveMenu(player);

CHOSEN_PISTOL = Tag.PISTOLS.ElementAt(Array.IndexOf([
"Desert Eagle", "Dualies", "Five Seven", "Glock 18", "HPK2000", "P250",
"USPS", "Tec9", "CZ75", "Revolver"
], option.Text));
CHOSEN_PISTOL = GUNS[Array.IndexOf(GUN_NAMES, option.Text)];

PrintToParticipants(player.PlayerName + " has chosen to use the " +
CHOSEN_PISTOL.GetFriendlyWeaponName());
PrintToParticipants(player.PlayerName + " chose the "
+ CHOSEN_PISTOL.GetFriendlyWeaponName());
State = LRState.ACTIVE;

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

//steal the VData of the prisoners gun for mag size
MAGAZINE_SIZE = Prisoner.GetWeaponBase(CHOSEN_PISTOL)!.VData!.MaxClip1;

whosShot = new Random().Next(2) == 0 ? Prisoner : Guard;
PrintToParticipants(whosShot.PlayerName + " has been chosen to shoot first");

whosShot.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(MAGAZINE_SIZE, 0);
magSize = magForMag ?
Prisoner.GetWeaponBase(CHOSEN_PISTOL)!.VData!.MaxClip1 :
1;

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

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

public override void Setup() {
Plugin.RegisterEventHandler<EventPlayerShoot>(OnPlayerShoot);
Plugin.RegisterEventHandler<EventBulletImpact>(OnPlayerShoot);

Prisoner.RemoveWeapons();
Guard.RemoveWeapons();

base.Setup();
Execute();

CHOSEN_PISTOL = String.Empty;
CHOSEN_PISTOL = string.Empty;
chatMenu.Title =
$"Shot For Shot - {Prisoner.PlayerName} vs {Guard.PlayerName}";
$"{chatMenu.Title} - {Prisoner.PlayerName} vs {Guard.PlayerName}";
}


public override void Execute() {
State = LRState.PENDING;
MenuManager.OpenChatMenu(Prisoner, chatMenu);

Plugin.AddTimer(10, timeout, TimerFlags.STOP_ON_MAPCHANGE);

Plugin.AddTimer(30, () => {
if (State != LRState.ACTIVE) return;
Prisoner.GiveNamedItem("weapon_knife");
Expand All @@ -75,9 +95,10 @@
LRResult.GUARD_WIN :
LRResult.PRISONER_WIN;
if (Guard.Health == Prisoner.Health) {
PrintToParticipants("Even health, since " + whosShot!.PlayerName
+ " had the shot last, they lose.");
result = whosShot.Slot == Prisoner.Slot ?
var active = whosShot == Prisoner.Slot ? Guard : Prisoner;
PrintToParticipants("Even health, since " + active.PlayerName
+ " had the shot, they lose.");
result = whosShot == Prisoner.Slot ?
LRResult.GUARD_WIN :
LRResult.PRISONER_WIN;
} else { PrintToParticipants("Health was the deciding factor. "); }
Expand All @@ -88,41 +109,40 @@
Guard.Pawn.Value?.CommitSuicide(false, true);
}, TimerFlags.STOP_ON_MAPCHANGE);
}

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

private HookResult OnPlayerShoot(EventPlayerShoot @event,
private HookResult OnPlayerShoot(EventBulletImpact @event,
GameEventInfo info) {
if (State != LRState.ACTIVE) return HookResult.Continue;

var player = @event.Userid;
if (player == null || whosShot == null || !player.IsReal())
if (player == null || whosShot == null || !player.IsValid
|| magSize == null)
return HookResult.Continue;

if (player.Slot != Prisoner.Slot && player.Slot != Guard.Slot)
return HookResult.Continue;
if (player.Slot != whosShot.Slot) {
if (player.Slot != whosShot) {
PrintToParticipants(player.PlayerName + " cheated.");
player.Pawn.Value?.CommitSuicide(false, true);
return HookResult.Handled;
}

if (player.GetWeaponBase(CHOSEN_PISTOL).Clip1 != 0)

Check warning on line 135 in mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'designerName' in 'CBasePlayerWeapon? PlayerExtensions.GetWeaponBase(CCSPlayerController player, string designerName)'.

Check warning on line 135 in mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 135 in mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'designerName' in 'CBasePlayerWeapon? PlayerExtensions.GetWeaponBase(CCSPlayerController player, string designerName)'.

Check warning on line 135 in mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
return HookResult.Continue;

PrintToParticipants(player.PlayerName + " has shot all their bullets.");
var opponent = player.Slot == Prisoner.Slot ? Guard : Prisoner;
opponent.PrintToChat("Your shot");
opponent.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(MAGAZINE_SIZE, 0);
whosShot = opponent;
opponent.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(magSize.Value, 0);
whosShot = opponent.Slot;
return HookResult.Continue;
}

public override void OnEnd(LRResult result) {
Plugin.DeregisterEventHandler<EventPlayerShoot>(OnPlayerShoot);
Plugin.DeregisterEventHandler<EventBulletImpact>(OnPlayerShoot);
State = LRState.COMPLETED;
}
}
121 changes: 0 additions & 121 deletions mod/Jailbreak.LastRequest/LastRequests/ShotForShot.cs

This file was deleted.

Loading
Loading