diff --git a/mod/Jailbreak.LastRequest/LastRequestManager.cs b/mod/Jailbreak.LastRequest/LastRequestManager.cs index ee87d64..680be55 100644 --- a/mod/Jailbreak.LastRequest/LastRequestManager.cs +++ b/mod/Jailbreak.LastRequest/LastRequestManager.cs @@ -41,6 +41,10 @@ public class LastRequestManager(ILRLocale messages, IServiceProvider provider) new("css_jb_lr_activate_lr_at", "Number of prisoners to activate LR at", 2, ConVarFlags.FCVAR_NONE, new RangeValidator(1, 32)); + public static readonly FakeConVar CV_MIN_PLAYERS_FOR_CREDITS = + new("css_jb_min_players_for_credits", + "Minimum number of players to start" + " giving credits out", 5); + private ILastRequestFactory? factory; public bool IsLREnabledForRound { get; set; } = true; @@ -91,6 +95,11 @@ public void DisableLRForRound() { IsLREnabledForRound = false; } + private static bool shouldGrantCredits() { + if (API.Gangs == null) return false; + return Utilities.GetPlayers().Count >= CV_MIN_PLAYERS_FOR_CREDITS.Value; + } + public void EnableLR(CCSPlayerController? died = null) { messages.LastRequestEnabled().ToAllChat(); IsLREnabled = true; @@ -105,25 +114,25 @@ public void EnableLR(CCSPlayerController? died = null) { RoundUtil.AddTimeRemaining(CV_LR_GUARD_TIME.Value * cts); - foreach (var player in Utilities.GetPlayers()) { + var players = Utilities.GetPlayers(); + foreach (var player in players) { player.ExecuteClientCommand("play sounds/lr"); if (player.Team != CsTeam.Terrorist || !player.PawnIsAlive) continue; if (died != null && player.SteamID == died.SteamID) continue; player.ExecuteClientCommandFromServer("css_lr"); } - if (API.Gangs != null) { - var eco = API.Gangs.Services.GetService(); - if (eco == null) return; - var survivors = Utilities.GetPlayers() - .Where(p => p is { IsBot: false, PawnIsAlive: true }) - .Select(p => new PlayerWrapper(p)) - .ToList(); - Task.Run(async () => { - foreach (var survivor in survivors) - await eco.Grant(survivor, 100, reason: "LR Reached"); - }); - } + if (!shouldGrantCredits()) return; + var eco = API.Gangs?.Services.GetService(); + if (eco == null) return; + var survivors = Utilities.GetPlayers() + .Where(p => p is { IsBot: false, PawnIsAlive: true }) + .Select(p => new PlayerWrapper(p)) + .ToList(); + Task.Run(async () => { + foreach (var survivor in survivors) + await eco.Grant(survivor, 100, reason: "LR Reached"); + }); } public bool InitiateLastRequest(CCSPlayerController prisoner, @@ -157,8 +166,8 @@ public bool EndLastRequest(AbstractLastRequest lr, LRResult result) { RoundUtil.AddTimeRemaining(CV_LR_BONUS_TIME.Value); messages.LastRequestDecided(lr, result).ToAllChat(); - if (API.Gangs != null) { - var eco = API.Gangs.Services.GetService(); + if (shouldGrantCredits()) { + var eco = API.Gangs?.Services.GetService(); if (eco == null) return false; var wrapper = new PlayerWrapper(result == LRResult.GUARD_WIN ? diff --git a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs index 5f627ed..87df084 100644 --- a/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs +++ b/mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs @@ -13,11 +13,6 @@ namespace Jailbreak.LastRequest.LastRequests; public class BulletForBullet : TeleportingRequest { - private static readonly string[] GUNS = [ - "weapon_deagle", "weapon_usp_silencer", "weapon_tec9", "weapon_ssg08", - "weapon_nova" - ]; - private readonly ChatMenu chatMenu; private readonly bool magForMag; private readonly ILRB4BLocale msg; @@ -30,9 +25,6 @@ public BulletForBullet(BasePlugin plugin, IServiceProvider provider, provider.GetRequiredService(), prisoner, guard) { this.magForMag = magForMag; chatMenu = new ChatMenu(magForMag ? "Mag for Mag" : "Shot for Shot"); - foreach (var pistol in GUNS) - chatMenu.AddMenuOption(pistol.GetFriendlyWeaponName(), - (player, option) => OnSelect(player, option, pistol)); msg = provider.GetRequiredService(); } @@ -40,36 +32,6 @@ public BulletForBullet(BasePlugin plugin, IServiceProvider provider, public override LRType Type => magForMag ? LRType.MAG_FOR_MAG : LRType.SHOT_FOR_SHOT; - private void OnSelect(CCSPlayerController player, ChatMenuOption _, - string designer) { - if (player.Slot != Prisoner.Slot) return; - designerName = designer; - MenuManager.CloseActiveMenu(player); - - msg.WeaponSelected(player, designerName.GetFriendlyWeaponName()) - .ToChat(Prisoner, Guard); - - State = LRState.ACTIVE; - - Prisoner.RemoveWeapons(); - Guard.RemoveWeapons(); - Prisoner.GiveNamedItem(designerName); - Guard.GiveNamedItem(designerName); - - Plugin.AddTimer(0.5f, () => { - magSize = (magForMag ? - Prisoner.GetWeaponBase(designerName)!.VData?.MaxClip1 : - 1) ?? 1; - Prisoner.GetWeaponBase(designerName).SetAmmo(0, 0); - Guard.GetWeaponBase(designerName).SetAmmo(0, 0); - var shooter = new Random().Next(2) == 0 ? Prisoner : Guard; - whosShot = shooter.Slot; - msg.PlayerGoesFirst(shooter).ToChat(Prisoner, Guard); - - shooter.GetWeaponBase(designer).SetAmmo(magSize.Value, 0); - }); - } - public override void Setup() { Plugin.RegisterEventHandler(OnPlayerShoot); @@ -78,17 +40,30 @@ public override void Setup() { base.Setup(); Execute(); - - chatMenu.Title = - $"{chatMenu.Title} - {Prisoner.PlayerName} vs {Guard.PlayerName}"; } + private const string weaponName = "weapon_deagle"; public override void Execute() { State = LRState.PENDING; MenuManager.OpenChatMenu(Prisoner, chatMenu); - Plugin.AddTimer(10, timeout, TimerFlags.STOP_ON_MAPCHANGE); + Plugin.AddTimer(5, () => { + if (State != LRState.PENDING) return; + Guard.GiveNamedItem(weaponName); + Prisoner.GiveNamedItem(weaponName); + + magSize = (magForMag ? + Prisoner.GetWeaponBase(weaponName)!.VData?.MaxClip1 : + 1) ?? 1; + Prisoner.GetWeaponBase(weaponName).SetAmmo(0, 0); + Guard.GetWeaponBase(weaponName).SetAmmo(0, 0); + var shooter = new Random().Next(2) == 0 ? Prisoner : Guard; + whosShot = shooter.Slot; + msg.PlayerGoesFirst(shooter).ToChat(Prisoner, Guard); + shooter.GetWeaponBase(weaponName).SetAmmo(magSize.Value, 0); + State = LRState.ACTIVE; + }, TimerFlags.STOP_ON_MAPCHANGE); Plugin.AddTimer(30, () => { if (State != LRState.ACTIVE) return; @@ -118,11 +93,6 @@ public override void Execute() { }, TimerFlags.STOP_ON_MAPCHANGE); } - private void timeout() { - if (string.IsNullOrEmpty(designerName)) - Manager.EndLastRequest(this, LRResult.TIMED_OUT); - } - private HookResult OnPlayerShoot(EventBulletImpact @event, GameEventInfo info) { if (State != LRState.ACTIVE) return HookResult.Continue; diff --git a/mod/Jailbreak.RTD/Rewards/WeaponReward.cs b/mod/Jailbreak.RTD/Rewards/WeaponReward.cs index 5b1b6f4..23d459d 100644 --- a/mod/Jailbreak.RTD/Rewards/WeaponReward.cs +++ b/mod/Jailbreak.RTD/Rewards/WeaponReward.cs @@ -21,7 +21,7 @@ public WeaponReward(string weapon, CsTeam? requiredTeam = CsTeam.Terrorist) { public virtual string Description => "You won a" - + (weapon.GetFriendlyWeaponName()[0].IsVowel() ? "n" : "" + " ") + + (weapon.GetFriendlyWeaponName()[0].IsVowel() ? "n" : "") + " " + weapon.GetFriendlyWeaponName() + " next round."; public bool CanGrantReward(CCSPlayerController player) { diff --git a/mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs b/mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs index bfacd76..25a95d2 100644 --- a/mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs +++ b/mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs @@ -268,7 +268,7 @@ private void detonate(CCSPlayerController player, CC4 bomb) { } } - if (API.Gangs != null) { + if (API.Gangs != null && killed > 0) { var eco = API.Gangs.Services.GetService(); if (eco != null) { var wrapper = new PlayerWrapper(player); diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index b9ccd7a..02b8e4f 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -123,7 +123,8 @@ private float getRebelTimePercentage(CCSPlayerController player) { } private Color getRebelColor(CCSPlayerController player) { - var percent = getRebelTimePercentage(player); + var percent = getRebelTimePercentage(player); + percent = Math.Clamp(percent, 0, 1); var percentRgb = 255 - (int)Math.Round(percent * 255.0); var color = Color.FromArgb(255, 255, percentRgb, percentRgb); if (percent <= 0) color = Color.White; diff --git a/public/Jailbreak.Public/Jailbreak.Public.csproj b/public/Jailbreak.Public/Jailbreak.Public.csproj index 5595dfa..a766d80 100644 --- a/public/Jailbreak.Public/Jailbreak.Public.csproj +++ b/public/Jailbreak.Public/Jailbreak.Public.csproj @@ -9,7 +9,7 @@ - + Mixin\GangsAPI.dll