mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-06 22:36:35 -08:00
Compare commits
58 Commits
0.20.0-dev
...
0.21.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
9dfb45583b | ||
|
|
f6d1b95a38 | ||
|
|
5393920f95 |
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
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
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; } = "";
|
||||
}
|
||||
@@ -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,8 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<TeamChangeHandler>();
|
||||
collection.AddModBehavior<TraitorChatHandler>();
|
||||
collection.AddModBehavior<PlayerMuter>();
|
||||
collection.AddModBehavior<MapChangeCausesEndListener>();
|
||||
// collection.AddModBehavior<EntityTargetHandlers>();
|
||||
|
||||
// Damage Cancelers
|
||||
collection.AddModBehavior<OutOfRoundCanceler>();
|
||||
@@ -82,6 +98,7 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<ScreenColorApplier>();
|
||||
collection.AddModBehavior<KarmaBanner>();
|
||||
collection.AddModBehavior<KarmaSyncer>();
|
||||
collection.AddModBehavior<MapHookListener>();
|
||||
|
||||
// Commands
|
||||
collection.AddModBehavior<TestCommand>();
|
||||
|
||||
38
TTT/CS2/Command/Test/SetTargetCommand.cs
Normal file
38
TTT/CS2/Command/Test/SetTargetCommand.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
|
||||
var name = "TRAITOR";
|
||||
|
||||
if (info.ArgCount == 2) name = info.Args[1];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class TestCommand(IServiceProvider provider) : ICommand, IPluginModule {
|
||||
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)", 90, 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", 125,
|
||||
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)", 25,
|
||||
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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
64
TTT/CS2/GameHandlers/EntityTargetHandlers.cs
Normal file
64
TTT/CS2/GameHandlers/EntityTargetHandlers.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Messages;
|
||||
|
||||
namespace TTT.CS2.GameHandlers;
|
||||
|
||||
public class EntityTargetHandlers(IServiceProvider provider) : IPluginModule {
|
||||
private readonly IMessenger messenger =
|
||||
provider.GetRequiredService<IMessenger>();
|
||||
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public void Start(BasePlugin? plugin) {
|
||||
plugin?.HookEntityOutput("*", "*", handler);
|
||||
}
|
||||
|
||||
private HookResult handler(CEntityIOOutput output, string name,
|
||||
CEntityInstance activator, CEntityInstance caller, CVariant value,
|
||||
float delay) {
|
||||
if (caller.DesignerName == "prop_dynamic") return HookResult.Continue;
|
||||
messenger.Debug("Entity Output Triggered: " + name);
|
||||
messenger.Debug("Activator: " + activator.DesignerName);
|
||||
messenger.Debug("Caller: " + caller.DesignerName);
|
||||
messenger.Debug("Value: " + value + " " + value.GetType());
|
||||
caller.AcceptInput("OnPass");
|
||||
activator.AcceptInput("OnPass");
|
||||
if (caller.DesignerName != "filter_activator_name")
|
||||
return HookResult.Continue;
|
||||
var csPlayer =
|
||||
Utilities.GetPlayerFromIndex((int)activator.EntityHandle.Index);
|
||||
if (csPlayer != null && csPlayer.IsValid) {
|
||||
messenger.DebugAnnounce(
|
||||
$"Filter Activator Name triggered by player: {csPlayer.PlayerName} {(int)csPlayer.Index}");
|
||||
}
|
||||
|
||||
var ptrPlayer = new CCSPlayerController(activator.Handle);
|
||||
if (ptrPlayer.IsValid) {
|
||||
messenger.DebugAnnounce(
|
||||
$"Filter Activator Name triggered by player controller: {ptrPlayer.PlayerName} {(int)ptrPlayer.Index}");
|
||||
}
|
||||
|
||||
messenger.DebugAnnounce(output + " - " + output.Description);
|
||||
|
||||
var connections = output.Connections;
|
||||
if (connections != null) debugConnection(connections);
|
||||
|
||||
caller.AcceptInput("OnPass");
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void debugConnection(EntityIOConnection_t connection) {
|
||||
messenger.DebugAnnounce("Connection:");
|
||||
messenger.DebugAnnounce(" Target: " + connection.Target);
|
||||
messenger.DebugAnnounce(" Input: " + connection.TargetInput);
|
||||
messenger.DebugAnnounce(" Parameter: " + connection.ValueOverride);
|
||||
messenger.DebugAnnounce(" Delay: " + connection.Delay);
|
||||
messenger.DebugAnnounce(" Times to fire: " + connection.TimesToFire);
|
||||
|
||||
if (connection.Next != null) debugConnection(connection.Next);
|
||||
}
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 _) {
|
||||
|
||||
@@ -47,10 +47,6 @@ 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;
|
||||
@@ -119,6 +115,11 @@ 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() {
|
||||
var onlineLengths = Utilities.GetPlayers()
|
||||
.Select(p => p.PlayerName.Length)
|
||||
.ToList();
|
||||
if (onlineLengths.Count == 0) return CreatePaddedName(Id, Name, 13);
|
||||
var namePadding = Math.Min(onlineLengths.Max(), 24);
|
||||
return CreatePaddedName(Id, Name, namePadding + 8);
|
||||
}
|
||||
|
||||
|
||||
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,11 @@ public class DamagedAction(IRoleAssigner roles, IPlayer victim,
|
||||
public string Verb => "damaged";
|
||||
public string Details => $"for {Damage} damage with {Weapon}";
|
||||
|
||||
public string Prefix
|
||||
=> PlayerRole is TraitorRole != OtherRole is TraitorRole ?
|
||||
"" :
|
||||
"[BAD ACTION]";
|
||||
|
||||
#region ConstructorAliases
|
||||
|
||||
public DamagedAction(IServiceProvider provider, IPlayer victim,
|
||||
|
||||
@@ -10,7 +10,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;
|
||||
|
||||
@@ -35,14 +35,18 @@ public sealed class KarmaStorage(IServiceProvider provider) : IKarmaService {
|
||||
return karmaElement.GetInt32();
|
||||
}
|
||||
|
||||
public Task Write(IPlayer key, int newData) {
|
||||
var data = new { steam_id = key.Id, karma = newData };
|
||||
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;
|
||||
|
||||
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");
|
||||
|
||||
return client.PatchAsync("user/" + key.Id, payload);
|
||||
await client.PatchAsync("user/" + key.Id, payload);
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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")} {typeof(TItem).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();
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -44,7 +44,8 @@ public class SpeedRound(IServiceProvider provider)
|
||||
public override void ApplyRoundEffects() {
|
||||
Provider.GetService<RoundTimerListener>()?.EndTimer?.Dispose();
|
||||
|
||||
setTime(config.InitialSeconds);
|
||||
Server.RunOnTick(Server.TickCount + 2,
|
||||
() => setTime(config.InitialSeconds));
|
||||
}
|
||||
|
||||
private void addTime(TimeSpan span) {
|
||||
|
||||
@@ -52,10 +52,19 @@ public class SpecialRoundStarter(IServiceProvider provider)
|
||||
}
|
||||
|
||||
private AbstractSpecialRound getSpecialRound() {
|
||||
return Provider.GetServices<ITerrorModule>()
|
||||
var rounds = Provider.GetServices<ITerrorModule>()
|
||||
.OfType<AbstractSpecialRound>()
|
||||
.OrderBy(_ => Random.Shared.Next())
|
||||
.First();
|
||||
.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?
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
using SpecialRoundAPI;
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -133,11 +133,7 @@ public class RoundListener(IServiceProvider provider)
|
||||
}
|
||||
|
||||
private async Task onRoundEnd(IGame game) {
|
||||
Console.WriteLine("RoundListener: onRoundEnd fired");
|
||||
if (CurrentRoundId == null) {
|
||||
Console.WriteLine("RoundListener: currentRoundId is null, skipping");
|
||||
return;
|
||||
}
|
||||
if (CurrentRoundId == null) return;
|
||||
|
||||
var ended_at = DateTime.UtcNow;
|
||||
var winning_role = game.WinningRole != null ?
|
||||
|
||||
@@ -9,10 +9,10 @@ public class StatsApi {
|
||||
|
||||
public static string ApiNameForRole(IRole role) {
|
||||
return role switch {
|
||||
_ when role is TraitorRole => "traitor",
|
||||
_ when role is DetectiveRole => "detective",
|
||||
_ when role is InnocentRole => "innocent",
|
||||
_ => "unknown"
|
||||
TraitorRole => "traitor",
|
||||
DetectiveRole => "detective",
|
||||
InnocentRole => "innocent",
|
||||
_ => "unknown"
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user