refactor: Cleanup and reformat

This commit is contained in:
MSWS
2025-11-10 03:53:14 -08:00
parent 125daa515e
commit 24cd1295b6
32 changed files with 89 additions and 101 deletions

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.346" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.346"/>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="8.0.3"/>
<PackageReference Include="System.Text.Json" Version="8.0.5"/>
<PackageReference Include="YamlDotNet" Version="16.3.0"/>

View File

@@ -1,5 +1,3 @@
using TTT.CS2.Items.Tripwire;
namespace TTT.CS2.API.Items;
public interface ITripwireTracker {

View File

@@ -13,7 +13,7 @@
<ProjectReference Include="..\Game\Game.csproj"/>
<ProjectReference Include="..\Karma\Karma.csproj"/>
<ProjectReference Include="..\ShopAPI\ShopAPI.csproj"/>
<ProjectReference Include="..\SpecialRoundAPI\SpecialRoundAPI.csproj" />
<ProjectReference Include="..\SpecialRoundAPI\SpecialRoundAPI.csproj"/>
</ItemGroup>
<ItemGroup>

View File

@@ -1,9 +1,7 @@
using CounterStrikeSharp.API;
using Microsoft.Extensions.DependencyInjection;
using ShopAPI;
using ShopAPI.Events;
using TTT.API.Command;
using TTT.API.Events;
using TTT.API.Player;
namespace TTT.CS2.Command.Test;

View File

@@ -44,9 +44,8 @@ public class SetRoleCommand(IServiceProvider provider) : ICommand {
break;
}
if (info.ArgCount == 3) {
if (info.ArgCount == 3)
targets = finder.GetMulti(info.Args[2], out targetName, executor);
}
Server.NextWorldUpdate(() => {
foreach (var player in targets) {

View File

@@ -24,7 +24,7 @@ public class SpecialRoundCommand(IServiceProvider provider) : ICommand {
}
if (info.ArgCount == 1) {
tracker.TryStartSpecialRound(null);
tracker.TryStartSpecialRound();
info.ReplySync("Started a random special round.");
return Task.FromResult(CommandResult.SUCCESS);
}

View File

@@ -48,17 +48,17 @@ public class CS2GameConfig : IStorage<TTTConfig>, IPluginModule {
public static readonly FakeConVar<int> CV_TRAITOR_ARMOR = new(
"css_ttt_rolearmor_traitor",
"Amount of armor to give to traitors at start of round", 100,
"Amount of armor to give to traitors at start of round", 0,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 1000));
public static readonly FakeConVar<int> CV_DETECTIVE_ARMOR = new(
"css_ttt_rolearmor_detective",
"Amount of armor to give to detectives at start of round", 100,
"Amount of armor to give to detectives at start of round", 0,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 1000));
public static readonly FakeConVar<int> CV_INNOCENT_ARMOR = new(
"css_ttt_rolearmor_innocent",
"Amount of armor to give to innocents at start of round", 100,
"Amount of armor to give to innocents at start of round", 0,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 1000));
public static readonly FakeConVar<string> CV_TRAITOR_WEAPONS = new(

View File

@@ -64,8 +64,8 @@ public class CS2KarmaConfig : IStorage<KarmaConfig>, IPluginModule {
public static readonly FakeConVar<int> CV_TRAITOR_ON_TRAITOR = new(
"css_ttt_karma_traitor_on_traitor",
"Karma lost when Traitor kills another Traitor", -12, ConVarFlags.FCVAR_NONE,
new RangeValidator<int>(-50, 50));
"Karma lost when Traitor kills another Traitor", -12,
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(-50, 50));
public static readonly FakeConVar<int> CV_INNO_ON_DETECTIVE = new(
"css_ttt_karma_inno_on_detective",

View File

@@ -97,7 +97,7 @@ public static class VectorExtensions {
public static Vector toVector(this Vector3 vec) {
return new Vector(vec.X, vec.Y, vec.Z);
}
public static QAngle toAngle(this Vector vec) {
var pitch = (float)(Math.Atan2(-vec.Z,
Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y)) * (180.0 / Math.PI));

View File

@@ -1,5 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core;
using Microsoft.Extensions.DependencyInjection;
using TTT.API;
using TTT.API.Game;

View File

@@ -16,7 +16,6 @@ using TTT.API.Game;
using TTT.API.Player;
using TTT.API.Storage;
using TTT.CS2.Extensions;
using TTT.CS2.Items.SilentAWP;
using TTT.CS2.RayTrace.Class;
using TTT.Game.Events.Body;
using TTT.Game.Events.Game;

View File

@@ -42,8 +42,8 @@ public class HealthStation(IServiceProvider provider)
}
/// <summary>
/// Scan all props and build a map: Player -> list of (StationInfo, potentialHeal).
/// Also fills toRemove for invalid/expired props.
/// Scan all props and build a map: Player -> list of (StationInfo, potentialHeal).
/// Also fills toRemove for invalid/expired props.
/// </summary>
private
Dictionary<CCSPlayerController, List<(StationInfo info, int potential)>>
@@ -90,8 +90,8 @@ public class HealthStation(IServiceProvider provider)
}
/// <summary>
/// Compute potential heal from a station given the distance.
/// Mirrors your original logic: ceil(HealthIncrements * healthScale).
/// Compute potential heal from a station given the distance.
/// Mirrors your original logic: ceil(HealthIncrements * healthScale).
/// </summary>
private int ComputePotentialHeal(double dist) {
var healthScale = 1.0 - dist / _Config.MaxRange;
@@ -99,9 +99,9 @@ public class HealthStation(IServiceProvider provider)
}
/// <summary>
/// Apply heals to each player once per tick.
/// Distributes the actual heal proportionally across contributing stations,
/// updates station.Info.HealthGiven and emits a single pickup sound if needed.
/// Apply heals to each player once per tick.
/// Distributes the actual heal proportionally across contributing stations,
/// updates station.Info.HealthGiven and emits a single pickup sound if needed.
/// </summary>
private void applyAccumulatedHeals(
Dictionary<CCSPlayerController, List<(StationInfo info, int potential)>>
@@ -125,7 +125,7 @@ public class HealthStation(IServiceProvider provider)
allocateProportionalInteger(totalHealAvailable, potentials);
// safety clamp: never allocate more than a station's potential
for (int i = 0; i < allocations.Count; i++)
for (var i = 0; i < allocations.Count; i++)
if (allocations[i] > potentials[i])
allocations[i] = potentials[i];
@@ -164,9 +164,9 @@ public class HealthStation(IServiceProvider provider)
}
/// <summary>
/// Proportionally distribute an integer total across integer potentials.
/// Uses floor of shares and assigns leftover to largest fractional remainders.
/// Returns a list of allocations with same length as potentials.
/// Proportionally distribute an integer total across integer potentials.
/// Uses floor of shares and assigns leftover to largest fractional remainders.
/// Returns a list of allocations with same length as potentials.
/// </summary>
private List<int>
allocateProportionalInteger(int total, List<int> potentials) {

View File

@@ -12,21 +12,21 @@ using TTT.CS2.Extensions;
namespace TTT.CS2.Items.Tripwire;
public class TripwireDamageListener(IServiceProvider provider) : IPluginModule {
public void Dispose() { }
public void Start() { }
private readonly ITripwireActivator? tripwireActivator =
provider.GetRequiredService<ITripwireActivator>();
private readonly ITripwireTracker? tripwires =
provider.GetService<ITripwireTracker>();
private readonly ITripwireActivator? tripwireActivator =
provider.GetRequiredService<ITripwireActivator>();
private TripwireConfig config
=> provider.GetService<IStorage<TripwireConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TripwireConfig();
public void Dispose() { }
public void Start() { }
[UsedImplicitly]
[GameEventHandler]
public HookResult OnBulletImpact(EventBulletImpact ev, GameEventInfo info) {

View File

@@ -17,17 +17,17 @@ namespace TTT.CS2.Items.Tripwire;
public class TripwireDefuserListener(IServiceProvider provider)
: IPluginModule {
private readonly ITripwireTracker? tripwireTracker =
provider.GetService<ITripwireTracker>();
private readonly IPlayerConverter<CCSPlayerController> converter =
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
private readonly IMsgLocalizer locale =
provider.GetRequiredService<IMsgLocalizer>();
private readonly IMessenger messenger =
provider.GetRequiredService<IMessenger>();
private readonly IMsgLocalizer locale =
provider.GetRequiredService<IMsgLocalizer>();
private readonly ITripwireTracker? tripwireTracker =
provider.GetService<ITripwireTracker>();
private TripwireConfig config
=> provider.GetService<IStorage<TripwireConfig>>()

View File

@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Reactive.Concurrency;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
@@ -36,25 +35,17 @@ public static class TripwireServiceCollection {
public class TripwireItem(IServiceProvider provider)
: RoleRestrictedItem<TraitorRole>(provider), IPluginModule, ITripwireTracker {
private TripwireConfig config
=> Provider.GetService<IStorage<TripwireConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TripwireConfig();
private readonly IPlayerConverter<CCSPlayerController> converter =
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
private readonly IScheduler scheduler =
provider.GetRequiredService<IScheduler>();
public List<TripwireInstance> ActiveTripwires { get; } = [];
public void RemoveTripwire(TripwireInstance instance) {
instance.Beam.Remove();
instance.TripwireProp.Remove();
ActiveTripwires.Remove(instance);
}
private TripwireConfig config
=> Provider.GetService<IStorage<TripwireConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TripwireConfig();
public override string Name => Locale[TripwireMsgs.SHOP_ITEM_TRIPWIRE];
@@ -71,6 +62,14 @@ public class TripwireItem(IServiceProvider provider)
onPrecache);
}
public List<TripwireInstance> ActiveTripwires { get; } = [];
public void RemoveTripwire(TripwireInstance instance) {
instance.Beam.Remove();
instance.TripwireProp.Remove();
ActiveTripwires.Remove(instance);
}
private void onPrecache(ResourceManifest manifest) {
manifest.AddResource(
"models/generic/conveyor_control_panel_01/conveyor_button_02.vmdl");

View File

@@ -27,12 +27,12 @@ public class TripwireMovementListener(IServiceProvider provider)
private readonly IPlayerConverter<CCSPlayerController> converter =
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
private readonly ITripwireTracker? tripwireTracker =
provider.GetService<ITripwireTracker>();
private readonly Dictionary<string, TripwireInstance> killedWithTripwire =
new();
private readonly ITripwireTracker? tripwireTracker =
provider.GetService<ITripwireTracker>();
private TripwireConfig config
=> Provider.GetService<IStorage<TripwireConfig>>()
?.Load()
@@ -44,6 +44,16 @@ public class TripwireMovementListener(IServiceProvider provider)
plugin?.AddTimer(0.2f, checkTripwires, TimerFlags.REPEAT);
}
public void ActivateTripwire(TripwireInstance instance) {
tripwireTracker?.RemoveTripwire(instance);
instance.TripwireProp.EmitSound("Flashbang.ExplodeDistant");
foreach (var player in Finder.GetOnline()) {
if (!dealTripwireDamage(instance, player, out var gamePlayer)) continue;
gamePlayer.EmitSound("Player.BurnDamage");
}
}
private void checkTripwires() {
if (tripwireTracker == null) return;
foreach (var wire in new List<TripwireInstance>(tripwireTracker
@@ -96,16 +106,6 @@ public class TripwireMovementListener(IServiceProvider provider)
ev.Body.Killer = info.owner;
}
public void ActivateTripwire(TripwireInstance instance) {
tripwireTracker?.RemoveTripwire(instance);
instance.TripwireProp.EmitSound("Flashbang.ExplodeDistant");
foreach (var player in Finder.GetOnline()) {
if (!dealTripwireDamage(instance, player, out var gamePlayer)) continue;
gamePlayer.EmitSound("Player.BurnDamage");
}
}
private bool dealTripwireDamage(TripwireInstance instance,
IOnlinePlayer player,
[NotNullWhen(true)] out CCSPlayerController? gamePlayer) {

View File

@@ -12,12 +12,12 @@ public class TripwireMsgs {
public static IMsg SHOP_ITEM_TRIPWIRE_TOOFAR
=> MsgFactory.Create(nameof(SHOP_ITEM_TRIPWIRE_TOOFAR));
public static IMsg SHOP_ITEM_TRIPWIRE_DEFUSING_CANCELED
=> MsgFactory.Create(nameof(SHOP_ITEM_TRIPWIRE_DEFUSING_CANCELED));
public static IMsg
SHOP_ITEM_TRIPWIRE_DEFUSING(double progress, TimeSpan time) {
return MsgFactory.Create(nameof(SHOP_ITEM_TRIPWIRE_DEFUSING),
progress.ToString("P0"), time.TotalSeconds.ToString("F1"));
}
public static IMsg SHOP_ITEM_TRIPWIRE_DEFUSING_CANCELED
=> MsgFactory.Create(nameof(SHOP_ITEM_TRIPWIRE_DEFUSING_CANCELED));
}

View File

@@ -2,6 +2,7 @@ using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using TTT.API.Player;
using TTT.CS2.Extensions;
namespace TTT.CS2.Player;
@@ -87,18 +88,17 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
}
public int Armor {
get => Player?.PawnArmor ?? 0;
get => Player != null && Player.IsValid ? Player.GetArmor().Item1 : 0;
set {
if (Player == null) return;
Player.PawnArmor = value;
Utilities.SetStateChanged(Player, "CCSPlayerController", "m_iPawnArmor");
if (Player == null || !Player.IsValid) return;
Player.SetArmor(value);
}
}
public bool IsAlive {
get
=> Player != null && Player is {
=> Player != null && Player.IsValid && Player is {
Team : CsTeam.CounterTerrorist or CsTeam.Terrorist,
Pawn.Value.Health: > 0
};

View File

@@ -1,6 +1,5 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Commands.Targeting;
using TTT.API.Player;
namespace TTT.CS2.Player;

View File

@@ -21,9 +21,9 @@ public record TTTConfig {
public int TraitorHealth { get; init; } = 100;
public int DetectiveHealth { get; init; } = 100;
public int InnocentHealth { get; init; } = 100;
public int TraitorArmor { get; init; } = 100;
public int DetectiveArmor { get; init; } = 100;
public int InnocentArmor { get; init; } = 100;
public int TraitorArmor { get; init; }
public int DetectiveArmor { get; init; }
public int InnocentArmor { get; init; }
public string[]? TraitorWeapons { get; init; } = ["knife", "pistol"];

View File

@@ -47,11 +47,10 @@ public class C4ShopItem(IServiceProvider provider)
if (c4sBought > config.MaxC4PerRound)
return PurchaseResult.ITEM_NOT_PURCHASABLE;
if (config.MaxC4AtOnce > 0) {
if (config.MaxC4AtOnce > 0)
if (finder.GetOnline().Count(p => Shop.HasItem<C4ShopItem>(p))
> config.MaxC4AtOnce)
return PurchaseResult.ITEM_NOT_PURCHASABLE;
}
return base.CanPurchase(player);
}

View File

@@ -24,6 +24,9 @@ public class PeriodicRewarder(IServiceProvider provider) : ITerrorModule {
private readonly IGameManager games =
provider.GetRequiredService<IGameManager>();
private readonly IMsgLocalizer localizer =
provider.GetRequiredService<IMsgLocalizer>();
private readonly Dictionary<string, List<Vector>> playerPositions = new();
private readonly IScheduler scheduler =
@@ -31,9 +34,6 @@ public class PeriodicRewarder(IServiceProvider provider) : ITerrorModule {
private readonly IShop shop = provider.GetRequiredService<IShop>();
private readonly IMsgLocalizer localizer =
provider.GetRequiredService<IMsgLocalizer>();
private IDisposable? rewardTimer, updateTimer;
private ShopConfig config

View File

@@ -11,8 +11,9 @@ public static class ShopMsgs {
public static IMsg SHOP_INACTIVE => MsgFactory.Create(nameof(SHOP_INACTIVE));
public static IMsg CREDITS_NAME => MsgFactory.Create(nameof(CREDITS_NAME));
public static IMsg SHOP_EXPLORATION => MsgFactory.Create(nameof(SHOP_EXPLORATION));
public static IMsg SHOP_EXPLORATION
=> MsgFactory.Create(nameof(SHOP_EXPLORATION));
public static IMsg SHOP_CANNOT_PURCHASE
=> MsgFactory.Create(nameof(SHOP_CANNOT_PURCHASE));

View File

@@ -19,6 +19,6 @@ public record TripwireConfig : ShopItemConfig {
public TimeSpan DefuseTime { get; init; } = TimeSpan.FromSeconds(5);
public TimeSpan DefuseRate { get; init; } = TimeSpan.FromMilliseconds(500);
public int DefuseReward { get; init; } = 20;
}

View File

@@ -40,7 +40,7 @@ public enum PurchaseResult {
/// <summary>
/// The item cannot be purchased multiple times, and the player already owns it.
/// </summary>
ALREADY_OWNED,
ALREADY_OWNED
}
public static class PurchaseResultExtensions {

View File

@@ -3,8 +3,8 @@
namespace SpecialRound.Events;
/// <summary>
/// Called when a special round is enabled.
/// Note that multiple special rounds may be enabled per round.
/// Called when a special round is enabled.
/// Note that multiple special rounds may be enabled per round.
/// </summary>
/// <param name="round"></param>
public class SpecialRoundEnableEvent(AbstractSpecialRound round)

View File

@@ -13,6 +13,7 @@ namespace SpecialRound.Rounds;
public class LowGravRound(IServiceProvider provider)
: AbstractSpecialRound(provider) {
private int originalGravity = 800;
public override string Name => "Low Grav";
public override IMsg Description => RoundMsgs.SPECIAL_ROUND_LOWGRAV;
public override SpecialRoundConfig Config => config;
@@ -23,8 +24,6 @@ public class LowGravRound(IServiceProvider provider)
.GetAwaiter()
.GetResult() ?? new LowGravRoundConfig();
private int originalGravity = 800;
public override void ApplyRoundEffects() {
var cvar = ConVar.Find("sv_gravity");
if (cvar == null) return;

View File

@@ -1,7 +1,5 @@
using CounterStrikeSharp.API.Modules.Utils;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using ShopAPI;
using ShopAPI.Events;
using SpecialRound.lang;
using SpecialRoundAPI;

View File

@@ -10,7 +10,7 @@
<ProjectReference Include="..\API\API.csproj"/>
<ProjectReference Include="..\CS2\CS2.csproj"/>
<ProjectReference Include="..\Game\Game.csproj"/>
<ProjectReference Include="..\SpecialRoundAPI\SpecialRoundAPI.csproj" />
<ProjectReference Include="..\SpecialRoundAPI\SpecialRoundAPI.csproj"/>
</ItemGroup>
</Project>

View File

@@ -7,9 +7,9 @@ public record SpecialRoundsConfig {
public float SpecialRoundChance { get; init; } = 0.2f;
/// <summary>
/// If a special round is started, the chance that another special round
/// will start in conjunction with it. This check is run until it fails,
/// or we run out of special rounds to start.
/// If a special round is started, the chance that another special round
/// will start in conjunction with it. This check is run until it fails,
/// or we run out of special rounds to start.
/// </summary>
public float MultiRoundChance { get; init; } = 0.33f;
}

View File

@@ -13,12 +13,12 @@ namespace Stats;
public class SpecialRoundListener(IServiceProvider provider)
: BaseListener(provider) {
private readonly IRoundTracker tracker =
provider.GetRequiredService<IRoundTracker>();
private readonly HttpClient client =
provider.GetRequiredService<HttpClient>();
private readonly IRoundTracker tracker =
provider.GetRequiredService<IRoundTracker>();
private AbstractSpecialRound? round;
[UsedImplicitly]

View File

@@ -9,7 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Game\Game.csproj"/>
<ProjectReference Include="..\ShopAPI\ShopAPI.csproj"/>
<ProjectReference Include="..\SpecialRound\SpecialRound.csproj" />
<ProjectReference Include="..\SpecialRound\SpecialRound.csproj"/>
</ItemGroup>
</Project>