mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-07 23:06:33 -08:00
Compare commits
102 Commits
0.19.0-dev
...
0.22.3-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acb3be9132 | ||
|
|
bbcc998559 | ||
|
|
56781c6ae8 | ||
|
|
0ca983943d | ||
|
|
8cd8e14e18 | ||
|
|
57ef5e3e24 | ||
|
|
9c99d316aa | ||
|
|
e679c5193b | ||
|
|
6ece0450bb | ||
|
|
daa24a0e87 | ||
|
|
1c8785b388 | ||
|
|
a80c36e3c5 | ||
|
|
ba6b6c448f | ||
|
|
d30e916319 | ||
|
|
9f275fa189 | ||
|
|
40bdcac4b0 | ||
|
|
6b3ae03ab3 | ||
|
|
9e8e1d1fb0 | ||
|
|
fba875f098 | ||
|
|
38fa801c15 | ||
|
|
b21fed3ff8 | ||
|
|
0e02d66350 | ||
|
|
7f6ac62348 | ||
|
|
f44e57215f | ||
|
|
ce48f5a5ac | ||
|
|
4f258e55dd | ||
|
|
b0ba6baac9 | ||
|
|
4d052f31c6 | ||
|
|
7c5e7c3f68 | ||
|
|
23e08134c8 | ||
|
|
16d9335292 | ||
|
|
840e04fd71 | ||
|
|
70c416bbe6 | ||
|
|
b85a3a415d | ||
|
|
2351ec55ec | ||
|
|
4af1be95f4 | ||
|
|
fdb22c1090 | ||
|
|
ddc309927f | ||
|
|
7b657b1595 | ||
|
|
05eed34ffd | ||
|
|
707a967445 | ||
|
|
d6c6562d32 | ||
|
|
64e9332fa6 | ||
|
|
536f0eafb5 | ||
|
|
3e513cb611 | ||
|
|
cba8470f09 | ||
|
|
275404582f | ||
|
|
76dc717a8b | ||
|
|
ff8d4dfc7e | ||
|
|
f63acf24c4 | ||
|
|
678b9b0de6 | ||
|
|
18144f5827 | ||
|
|
e590ae2b7a | ||
|
|
6bc0f57bed | ||
|
|
83a1d0e3e3 | ||
|
|
4d0fdfa25e | ||
|
|
9f673f9d8b | ||
|
|
3ad4339073 | ||
|
|
890ba71fdf | ||
|
|
c6fea1a21e | ||
|
|
db9ad9303f | ||
|
|
9224e823c0 | ||
|
|
4ab16d71db | ||
|
|
627c048183 | ||
|
|
66d1106d4c | ||
|
|
39c7a4762d | ||
|
|
f2352ede1f | ||
|
|
f675a87ffd | ||
|
|
7f455d5354 | ||
|
|
d1972fc556 | ||
|
|
f2dbc72aee | ||
|
|
77a2289367 | ||
|
|
456ae22b12 | ||
|
|
2616b231dc | ||
|
|
3cb86aa2f8 | ||
|
|
4c72f3dfff | ||
|
|
bc45f3fb74 | ||
|
|
2bcf436677 | ||
|
|
9dfb45583b | ||
|
|
3fa1558011 | ||
|
|
6c7bc22395 | ||
|
|
c95fba0fc5 | ||
|
|
40c7a6d471 | ||
|
|
b79519f6b4 | ||
|
|
bea87d20f3 | ||
|
|
5bbc621d86 | ||
|
|
5ed244f84c | ||
|
|
31d2354e6f | ||
|
|
44d9644694 | ||
|
|
f6d1b95a38 | ||
|
|
cf1d040b44 | ||
|
|
5393920f95 | ||
|
|
8158206101 | ||
|
|
06f8f083df | ||
|
|
5c18a046b8 | ||
|
|
063813baca | ||
|
|
a10ce25846 | ||
|
|
89077c8361 | ||
|
|
fd3ffc6d59 | ||
|
|
f9e2734390 | ||
|
|
251d8efeaf | ||
|
|
247f7de49b |
4
.github/workflows/dotnet.yml
vendored
4
.github/workflows/dotnet.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
- name: Publish Test Project
|
||||
run: dotnet publish TTT/Test/Test.csproj --no-restore --no-build -o build_output -c Debug
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
- uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: build_output
|
||||
path: build_output
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Download Build Output
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: build_output
|
||||
path: build_output
|
||||
|
||||
29
SpecialRoundAPI/SpecialRoundAPI/AbstractSpecialRound.cs
Normal file
29
SpecialRoundAPI/SpecialRoundAPI/AbstractSpecialRound.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public abstract class AbstractSpecialRound(IServiceProvider provider)
|
||||
: ITerrorModule, IListener {
|
||||
protected readonly IServiceProvider Provider = provider;
|
||||
|
||||
protected readonly ISpecialRoundTracker Tracker =
|
||||
provider.GetRequiredService<ISpecialRoundTracker>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public abstract string Name { get; }
|
||||
public abstract IMsg Description { get; }
|
||||
public abstract SpecialRoundConfig Config { get; }
|
||||
|
||||
public abstract void ApplyRoundEffects();
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public abstract void OnGameState(GameStateUpdateEvent ev);
|
||||
}
|
||||
5
SpecialRoundAPI/SpecialRoundAPI/BhopRoundConfig.cs
Normal file
5
SpecialRoundAPI/SpecialRoundAPI/BhopRoundConfig.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public record BhopRoundConfig : SpecialRoundConfig {
|
||||
public override float Weight { get; init; } = 0.2f;
|
||||
}
|
||||
13
SpecialRoundAPI/SpecialRoundAPI/ISpecialRoundStarter.cs
Normal file
13
SpecialRoundAPI/SpecialRoundAPI/ISpecialRoundStarter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public interface ISpecialRoundStarter {
|
||||
/// <summary>
|
||||
/// Attempts to start the given special round.
|
||||
/// Will bypass most checks, but may still return null if starting the round
|
||||
/// is not possible.
|
||||
/// </summary>
|
||||
/// <param name="round"></param>
|
||||
/// <returns></returns>
|
||||
public AbstractSpecialRound?
|
||||
TryStartSpecialRound(AbstractSpecialRound? round);
|
||||
}
|
||||
6
SpecialRoundAPI/SpecialRoundAPI/ISpecialRoundTracker.cs
Normal file
6
SpecialRoundAPI/SpecialRoundAPI/ISpecialRoundTracker.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public interface ISpecialRoundTracker {
|
||||
public AbstractSpecialRound? CurrentRound { get; set; }
|
||||
public int RoundsSinceLastSpecial { get; set; }
|
||||
}
|
||||
15
SpecialRoundAPI/SpecialRoundAPI/SpecialRoundAPI.csproj
Normal file
15
SpecialRoundAPI/SpecialRoundAPI/SpecialRoundAPI.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Locale\Locale.csproj" />
|
||||
<ProjectReference Include="..\..\TTT\API\API.csproj" />
|
||||
<ProjectReference Include="..\..\TTT\Game\Game.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
5
SpecialRoundAPI/SpecialRoundAPI/SpecialRoundConfig.cs
Normal file
5
SpecialRoundAPI/SpecialRoundAPI/SpecialRoundConfig.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public abstract record SpecialRoundConfig {
|
||||
public abstract float Weight { get; init; }
|
||||
}
|
||||
8
SpecialRoundAPI/SpecialRoundAPI/SpeedRoundConfig.cs
Normal file
8
SpecialRoundAPI/SpecialRoundAPI/SpeedRoundConfig.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public record SpeedRoundConfig : SpecialRoundConfig {
|
||||
public override float Weight { get; init; } = 0.5f;
|
||||
|
||||
public TimeSpan InitialSeconds { get; init; } = TimeSpan.FromSeconds(40);
|
||||
public TimeSpan SecondsPerKill { get; init; } = TimeSpan.FromSeconds(10);
|
||||
}
|
||||
5
SpecialRoundAPI/SpecialRoundAPI/VanillaRoundConfig.cs
Normal file
5
SpecialRoundAPI/SpecialRoundAPI/VanillaRoundConfig.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace SpecialRoundAPI;
|
||||
|
||||
public record VanillaRoundConfig : SpecialRoundConfig {
|
||||
public override float Weight { get; init; } = 0.3f;
|
||||
}
|
||||
12
TTT.sln
12
TTT.sln
@@ -27,6 +27,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RTD", "TTT\RTD\RTD.csproj",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stats", "TTT\Stats\Stats.csproj", "{256473A2-6ACD-440C-83FA-6056147656C7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecialRound", "TTT\SpecialRound\SpecialRound.csproj", "{5092069A-3CFA-41C8-B685-341040AB435C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecialRoundAPI", "SpecialRoundAPI\SpecialRoundAPI\SpecialRoundAPI.csproj", "{360FEF16-54DA-42EE-995A-3D31C699287D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -84,6 +88,14 @@ Global
|
||||
{256473A2-6ACD-440C-83FA-6056147656C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{256473A2-6ACD-440C-83FA-6056147656C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{256473A2-6ACD-440C-83FA-6056147656C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5092069A-3CFA-41C8-B685-341040AB435C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5092069A-3CFA-41C8-B685-341040AB435C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5092069A-3CFA-41C8-B685-341040AB435C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5092069A-3CFA-41C8-B685-341040AB435C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{360FEF16-54DA-42EE-995A-3D31C699287D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{360FEF16-54DA-42EE-995A-3D31C699287D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{360FEF16-54DA-42EE-995A-3D31C699287D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{360FEF16-54DA-42EE-995A-3D31C699287D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
EndGlobalSection
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface IAction {
|
||||
string Id { get; }
|
||||
string Verb { get; }
|
||||
string Details { get; }
|
||||
string Prefix => "";
|
||||
|
||||
public string Format() {
|
||||
var pRole = PlayerRole != null ?
|
||||
@@ -20,7 +21,7 @@ public interface IAction {
|
||||
$" [{OtherRole.Name.First(char.IsAsciiLetter)}]" :
|
||||
"";
|
||||
return Other is not null ?
|
||||
$"{Player}{pRole} {Verb} {Other}{oRole} {Details}" :
|
||||
$"{Player}{pRole} {Verb} {Details}";
|
||||
$"{Prefix}{Player}{pRole} {Verb} {Other}{oRole} {Details}" :
|
||||
$"{Prefix}{Player}{pRole} {Verb} {Details}";
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public interface IPlayer : IEquatable<IPlayer> {
|
||||
/// </summary>
|
||||
string Id { get; }
|
||||
|
||||
string Name { get; }
|
||||
string Name { get; set; }
|
||||
|
||||
bool IEquatable<IPlayer>.Equals(IPlayer? other) {
|
||||
if (other is null) return false;
|
||||
|
||||
19
TTT/CS2/Actions/TaserAction.cs
Normal file
19
TTT/CS2/Actions/TaserAction.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
|
||||
namespace TTT.CS2.Actions;
|
||||
|
||||
public class TaserAction(IRoleAssigner roles, IPlayer victim,
|
||||
IPlayer identifier) : IAction {
|
||||
public IPlayer Player { get; } = identifier;
|
||||
public IPlayer? Other { get; } = victim;
|
||||
|
||||
public IRole? PlayerRole { get; } =
|
||||
roles.GetRoles(identifier).FirstOrDefault();
|
||||
|
||||
public IRole? OtherRole { get; } = roles.GetRoles(victim).FirstOrDefault();
|
||||
public string Id { get; } = "cs2.action.tased";
|
||||
public string Verb { get; } = "tased";
|
||||
public string Details { get; } = "";
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\SpecialRoundAPI\SpecialRoundAPI\SpecialRoundAPI.csproj" />
|
||||
<ProjectReference Include="..\API\API.csproj"/>
|
||||
<ProjectReference Include="..\Game\Game.csproj"/>
|
||||
<ProjectReference Include="..\Karma\Karma.csproj"/>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShopAPI.Configs;
|
||||
using ShopAPI.Configs.Detective;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API.Command;
|
||||
using TTT.API.Extensions;
|
||||
@@ -50,6 +52,18 @@ public static class CS2ServiceCollection {
|
||||
.AddModBehavior<IStorage<PoisonSmokeConfig>, CS2PoisonSmokeConfig>();
|
||||
collection.AddModBehavior<IStorage<KarmaConfig>, CS2KarmaConfig>();
|
||||
collection.AddModBehavior<IStorage<CamoConfig>, CS2CamoConfig>();
|
||||
collection.AddModBehavior<IStorage<StickersConfig>, CS2StickersConfig>();
|
||||
collection.AddModBehavior<IStorage<BodyPaintConfig>, CS2BodyPaintConfig>();
|
||||
collection
|
||||
.AddModBehavior<IStorage<DnaScannerConfig>, CS2DnaScannerConfig>();
|
||||
collection
|
||||
.AddModBehavior<IStorage<HealthStationConfig>, CS2HealthStationConfig>();
|
||||
collection
|
||||
.AddModBehavior<IStorage<ClusterGrenadeConfig>, CS2ClusterGrenadeConfig>();
|
||||
collection.AddModBehavior<IStorage<GlovesConfig>, CS2GlovesConfig>();
|
||||
collection
|
||||
.AddModBehavior<IStorage<OneHitKnifeConfig>, CS2OneHitKnifeConfig>();
|
||||
collection.AddModBehavior<IStorage<SilentAWPConfig>, CS2SilentAWPConfig>();
|
||||
|
||||
// TTT - CS2 Specific optionals
|
||||
collection.AddScoped<ITextSpawner, TextSpawner>();
|
||||
@@ -67,6 +81,9 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<TeamChangeHandler>();
|
||||
collection.AddModBehavior<TraitorChatHandler>();
|
||||
collection.AddModBehavior<PlayerMuter>();
|
||||
collection.AddModBehavior<MapChangeCausesEndListener>();
|
||||
collection.AddModBehavior<NameUpdater>();
|
||||
// collection.AddModBehavior<EntityTargetHandlers>();
|
||||
|
||||
// Damage Cancelers
|
||||
collection.AddModBehavior<OutOfRoundCanceler>();
|
||||
@@ -82,6 +99,7 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<ScreenColorApplier>();
|
||||
collection.AddModBehavior<KarmaBanner>();
|
||||
collection.AddModBehavior<KarmaSyncer>();
|
||||
collection.AddModBehavior<MapHookListener>();
|
||||
|
||||
// Commands
|
||||
collection.AddModBehavior<TestCommand>();
|
||||
|
||||
34
TTT/CS2/Command/Test/SetTargetCommand.cs
Normal file
34
TTT/CS2/Command/Test/SetTargetCommand.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Numerics;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Command;
|
||||
using TTT.API.Player;
|
||||
using TTT.CS2.Extensions;
|
||||
using TTT.CS2.Utils;
|
||||
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;
|
||||
|
||||
namespace TTT.CS2.Command.Test;
|
||||
|
||||
public class SetTargetCommand(IServiceProvider provider) : ICommand {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public string Id => "settarget";
|
||||
|
||||
public Task<CommandResult>
|
||||
Execute(IOnlinePlayer? executor, ICommandInfo info) {
|
||||
if (executor == null) return Task.FromResult(CommandResult.PLAYER_ONLY);
|
||||
|
||||
Server.NextWorldUpdate(() => {
|
||||
var gamePlayer = converter.GetPlayer(executor);
|
||||
if (gamePlayer == null) return;
|
||||
gamePlayer.Pawn.Value?.AcceptInput("AddContext", null, null, "TRAITOR:1");
|
||||
});
|
||||
return Task.FromResult(CommandResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
41
TTT/CS2/Command/Test/SpecialRoundCommand.cs
Normal file
41
TTT/CS2/Command/Test/SpecialRoundCommand.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API;
|
||||
using TTT.API.Command;
|
||||
using TTT.API.Player;
|
||||
|
||||
namespace TTT.CS2.Command.Test;
|
||||
|
||||
public class SpecialRoundCommand(IServiceProvider provider) : ICommand {
|
||||
private readonly ISpecialRoundStarter tracker =
|
||||
provider.GetRequiredService<ISpecialRoundStarter>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public string Id => "specialround";
|
||||
|
||||
public Task<CommandResult>
|
||||
Execute(IOnlinePlayer? executor, ICommandInfo info) {
|
||||
if (info.ArgCount == 1) {
|
||||
tracker.TryStartSpecialRound(null);
|
||||
info.ReplySync("Started a random special round.");
|
||||
return Task.FromResult(CommandResult.SUCCESS);
|
||||
}
|
||||
|
||||
var rounds = provider.GetServices<ITerrorModule>()
|
||||
.OfType<AbstractSpecialRound>()
|
||||
.ToDictionary(r => r.GetType().Name.ToLower(), r => r);
|
||||
|
||||
var roundName = info.Args[1].ToLower();
|
||||
if (!rounds.TryGetValue(roundName, out var round)) {
|
||||
info.ReplySync($"No special round found with name '{roundName}'.");
|
||||
foreach (var name in rounds.Keys) info.ReplySync($"- {name}");
|
||||
return Task.FromResult(CommandResult.INVALID_ARGS);
|
||||
}
|
||||
|
||||
tracker.TryStartSpecialRound(round);
|
||||
info.ReplySync($"Started special round '{roundName}'.");
|
||||
return Task.FromResult(CommandResult.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ public class TestCommand(IServiceProvider provider) : ICommand, IPluginModule {
|
||||
subCommands.Add("credits", new CreditsCommand(provider));
|
||||
subCommands.Add("spec", new SpecCommand(provider));
|
||||
subCommands.Add("reload", new ReloadModuleCommand(provider));
|
||||
subCommands.Add("specialround", new SpecialRoundCommand(provider));
|
||||
subCommands.Add("settarget", new SetTargetCommand(provider));
|
||||
}
|
||||
|
||||
public Task<CommandResult>
|
||||
|
||||
@@ -24,7 +24,7 @@ public class CS2GameConfig : IStorage<TTTConfig>, IPluginModule {
|
||||
|
||||
public static readonly FakeConVar<int> CV_ROUND_DURATION_PER_PLAYER = new(
|
||||
"css_ttt_round_duration_per_player",
|
||||
"Additional round duration per player in seconds", 10,
|
||||
"Additional round duration per player in seconds", 15,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 60));
|
||||
|
||||
public static readonly FakeConVar<int> CV_ROUND_DURATION_MAX = new(
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace TTT.CS2.Configs;
|
||||
|
||||
public class CS2ShopConfig : IStorage<ShopConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_STARTING_INNOCENT_CREDITS = new(
|
||||
"css_ttt_shop_start_innocent", "Starting credits for Innocents", 80,
|
||||
"css_ttt_shop_start_innocent", "Starting credits for Innocents", 60,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_STARTING_TRAITOR_CREDITS = new(
|
||||
|
||||
52
TTT/CS2/Configs/ShopItems/CS2BodyPaintConfig.cs
Normal file
52
TTT/CS2/Configs/ShopItems/CS2BodyPaintConfig.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2BodyPaintConfig : IStorage<BodyPaintConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_bodypaint_price", "Price of the Body Paint item", 40,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_MAX_USES = new(
|
||||
"css_ttt_shop_bodypaint_max_uses",
|
||||
"Maximum number of times the Body Paint can be applied per item", 4,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(1, 100));
|
||||
|
||||
public static readonly FakeConVar<string> CV_COLOR = new(
|
||||
"css_ttt_shop_bodypaint_color",
|
||||
"Color to apply to the player's body (HTML hex or known color name)",
|
||||
"GreenYellow", ConVarFlags.FCVAR_NONE);
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<BodyPaintConfig?> Load() {
|
||||
Color parsedColor;
|
||||
try { parsedColor = ColorTranslator.FromHtml(CV_COLOR.Value); } catch {
|
||||
try { parsedColor = Color.FromName(CV_COLOR.Value); } catch {
|
||||
parsedColor = Color.GreenYellow;
|
||||
}
|
||||
}
|
||||
|
||||
var cfg = new BodyPaintConfig {
|
||||
Price = CV_PRICE.Value,
|
||||
MaxUses = CV_MAX_USES.Value,
|
||||
ColorToApply = parsedColor
|
||||
};
|
||||
|
||||
return Task.FromResult<BodyPaintConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class CS2CamoConfig : IStorage<CamoConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<float> CV_CAMO_VISIBILITY = new(
|
||||
"css_ttt_shop_camo_visibility",
|
||||
"Player visibility multiplier while camouflaged (0 = invisible, 1 = fully visible)",
|
||||
0.4f, ConVarFlags.FCVAR_NONE, new RangeValidator<float>(0f, 1f));
|
||||
0.6f, ConVarFlags.FCVAR_NONE, new RangeValidator<float>(0f, 1f));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
|
||||
57
TTT/CS2/Configs/ShopItems/CS2ClusterGrenadeConfig.cs
Normal file
57
TTT/CS2/Configs/ShopItems/CS2ClusterGrenadeConfig.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2ClusterGrenadeConfig : IStorage<ClusterGrenadeConfig>,
|
||||
IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_clustergrenade_price",
|
||||
"Price of the Cluster Grenade item (Traitor)", 100, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_GRENADE_COUNT = new(
|
||||
"css_ttt_shop_clustergrenade_count",
|
||||
"Number of grenades released upon explosion", 8, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(1, 50));
|
||||
|
||||
public static readonly FakeConVar<string> CV_WEAPON_ID = new(
|
||||
"css_ttt_shop_clustergrenade_weapon",
|
||||
"Weapon entity ID used for the Cluster Grenade", "weapon_hegrenade",
|
||||
ConVarFlags.FCVAR_NONE);
|
||||
|
||||
public static readonly FakeConVar<float> CV_UP_FORCE = new(
|
||||
"css_ttt_shop_clustergrenade_up_force",
|
||||
"Upward force applied to cluster fragments", 200f, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<float>(0f, 1000f));
|
||||
|
||||
public static readonly FakeConVar<float> CV_THROW_FORCE = new(
|
||||
"css_ttt_shop_clustergrenade_throw_force",
|
||||
"Forward throw force applied to cluster fragments", 250f,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<float>(0f, 1000f));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<ClusterGrenadeConfig?> Load() {
|
||||
var cfg = new ClusterGrenadeConfig {
|
||||
Price = CV_PRICE.Value,
|
||||
GrenadeCount = CV_GRENADE_COUNT.Value,
|
||||
UpForce = CV_UP_FORCE.Value,
|
||||
ThrowForce = CV_THROW_FORCE.Value
|
||||
};
|
||||
|
||||
return Task.FromResult<ClusterGrenadeConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
44
TTT/CS2/Configs/ShopItems/CS2DnaScannerConfig.cs
Normal file
44
TTT/CS2/Configs/ShopItems/CS2DnaScannerConfig.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Detective;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2DnaScannerConfig : IStorage<DnaScannerConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_dna_price", "Price of the DNA Scanner item (Detective)", 110,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_MAX_SAMPLES = new(
|
||||
"css_ttt_shop_dna_max_samples",
|
||||
"Maximum number of DNA samples that can be stored at once", 0,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 100));
|
||||
|
||||
public static readonly FakeConVar<int> CV_DECAY_TIME_SECONDS = new(
|
||||
"css_ttt_shop_dna_decay_time",
|
||||
"Time (in seconds) before a DNA sample decays", 120, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(10, 3600));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<DnaScannerConfig?> Load() {
|
||||
var cfg = new DnaScannerConfig {
|
||||
Price = CV_PRICE.Value,
|
||||
MaxSamples = CV_MAX_SAMPLES.Value,
|
||||
DecayTime = TimeSpan.FromSeconds(CV_DECAY_TIME_SECONDS.Value)
|
||||
};
|
||||
|
||||
return Task.FromResult<DnaScannerConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
37
TTT/CS2/Configs/ShopItems/CS2GlovesConfig.cs
Normal file
37
TTT/CS2/Configs/ShopItems/CS2GlovesConfig.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2GlovesConfig : IStorage<GlovesConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_gloves_price", "Price of the Gloves item (Traitor)", 40,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_MAX_USES = new(
|
||||
"css_ttt_shop_gloves_max_uses",
|
||||
"Maximum number of times the Gloves can be used before breaking", 5,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(1, 100));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<GlovesConfig?> Load() {
|
||||
var cfg = new GlovesConfig {
|
||||
Price = CV_PRICE.Value, MaxUses = CV_MAX_USES.Value
|
||||
};
|
||||
|
||||
return Task.FromResult<GlovesConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
70
TTT/CS2/Configs/ShopItems/CS2HealthStationConfig.cs
Normal file
70
TTT/CS2/Configs/ShopItems/CS2HealthStationConfig.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Detective;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2HealthStationConfig : IStorage<HealthStationConfig>,
|
||||
IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_healthstation_price",
|
||||
"Price of the Health Station item (Detective)", 50, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<string> CV_USE_SOUND = new(
|
||||
"css_ttt_shop_healthstation_use_sound",
|
||||
"Sound played when using the Health Station", "sounds/buttons/blip1",
|
||||
ConVarFlags.FCVAR_NONE);
|
||||
|
||||
public static readonly FakeConVar<int> CV_HEALTH_INCREMENTS = new(
|
||||
"css_ttt_shop_healthstation_increments",
|
||||
"Number of health increments applied per use", 10, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(1, 100));
|
||||
|
||||
public static readonly FakeConVar<int> CV_HEALTH_INTERVAL = new(
|
||||
"css_ttt_shop_healthstation_interval",
|
||||
"Interval (in seconds) between health increments", 1,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(1, 60));
|
||||
|
||||
public static readonly FakeConVar<int> CV_STATION_HEALTH = new(
|
||||
"css_ttt_shop_healthstation_station_health",
|
||||
"Maximum health of the station object itself", 200, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(50, 1000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_TOTAL_HEALTH_GIVEN = new(
|
||||
"css_ttt_shop_healthstation_total_health_given",
|
||||
"Total health the station can provide before depleting (0 = infinite)", 0,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<float> CV_MAX_RANGE = new(
|
||||
"css_ttt_shop_healthstation_max_range",
|
||||
"Maximum range (in units) from which players can use the station", 256f,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<float>(50f, 2048f));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<HealthStationConfig?> Load() {
|
||||
var cfg = new HealthStationConfig {
|
||||
Price = CV_PRICE.Value,
|
||||
UseSound = CV_USE_SOUND.Value,
|
||||
HealthIncrements = CV_HEALTH_INCREMENTS.Value,
|
||||
HealthInterval = TimeSpan.FromSeconds(CV_HEALTH_INTERVAL.Value),
|
||||
StationHealth = CV_STATION_HEALTH.Value,
|
||||
TotalHealthGiven = CV_TOTAL_HEALTH_GIVEN.Value,
|
||||
MaxRange = CV_MAX_RANGE.Value
|
||||
};
|
||||
|
||||
return Task.FromResult<HealthStationConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2M4A1Config : IStorage<M4A1Config>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_m4a1_price", "Price of the M4A1 item", 75,
|
||||
"css_ttt_shop_m4a1_price", "Price of the M4A1 item", 50,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<string> CV_CLEAR_SLOTS = new(
|
||||
|
||||
38
TTT/CS2/Configs/ShopItems/CS2OneHitKnifeConfig.cs
Normal file
38
TTT/CS2/Configs/ShopItems/CS2OneHitKnifeConfig.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2OneHitKnifeConfig : IStorage<OneHitKnifeConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_onehitknife_price",
|
||||
"Price of the One-Hit Knife item (Traitor)", 80, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<bool> CV_FRIENDLY_FIRE = new(
|
||||
"css_ttt_shop_onehitknife_friendly_fire",
|
||||
"Whether the One-Hit Knife can damage teammates", false,
|
||||
ConVarFlags.FCVAR_NONE);
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<OneHitKnifeConfig?> Load() {
|
||||
var cfg = new OneHitKnifeConfig {
|
||||
Price = CV_PRICE.Value, FriendlyFire = CV_FRIENDLY_FIRE.Value
|
||||
};
|
||||
|
||||
return Task.FromResult<OneHitKnifeConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace TTT.CS2.Configs.ShopItems;
|
||||
public class CS2OneShotDeagleConfig : IStorage<OneShotDeagleConfig>,
|
||||
IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_onedeagle_price", "Price of the One-Shot Deagle item", 110,
|
||||
"css_ttt_shop_onedeagle_price", "Price of the One-Shot Deagle item", 130,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<bool> CV_FRIENDLY_FIRE = new(
|
||||
|
||||
54
TTT/CS2/Configs/ShopItems/CS2SilentAWPConfig.cs
Normal file
54
TTT/CS2/Configs/ShopItems/CS2SilentAWPConfig.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2SilentAWPConfig : IStorage<SilentAWPConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_silentawp_price", "Price of the Silent AWP item (Traitor)",
|
||||
80, ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_WEAPON_INDEX = new(
|
||||
"css_ttt_shop_silentawp_index", "Weapon slot index for the Silent AWP", 9,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 64));
|
||||
|
||||
public static readonly FakeConVar<string> CV_WEAPON_ID = new(
|
||||
"css_ttt_shop_silentawp_weapon", "Weapon entity ID for the Silent AWP",
|
||||
"weapon_awp", ConVarFlags.FCVAR_NONE);
|
||||
|
||||
public static readonly FakeConVar<int> CV_RESERVE_AMMO = new(
|
||||
"css_ttt_shop_silentawp_reserve_ammo",
|
||||
"Reserve ammo count for the Silent AWP", 0, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 100));
|
||||
|
||||
public static readonly FakeConVar<int> CV_CURRENT_AMMO = new(
|
||||
"css_ttt_shop_silentawp_current_ammo",
|
||||
"Current ammo loaded in the Silent AWP", 1, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 10));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<SilentAWPConfig?> Load() {
|
||||
var cfg = new SilentAWPConfig {
|
||||
Price = CV_PRICE.Value,
|
||||
WeaponIndex = CV_WEAPON_INDEX.Value,
|
||||
WeaponId = CV_WEAPON_ID.Value,
|
||||
ReserveAmmo = CV_RESERVE_AMMO.Value,
|
||||
CurrentAmmo = CV_CURRENT_AMMO.Value
|
||||
};
|
||||
|
||||
return Task.FromResult<SilentAWPConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
30
TTT/CS2/Configs/ShopItems/CS2StickersConfig.cs
Normal file
30
TTT/CS2/Configs/ShopItems/CS2StickersConfig.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Cvars.Validators;
|
||||
using ShopAPI.Configs.Detective;
|
||||
using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2StickersConfig : IStorage<StickersConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_stickers_price", "Price of the Stickers item (Detective)", 35,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
ArgumentNullException.ThrowIfNull(plugin, nameof(plugin));
|
||||
plugin.RegisterFakeConVars(this);
|
||||
}
|
||||
|
||||
public Task<StickersConfig?> Load() {
|
||||
var cfg = new StickersConfig { Price = CV_PRICE.Value };
|
||||
|
||||
return Task.FromResult<StickersConfig?>(cfg);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using TTT.API;
|
||||
using TTT.API.Storage;
|
||||
using TTT.CS2.Validators;
|
||||
|
||||
namespace TTT.CS2.Configs;
|
||||
namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2TaserConfig : IStorage<TaserConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
@@ -1,4 +1,5 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using JetBrains.Annotations;
|
||||
@@ -29,9 +30,9 @@ public class BuyMenuHandler(IServiceProvider provider) : IPluginModule {
|
||||
{ "weapon_usp_silencer", "M4A1" },
|
||||
{ "weapon_sg556", "M4A1" },
|
||||
{ "weapon_mp5sd", "M4A1" },
|
||||
{ "weapon_decoy", "healthshot" },
|
||||
{ "weapon_awp", "AWP" },
|
||||
{ "weapon_hegrenade", "Cluster" }
|
||||
{ "weapon_hegrenade", "Cluster" },
|
||||
{ "weapon_decoy", "Teleport Decoy" },
|
||||
};
|
||||
|
||||
public void Dispose() { }
|
||||
@@ -49,6 +50,14 @@ public class BuyMenuHandler(IServiceProvider provider) : IPluginModule {
|
||||
}
|
||||
|
||||
inventory.RemoveWeapon(player, new BaseWeapon(ev.Weapon));
|
||||
switch (ev.Weapon) {
|
||||
case "weapon_m4a1_silencer":
|
||||
inventory.RemoveWeaponInSlot(player, 0);
|
||||
break;
|
||||
case "weapon_revolver":
|
||||
inventory.RemoveWeaponInSlot(player, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!shopAliases.TryGetValue(ev.Weapon, out var alias))
|
||||
return HookResult.Continue;
|
||||
|
||||
@@ -52,6 +52,17 @@ public class CombatHandler(IServiceProvider provider) : IPluginModule {
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[GameEventHandler(HookMode.Pre)]
|
||||
public HookResult OnPlayerDamage(EventPlayerHurt ev, GameEventInfo info) {
|
||||
var player = ev.Userid;
|
||||
if (player == null) return HookResult.Continue;
|
||||
|
||||
hideAndTrackStats(ev);
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void hideAndTrackStats(EventPlayerDeath ev,
|
||||
CCSPlayerController player) {
|
||||
var victimStats = player.ActionTrackingServices?.MatchStats;
|
||||
@@ -89,6 +100,16 @@ public class CombatHandler(IServiceProvider provider) : IPluginModule {
|
||||
"m_pActionTrackingServices");
|
||||
}
|
||||
|
||||
private void hideAndTrackStats(EventPlayerHurt ev) {
|
||||
var attackerStats = ev.Attacker?.ActionTrackingServices?.MatchStats;
|
||||
|
||||
if (attackerStats == null) return;
|
||||
if (ev.Attacker == null) return;
|
||||
attackerStats.Damage -= ev.DmgHealth;
|
||||
Utilities.SetStateChanged(ev.Attacker, "CCSPlayerController",
|
||||
"m_pActionTrackingServices");
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerHurt(EventPlayerHurt ev, GameEventInfo _) {
|
||||
|
||||
@@ -30,6 +30,10 @@ public class DamageCanceler(IServiceProvider provider) : IPluginModule {
|
||||
}
|
||||
|
||||
private HookResult onTakeDamage(DynamicHook hook) {
|
||||
var playerPawn = hook.GetParam<CCSPlayerPawn>(0);
|
||||
var player = playerPawn.Controller.Value?.As<CCSPlayerController>();
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
var damagedEvent = new PlayerDamagedEvent(converter, hook);
|
||||
|
||||
bus.Dispatch(damagedEvent);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using TTT.API.Events;
|
||||
using JetBrains.Annotations;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.CS2.Actions;
|
||||
using TTT.CS2.lang;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Listeners;
|
||||
@@ -8,6 +10,7 @@ namespace TTT.CS2.GameHandlers.DamageCancelers;
|
||||
|
||||
public class TaserListenCanceler(IServiceProvider provider)
|
||||
: BaseListener(provider) {
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnHurt(PlayerDamagedEvent ev) {
|
||||
if (Games.ActiveGame is not { State: State.IN_PROGRESS }) return;
|
||||
@@ -23,5 +26,6 @@ public class TaserListenCanceler(IServiceProvider provider)
|
||||
|
||||
Messenger.Message(attacker,
|
||||
Locale[CS2Msgs.TASER_SCANNED(victim, Roles.GetRoles(victim).First())]);
|
||||
Games.ActiveGame.Logger.LogAction(new TaserAction(Roles, victim, attacker));
|
||||
}
|
||||
}
|
||||
26
TTT/CS2/GameHandlers/MapChangeCausesEndListener.cs
Normal file
26
TTT/CS2/GameHandlers/MapChangeCausesEndListener.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Game;
|
||||
|
||||
namespace TTT.CS2.GameHandlers;
|
||||
|
||||
public class MapChangeCausesEndListener(IServiceProvider provider)
|
||||
: IPluginModule {
|
||||
private readonly IGameManager games =
|
||||
provider.GetRequiredService<IGameManager>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
plugin?.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnMapStart>(
|
||||
onMapChange);
|
||||
}
|
||||
|
||||
private void onMapChange(string mapName) {
|
||||
games.ActiveGame?.EndGame(new EndReason("Map Change"));
|
||||
Server.PrintToConsole("Detected map change, ending active game.");
|
||||
}
|
||||
}
|
||||
24
TTT/CS2/GameHandlers/NameUpdater.cs
Normal file
24
TTT/CS2/GameHandlers/NameUpdater.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Player;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Listeners;
|
||||
|
||||
namespace TTT.CS2.GameHandlers;
|
||||
|
||||
public class NameUpdater(IServiceProvider provider) : BaseListener(provider) {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnGameInit(GameInitEvent ev) {
|
||||
foreach (var player in Utilities.GetPlayers()) {
|
||||
converter.GetPlayer(player).Name = player.PlayerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class TraitorChatHandler(IServiceProvider provider) : IPluginModule {
|
||||
|
||||
private HookResult onSay(CCSPlayerController? player,
|
||||
CommandInfo commandInfo) {
|
||||
if (mutedPlayers != null
|
||||
if (mutedPlayers != null && player != null && player.GetHealth() > 0
|
||||
&& mutedPlayers.Contains(player?.SteamID.ToString() ?? ""))
|
||||
return HookResult.Handled;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using TTT.Game.Roles;
|
||||
namespace TTT.CS2.Items.PoisonShots;
|
||||
|
||||
public static class PoisonShotServiceCollection {
|
||||
public static void AddPoisonShots(this IServiceCollection services) {
|
||||
public static void AddPoisonShotsServices(this IServiceCollection services) {
|
||||
services.AddModBehavior<PoisonShotsItem>();
|
||||
services.AddModBehavior<PoisonShotsListener>();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using TTT.Game.Roles;
|
||||
namespace TTT.CS2.Items.PoisonSmoke;
|
||||
|
||||
public static class PoisonSmokeServiceCollection {
|
||||
public static void AddPoisonSmoke(this IServiceCollection services) {
|
||||
public static void AddPoisonSmokeServices(this IServiceCollection services) {
|
||||
services.AddModBehavior<PoisonSmokeItem>();
|
||||
services.AddModBehavior<PoisonSmokeListener>();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using TTT.Game.Roles;
|
||||
namespace TTT.CS2.Items.Station;
|
||||
|
||||
public static class HealthStationCollection {
|
||||
public static void AddHealthStation(this IServiceCollection collection) {
|
||||
public static void AddHealthStationServices(this IServiceCollection collection) {
|
||||
collection.AddModBehavior<HealthStation>();
|
||||
}
|
||||
}
|
||||
|
||||
39
TTT/CS2/Items/TeleportDecoy/TeleportDecoyItem.cs
Normal file
39
TTT/CS2/Items/TeleportDecoy/TeleportDecoyItem.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShopAPI;
|
||||
using ShopAPI.Configs;
|
||||
using ShopAPI.Configs.Traitor;
|
||||
using TTT.API.Extensions;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Storage;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.CS2.Items.TeleportDecoy;
|
||||
|
||||
public static class TeleportDecoyServiceCollection {
|
||||
public static void AddTeleportDecoyServices(
|
||||
this IServiceCollection collection) {
|
||||
collection.AddModBehavior<TeleportDecoyItem>();
|
||||
collection.AddModBehavior<TeleportDecoyListener>();
|
||||
}
|
||||
}
|
||||
|
||||
public class TeleportDecoyItem(IServiceProvider provider)
|
||||
: RoleRestrictedItem<TraitorRole>(provider) {
|
||||
public override string Name
|
||||
=> Locale[TeleportDecoyMsgs.SHOP_ITEM_TELEPORT_DECOY];
|
||||
|
||||
public override string Description
|
||||
=> Locale[TeleportDecoyMsgs.SHOP_ITEM_TELEPORT_DECOY_DESC];
|
||||
|
||||
private TeleportDecoyConfig config
|
||||
=> Provider.GetService<IStorage<TeleportDecoyConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new TeleportDecoyConfig();
|
||||
|
||||
public override ShopItemConfig Config => config;
|
||||
|
||||
public override void OnPurchase(IOnlinePlayer player) {
|
||||
Inventory.GiveWeapon(player, new BaseWeapon("weapon_decoy"));
|
||||
}
|
||||
}
|
||||
37
TTT/CS2/Items/TeleportDecoy/TeleportDecoyListener.cs
Normal file
37
TTT/CS2/Items/TeleportDecoy/TeleportDecoyListener.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShopAPI;
|
||||
using TTT.API;
|
||||
using TTT.API.Player;
|
||||
|
||||
namespace TTT.CS2.Items.TeleportDecoy;
|
||||
|
||||
public class TeleportDecoyListener(IServiceProvider provider) : IPluginModule {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
private readonly IShop shop = provider.GetRequiredService<IShop>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
[UsedImplicitly]
|
||||
[GameEventHandler]
|
||||
public HookResult OnDecoyDetonate(EventDecoyDetonate ev, GameEventInfo _) {
|
||||
if (ev.Userid == null) return HookResult.Continue;
|
||||
var player = converter.GetPlayer(ev.Userid) as IOnlinePlayer;
|
||||
if (player == null) return HookResult.Continue;
|
||||
|
||||
if (!shop.HasItem<TeleportDecoyItem>(player)) return HookResult.Continue;
|
||||
|
||||
shop.RemoveItem<TeleportDecoyItem>(player);
|
||||
|
||||
var vec = new Vector(ev.X, ev.Y, ev.Z + 16);
|
||||
ev.Userid.Pawn.Value?.Teleport(vec);
|
||||
return HookResult.Continue;
|
||||
}
|
||||
}
|
||||
11
TTT/CS2/Items/TeleportDecoy/TeleportDecoyMsgs.cs
Normal file
11
TTT/CS2/Items/TeleportDecoy/TeleportDecoyMsgs.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using TTT.Locale;
|
||||
|
||||
namespace TTT.CS2.Items.TeleportDecoy;
|
||||
|
||||
public class TeleportDecoyMsgs {
|
||||
public static IMsg SHOP_ITEM_TELEPORT_DECOY
|
||||
=> MsgFactory.Create(nameof(SHOP_ITEM_TELEPORT_DECOY));
|
||||
|
||||
public static IMsg SHOP_ITEM_TELEPORT_DECOY_DESC
|
||||
=> MsgFactory.Create(nameof(SHOP_ITEM_TELEPORT_DECOY_DESC));
|
||||
}
|
||||
@@ -77,7 +77,8 @@ public class AfkTimerListener(IServiceProvider provider)
|
||||
private List<CCSPlayerController> getAfkPlayers() {
|
||||
return Utilities.GetPlayers()
|
||||
.Where(p => p.PlayerPawn.Value != null
|
||||
&& !p.PlayerPawn.Value.HasMovedSinceSpawn)
|
||||
&& p is { Team: CsTeam.CounterTerrorist or CsTeam.Terrorist }
|
||||
&& p.GetHealth() >= 0 && !p.PlayerPawn.Value.HasMovedSinceSpawn)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
48
TTT/CS2/Listeners/MapHookListener.cs
Normal file
48
TTT/CS2/Listeners/MapHookListener.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Player;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Listeners;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.CS2.Listeners;
|
||||
|
||||
public class MapHookListener(IServiceProvider provider)
|
||||
: BaseListener(provider) {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler(Priority = Priority.MONITOR, IgnoreCanceled = true)]
|
||||
public void OnRoleAssign(PlayerRoleAssignEvent ev) {
|
||||
var player = converter.GetPlayer(ev.Player);
|
||||
if (player == null) return;
|
||||
|
||||
switch (ev.Role) {
|
||||
case TraitorRole:
|
||||
player.Pawn.Value?.AcceptInput("AddContext", null, null, "TRAITOR:1");
|
||||
break;
|
||||
case DetectiveRole:
|
||||
player.Pawn.Value?.AcceptInput("AddContext", null, null, "DETECTIVE:1");
|
||||
break;
|
||||
case InnocentRole:
|
||||
player.Pawn.Value?.AcceptInput("AddContext", null, null, "INNOCENT:1");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnRoundEnd(GameInitEvent ev) {
|
||||
foreach (var player in Utilities.GetPlayers()) {
|
||||
if (player.Pawn.Value == null) continue;
|
||||
player.Pawn.Value.AcceptInput("RemoveContext", null, null, "TRAITOR");
|
||||
player.Pawn.Value.AcceptInput("RemoveContext", null, null, "DETECTIVE");
|
||||
player.Pawn.Value.AcceptInput("RemoveContext", null, null, "INNOCENT");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,14 @@ public class PlayerStatsTracker(IServiceProvider provider) : IListener {
|
||||
|
||||
private readonly ISet<int> revealedDeaths = new HashSet<int>();
|
||||
|
||||
private readonly IDictionary<int, (int, int)> roundKillsAndAssists =
|
||||
new Dictionary<int, (int, int)>();
|
||||
private readonly IDictionary<int, RoundData> roundStats =
|
||||
new Dictionary<int, RoundData>();
|
||||
|
||||
record RoundData {
|
||||
public int Kills;
|
||||
public int Assists;
|
||||
public int Damage;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -50,24 +56,39 @@ public class PlayerStatsTracker(IServiceProvider provider) : IListener {
|
||||
ev.Assister == null ? null : converter.GetPlayer(ev.Assister);
|
||||
|
||||
if (killer != null) {
|
||||
roundKillsAndAssists.TryGetValue(killer.Slot, out var def);
|
||||
def.Item1++;
|
||||
roundKillsAndAssists[killer.Slot] = def;
|
||||
roundStats.TryGetValue(killer.Slot, out var def);
|
||||
def ??= new RoundData();
|
||||
def.Kills++;
|
||||
roundStats[killer.Slot] = def;
|
||||
}
|
||||
|
||||
if (assister != null && assister != killer) {
|
||||
roundKillsAndAssists.TryGetValue(assister.Slot, out var def);
|
||||
def.Item2++;
|
||||
roundKillsAndAssists[assister.Slot] = def;
|
||||
roundStats.TryGetValue(assister.Slot, out var def);
|
||||
def ??= new RoundData();
|
||||
def.Assists++;
|
||||
roundStats[assister.Slot] = def;
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler(Priority = Priority.HIGH)]
|
||||
public void OnDamage(PlayerDamagedEvent ev) {
|
||||
var attacker =
|
||||
ev.Attacker == null ? null : converter.GetPlayer(ev.Attacker);
|
||||
if (attacker == null) return;
|
||||
|
||||
roundStats.TryGetValue(attacker.Slot, out var def);
|
||||
def ??= new RoundData();
|
||||
def.Damage += ev.DmgDealt;
|
||||
roundStats[attacker.Slot] = def;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnRoundEnd(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState == State.IN_PROGRESS) {
|
||||
revealedDeaths.Clear();
|
||||
roundKillsAndAssists.Clear();
|
||||
roundStats.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,15 +121,16 @@ public class PlayerStatsTracker(IServiceProvider provider) : IListener {
|
||||
var online = finder.GetOnline()
|
||||
.Select(p => converter.GetPlayer(p))
|
||||
.OfType<CCSPlayerController>()
|
||||
.Where(p => p.IsValid && roundKillsAndAssists.ContainsKey(p.Slot));
|
||||
.Where(p => p.IsValid && roundStats.ContainsKey(p.Slot));
|
||||
|
||||
foreach (var player in online) {
|
||||
var stats = player.ActionTrackingServices?.MatchStats;
|
||||
if (stats == null) continue;
|
||||
|
||||
var (kills, assists) = roundKillsAndAssists[player.Slot];
|
||||
stats.Kills += kills;
|
||||
stats.Assists += assists;
|
||||
if (!roundStats.TryGetValue(player.Slot, out var data)) continue;
|
||||
|
||||
stats.Kills += data.Kills;
|
||||
stats.Assists += data.Assists;
|
||||
Utilities.SetStateChanged(player, "CCSPlayerController",
|
||||
"m_pActionTrackingServices");
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class RoundTimerListener(IServiceProvider provider)
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
private IDisposable? endTimer;
|
||||
public IDisposable? EndTimer;
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler(IgnoreCanceled = true)]
|
||||
@@ -63,14 +63,14 @@ public class RoundTimerListener(IServiceProvider provider)
|
||||
player.Respawn();
|
||||
});
|
||||
|
||||
if (ev.NewState == State.FINISHED) endTimer?.Dispose();
|
||||
if (ev.NewState == State.FINISHED) EndTimer?.Dispose();
|
||||
if (ev.NewState != State.IN_PROGRESS) return;
|
||||
var duration = config.RoundCfg.RoundDuration(ev.Game.Players.Count);
|
||||
Server.NextWorldUpdate(()
|
||||
=> RoundUtil.SetTimeRemaining((int)duration.TotalSeconds));
|
||||
|
||||
endTimer?.Dispose();
|
||||
endTimer = Scheduler.Schedule(duration,
|
||||
EndTimer?.Dispose();
|
||||
EndTimer = Scheduler.Schedule(duration,
|
||||
() => {
|
||||
Server.NextWorldUpdate(()
|
||||
=> ev.Game.EndGame(EndReason.TIMEOUT(new InnocentRole(Provider))));
|
||||
@@ -137,6 +137,6 @@ public class RoundTimerListener(IServiceProvider provider)
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
|
||||
endTimer?.Dispose();
|
||||
EndTimer?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -60,8 +60,12 @@ public class CS2AliveSpoofer : IAliveSpoofer, IPluginModule {
|
||||
this.plugin = plugin;
|
||||
plugin?.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnTick>(
|
||||
onTick);
|
||||
plugin?.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnMapStart>(
|
||||
onMapStart);
|
||||
}
|
||||
|
||||
private void onMapStart(string mapName) { _fakeAlivePlayers.Clear(); }
|
||||
|
||||
[UsedImplicitly]
|
||||
[GameEventHandler]
|
||||
public HookResult OnDisconnect(EventPlayerDisconnect ev, GameEventInfo _) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using TTT.API.Player;
|
||||
|
||||
namespace TTT.CS2.Player;
|
||||
@@ -47,17 +48,13 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
|
||||
}
|
||||
}
|
||||
|
||||
private int namePadding
|
||||
=> Math.Min(Utilities.GetPlayers().Select(p => p.PlayerName.Length).Max(),
|
||||
24);
|
||||
|
||||
public bool Equals(CS2Player? other) {
|
||||
if (other is null) return false;
|
||||
return Id == other.Id;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Name { get; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int Health {
|
||||
get => Player?.Pawn.Value != null ? Player.Pawn.Value.Health : 0;
|
||||
@@ -100,7 +97,11 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
|
||||
}
|
||||
|
||||
public bool IsAlive {
|
||||
get => Player != null && Player.Pawn.Value is { Health: > 0 };
|
||||
get
|
||||
=> Player != null && Player is {
|
||||
Team : CsTeam.CounterTerrorist or CsTeam.Terrorist,
|
||||
Pawn.Value.Health: > 0
|
||||
};
|
||||
|
||||
set
|
||||
=> throw new NotSupportedException(
|
||||
@@ -118,9 +119,7 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
|
||||
|
||||
// Goal: Pad the name to a fixed width for better alignment in logs
|
||||
// Left-align ID, right-align name
|
||||
private string createPaddedName() {
|
||||
return CreatePaddedName(Id, Name, namePadding + 8);
|
||||
}
|
||||
private string createPaddedName() { return CreatePaddedName(Id, Name, 24); }
|
||||
|
||||
public static string CreatePaddedName(string id, string name, int len) {
|
||||
var suffix = id.Length > 5 ? id[^5..] : id.PadLeft(5, '0');
|
||||
|
||||
21
TTT/CS2/Roles/CS2TraitorRole.cs
Normal file
21
TTT/CS2/Roles/CS2TraitorRole.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Player;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.CS2.Roles;
|
||||
|
||||
public class CS2TraitorRole(IServiceProvider provider) : TraitorRole(provider) {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
public override void OnAssign(IOnlinePlayer player) {
|
||||
base.OnAssign(player);
|
||||
|
||||
var gamePlayer = converter.GetPlayer(player);
|
||||
if (gamePlayer == null) return;
|
||||
|
||||
gamePlayer.AcceptInput("SetTargetName", null, null, "traitor");
|
||||
if (gamePlayer.Pawn.Value != null) gamePlayer.Pawn.Value.Target = "traitor";
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,8 @@ public static class RoundUtil {
|
||||
|
||||
public static void EndRound(RoundEndReason reason) {
|
||||
var gameRules = ServerUtil.GameRulesProxy;
|
||||
if (gameRules == null || gameRules.GameRules == null) return;
|
||||
if (gameRules == null || gameRules.GameRules == null || !gameRules.IsValid)
|
||||
return;
|
||||
// TODO: Figure out what these params do
|
||||
// TerminateRoundFunc.Invoke(gameRules.GameRules.Handle, 5f, reason, 0, 0);
|
||||
VirtualFunctions.TerminateRoundFunc.Invoke(gameRules.GameRules.Handle,
|
||||
|
||||
@@ -11,7 +11,9 @@ public static class ServerUtil {
|
||||
.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules")
|
||||
.FirstOrDefault();
|
||||
|
||||
return GameRulesProxy?.GameRules;
|
||||
if (GameRulesProxy == null || !GameRulesProxy.IsValid) return null;
|
||||
|
||||
return GameRulesProxy.GameRules;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,4 +49,7 @@ SHOP_ITEM_SILENT_AWP: "Silent AWP"
|
||||
SHOP_ITEM_SILENT_AWP_DESC: "Receive a silenced AWP with limited ammo."
|
||||
|
||||
SHOP_ITEM_CLUSTER_GRENADE: "Cluster Grenade"
|
||||
SHOP_ITEM_CLUSTER_GRENADE_DESC: "A grenade that splits into multiple smaller grenades."
|
||||
SHOP_ITEM_CLUSTER_GRENADE_DESC: "A grenade that splits into multiple smaller grenades."
|
||||
|
||||
SHOP_ITEM_TELEPORT_DECOY: "Teleport Decoy"
|
||||
SHOP_ITEM_TELEPORT_DECOY_DESC: "A decoy that teleports you to it upon explosion."
|
||||
@@ -3,6 +3,7 @@ using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.Game.Actions;
|
||||
|
||||
@@ -24,6 +25,12 @@ public class DamagedAction(IRoleAssigner roles, IPlayer victim,
|
||||
public string Verb => "damaged";
|
||||
public string Details => $"for {Damage} damage with {Weapon}";
|
||||
|
||||
public string Prefix
|
||||
=> PlayerRole != null && OtherRole != null
|
||||
&& PlayerRole is TraitorRole != OtherRole is TraitorRole ?
|
||||
"" :
|
||||
"[BAD] ";
|
||||
|
||||
#region ConstructorAliases
|
||||
|
||||
public DamagedAction(IServiceProvider provider, IPlayer victim,
|
||||
|
||||
@@ -3,6 +3,7 @@ using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Roles;
|
||||
|
||||
namespace TTT.Game.Actions;
|
||||
|
||||
@@ -10,7 +11,7 @@ public class DeathAction(IRoleAssigner roles, IPlayer victim, IPlayer? killer)
|
||||
: IAction {
|
||||
public DeathAction(IRoleAssigner roles, PlayerDeathEvent ev) : this(roles,
|
||||
ev.Player, ev.Killer) {
|
||||
Details = $"using {ev.Weapon}";
|
||||
if (!string.IsNullOrWhiteSpace(ev.Weapon)) Details = $"using {ev.Weapon}";
|
||||
}
|
||||
|
||||
public IPlayer Player { get; } = victim;
|
||||
@@ -34,10 +35,16 @@ public class DeathAction(IRoleAssigner roles, IPlayer victim, IPlayer? killer)
|
||||
$" [{OtherRole.Name.First(char.IsAsciiLetter)}]" :
|
||||
"";
|
||||
return Other is not null ?
|
||||
$"{Other}{oRole} {Verb} {Player}{pRole} {Details}" :
|
||||
$"{Player}{pRole} {Verb} {Details}";
|
||||
$"{Prefix}{Other}{oRole} {Verb} {Player}{pRole} {Details}" :
|
||||
$"{Prefix}{Player}{pRole} {Verb} {Details}";
|
||||
}
|
||||
|
||||
public string Prefix
|
||||
=> PlayerRole != null && OtherRole != null
|
||||
&& PlayerRole is TraitorRole != OtherRole is TraitorRole ?
|
||||
"" :
|
||||
"[BAD] ";
|
||||
|
||||
#region ConstructorAliases
|
||||
|
||||
public DeathAction(IServiceProvider provider, IPlayer victim, IPlayer? killer)
|
||||
|
||||
@@ -11,5 +11,7 @@ public class RoleAssignedAction(IPlayer player, IRole role) : IAction {
|
||||
public IRole? OtherRole { get; } = null;
|
||||
public string Id => "basegame.action.roleassigned";
|
||||
public string Verb => "was assigned";
|
||||
public string Details { get; } = role.Name;
|
||||
|
||||
public string Details { get; } =
|
||||
new(role.Name.Where(char.IsAsciiLetter).ToArray());
|
||||
}
|
||||
@@ -8,28 +8,30 @@ using TTT.Game.Events.Player;
|
||||
namespace TTT.Game.Roles;
|
||||
|
||||
public class RoleAssigner(IServiceProvider provider) : IRoleAssigner {
|
||||
private readonly IDictionary<IPlayer, ICollection<IRole>> assignedRoles =
|
||||
new Dictionary<IPlayer, ICollection<IRole>>();
|
||||
private readonly IDictionary<string, ICollection<IRole>> assignedRoles =
|
||||
new Dictionary<string, ICollection<IRole>>();
|
||||
|
||||
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
|
||||
|
||||
private readonly IMessenger? onlineMessenger =
|
||||
provider.GetService<IMessenger>();
|
||||
|
||||
private static readonly Random rng = new();
|
||||
|
||||
public void AssignRoles(ISet<IOnlinePlayer> players, IList<IRole> roles) {
|
||||
assignedRoles.Clear();
|
||||
var shuffled = players.OrderBy(_ => Guid.NewGuid()).ToHashSet();
|
||||
var shuffled = players.OrderBy(_ => rng.NextDouble()).ToHashSet();
|
||||
bool roleAssigned;
|
||||
do { roleAssigned = tryAssignRole(shuffled, roles); } while (roleAssigned);
|
||||
}
|
||||
|
||||
public Task<ICollection<IRole>?> Load(IPlayer key) {
|
||||
assignedRoles.TryGetValue(key, out var roles);
|
||||
assignedRoles.TryGetValue(key.Id, out var roles);
|
||||
return Task.FromResult(roles);
|
||||
}
|
||||
|
||||
public Task Write(IPlayer key, ICollection<IRole> newData) {
|
||||
assignedRoles[key] = newData;
|
||||
assignedRoles[key.Id] = newData;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -44,9 +46,9 @@ public class RoleAssigner(IServiceProvider provider) : IRoleAssigner {
|
||||
|
||||
if (ev.IsCanceled) continue;
|
||||
|
||||
if (!assignedRoles.ContainsKey(player))
|
||||
assignedRoles[player] = new List<IRole>();
|
||||
assignedRoles[player].Add(ev.Role);
|
||||
if (!assignedRoles.ContainsKey(player.Id))
|
||||
assignedRoles[player.Id] = new List<IRole>();
|
||||
assignedRoles[player.Id].Add(ev.Role);
|
||||
ev.Role.OnAssign(player);
|
||||
|
||||
onlineMessenger?.Debug(
|
||||
|
||||
@@ -11,11 +11,4 @@
|
||||
<ProjectReference Include="..\Game\Game.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.66"/>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.9"/>
|
||||
<PackageReference Include="MySqlConnector" Version="2.4.0"/>
|
||||
<PackageReference Include="SQLite" Version="3.13.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.Diagnostics;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Player;
|
||||
@@ -15,142 +13,42 @@ using TTT.Karma.Events;
|
||||
namespace TTT.Karma;
|
||||
|
||||
public sealed class KarmaStorage(IServiceProvider provider) : IKarmaService {
|
||||
// Toggle immediate writes. If false, every Write triggers a flush
|
||||
private const bool EnableCache = true;
|
||||
private readonly IEventBus _bus = provider.GetRequiredService<IEventBus>();
|
||||
private readonly HttpClient client =
|
||||
provider.GetRequiredService<HttpClient>();
|
||||
|
||||
private readonly SemaphoreSlim _flushGate = new(1, 1);
|
||||
private KarmaConfig config
|
||||
=> provider.GetService<IStorage<KarmaConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new KarmaConfig();
|
||||
|
||||
// Cache keyed by stable player id to avoid relying on IPlayer equality
|
||||
private readonly ConcurrentDictionary<string, int> _karmaCache = new();
|
||||
public async Task<int> Load(IPlayer key) {
|
||||
var result = await client.GetAsync("user/" + key.Id);
|
||||
|
||||
private readonly IScheduler _scheduler =
|
||||
provider.GetRequiredService<IScheduler>();
|
||||
if (!result.IsSuccessStatusCode) return config.DefaultKarma;
|
||||
|
||||
private KarmaConfig _config = new();
|
||||
private IDbConnection? _connection;
|
||||
private IDisposable? _flushSubscription;
|
||||
var content = await result.Content.ReadAsStringAsync();
|
||||
var json = System.Text.Json.JsonDocument.Parse(content);
|
||||
if (!json.RootElement.TryGetProperty("karma", out var karmaElement))
|
||||
return config.DefaultKarma;
|
||||
|
||||
public string Id => nameof(KarmaStorage);
|
||||
public string Version => GitVersionInformation.FullSemVer;
|
||||
|
||||
public void Start() {
|
||||
// Open a dedicated connection used only by this service
|
||||
_connection = new SqliteConnection(_config.DbString);
|
||||
_connection.Open();
|
||||
|
||||
// Ensure schema before any reads or writes
|
||||
_connection.Execute(@"CREATE TABLE IF NOT EXISTS PlayerKarma (
|
||||
PlayerId TEXT PRIMARY KEY,
|
||||
Karma INTEGER NOT NULL
|
||||
)");
|
||||
|
||||
// Periodic flush with proper error handling and serialization
|
||||
_flushSubscription = Observable
|
||||
.Interval(TimeSpan.FromSeconds(30), _scheduler)
|
||||
.SelectMany(_ => FlushAsync().ToObservable())
|
||||
.Subscribe(_ => { }, // no-op on success
|
||||
ex => {
|
||||
// Replace with your logger if available
|
||||
Trace.TraceError($"Karma flush failed: {ex}");
|
||||
});
|
||||
return karmaElement.GetInt32();
|
||||
}
|
||||
|
||||
public async Task<int> Load(IPlayer player) {
|
||||
if (player is null) throw new ArgumentNullException(nameof(player));
|
||||
var key = player.Id;
|
||||
public async Task Write(IPlayer key, int newData) {
|
||||
var oldKarma = await Load(key);
|
||||
var karmaUpdateEvent = new KarmaUpdateEvent(key, oldKarma, newData);
|
||||
provider.GetService<IEventBus>()?.Dispatch(karmaUpdateEvent);
|
||||
if (karmaUpdateEvent.IsCanceled) return;
|
||||
|
||||
if (EnableCache && _karmaCache.TryGetValue(key, out var cached))
|
||||
return cached;
|
||||
var data = new { steam_id = key.Id, karma = karmaUpdateEvent.Karma };
|
||||
var payload = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(data),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var conn = EnsureConnection();
|
||||
|
||||
// Parameterize the default value to keep SQL static
|
||||
var sql = @"
|
||||
SELECT COALESCE(
|
||||
(SELECT Karma FROM PlayerKarma WHERE PlayerId = @PlayerId),
|
||||
@DefaultKarma
|
||||
)";
|
||||
var karma = await conn.QuerySingleAsync<int>(sql,
|
||||
new { PlayerId = key, _config.DefaultKarma });
|
||||
|
||||
if (EnableCache) _karmaCache[key] = karma;
|
||||
return karma;
|
||||
await client.PatchAsync("user/" + key.Id, payload);
|
||||
}
|
||||
|
||||
public async Task Write(IPlayer player, int newValue) {
|
||||
if (player is null) throw new ArgumentNullException(nameof(player));
|
||||
var key = player.Id;
|
||||
|
||||
var max = _config.MaxKarma(player);
|
||||
if (newValue > max)
|
||||
throw new ArgumentOutOfRangeException(nameof(newValue),
|
||||
$"Karma must be less than {max} for player {key}.");
|
||||
|
||||
int oldValue;
|
||||
if (!_karmaCache.TryGetValue(key, out oldValue))
|
||||
oldValue = await Load(player);
|
||||
|
||||
if (oldValue == newValue) return;
|
||||
|
||||
var evt = new KarmaUpdateEvent(player, oldValue, newValue);
|
||||
try { _bus.Dispatch(evt); } catch {
|
||||
// Replace with your logger if available
|
||||
Trace.TraceError("Exception during KarmaUpdateEvent dispatch.");
|
||||
throw;
|
||||
}
|
||||
|
||||
if (evt.IsCanceled) return;
|
||||
|
||||
_karmaCache[key] = newValue;
|
||||
|
||||
if (!EnableCache) await FlushAsync();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
try {
|
||||
_flushSubscription?.Dispose();
|
||||
// Best effort final flush
|
||||
if (_connection is { State: ConnectionState.Open })
|
||||
FlushAsync().GetAwaiter().GetResult();
|
||||
} catch (Exception ex) {
|
||||
Trace.TraceError($"Dispose flush failed: {ex}");
|
||||
} finally {
|
||||
_connection?.Dispose();
|
||||
_flushGate.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task FlushAsync() {
|
||||
var conn = EnsureConnection();
|
||||
|
||||
// Fast path if there is nothing to flush
|
||||
if (_karmaCache.IsEmpty) return;
|
||||
|
||||
await _flushGate.WaitAsync().ConfigureAwait(false);
|
||||
try {
|
||||
// Snapshot to avoid long lock on dictionary and to provide a stable view
|
||||
var snapshot = _karmaCache.ToArray();
|
||||
if (snapshot.Length == 0) return;
|
||||
|
||||
using var tx = conn.BeginTransaction();
|
||||
const string upsert = @"
|
||||
INSERT INTO PlayerKarma (PlayerId, Karma)
|
||||
VALUES (@PlayerId, @Karma)
|
||||
ON CONFLICT(PlayerId) DO UPDATE SET Karma = excluded.Karma
|
||||
";
|
||||
foreach (var (playerId, karma) in snapshot)
|
||||
await conn.ExecuteAsync(upsert,
|
||||
new { PlayerId = playerId, Karma = karma }, tx);
|
||||
|
||||
tx.Commit();
|
||||
} finally { _flushGate.Release(); }
|
||||
}
|
||||
|
||||
private IDbConnection EnsureConnection() {
|
||||
if (_connection is not { State: ConnectionState.Open })
|
||||
throw new InvalidOperationException(
|
||||
"Storage connection is not initialized.");
|
||||
return _connection;
|
||||
}
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
<ProjectReference Include="..\Shop\Shop.csproj"/>
|
||||
<ProjectReference Include="..\RTD\RTD.csproj"/>
|
||||
<ProjectReference Include="..\Stats\Stats.csproj"/>
|
||||
<ProjectReference Include="..\SpecialRound\SpecialRound.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Reactive.Concurrency;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SpecialRound;
|
||||
using Stats;
|
||||
using TTT.CS2;
|
||||
using TTT.Game;
|
||||
@@ -20,8 +21,9 @@ public class TTTServiceCollection : IPluginServiceCollection<TTT> {
|
||||
serviceCollection.AddCS2Services();
|
||||
serviceCollection.AddShopServices();
|
||||
serviceCollection.AddRtdServices();
|
||||
serviceCollection.AddSpecialRounds();
|
||||
|
||||
if (Environment.GetEnvironmentVariable("TTT_STATS_API_URL") == null) return;
|
||||
serviceCollection.AddStatsSerivces();
|
||||
serviceCollection.AddStatsServices();
|
||||
}
|
||||
}
|
||||
16
TTT/RTD/Actions/RolledAction.cs
Normal file
16
TTT/RTD/Actions/RolledAction.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
|
||||
namespace TTT.RTD.Actions;
|
||||
|
||||
public class RolledAction(IRoleAssigner roles, IPlayer player, string roll)
|
||||
: IAction {
|
||||
public IPlayer Player { get; } = player;
|
||||
public IPlayer? Other { get; } = null;
|
||||
public IRole? PlayerRole { get; } = roles.GetRoles(player).FirstOrDefault();
|
||||
public IRole? OtherRole { get; } = null;
|
||||
public string Id { get; } = "rtd.action.rolled";
|
||||
public string Verb { get; } = "rolled";
|
||||
public string Details { get; } = roll;
|
||||
}
|
||||
107
TTT/RTD/AutoRTDCommand.cs
Normal file
107
TTT/RTD/AutoRTDCommand.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using JetBrains.Annotations;
|
||||
using MAULActainShared.plugin.models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Command;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Messages;
|
||||
using TTT.API.Player;
|
||||
using TTT.CS2.Command;
|
||||
using TTT.CS2.ThirdParties.eGO;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
using TTT.RTD.lang;
|
||||
|
||||
namespace TTT.RTD;
|
||||
|
||||
public class AutoRTDCommand(IServiceProvider provider) : ICommand, IListener {
|
||||
public string Id => "autortd";
|
||||
private ICookie? autoRtdCookie;
|
||||
|
||||
private readonly IPlayerFinder finder =
|
||||
provider.GetRequiredService<IPlayerFinder>();
|
||||
|
||||
private readonly ICommandManager commands =
|
||||
provider.GetRequiredService<ICommandManager>();
|
||||
|
||||
private readonly IMsgLocalizer localizer =
|
||||
provider.GetRequiredService<IMsgLocalizer>();
|
||||
|
||||
public bool MustBeOnMainThread => true;
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public void Start() {
|
||||
Task.Run(async () => {
|
||||
var api = EgoApi.MAUL.Get();
|
||||
if (api != null) {
|
||||
await api.getCookieService().RegClientCookie("ttt_autortd");
|
||||
autoRtdCookie =
|
||||
await api.getCookieService().FindClientCookie("ttt_autortd");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public string[] RequiredFlags => ["@ttt/autortd"];
|
||||
private Dictionary<string, bool> playerStatuses = new();
|
||||
|
||||
public async Task<CommandResult> Execute(IOnlinePlayer? executor,
|
||||
ICommandInfo info) {
|
||||
if (executor == null) return CommandResult.PLAYER_ONLY;
|
||||
if (autoRtdCookie == null) {
|
||||
info.ReplySync("AutoRTD system is not available.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (!ulong.TryParse(executor.Id, out var executorId)) {
|
||||
info.ReplySync("Your player ID is invalid for AutoRTD.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
var value = await autoRtdCookie.Get(executorId);
|
||||
if (value == "1") {
|
||||
await autoRtdCookie.Set(executorId, "0");
|
||||
info.ReplySync(localizer[RtdMsgs.COMMAND_AUTORTD_DISABLED]);
|
||||
} else {
|
||||
await autoRtdCookie.Set(executorId, "1");
|
||||
info.ReplySync(localizer[RtdMsgs.COMMAND_AUTORTD_ENABLED]);
|
||||
}
|
||||
|
||||
playerStatuses[executor.Id] = value != "1";
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnRoundStart(GameInitEvent ev) {
|
||||
var messenger = provider.GetRequiredService<IMessenger>();
|
||||
Task.Run(async () => {
|
||||
foreach (var player in finder.GetOnline()) {
|
||||
if (!playerStatuses.TryGetValue(player.Id, out var status)) {
|
||||
await fetchCookie(player);
|
||||
status = playerStatuses.GetValueOrDefault(player.Id, false);
|
||||
}
|
||||
|
||||
if (!status) continue;
|
||||
|
||||
var info = new CS2CommandInfo(provider, player, 0, "css_rtd") {
|
||||
CallingContext = CommandCallingContext.Chat
|
||||
};
|
||||
|
||||
await Server.NextWorldUpdateAsync(() => commands.ProcessCommand(info));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task fetchCookie(IPlayer player) {
|
||||
if (autoRtdCookie == null) return;
|
||||
if (!ulong.TryParse(player.Id, out var playerId)) return;
|
||||
|
||||
var value = await autoRtdCookie.Get(playerId);
|
||||
playerStatuses[player.Id] = value == "1";
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,10 @@
|
||||
<ProjectReference Include="..\Shop\Shop.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="MAULActainShared">
|
||||
<HintPath>..\CS2\ThirdParties\Binaries\MAULActainShared.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -8,10 +8,11 @@ public class ShopItemReward<TItem>(IServiceProvider provider)
|
||||
: RoundStartReward(provider) where TItem : IShopItem {
|
||||
private readonly IShop shop = provider.GetRequiredService<IShop>();
|
||||
|
||||
public override string Name => typeof(TItem).Name;
|
||||
public override string Name
|
||||
=> shop.Items.OfType<TItem>().FirstOrDefault()?.Name ?? typeof(TItem).Name;
|
||||
|
||||
public override string Description
|
||||
=> $"you will receive {("aeiou".Contains(Name.ToLower()[0]) ? "an" : "a")} {typeof(TItem).Name} next round";
|
||||
=> $"you will receive {("aeiou".Contains(Name.ToLower()[0]) ? "an" : "a")} {Name} item next round";
|
||||
|
||||
public override void GiveOnRound(IOnlinePlayer player) {
|
||||
var instance = shop.Items.OfType<TItem>().FirstOrDefault();
|
||||
|
||||
@@ -4,8 +4,10 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
using TTT.RTD.Actions;
|
||||
|
||||
namespace TTT.RTD;
|
||||
|
||||
@@ -16,12 +18,15 @@ public abstract class RoundStartReward(IServiceProvider provider)
|
||||
|
||||
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
|
||||
|
||||
private readonly IRoleAssigner roles =
|
||||
provider.GetRequiredService<IRoleAssigner>();
|
||||
|
||||
public abstract string Name { get; }
|
||||
public abstract string Description { get; }
|
||||
|
||||
public void GrantReward(IOnlinePlayer player) { givenPlayers.Add(player); }
|
||||
public abstract void GiveOnRound(IOnlinePlayer player);
|
||||
|
||||
|
||||
protected readonly IMsgLocalizer Locale =
|
||||
provider.GetRequiredService<IMsgLocalizer>();
|
||||
|
||||
@@ -30,7 +35,10 @@ public abstract class RoundStartReward(IServiceProvider provider)
|
||||
public virtual void OnRoundStart(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.IN_PROGRESS) return;
|
||||
|
||||
foreach (var player in givenPlayers) GiveOnRound(player);
|
||||
foreach (var player in givenPlayers) {
|
||||
GiveOnRound(player);
|
||||
ev.Game.Logger.LogAction(new RolledAction(roles, player, Name));
|
||||
}
|
||||
|
||||
givenPlayers.Clear();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class RTDCommand(IRewardGenerator generator, IPermissionManager perms,
|
||||
if (executor == null) return Task.FromResult(CommandResult.PLAYER_ONLY);
|
||||
var bypass = perms.HasFlags(executor, "@css/root") && info.ArgCount == 2;
|
||||
#if DEBUG
|
||||
bypass = true;
|
||||
bypass = info.ArgCount == 2;
|
||||
#endif
|
||||
|
||||
if (!bypass && playerRewards.TryGetValue(executor.Id, out var existing)) {
|
||||
|
||||
@@ -9,6 +9,7 @@ public static class RtdServiceExtensions {
|
||||
services.AddModBehavior<IRewardGenerator, RewardGenerator>();
|
||||
services.AddModBehavior<RtdStatsCommand>();
|
||||
services.AddModBehavior<RTDCommand>();
|
||||
services.AddModBehavior<AutoRTDCommand>();
|
||||
services.AddSingleton<IMuted, Muted>();
|
||||
}
|
||||
}
|
||||
@@ -20,4 +20,10 @@ public class RtdMsgs {
|
||||
|
||||
public static IMsg CREDITS_REWARD_DESC(int amo)
|
||||
=> MsgFactory.Create(nameof(CREDITS_REWARD_DESC), amo);
|
||||
|
||||
public static IMsg COMMAND_AUTORTD_ENABLED
|
||||
=> MsgFactory.Create(nameof(COMMAND_AUTORTD_ENABLED));
|
||||
|
||||
public static IMsg COMMAND_AUTORTD_DISABLED
|
||||
=> MsgFactory.Create(nameof(COMMAND_AUTORTD_DISABLED));
|
||||
}
|
||||
@@ -4,4 +4,6 @@ RTD_CANNOT_ROLL_YET: "%RTD_PREFIX%You must wait until death to roll the die."
|
||||
RTD_ROLLED: "%RTD_PREFIX%You rolled {default}{0}{grey}, {1}."
|
||||
RTD_MUTED: "%RTD_PREFIX%You cannot speak due to your dice roll."
|
||||
CREDITS_REWARD: "{0} %CREDITS_NAME%%s%"
|
||||
CREDITS_REWARD_DESC: "you will receive {yellow}{0} %CREDITS_NAME%%s%{grey} next round"
|
||||
CREDITS_REWARD_DESC: "you will receive {yellow}{0} %CREDITS_NAME%%s%{grey} next round"
|
||||
COMMAND_AUTORTD_ENABLED: "%RTD_PREFIX%Auto-RTD has been {green}enabled{grey}."
|
||||
COMMAND_AUTORTD_DISABLED: "%RTD_PREFIX%Auto-RTD has been {red}disabled{grey}."
|
||||
@@ -13,7 +13,7 @@ using TTT.Game.Roles;
|
||||
namespace TTT.Shop.Items.Healthshot;
|
||||
|
||||
public static class HealthshotServiceCollection {
|
||||
public static void AddHealthshot(this IServiceCollection services) {
|
||||
public static void AddHealthshotServices(this IServiceCollection services) {
|
||||
services.AddModBehavior<HealthshotItem>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using TTT.Game.Roles;
|
||||
namespace TTT.Shop.Items.Taser;
|
||||
|
||||
public static class TaserServiceCollection {
|
||||
public static void AddTaserItem(this IServiceCollection collection) {
|
||||
public static void AddTaserServices(this IServiceCollection collection) {
|
||||
collection.AddModBehavior<TaserItem>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class PeriodicRewarder(IServiceProvider provider) : ITerrorModule {
|
||||
if (positions.Count < 2) return 0f;
|
||||
var totalDistance = 0f;
|
||||
for (var i = 1; i < positions.Count; i++)
|
||||
totalDistance += positions[i].Distance(positions[i - 1]);
|
||||
totalDistance += positions[i].DistanceSquared(positions[i - 1]);
|
||||
|
||||
|
||||
return totalDistance;
|
||||
|
||||
@@ -12,6 +12,7 @@ using TTT.CS2.Items.PoisonShots;
|
||||
using TTT.CS2.Items.PoisonSmoke;
|
||||
using TTT.CS2.Items.SilentAWP;
|
||||
using TTT.CS2.Items.Station;
|
||||
using TTT.CS2.Items.TeleportDecoy;
|
||||
using TTT.Shop.Commands;
|
||||
using TTT.Shop.Items;
|
||||
using TTT.Shop.Items.Detective.Stickers;
|
||||
@@ -49,15 +50,16 @@ public static class ShopServiceCollection {
|
||||
collection.AddDeagleServices();
|
||||
collection.AddDnaScannerServices();
|
||||
collection.AddGlovesServices();
|
||||
collection.AddHealthStation();
|
||||
collection.AddHealthshot();
|
||||
collection.AddHealthStationServices();
|
||||
collection.AddHealthshotServices();
|
||||
collection.AddInnoCompassServices();
|
||||
collection.AddM4A1Services();
|
||||
collection.AddOneHitKnifeService();
|
||||
collection.AddPoisonShots();
|
||||
collection.AddPoisonSmoke();
|
||||
collection.AddPoisonShotsServices();
|
||||
collection.AddPoisonSmokeServices();
|
||||
collection.AddSilentAWPServices();
|
||||
collection.AddStickerServices();
|
||||
collection.AddTaserItem();
|
||||
collection.AddTaserServices();
|
||||
collection.AddTeleportDecoyServices();
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ SHOP_ITEM_TASER: "Taser"
|
||||
SHOP_ITEM_TASER_DESC: "A taser that allows you to identify the roles of players you hit."
|
||||
|
||||
SHOP_ITEM_HEALTHSHOT: "Healthshot"
|
||||
SHOP_ITEM_HEALTHSHOT_DESC: "A healthshot that instantly heals you for 50 health."
|
||||
SHOP_ITEM_HEALTHSHOT_DESC: "A healthshot that heals you gradually for 50 health."
|
||||
|
||||
SHOP_INSUFFICIENT_BALANCE: "%SHOP_PREFIX%You cannot afford {white}{0}{grey}, it costs {yellow}{1}{grey} %CREDITS_NAME%%s%, and you have {yellow}{2}{grey}."
|
||||
SHOP_CANNOT_PURCHASE: "%SHOP_PREFIX%You cannot purchase this item."
|
||||
@@ -34,7 +34,7 @@ SHOP_CANNOT_PURCHASE_WITH_REASON: "%SHOP_PREFIX%You cannot purchase this item: {
|
||||
SHOP_PURCHASED: "%SHOP_PREFIX%You purchased {white}{0}{grey}."
|
||||
SHOP_LIST_FOOTER: "%SHOP_PREFIX%You are %an% {0}{grey}, you have {yellow}{1}{grey} %CREDITS_NAME%%s%."
|
||||
|
||||
CREDITS_NAME: "credit"
|
||||
CREDITS_NAME: "point"
|
||||
CREDITS_GIVEN: "%SHOP_PREFIX%{0}{1} %CREDITS_NAME%%s%"
|
||||
CREDITS_GIVEN_REASON: "%SHOP_PREFIX%{0}{1} %CREDITS_NAME%%s% {grey}({white}{2}{grey})"
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@ namespace ShopAPI.Configs;
|
||||
|
||||
public record BodyPaintConfig : ShopItemConfig {
|
||||
public override int Price { get; init; } = 40;
|
||||
public int MaxUses { get; init; } = 2;
|
||||
public int MaxUses { get; init; } = 4;
|
||||
public Color ColorToApply { get; init; } = Color.GreenYellow;
|
||||
}
|
||||
@@ -2,5 +2,5 @@ namespace ShopAPI.Configs;
|
||||
|
||||
public record CamoConfig : ShopItemConfig {
|
||||
public override int Price { get; init; } = 75;
|
||||
public float CamoVisibility { get; init; } = 0.4f;
|
||||
public float CamoVisibility { get; init; } = 0.6f;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace ShopAPI.Configs.Detective;
|
||||
|
||||
public record HealthStationConfig : StationConfig {
|
||||
public override string UseSound { get; init; } = "sounds/buttons/blip1";
|
||||
public virtual string UseSound { get; init; } = "sounds/buttons/blip1";
|
||||
|
||||
public override int Price { get; init; } = 50;
|
||||
|
||||
|
||||
@@ -5,12 +5,11 @@ namespace ShopAPI.Configs;
|
||||
public abstract record StationConfig : ShopItemConfig {
|
||||
public virtual int HealthIncrements { get; init; } = 5;
|
||||
public virtual int TotalHealthGiven { get; init; } = 0;
|
||||
public virtual int StationHealth { get; init; } = 1000;
|
||||
public virtual int StationHealth { get; init; } = 200;
|
||||
public virtual float MaxRange { get; init; } = 256;
|
||||
|
||||
public virtual TimeSpan HealthInterval { get; init; } =
|
||||
TimeSpan.FromSeconds(1);
|
||||
|
||||
public abstract string UseSound { get; init; }
|
||||
public abstract Color GetColor(float health);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ public record DamageStationConfig : StationConfig {
|
||||
public override int HealthIncrements { get; init; } = -25;
|
||||
public override int TotalHealthGiven { get; init; } = -3000;
|
||||
|
||||
public override string UseSound { get; init; } = "sounds/buttons/blip2";
|
||||
public virtual string UseSound { get; init; } = "sounds/buttons/blip2";
|
||||
|
||||
public override int Price { get; init; } = 65;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ShopAPI.Configs.Traitor;
|
||||
|
||||
public record OneHitKnifeConfig : ShopItemConfig {
|
||||
public override int Price { get; init; } = 70;
|
||||
public override int Price { get; init; } = 80;
|
||||
public bool FriendlyFire { get; init; } = true;
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace ShopAPI.Configs.Traitor;
|
||||
|
||||
public record SilentAWPConfig : ShopItemConfig, IWeapon {
|
||||
public override int Price { get; init; } = 90;
|
||||
public int WeaponIndex { get; } = 9;
|
||||
public string WeaponId { get; } = "weapon_awp";
|
||||
public int? ReserveAmmo { get; } = 0;
|
||||
public int? CurrentAmmo { get; } = 2;
|
||||
public override int Price { get; init; } = 80;
|
||||
public int WeaponIndex { get; init; } = 9;
|
||||
public string WeaponId { get; init; } = "weapon_awp";
|
||||
public int? ReserveAmmo { get; init; } = 0;
|
||||
public int? CurrentAmmo { get; init; } = 1;
|
||||
}
|
||||
5
TTT/ShopAPI/Configs/Traitor/TeleportDecoyConfig.cs
Normal file
5
TTT/ShopAPI/Configs/Traitor/TeleportDecoyConfig.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace ShopAPI.Configs.Traitor;
|
||||
|
||||
public record TeleportDecoyConfig : ShopItemConfig {
|
||||
public override int Price { get; init; } = 80;
|
||||
}
|
||||
39
TTT/SpecialRound/Rounds/BhopRound.cs
Normal file
39
TTT/SpecialRound/Rounds/BhopRound.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRound.lang;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Storage;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRound.Rounds;
|
||||
|
||||
public class BhopRound(IServiceProvider provider)
|
||||
: AbstractSpecialRound(provider) {
|
||||
public override string Name => "BHop";
|
||||
public override IMsg Description => RoundMsgs.SPECIAL_ROUND_BHOP;
|
||||
public override SpecialRoundConfig Config => config;
|
||||
|
||||
private BhopRoundConfig config
|
||||
=> Provider.GetService<IStorage<BhopRoundConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new BhopRoundConfig();
|
||||
|
||||
public override void ApplyRoundEffects() {
|
||||
Server.NextWorldUpdate(() => {
|
||||
Server.ExecuteCommand("sv_enablebunnyhopping 1");
|
||||
Server.ExecuteCommand("sv_autobunnyhopping 1");
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnGameState(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.FINISHED) return;
|
||||
|
||||
Server.NextWorldUpdate(() => {
|
||||
Server.ExecuteCommand("sv_enablebunnyhopping 0");
|
||||
Server.ExecuteCommand("sv_autobunnyhopping 0");
|
||||
});
|
||||
}
|
||||
}
|
||||
89
TTT/SpecialRound/Rounds/SpeedRound.cs
Normal file
89
TTT/SpecialRound/Rounds/SpeedRound.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Reactive.Concurrency;
|
||||
using CounterStrikeSharp.API;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRound.lang;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Role;
|
||||
using TTT.API.Storage;
|
||||
using TTT.CS2.Listeners;
|
||||
using TTT.CS2.Utils;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Roles;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRound.Rounds;
|
||||
|
||||
public class SpeedRound(IServiceProvider provider)
|
||||
: AbstractSpecialRound(provider) {
|
||||
private readonly IScheduler scheduler =
|
||||
provider.GetRequiredService<IScheduler>();
|
||||
|
||||
private readonly IGameManager games =
|
||||
provider.GetRequiredService<IGameManager>();
|
||||
|
||||
private readonly IRoleAssigner roles =
|
||||
provider.GetRequiredService<IRoleAssigner>();
|
||||
|
||||
public override string Name => "Speed";
|
||||
public override IMsg Description => RoundMsgs.SPECIAL_ROUND_SPEED;
|
||||
|
||||
public override SpecialRoundConfig Config => config;
|
||||
|
||||
private SpeedRoundConfig config
|
||||
=> Provider.GetService<IStorage<SpeedRoundConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new SpeedRoundConfig();
|
||||
|
||||
private IDisposable? endTimer;
|
||||
|
||||
public override void ApplyRoundEffects() {
|
||||
Provider.GetService<RoundTimerListener>()?.EndTimer?.Dispose();
|
||||
|
||||
Server.RunOnTick(Server.TickCount + 2,
|
||||
() => setTime(config.InitialSeconds));
|
||||
}
|
||||
|
||||
private void addTime(TimeSpan span) {
|
||||
Server.NextWorldUpdate(() => {
|
||||
var remaining = RoundUtil.GetTimeRemaining();
|
||||
var newSpan = TimeSpan.FromSeconds(remaining + (int)span.TotalSeconds);
|
||||
|
||||
setTime(newSpan);
|
||||
});
|
||||
}
|
||||
|
||||
private void setTime(TimeSpan span) {
|
||||
Server.NextWorldUpdate(() => {
|
||||
RoundUtil.SetTimeRemaining((int)span.TotalSeconds);
|
||||
});
|
||||
|
||||
endTimer?.Dispose();
|
||||
endTimer = scheduler.Schedule(span,
|
||||
() => Server.NextWorldUpdate(() => games.ActiveGame?.EndGame(
|
||||
EndReason.TIMEOUT(new InnocentRole(Provider)))));
|
||||
}
|
||||
|
||||
public override void OnGameState(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.FINISHED) return;
|
||||
|
||||
endTimer?.Dispose();
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnDeath(PlayerDeathEvent ev) {
|
||||
var game = games.ActiveGame;
|
||||
if (game == null) return;
|
||||
if (Tracker.CurrentRound != this) return;
|
||||
|
||||
var victimRoles = roles.GetRoles(ev.Victim);
|
||||
if (!victimRoles.Any(r => r is InnocentRole)) return;
|
||||
|
||||
addTime(config.SecondsPerKill);
|
||||
}
|
||||
}
|
||||
45
TTT/SpecialRound/Rounds/VanillaRound.cs
Normal file
45
TTT/SpecialRound/Rounds/VanillaRound.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShopAPI.Events;
|
||||
using SpecialRound.lang;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Messages;
|
||||
using TTT.API.Storage;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRound.Rounds;
|
||||
|
||||
public class VanillaRound(IServiceProvider provider)
|
||||
: AbstractSpecialRound(provider) {
|
||||
public override string Name => "Vanilla";
|
||||
public override IMsg Description => RoundMsgs.SPECIAL_ROUND_VANILLA;
|
||||
|
||||
private readonly IMessenger messenger =
|
||||
provider.GetRequiredService<IMessenger>();
|
||||
|
||||
private readonly IMsgLocalizer locale =
|
||||
provider.GetRequiredService<IMsgLocalizer>();
|
||||
|
||||
private VanillaRoundConfig config
|
||||
=> Provider.GetService<IStorage<VanillaRoundConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new VanillaRoundConfig();
|
||||
|
||||
public override SpecialRoundConfig Config => config;
|
||||
|
||||
public override void ApplyRoundEffects() { }
|
||||
|
||||
public override void OnGameState(GameStateUpdateEvent ev) { }
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler(Priority = Priority.HIGH)]
|
||||
public void OnPurchase(PlayerPurchaseItemEvent ev) {
|
||||
if (Tracker.CurrentRound != this) return;
|
||||
ev.IsCanceled = true;
|
||||
|
||||
messenger.Message(ev.Player, locale[RoundMsgs.VANILLA_ROUND_REMINDER]);
|
||||
}
|
||||
}
|
||||
16
TTT/SpecialRound/SpecialRound.csproj
Normal file
16
TTT/SpecialRound/SpecialRound.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\SpecialRoundAPI\SpecialRoundAPI\SpecialRoundAPI.csproj" />
|
||||
<ProjectReference Include="..\API\API.csproj" />
|
||||
<ProjectReference Include="..\CS2\CS2.csproj" />
|
||||
<ProjectReference Include="..\Game\Game.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
17
TTT/SpecialRound/SpecialRoundCollection.cs
Normal file
17
TTT/SpecialRound/SpecialRoundCollection.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRound.Rounds;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Extensions;
|
||||
|
||||
namespace SpecialRound;
|
||||
|
||||
public static class SpecialRoundCollection {
|
||||
public static void AddSpecialRounds(this IServiceCollection services) {
|
||||
services.AddModBehavior<ISpecialRoundStarter, SpecialRoundStarter>();
|
||||
services.AddModBehavior<ISpecialRoundTracker, SpecialRoundTracker>();
|
||||
|
||||
services.AddModBehavior<SpeedRound>();
|
||||
services.AddModBehavior<BhopRound>();
|
||||
services.AddModBehavior<VanillaRound>();
|
||||
}
|
||||
}
|
||||
81
TTT/SpecialRound/SpecialRoundStarter.cs
Normal file
81
TTT/SpecialRound/SpecialRoundStarter.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRound.lang;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Storage;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Listeners;
|
||||
|
||||
namespace SpecialRound;
|
||||
|
||||
public class SpecialRoundStarter(IServiceProvider provider)
|
||||
: BaseListener(provider), IPluginModule, ISpecialRoundStarter {
|
||||
private readonly ISpecialRoundTracker tracker =
|
||||
provider.GetRequiredService<ISpecialRoundTracker>();
|
||||
|
||||
private SpecialRoundsConfig config
|
||||
=> Provider.GetService<IStorage<SpecialRoundsConfig>>()
|
||||
?.Load()
|
||||
.GetAwaiter()
|
||||
.GetResult() ?? new SpecialRoundsConfig();
|
||||
|
||||
private int roundsSinceMapChange = 0;
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
plugin?.RegisterListener<Listeners.OnMapStart>(onMapChange);
|
||||
}
|
||||
|
||||
private void onMapChange(string mapName) { roundsSinceMapChange = 0; }
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnRound(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.IN_PROGRESS) return;
|
||||
|
||||
roundsSinceMapChange++;
|
||||
tracker.RoundsSinceLastSpecial++;
|
||||
|
||||
if (tracker.RoundsSinceLastSpecial < config.MinRoundsBetweenSpecial) return;
|
||||
|
||||
if (ev.Game.Players.Count < config.MinPlayersForSpecial) return;
|
||||
if (roundsSinceMapChange < config.MinRoundsAfterMapChange) return;
|
||||
if (Random.Shared.NextSingle() > config.SpecialRoundChance) return;
|
||||
|
||||
var specialRound = getSpecialRound();
|
||||
|
||||
TryStartSpecialRound(specialRound);
|
||||
}
|
||||
|
||||
private AbstractSpecialRound getSpecialRound() {
|
||||
var rounds = Provider.GetServices<ITerrorModule>()
|
||||
.OfType<AbstractSpecialRound>()
|
||||
.Where(r => r.Config.Weight > 0)
|
||||
.ToList();
|
||||
var totalWeight = rounds.Sum(r => r.Config.Weight);
|
||||
var roll = Random.Shared.NextDouble() * totalWeight;
|
||||
foreach (var round in rounds) {
|
||||
roll -= round.Config.Weight;
|
||||
if (roll <= 0) return round;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
"Failed to select a special round. This should never happen.");
|
||||
}
|
||||
|
||||
public AbstractSpecialRound?
|
||||
TryStartSpecialRound(AbstractSpecialRound? round) {
|
||||
round ??= getSpecialRound();
|
||||
Messenger.MessageAll(Locale[RoundMsgs.SPECIAL_ROUND_STARTED(round)]);
|
||||
Messenger.MessageAll(Locale[round.Description]);
|
||||
|
||||
round?.ApplyRoundEffects();
|
||||
tracker.CurrentRound = round;
|
||||
tracker.RoundsSinceLastSpecial = 0;
|
||||
return round;
|
||||
}
|
||||
}
|
||||
23
TTT/SpecialRound/SpecialRoundTracker.cs
Normal file
23
TTT/SpecialRound/SpecialRoundTracker.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using JetBrains.Annotations;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.Game.Events.Game;
|
||||
|
||||
namespace SpecialRound;
|
||||
|
||||
public class SpecialRoundTracker : ISpecialRoundTracker, ITerrorModule,
|
||||
IListener {
|
||||
public AbstractSpecialRound? CurrentRound { get; set; }
|
||||
public int RoundsSinceLastSpecial { get; set; }
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnRoundEnd(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.FINISHED) return;
|
||||
CurrentRound = null;
|
||||
}
|
||||
}
|
||||
8
TTT/SpecialRound/SpecialRoundsConfig.cs
Normal file
8
TTT/SpecialRound/SpecialRoundsConfig.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace SpecialRound;
|
||||
|
||||
public record SpecialRoundsConfig {
|
||||
public int MinRoundsBetweenSpecial { get; init; } = 3;
|
||||
public int MinPlayersForSpecial { get; init; } = 8;
|
||||
public int MinRoundsAfterMapChange { get; init; } = 2;
|
||||
public float SpecialRoundChance { get; init; } = 0.2f;
|
||||
}
|
||||
22
TTT/SpecialRound/lang/RoundMsgs.cs
Normal file
22
TTT/SpecialRound/lang/RoundMsgs.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using SpecialRoundAPI;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRound.lang;
|
||||
|
||||
public class RoundMsgs {
|
||||
public static IMsg SPECIAL_ROUND_STARTED(AbstractSpecialRound round) {
|
||||
return MsgFactory.Create(nameof(SPECIAL_ROUND_STARTED), round.Name);
|
||||
}
|
||||
|
||||
public static IMsg SPECIAL_ROUND_SPEED
|
||||
=> MsgFactory.Create(nameof(SPECIAL_ROUND_SPEED));
|
||||
|
||||
public static IMsg SPECIAL_ROUND_BHOP
|
||||
=> MsgFactory.Create(nameof(SPECIAL_ROUND_BHOP));
|
||||
|
||||
public static IMsg SPECIAL_ROUND_VANILLA
|
||||
=> MsgFactory.Create(nameof(SPECIAL_ROUND_VANILLA));
|
||||
|
||||
public static IMsg VANILLA_ROUND_REMINDER
|
||||
=> MsgFactory.Create(nameof(VANILLA_ROUND_REMINDER));
|
||||
}
|
||||
5
TTT/SpecialRound/lang/en.yml
Normal file
5
TTT/SpecialRound/lang/en.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
SPECIAL_ROUND_STARTED: "%PREFIX%This round is a {purple}Special Round{grey}! This round is a {lightpurple}{0}{grey} round!"
|
||||
SPECIAL_ROUND_SPEED: " {yellow}SPEED{grey}: The round is faster than usual! {red}Traitors{grey} must kill to gain more time."
|
||||
SPECIAL_ROUND_BHOP: " {Yellow}BHOP{grey}: Bunny hopping is enabled! Hold jump to move faster!"
|
||||
SPECIAL_ROUND_VANILLA: " {green}VANILLA{grey}: The shop has been disabled!"
|
||||
VANILLA_ROUND_REMINDER: "%SHOP_PREFIX%This is a {purple}Vanilla{grey} round. The shop is disabled."
|
||||
@@ -13,6 +13,9 @@ public class KillListener(IServiceProvider provider) : IListener {
|
||||
private readonly IGameManager game =
|
||||
provider.GetRequiredService<IGameManager>();
|
||||
|
||||
private readonly IRoundTracker? roundTracker =
|
||||
provider.GetService<IRoundTracker>();
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
[UsedImplicitly]
|
||||
@@ -24,6 +27,7 @@ public class KillListener(IServiceProvider provider) : IListener {
|
||||
var data = new {
|
||||
killer_steam_id = ev.Killer.Id,
|
||||
victim_steam_id = ev.Victim.Id,
|
||||
round_id = roundTracker?.CurrentRoundId,
|
||||
weapon = ev.Weapon
|
||||
};
|
||||
|
||||
@@ -31,6 +35,6 @@ public class KillListener(IServiceProvider provider) : IListener {
|
||||
System.Text.Json.JsonSerializer.Serialize(data),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
Task.Run(async () => { await client.PostAsync("kill", payload); });
|
||||
Task.Run(async () => await client.PostAsync("kill", payload));
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Stats.lang;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Messages;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace Stats;
|
||||
|
||||
@@ -13,6 +16,12 @@ public class LogsUploader(IServiceProvider provider) : IListener {
|
||||
private readonly IRoundTracker roundTracker =
|
||||
provider.GetRequiredService<IRoundTracker>();
|
||||
|
||||
private readonly IMsgLocalizer localizer =
|
||||
provider.GetRequiredService<IMsgLocalizer>();
|
||||
|
||||
private readonly IMessenger messenger =
|
||||
provider.GetRequiredService<IMessenger>();
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
[UsedImplicitly]
|
||||
@@ -29,7 +38,13 @@ public class LogsUploader(IServiceProvider provider) : IListener {
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
Task.Run(async () => {
|
||||
await client.PatchAsync("round/" + roundTracker.CurrentRoundId, payload);
|
||||
var id = roundTracker.CurrentRoundId;
|
||||
if (id == null) return;
|
||||
var result = await client.PatchAsync("round/" + id.Value, payload);
|
||||
|
||||
if (!result.IsSuccessStatusCode) return;
|
||||
|
||||
await messenger.MessageAll(localizer[StatsMsgs.API_ROUND_END(id.Value)]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -27,13 +27,13 @@ public class PlayerCreationListener(IServiceProvider provider) : IListener {
|
||||
|
||||
private async Task putPlayer(IPlayer player) {
|
||||
var client = provider.GetRequiredService<HttpClient>();
|
||||
var userJson = new { steam_id = player.Id, name = player.Name };
|
||||
var userJson = new { name = player.Name };
|
||||
|
||||
var content = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(userJson),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await client.PutAsync("user", content);
|
||||
var response = await client.PutAsync("user/" + player.Id, content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,19 @@ public class PurchaseListener(IServiceProvider provider) : IListener {
|
||||
private readonly HttpClient client =
|
||||
provider.GetRequiredService<HttpClient>();
|
||||
|
||||
private readonly IRoundTracker? roundTracker =
|
||||
provider.GetService<IRoundTracker>();
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnPurchase(PlayerPurchaseItemEvent ev) {
|
||||
var body = new { steam_id = ev.Player.Id, item_id = ev.Item.Id };
|
||||
var body = new {
|
||||
steam_id = ev.Player.Id,
|
||||
item_id = ev.Item.Id,
|
||||
round_id = roundTracker?.CurrentRoundId
|
||||
};
|
||||
|
||||
var payload = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(body),
|
||||
|
||||
@@ -3,14 +3,17 @@ using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Stats.lang;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Game;
|
||||
using TTT.API.Messages;
|
||||
using TTT.API.Player;
|
||||
using TTT.API.Role;
|
||||
using TTT.Game.Events.Body;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Events.Player;
|
||||
using TTT.Game.Roles;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace Stats;
|
||||
|
||||
@@ -23,12 +26,18 @@ public class RoundListener(IServiceProvider provider)
|
||||
private readonly IRoleAssigner roles =
|
||||
provider.GetRequiredService<IRoleAssigner>();
|
||||
|
||||
private readonly IMessenger messenger =
|
||||
provider.GetRequiredService<IMessenger>();
|
||||
|
||||
private readonly IMsgLocalizer localizer =
|
||||
provider.GetRequiredService<IMsgLocalizer>();
|
||||
|
||||
private Dictionary<string, (int, int, int)> kills = new();
|
||||
private Dictionary<string, int> bodiesFound = new();
|
||||
private HashSet<string> deaths = new();
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
[EventHandler(Priority = Priority.MONITOR, IgnoreCanceled = true)]
|
||||
public void OnGameState(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState == State.IN_PROGRESS) {
|
||||
kills.Clear();
|
||||
@@ -36,8 +45,9 @@ public class RoundListener(IServiceProvider provider)
|
||||
Task.Run(async () => await onRoundStart(ev.Game));
|
||||
}
|
||||
|
||||
var game = ev.Game;
|
||||
if (ev.NewState == State.FINISHED)
|
||||
Task.Run(async () => await onRoundEnd(ev.Game));
|
||||
Task.Run(async () => await onRoundEnd(game));
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
@@ -77,85 +87,75 @@ public class RoundListener(IServiceProvider provider)
|
||||
await Server.NextWorldUpdateAsync(() => {
|
||||
var map_name = Server.MapName;
|
||||
var startedAt = DateTime.UtcNow;
|
||||
Task.Run(async () => {
|
||||
var data = new {
|
||||
map_name, startedAt, participants = getParticipants(game)
|
||||
};
|
||||
|
||||
var content = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(data),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
Console.WriteLine("json data: "
|
||||
+ System.Text.Json.JsonSerializer.Serialize(data));
|
||||
|
||||
var client = provider.GetRequiredService<HttpClient>();
|
||||
|
||||
Console.WriteLine("RoundListener: sending POST /round to "
|
||||
+ client.BaseAddress + "round");
|
||||
|
||||
var response = await provider.GetRequiredService<HttpClient>()
|
||||
.PostAsync("round", content);
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var jsonDoc = System.Text.Json.JsonDocument.Parse(json);
|
||||
Console.WriteLine("response json: " + json);
|
||||
CurrentRoundId = jsonDoc.RootElement.GetProperty("round_id").GetInt32();
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Conflict)
|
||||
await client.DeleteAsync("round/" + CurrentRoundId);
|
||||
|
||||
// Retry
|
||||
response = await client.PostAsync("round", content);
|
||||
Console.WriteLine("response status: " + response.StatusCode);
|
||||
|
||||
jsonDoc = System.Text.Json.JsonDocument.Parse(
|
||||
await response.Content.ReadAsStringAsync());
|
||||
CurrentRoundId = jsonDoc.RootElement.GetProperty("round_id").GetInt32();
|
||||
});
|
||||
Task.Run(async () => await createNewRound(game, map_name, startedAt));
|
||||
});
|
||||
}
|
||||
|
||||
private async Task onRoundEnd(IGame game) {
|
||||
Console.WriteLine("RoundListener: onRoundEnd fired");
|
||||
if (CurrentRoundId == null) {
|
||||
Console.WriteLine("RoundListener: currentRoundId is null, skipping");
|
||||
private async Task createNewRound(IGame game, string map_name,
|
||||
DateTime startedAt) {
|
||||
var data = new {
|
||||
map_name, startedAt, participants = getParticipants(game)
|
||||
};
|
||||
|
||||
var content = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(data),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var client = provider.GetRequiredService<HttpClient>();
|
||||
var response = await provider.GetRequiredService<HttpClient>()
|
||||
.PostAsync("round", content);
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var jsonDoc = System.Text.Json.JsonDocument.Parse(json);
|
||||
CurrentRoundId = jsonDoc.RootElement.GetProperty("round_id").GetInt32();
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Created) {
|
||||
await notifyNewRound(CurrentRoundId.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
var finishedAt = DateTime.UtcNow;
|
||||
if (response.StatusCode == HttpStatusCode.Conflict)
|
||||
await client.DeleteAsync("round/" + CurrentRoundId);
|
||||
|
||||
// Retry
|
||||
response = await client.PostAsync("round", content);
|
||||
|
||||
jsonDoc = System.Text.Json.JsonDocument.Parse(
|
||||
await response.Content.ReadAsStringAsync());
|
||||
CurrentRoundId = jsonDoc.RootElement.GetProperty("round_id").GetInt32();
|
||||
if (response.StatusCode == HttpStatusCode.Created) {
|
||||
await notifyNewRound(CurrentRoundId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private Task notifyNewRound(int id) {
|
||||
return messenger.MessageAll(localizer[StatsMsgs.API_ROUND_START(id)]);
|
||||
}
|
||||
|
||||
private async Task onRoundEnd(IGame game) {
|
||||
if (CurrentRoundId == null) return;
|
||||
|
||||
var ended_at = DateTime.UtcNow;
|
||||
var winning_role = game.WinningRole != null ?
|
||||
StatsApi.ApiNameForRole(game.WinningRole) :
|
||||
null;
|
||||
var participants = getParticipants(game);
|
||||
await Task.Run(async () => {
|
||||
var winningRole = game.WinningRole;
|
||||
var data = new {
|
||||
finishedAt,
|
||||
winning_role =
|
||||
winningRole != null ? StatsApi.ApiName(winningRole) : null,
|
||||
participants = getParticipants(game)
|
||||
};
|
||||
var data = new { ended_at, winning_role, participants };
|
||||
|
||||
var content = new StringContent(
|
||||
System.Text.Json.JsonSerializer.Serialize(data),
|
||||
System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
Console.WriteLine("json data: "
|
||||
+ System.Text.Json.JsonSerializer.Serialize(data));
|
||||
|
||||
var client = provider.GetRequiredService<HttpClient>();
|
||||
|
||||
Console.WriteLine("RoundListener: sending PATCH /round/" + CurrentRoundId
|
||||
+ " to " + client.BaseAddress + "round/" + CurrentRoundId);
|
||||
|
||||
var response = await client.PatchAsync(
|
||||
"round/" + CurrentRoundId, content);
|
||||
|
||||
Console.WriteLine("response status: " + response.StatusCode);
|
||||
CurrentRoundId = null;
|
||||
await client.PatchAsync("round/" + CurrentRoundId, content);
|
||||
});
|
||||
}
|
||||
|
||||
private record Participant {
|
||||
public string steam_id { get; init; }
|
||||
public string role { get; init; }
|
||||
public required string steam_id { get; init; }
|
||||
public required string role { get; init; }
|
||||
public int? inno_kills { get; init; }
|
||||
public int? traitor_kills { get; init; }
|
||||
public int? detective_kills { get; init; }
|
||||
@@ -170,7 +170,7 @@ public class RoundListener(IServiceProvider provider)
|
||||
var playerRoles = roles.GetRoles(player);
|
||||
if (playerRoles.Count == 0) continue;
|
||||
|
||||
var role = StatsApi.ApiName(playerRoles.First());
|
||||
var role = StatsApi.ApiNameForRole(playerRoles.First());
|
||||
kills.TryGetValue(player.Id, out var killCounts);
|
||||
bodiesFound.TryGetValue(player.Id, out var foundCount);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user