Skip to content

Commit

Permalink
Add credit rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Oct 22, 2024
1 parent 84fb944 commit b4e14f5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
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;
}
}
31 changes: 23 additions & 8 deletions mod/Jailbreak.RTD/Rewards/CreditReward.cs
Original file line number Diff line number Diff line change
@@ -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<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; }
}

0 comments on commit b4e14f5

Please sign in to comment.