From b4e14f5061a85f9c6078a13d9b55fb4b74f62796 Mon Sep 17 00:00:00 2001 From: MSWS Date: Mon, 21 Oct 2024 21:41:58 -0700 Subject: [PATCH] Add credit rewards --- mod/Jailbreak.RTD/Jailbreak.RTD.csproj | 3 +++ mod/Jailbreak.RTD/RTDRewarder.cs | 4 ++- mod/Jailbreak.RTD/RewardGenerator.cs | 24 ++++++++++++------ mod/Jailbreak.RTD/Rewards/ColorReward.cs | 2 ++ mod/Jailbreak.RTD/Rewards/CreditReward.cs | 31 +++++++++++++++++------ 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/mod/Jailbreak.RTD/Jailbreak.RTD.csproj b/mod/Jailbreak.RTD/Jailbreak.RTD.csproj index 9d36a223..929c377d 100644 --- a/mod/Jailbreak.RTD/Jailbreak.RTD.csproj +++ b/mod/Jailbreak.RTD/Jailbreak.RTD.csproj @@ -13,6 +13,9 @@ + + ..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll + ..\..\public\Jailbreak.Public\Mixin\MAULActainShared.dll diff --git a/mod/Jailbreak.RTD/RTDRewarder.cs b/mod/Jailbreak.RTD/RTDRewarder.cs index 65478d56..711f609d 100644 --- a/mod/Jailbreak.RTD/RTDRewarder.cs +++ b/mod/Jailbreak.RTD/RTDRewarder.cs @@ -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); }); diff --git a/mod/Jailbreak.RTD/RewardGenerator.cs b/mod/Jailbreak.RTD/RewardGenerator.cs index e9ad3049..31e3eefd 100644 --- a/mod/Jailbreak.RTD/RewardGenerator.cs +++ b/mod/Jailbreak.RTD/RewardGenerator.cs @@ -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 = []; @@ -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), @@ -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), @@ -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), @@ -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) diff --git a/mod/Jailbreak.RTD/Rewards/ColorReward.cs b/mod/Jailbreak.RTD/Rewards/ColorReward.cs index a727967d..fea84d08 100644 --- a/mod/Jailbreak.RTD/Rewards/ColorReward.cs +++ b/mod/Jailbreak.RTD/Rewards/ColorReward.cs @@ -1,4 +1,5 @@ using System.Drawing; +using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Extensions; @@ -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; } } \ No newline at end of file diff --git a/mod/Jailbreak.RTD/Rewards/CreditReward.cs b/mod/Jailbreak.RTD/Rewards/CreditReward.cs index 327aaa80..21dddec0 100644 --- a/mod/Jailbreak.RTD/Rewards/CreditReward.cs +++ b/mod/Jailbreak.RTD/Rewards/CreditReward.cs @@ -1,24 +1,39 @@ -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 static readonly string PREFIX = + $" {ChatColors.Purple}[{ChatColors.LightPurple}RTD{ChatColors.Purple}]"; + public string Name => credits + " Credit"; public string Description => "You won " + credits + " credit" + (credits == 1 ? "" : "s") + (credits > 500 ? "!" : "."); - public bool Enabled => false; // TODO: Implement + public bool Enabled => API.Gangs != null; - public bool PrepareReward(int userid) { - // TODO: When we do implement, set their credits here - return true; - } + public bool PrepareReward(CCSPlayerController player) { + var eco = API.Gangs?.Services.GetService(); + 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; } } \ No newline at end of file