-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
836 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using Jailbreak.Formatting.Base; | ||
using Jailbreak.Formatting.Logistics; | ||
using Jailbreak.Formatting.Views; | ||
using Jailbreak.Public.Mod.RTD; | ||
|
||
namespace Jailbreak.English.RTD; | ||
|
||
public class RTDLocale : IRTDLocale, ILanguage<Formatting.Languages.English> { | ||
public static readonly string PREFIX = | ||
$" {ChatColors.Purple}[{ChatColors.LightPurple}RTD{ChatColors.Purple}]"; | ||
|
||
public IView RewardSelected(IRTDReward reward) { | ||
return new SimpleView { | ||
{ PREFIX, "You rolled ", reward.Name + "." }, | ||
SimpleView.NEWLINE, | ||
{ PREFIX, reward.Description } | ||
}; | ||
} | ||
|
||
public IView AlreadyRolled(IRTDReward reward) { | ||
return new SimpleView { | ||
PREFIX, | ||
ChatColors.Red + "You already rolled " + ChatColors.DarkRed + reward.Name | ||
+ ChatColors.Red + ".", | ||
}; | ||
} | ||
|
||
public IView CannotRollYet() { | ||
return new SimpleView { | ||
PREFIX, "You can only roll once the round ends or you die." | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.RTD; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public class AutoRTDListener(IRTDRewarder rewarder) : IPluginBehavior { | ||
[GameEventHandler] | ||
public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { | ||
foreach (var player in Utilities.GetPlayers() | ||
.Where(player | ||
=> AdminManager.PlayerHasPermissions(player, "@ego/dssilver")) | ||
.Where(player => !rewarder.HasReward(player))) { | ||
player.ExecuteClientCommandFromServer("css_rtd"); | ||
} | ||
|
||
return HookResult.Continue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\public\Jailbreak.Formatting\Jailbreak.Formatting.csproj" /> | ||
<ProjectReference Include="..\..\public\Jailbreak.Public\Jailbreak.Public.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using Jailbreak.Formatting.Extensions; | ||
using Jailbreak.Formatting.Views; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.RTD; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public class RTDCommand(IRTDRewarder rewarder, IRewardGenerator generator, | ||
IRTDLocale locale, IGenericCmdLocale generic) : IPluginBehavior { | ||
private bool inBetweenRounds; | ||
|
||
[ConsoleCommand("css_rtd", "Roll the dice!")] | ||
public void Command_RTD(CCSPlayerController? executor, CommandInfo info) { | ||
if (executor == null) return; | ||
var bypass = AdminManager.PlayerHasPermissions(executor, "@css/root") | ||
&& info.ArgCount == 2; | ||
|
||
var old = rewarder.GetReward(executor); | ||
if (!bypass && old != null) { | ||
locale.AlreadyRolled(old).ToChat(executor); | ||
return; | ||
} | ||
|
||
if (!bypass && !inBetweenRounds && executor.PawnIsAlive) { | ||
locale.CannotRollYet().ToChat(executor); | ||
return; | ||
} | ||
|
||
var reward = generator.GenerateReward(executor); | ||
if (bypass) { | ||
if (!int.TryParse(info.GetArg(1), out var slot)) { | ||
generic.InvalidParameter(info.GetArg(1), "integer").ToChat(executor); | ||
return; | ||
} | ||
|
||
if (slot != -1) { | ||
var rewards = generator.ToList(); | ||
|
||
if (slot < 0 || slot >= rewards.Count) { | ||
generic.InvalidParameter(info.GetArg(1), "0-" + (rewards.Count - 1)) | ||
.ToChat(executor); | ||
return; | ||
} | ||
|
||
reward = generator.ToList()[slot].Item1; | ||
} | ||
} | ||
|
||
rewarder.SetReward(executor, reward); | ||
locale.RewardSelected(reward).ToChat(executor); | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnEnd(EventRoundEnd @event, GameEventInfo info) { | ||
inBetweenRounds = true; | ||
return HookResult.Continue; | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnStart(EventRoundStart @event, GameEventInfo info) { | ||
inBetweenRounds = false; | ||
return HookResult.Continue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using Jailbreak.Formatting.Base; | ||
using Jailbreak.Formatting.Extensions; | ||
using Jailbreak.Formatting.Views; | ||
using Jailbreak.Formatting.Views.Logging; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.Logs; | ||
using Jailbreak.Public.Mod.RTD; | ||
using Jailbreak.Public.Utils; | ||
using Microsoft.VisualBasic.CompilerServices; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public class RTDRewarder(IRichLogService logs, IRTDLocale locale) | ||
Check warning on line 16 in mod/Jailbreak.RTD/RTDRewarder.cs GitHub Actions / build
|
||
: IRTDRewarder, IPluginBehavior { | ||
private readonly Dictionary<int, IRTDReward> rewards = new(); | ||
|
||
public bool HasReward(int id) { return GetReward(id) != null; } | ||
|
||
public IRTDReward? GetReward(int id) { | ||
return rewards.TryGetValue(id, out var reward) ? reward : null; | ||
} | ||
|
||
public bool SetReward(int id, IRTDReward reward) { | ||
if (!reward.PrepareReward(id)) return false; | ||
rewards[id] = reward; | ||
return true; | ||
} | ||
|
||
[GameEventHandler] | ||
public HookResult OnStart(EventRoundStart @event, GameEventInfo info) { | ||
foreach (var player in PlayerUtil.GetAlive()) { | ||
var id = player.UserId ?? -1; | ||
|
||
var reward = GetReward(id); | ||
if (reward == null) continue; | ||
|
||
logs.Append("Granted", reward.Name, "to", logs.Player(player)); | ||
reward.GrantReward(id); | ||
} | ||
|
||
rewards.Clear(); | ||
return HookResult.Continue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Jailbreak.Public.Extensions; | ||
using Jailbreak.Public.Mod.RTD; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public static class RTDServiceExtensions { | ||
public static void AddDiceRoll(this IServiceCollection collection) { | ||
collection.AddPluginBehavior<IRewardGenerator, RewardGenerator>(); | ||
collection.AddPluginBehavior<IRTDRewarder, RTDRewarder>(); | ||
collection.AddPluginBehavior<RTDCommand>(); | ||
collection.AddPluginBehavior<AutoRTDListener>(); | ||
collection.AddPluginBehavior<RTDStatsCommand>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Core.Attributes.Registration; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using CounterStrikeSharp.API.Modules.Utils; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.RTD; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public class RTDStatsCommand(IRewardGenerator generator) : IPluginBehavior { | ||
[ConsoleCommand("css_rtdstats", "View stats and probabilities of the die")] | ||
public void | ||
Command_RTDStats(CCSPlayerController? executor, CommandInfo info) { | ||
if (executor == null) return; | ||
var total = generator.Sum(r => r.Item2); | ||
|
||
var rewards = generator.ToList(); | ||
rewards.Sort((a, b) => a.Item2.CompareTo(b.Item2)); | ||
|
||
var index = 0; | ||
foreach (var (reward, prob) in rewards) { | ||
var name = reward.Name; | ||
var percent = prob / total * 100; | ||
executor.PrintToChat( | ||
$"{ChatColors.Orange}{index++}. {ChatColors.LightBlue}{name}{ChatColors.Grey}: {ChatColors.Yellow}{percent:0.00}%"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System.Collections; | ||
using System.Drawing; | ||
using CounterStrikeSharp.API.Core; | ||
using Jailbreak.Public.Behaviors; | ||
using Jailbreak.Public.Mod.Rebel; | ||
using Jailbreak.Public.Mod.RTD; | ||
using Jailbreak.Public.Mod.Zones; | ||
using Jailbreak.RTD.Rewards; | ||
|
||
namespace Jailbreak.RTD; | ||
|
||
public class RewardGenerator(IZoneManager mgr, IC4Service bomb) | ||
: IPluginBehavior, IRewardGenerator { | ||
private static readonly float PROB_LOTTERY = 1 / 5000f; | ||
Check warning on line 14 in mod/Jailbreak.RTD/RewardGenerator.cs GitHub Actions / build
|
||
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; | ||
Check warning on line 20 in mod/Jailbreak.RTD/RewardGenerator.cs GitHub Actions / build
|
||
|
||
private readonly List<(IRTDReward, float)> rewards = [ | ||
(new NothingReward(), PROB_OFTEN), | ||
(new WeaponReward("weapon_healthshot"), PROB_OFTEN), | ||
(new WeaponReward("weapon_decoy"), PROB_OFTEN), | ||
(new CreditReward(1), PROB_MEDIUM), (new CreditReward(2), PROB_MEDIUM), | ||
(new CreditReward(3), PROB_MEDIUM), | ||
(new WeaponReward("weapon_flashbang"), PROB_MEDIUM), | ||
(new WeaponReward("weapon_hegrenade"), PROB_MEDIUM), | ||
(new WeaponReward("weapon_smokegrenade"), PROB_MEDIUM), | ||
(new WeaponReward("weapon_molotov"), PROB_MEDIUM), | ||
(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 TransparentReward(), PROB_LOW), | ||
(new AmmoWeaponReward("weapon_glock", 2, 0), PROB_LOW), | ||
(new AmmoWeaponReward("weapon_negev", 0, 5), PROB_LOW), | ||
(new NoWeaponReward(), PROB_VERY_LOW), | ||
(new AmmoWeaponReward("weapon_deagle", 1, 0), PROB_VERY_LOW), | ||
(new RandomTeleportReward(mgr), PROB_VERY_LOW), | ||
(new BombReward(bomb), PROB_VERY_LOW), | ||
(new AmmoWeaponReward("weapon_awp", 1, 0), PROB_EXTREMELY_LOW) | ||
]; | ||
|
||
public void Start(BasePlugin basePlugin) { | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.GRENADE), | ||
PROB_LOW)); | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.UTILITY), | ||
PROB_LOW)); | ||
rewards.Add(( | ||
new CannotPickupReward(basePlugin, | ||
WeaponType.GRENADE | WeaponType.UTILITY), PROB_LOW)); | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.PISTOLS), | ||
PROB_VERY_LOW)); | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.SNIPERS), | ||
PROB_VERY_LOW)); | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.HEAVY), | ||
PROB_VERY_LOW)); | ||
rewards.Add((new CannotPickupReward(basePlugin, WeaponType.RIFLES), | ||
PROB_EXTREMELY_LOW)); | ||
} | ||
|
||
private readonly Random rng = new(); | ||
|
||
private float totalWeight | ||
=> rewards.Where(r => r.Item1.Enabled).Select(s => s.Item2).Sum(); | ||
|
||
public IRTDReward GenerateReward(int slot) { | ||
var roll = rng.NextDouble() * totalWeight; | ||
|
||
foreach (var reward in rewards.Where(reward => reward.Item1.Enabled)) { | ||
roll -= reward.Item2; | ||
if (roll <= 0) return reward.Item1; | ||
} | ||
|
||
throw new InvalidOperationException("No reward was generated."); | ||
} | ||
|
||
public IEnumerator<(IRTDReward, float)> GetEnumerator() { | ||
return rewards.Where(r => r.Item1.Enabled).GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } | ||
public int Count => rewards.Count(r => r.Item1.Enabled); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Diagnostics; | ||
using CounterStrikeSharp.API.Core; | ||
using Jailbreak.Public.Extensions; | ||
|
||
namespace Jailbreak.RTD.Rewards; | ||
|
||
public class AmmoWeaponReward : WeaponReward { | ||
private readonly int primary, secondary; | ||
|
||
public AmmoWeaponReward(string weapon, int primary, int secondary) : | ||
base(weapon) { | ||
Trace.Assert(Tag.GUNS.Contains(weapon)); | ||
this.primary = primary; | ||
this.secondary = secondary; | ||
} | ||
|
||
public override bool GrantReward(CCSPlayerController player) { | ||
var success = base.GrantReward(player); | ||
if (!success) return false; | ||
|
||
player.GetWeaponBase(weapon).SetAmmo(primary, secondary); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.