Skip to content

Commit

Permalink
Merge s4s and m4m into one
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 2, 2024
1 parent b349954 commit 8cc0763
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 168 deletions.
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,16 +9,25 @@

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);
}
Expand All @@ -28,13 +39,9 @@ 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 "
PrintToParticipants(player.PlayerName + " chose the "
+ CHOSEN_PISTOL.GetFriendlyWeaponName());
State = LRState.ACTIVE;

Expand All @@ -44,24 +51,32 @@ private void OnSelect(CCSPlayerController player, ChatMenuOption option) {
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;
magSize = magForMag ?
Prisoner.GetWeaponBase(CHOSEN_PISTOL)!.VData!.MaxClip1 :
1;

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

whosShot.GetWeaponBase(CHOSEN_PISTOL).SetAmmo(MAGAZINE_SIZE, 0);
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);
Expand All @@ -80,9 +95,10 @@ public override void Execute() {
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 @@ -99,17 +115,18 @@ private void timeout() {
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;
Expand All @@ -118,16 +135,14 @@ private HookResult OnPlayerShoot(EventPlayerShoot @event,
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;
}
}
126 changes: 0 additions & 126 deletions mod/Jailbreak.LastRequest/LastRequests/ShotForShot.cs

This file was deleted.

0 comments on commit 8cc0763

Please sign in to comment.