Skip to content

Commit

Permalink
Add noscope reward
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Aug 28, 2024

Verified

This commit was signed with the committer’s verified signature.
MSWS Isaac
1 parent 93dc66e commit 125a634
Showing 12 changed files with 157 additions and 9 deletions.
8 changes: 5 additions & 3 deletions mod/Jailbreak.RTD/RewardGenerator.cs
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@ public class RewardGenerator(IZoneManager mgr, IC4Service bomb)
(new WeaponReward("weapon_taser"), PROB_MEDIUM),
(new HPReward(150), PROB_MEDIUM), (new HPReward(50), PROB_MEDIUM),
(new ArmorReward(150), PROB_MEDIUM), (new HPReward(1), PROB_LOW),
(new ColorReward(Color.FromArgb(0, 255, 0)), PROB_LOW),
(new ColorReward(Color.FromArgb(255, 0, 0)), PROB_LOW),
(new ColorReward(Color.FromArgb(0, 255, 0), true), PROB_LOW),
(new ColorReward(Color.FromArgb(255, 0, 0), true), PROB_LOW),
(new TransparentReward(), PROB_LOW),
(new AmmoWeaponReward("weapon_glock", 2, 0), PROB_LOW),
(new AmmoWeaponReward("weapon_negev", 0, 5), PROB_LOW),
@@ -49,6 +49,7 @@ public void Start(BasePlugin basePlugin) {
PROB_LOW));
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.UTILITY),
PROB_LOW));
rewards.Add((new CannotScopeReward(basePlugin), PROB_LOW));
rewards.Add((
new CannotPickupReward(basePlugin,
WeaponType.GRENADE | WeaponType.UTILITY), PROB_LOW));
@@ -67,10 +68,11 @@ public void Start(BasePlugin basePlugin) {
private float totalWeight
=> rewards.Where(r => r.Item1.Enabled).Select(s => s.Item2).Sum();

public IRTDReward GenerateReward(int slot) {
public IRTDReward GenerateReward(int? id) {
var roll = rng.NextDouble() * totalWeight;

foreach (var reward in rewards.Where(reward => reward.Item1.Enabled)) {
if (id != null && reward.Item1.CanGrantReward(id.Value)) continue;
roll -= reward.Item2;
if (roll <= 0) return reward.Item1;
}
5 changes: 5 additions & 0 deletions mod/Jailbreak.RTD/Rewards/BombReward.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Mod.RTD;

@@ -14,6 +15,10 @@ public bool PrepareReward(int userid) {
return true;
}

public bool CanGrantReward(CCSPlayerController player) {
return player.Team == CsTeam.Terrorist;
}

public bool GrantReward(CCSPlayerController player) {
bombService.TryGiveC4ToPlayer(player);
return true;
72 changes: 72 additions & 0 deletions mod/Jailbreak.RTD/Rewards/CannotScopeReward.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Collections.Immutable;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.RTD;

namespace Jailbreak.RTD.Rewards;

public class CannotScopeReward : IRTDReward {
private readonly BasePlugin plugin;

public CannotScopeReward(BasePlugin plugin, WeaponType blocked) : this(plugin,
blocked.GetItems().ToArray()) { }

public CannotScopeReward(BasePlugin plugin, params string[] weapons) {
this.plugin = plugin;
this.plugin.RegisterEventHandler<EventRoundEnd>(onRoundEnd);
}

public string Name => "Cannot Scope";

public string Description
=> $"You will not be able to pickup {Name} the next round.";

private bool registered;

private readonly HashSet<int> blockedPlayerIDs = [];

public bool GrantReward(CCSPlayerController player) {
if (player.UserId == null) return false;
if (!registered) {
plugin.RegisterListener<Listeners.OnTick>(onTick);
registered = true;
}

blockedPlayerIDs.Add(player.UserId.Value);
return true;
}

private HookResult onRoundEnd(EventRoundEnd @event, GameEventInfo info) {
blockedPlayerIDs.Clear();
plugin.RemoveListener<Listeners.OnTick>(onTick);
registered = false;
return HookResult.Continue;
}

private void onTick() {
registered = true;
if (blockedPlayerIDs.Count == 0) {
plugin.RemoveListener<Listeners.OnTick>(onTick);
registered = false;
return;
}

foreach (var player in blockedPlayerIDs.Select(
Utilities.GetPlayerFromUserid)) {
if (player == null || player.UserId == null || !player.IsValid) continue;
disableScope(player);
}
}

private void disableScope(CCSPlayerController player) {
if (!player.IsReal()) return;
var pawn = player.PlayerPawn.Value;
if (pawn == null || !pawn.IsValid) return;
var weaponServices = pawn.WeaponServices;
if (weaponServices == null) return;
var activeWeapon = weaponServices.ActiveWeapon.Value;
if (activeWeapon == null || !activeWeapon.IsValid) return;
activeWeapon.NextSecondaryAttackTick = Server.TickCount + 500;
}
}
6 changes: 5 additions & 1 deletion mod/Jailbreak.RTD/Rewards/ColorReward.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

namespace Jailbreak.RTD.Rewards;

public class ColorReward(Color color) : IRTDReward {
public class ColorReward(Color color, bool prisonerOnly) : IRTDReward {
public virtual string Name => "Spawn " + ColorName;

public virtual string Description
@@ -36,6 +36,10 @@ public char ChatColor
_ => ChatColors.White
};

public bool CanGrantReward(CCSPlayerController player) {
return player.Team == CsTeam.Terrorist || !prisonerOnly;
}

public bool GrantReward(CCSPlayerController player) {
player.SetColor(color);
return true;
23 changes: 23 additions & 0 deletions mod/Jailbreak.RTD/Rewards/GuaranteedWardenReward.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Mod.RTD;
using Jailbreak.Public.Mod.Warden;

namespace Jailbreak.RTD.Rewards;

public class GuaranteedWardenReward(IWardenSelectionService service)
: IRTDReward {
public string Name => "Guaranteed Warden";

public string Description
=> "You are guaranteed to be warden next round if you queue for it";

public bool CanGrantReward(CCSPlayerController player) {
return player.Team == CsTeam.CounterTerrorist;
}

public bool GrantReward(CCSPlayerController player) {
service.SetGuaranteedWarden(player);
return true;
}
}
5 changes: 5 additions & 0 deletions mod/Jailbreak.RTD/Rewards/RandomTeleportReward.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Mod.RTD;
using Jailbreak.Public.Mod.Zones;
using Jailbreak.Public.Utils;
@@ -11,6 +12,10 @@ public class RandomTeleportReward(IZoneManager zones) : IRTDReward {
public string Description
=> "You will be teleported to a random location next round.";

public bool CanGrantReward(CCSPlayerController player) {
return player.Team == CsTeam.Terrorist;
}

public bool GrantReward(CCSPlayerController player) {
var zone = MapUtil.GetRandomSpawns(1, zones).FirstOrDefault();
if (zone == null) return false;
2 changes: 1 addition & 1 deletion mod/Jailbreak.RTD/Rewards/TransparentReward.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
namespace Jailbreak.RTD.Rewards;

public class TransparentReward()
: ColorReward(Color.FromArgb(128, 255, 255, 255)) {
: ColorReward(Color.FromArgb(128, 255, 255, 255), false) {
public override string Name => "Spawn Transparent";

public override string Description
6 changes: 6 additions & 0 deletions mod/Jailbreak.RTD/Rewards/WeaponReward.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using System.Reflection;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.RTD;

@@ -22,6 +23,11 @@ public string Description
+ (weapon.GetFriendlyWeaponName()[0].IsVowel() ? "n" : "" + " ")
+ weapon.GetFriendlyWeaponName() + " next round.";

public bool CanGrantReward(CCSPlayerController player) {
// No point in giving a weapon to someone on CT
return player.Team == CsTeam.Terrorist;
}

public virtual bool GrantReward(CCSPlayerController player) {
player.GiveNamedItem(weapon);
return true;
12 changes: 12 additions & 0 deletions mod/Jailbreak.Warden/Selection/WardenSelectionBehavior.cs
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@ public class

private readonly IWardenService warden;

private readonly HashSet<int> guaranteedWarden = [];

/// <summary>
/// Whether or not to use the queue.
/// When true, the queue should be skipped and turn to first-come-first-serve.
@@ -57,9 +59,18 @@ public void Start(BasePlugin basePlugin) { }

public void Dispose() { }

public void SetGuaranteedWarden(CCSPlayerController player) {
guaranteedWarden.Add(player.UserId ?? -1);
}

public bool TryEnter(CCSPlayerController player) {
if (!canEnterQueue(player)) return false;

if (guaranteedWarden.Contains(player.UserId ?? -1)) {
warden.TrySetWarden(player);
return true;
}

queue.Get(player).InQueue = true;
return true;
}
@@ -100,6 +111,7 @@ public void ScheduleChooseWarden(float time = 7.0f) {
/// Timer callback that states it's time to choose the warden.
/// </summary>
protected void OnChooseWarden() {
if (warden.HasWarden) return;
var eligible = Utilities.GetPlayers()
.Where(player => player.PawnIsAlive)
.Where(player => player.Team == CsTeam.CounterTerrorist)
15 changes: 13 additions & 2 deletions public/Jailbreak.Public/Mod/RTD/IRTDReward.cs
Original file line number Diff line number Diff line change
@@ -8,9 +8,20 @@ public interface IRTDReward {
public string Description { get; }
bool Enabled => true;

bool CanGrantReward(int userid) { return true; }
bool CanGrantReward(int userid) {
var player = Utilities.GetPlayerFromUserid(userid);
return player != null && player.IsValid && CanGrantReward(player);
}

bool CanGrantReward(CCSPlayerController player) { return true; }

bool PrepareReward(int userid) {
var player = Utilities.GetPlayerFromUserid(userid);
if (player == null || !player.IsValid) return false;
return PrepareReward(player);
}

bool PrepareReward(int userid) { return true; }
bool PrepareReward(CCSPlayerController player) { return true; }

bool GrantReward(int userid) {
var player = Utilities.GetPlayerFromUserid(userid);
4 changes: 2 additions & 2 deletions public/Jailbreak.Public/Mod/RTD/IRewardGenerator.cs
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
namespace Jailbreak.Public.Mod.RTD;

public interface IRewardGenerator : IReadOnlyCollection<(IRTDReward, float)> {
IRTDReward GenerateReward(int slot);
IRTDReward GenerateReward(int? id);

IRTDReward GenerateReward(CCSPlayerController player) {
return GenerateReward(player.UserId ?? -1);
return GenerateReward(player.UserId);
}
}
8 changes: 8 additions & 0 deletions public/Jailbreak.Public/Mod/Warden/IWardenSelectionService.cs
Original file line number Diff line number Diff line change
@@ -8,6 +8,14 @@ public interface IWardenSelectionService {
/// </summary>
bool Active { get; }

/// <summary>
/// Whether the player should be guaranteed warden if they enter the queue
/// this will act as a bypass to the queue. Thus, if multiple players are
/// applied with this, the first player to be apply for warden will receive it.
/// </summary>
/// <param name="player"></param>
void SetGuaranteedWarden(CCSPlayerController player);

/// <summary>
/// Enter this player into the warden queue
/// </summary>

0 comments on commit 125a634

Please sign in to comment.