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

Add credit rewards, fix count command #315

Merged
merged 8 commits into from
Oct 28, 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
3 changes: 3 additions & 0 deletions mod/Jailbreak.RTD/Jailbreak.RTD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
</ItemGroup>

<ItemGroup>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
<Reference Include="MAULActainShared">
<HintPath>..\..\public\Jailbreak.Public\Mixin\MAULActainShared.dll</HintPath>
</Reference>
Expand Down
4 changes: 3 additions & 1 deletion mod/Jailbreak.RTD/RTDRewarder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public HookResult OnSpawn(EventPlayerSpawn @event, GameEventInfo info) {
if (!reward.CanGrantReward(player)) return HookResult.Continue;

Server.RunOnTick(Server.TickCount + 2, () => {
logs.Append("Granted", reward.Name, "to", logs.Player(player));
if (!player.IsValid) return;
if (reward.Name != "Nothing")
logs.Append("Granted", reward.Name, "to", logs.Player(player));
reward.GrantReward(id);
rewards.Remove(id);
});
Expand Down
24 changes: 16 additions & 8 deletions mod/Jailbreak.RTD/RewardGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Jailbreak.RTD;

public class RewardGenerator(IZoneManager mgr, IC4Service bomb,
IWardenSelectionService warden) : IPluginBehavior, IRewardGenerator {
private static readonly float PROB_LOTTERY = 1 / 5000f;
private static readonly float PROB_EXTREMELY_LOW = 1 / 1000f;
private static readonly float PROB_VERY_LOW = 1 / 100f;
private static readonly float PROB_LOW = 1 / 20f;
private static readonly float PROB_MEDIUM = 1 / 10f;
private static readonly float PROB_OFTEN = 1 / 5f;
private static readonly float PROB_VERY_OFTEN = 1 / 2f;
private const float PROB_LOTTERY = 1 / 3000f;
private const float PROB_EXTREMELY_LOW = 1 / 800f;
private const float PROB_VERY_LOW = 1 / 100f;
private const float PROB_LOW = 1 / 20f;
private const float PROB_MEDIUM = 1 / 10f;
private const float PROB_OFTEN = 1 / 5f;
private const float PROB_VERY_OFTEN = 1 / 2f;

private readonly List<(IRTDReward, float)> rewards = [];

Expand All @@ -32,11 +32,14 @@ public void Start(BasePlugin basePlugin) {
rewards.AddRange([
// Very often
(new NothingReward(), PROB_VERY_OFTEN),
(new CreditReward(1), PROB_VERY_OFTEN),
(new CreditReward(-1), PROB_VERY_OFTEN),

// Often
(new WeaponReward("weapon_healthshot"), PROB_OFTEN),
(new WeaponReward("weapon_decoy"), PROB_OFTEN),
(new HPReward(110), PROB_OFTEN), (new ArmorReward(15), PROB_OFTEN),
(new CreditReward(-10), PROB_VERY_OFTEN),

// Medium
(new CreditReward(1), PROB_MEDIUM), (new CreditReward(2), PROB_MEDIUM),
Expand All @@ -50,6 +53,7 @@ public void Start(BasePlugin basePlugin) {
(new ArmorReward(150), PROB_MEDIUM),
(new GuaranteedWardenReward(warden), PROB_MEDIUM),
(new WeaponReward("weapon_g3sg1", CsTeam.CounterTerrorist), PROB_MEDIUM),
(new CreditReward(5), PROB_MEDIUM),

// Low
(new ChatSpyReward(basePlugin), PROB_LOW),
Expand All @@ -63,7 +67,7 @@ public void Start(BasePlugin basePlugin) {
(new AmmoWeaponReward("weapon_negev", 0, 5), PROB_LOW),
(new CannotUseReward(basePlugin, WeaponType.SNIPERS), PROB_LOW),
(new CannotUseReward(basePlugin, WeaponType.HEAVY), PROB_LOW),
(new HPReward(1), PROB_LOW / 2),
(new CreditReward(50), PROB_LOW), (new HPReward(1), PROB_LOW / 2),

// Very low
(new FakeBombReward(), PROB_VERY_LOW * 2),
Expand All @@ -75,12 +79,16 @@ public void Start(BasePlugin basePlugin) {
(new RandomTeleportReward(mgr), PROB_VERY_LOW),
(new BombReward(bomb), PROB_VERY_LOW),
(new CannotUseReward(basePlugin, WeaponType.UTILITY), PROB_VERY_LOW),
(new CreditReward(-100), PROB_VERY_LOW),
(new CreditReward(500), PROB_VERY_LOW),
(new AmmoWeaponReward("weapon_awp", 1, 0), PROB_VERY_LOW / 2),

// Extremely low
(new AmmoWeaponReward("weapon_awp", 3, 0), PROB_EXTREMELY_LOW),
(new WeaponReward("weapon_glock"), PROB_EXTREMELY_LOW),
(new CannotUseReward(basePlugin, WeaponType.GUNS), PROB_EXTREMELY_LOW),
(new CreditReward(1000), PROB_EXTREMELY_LOW),
(new CreditReward(-5000), PROB_EXTREMELY_LOW / 2),

// Lottery
(new CreditReward(10000), PROB_LOTTERY)
Expand Down
2 changes: 2 additions & 0 deletions mod/Jailbreak.RTD/Rewards/ColorReward.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Drawing;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Public.Extensions;
Expand Down Expand Up @@ -42,6 +43,7 @@ public bool CanGrantReward(CCSPlayerController player) {

public bool GrantReward(CCSPlayerController player) {
player.SetColor(color);
Server.RunOnTick(Server.TickCount + 2, () => GrantReward(player));
return true;
}
}
37 changes: 25 additions & 12 deletions mod/Jailbreak.RTD/Rewards/CreditReward.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using GangsAPI.Data;
using GangsAPI.Services;
using Jailbreak.Public;
using Jailbreak.Public.Mod.RTD;
using Microsoft.Extensions.DependencyInjection;

namespace Jailbreak.RTD.Rewards;

public class CreditReward(int credits) : IRTDReward {
public string Name => credits + " Credit";
public static readonly string PREFIX =
$" {ChatColors.Purple}[{ChatColors.LightPurple}RTD{ChatColors.Purple}]";

public string Description
=> "You won " + credits + " credit" + (credits == 1 ? "" : "s")
+ (credits > 500 ? "!" : ".");
public string Name => $"{credits} credit{(credits == 1 ? "" : "s")}";

public bool Enabled => false; // TODO: Implement
public string Description => $"You won {Name}{(credits > 500 ? "!" : ".")}";

public bool PrepareReward(int userid) {
// TODO: When we do implement, set their credits here
return true;
}
public bool Enabled => API.Gangs != null;

public bool PrepareReward(CCSPlayerController player) {
var eco = API.Gangs?.Services.GetService<IEcoManager>();
if (eco == null) return false;
var wrapper = new PlayerWrapper(player);
eco.Grant(wrapper, credits, true, "RTD");

if (Math.Abs(credits) >= 5000) {
Server.PrintToChatAll(
$"{PREFIX} {ChatColors.Yellow}{wrapper.Name} {ChatColors.Default}won the jackpot of {ChatColors.Green}{credits} {ChatColors.Default}credits!");
}

public bool GrantReward(CCSPlayerController player) {
// We would have already set their credits in PrepareReward, so do nothing here
return true;
}

public bool GrantReward(CCSPlayerController player) { return true; }
}
8 changes: 5 additions & 3 deletions mod/Jailbreak.Warden/Commands/CountCommandsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public void Command_Count(CCSPlayerController? executor, CommandInfo info) {
return;
}

if (RoundUtil.GetTimeElapsed() < CV_COUNT_COMMAND_COOLDOWN.Value) {
locale.CannotCountYet(CV_COUNT_COMMAND_COOLDOWN.Value).ToChat(executor);
var timeTillCount =
CV_COUNT_COMMAND_COOLDOWN.Value - RoundUtil.GetTimeElapsed();
if (timeTillCount > 0) {
locale.CannotCountYet(timeTillCount).ToChat(executor);
return;
}

Expand All @@ -40,6 +42,6 @@ public void Command_Count(CCSPlayerController? executor, CommandInfo info) {
var prisoners = PlayerUtil.FromTeam(CsTeam.Terrorist)
.Count(markers.InMarker);

locale.PrisonersInMarker(prisoners);
locale.PrisonersInMarker(prisoners).ToChat(executor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class WardenOpenCommandsBehavior(IWardenService warden,
IZoneManager zoneManager) : IPluginBehavior, IWardenOpenCommand {
public static readonly FakeConVar<int> CV_OPEN_COMMAND_COOLDOWN = new(
"css_jb_warden_open_cooldown",
"Minimum seconds warden must wait before being able to open the cells.", 30,
"Minimum seconds warden must wait before being able to open the cells.", 25,
customValidators: new RangeValidator<int>(0, 300));

public bool OpenedCells { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion mod/Jailbreak.Warden/Global/WardenBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class WardenBehavior(ILogger<WardenBehavior> logger,
IMuteService mute, IServiceProvider provider)
: IPluginBehavior, IWardenService {
public static readonly FakeConVar<int> CV_ARMOR_EQUAL =
new("css_jb_hp_outnumbered", "Health points for CTs have equal balance", 50,
new("css_jb_hp_equal", "Health points for when CTs have equal ratio", 50,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(1, 200));

public static readonly FakeConVar<int> CV_ARMOR_OUTNUMBER =
Expand Down
Loading