mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-06 06:22:44 -08:00
Compare commits
30 Commits
0.20.0-dev
...
0.20.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f63acf24c4 | ||
|
|
18144f5827 | ||
|
|
e590ae2b7a | ||
|
|
6bc0f57bed | ||
|
|
83a1d0e3e3 | ||
|
|
4d0fdfa25e | ||
|
|
9f673f9d8b | ||
|
|
3ad4339073 | ||
|
|
c6fea1a21e | ||
|
|
db9ad9303f | ||
|
|
4ab16d71db | ||
|
|
627c048183 | ||
|
|
66d1106d4c | ||
|
|
f2352ede1f | ||
|
|
f675a87ffd | ||
|
|
d1972fc556 | ||
|
|
f2dbc72aee | ||
|
|
77a2289367 | ||
|
|
456ae22b12 | ||
|
|
2616b231dc | ||
|
|
3cb86aa2f8 | ||
|
|
4c72f3dfff | ||
|
|
bc45f3fb74 | ||
|
|
2bcf436677 | ||
|
|
9dfb45583b | ||
|
|
3fa1558011 | ||
|
|
6c7bc22395 | ||
|
|
c95fba0fc5 | ||
|
|
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
|
||||
|
||||
@@ -17,6 +17,7 @@ public abstract class AbstractSpecialRound(IServiceProvider provider)
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public abstract string Name { get; }
|
||||
public abstract IMsg Description { get; }
|
||||
public abstract SpecialRoundConfig Config { get; }
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<TeamChangeHandler>();
|
||||
collection.AddModBehavior<TraitorChatHandler>();
|
||||
collection.AddModBehavior<PlayerMuter>();
|
||||
collection.AddModBehavior<MapChangeCausesEndListener>();
|
||||
|
||||
// Damage Cancelers
|
||||
collection.AddModBehavior<OutOfRoundCanceler>();
|
||||
|
||||
@@ -13,6 +13,8 @@ public class SpecialRoundCommand(IServiceProvider provider) : ICommand {
|
||||
public void Dispose() { }
|
||||
public void Start() { }
|
||||
|
||||
public string Id => "specialround";
|
||||
|
||||
public Task<CommandResult>
|
||||
Execute(IOnlinePlayer? executor, ICommandInfo info) {
|
||||
if (info.ArgCount == 1) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
26
TTT/CS2/GameHandlers/MapChangeCausesEndListener.cs
Normal file
26
TTT/CS2/GameHandlers/MapChangeCausesEndListener.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using JetBrains.Annotations;
|
||||
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"));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 _) {
|
||||
|
||||
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>
|
||||
|
||||
@@ -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}."
|
||||
@@ -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;
|
||||
|
||||
@@ -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 override int Price { get; init; } = 80;
|
||||
public int WeaponIndex { get; } = 9;
|
||||
public string WeaponId { get; } = "weapon_awp";
|
||||
public int? ReserveAmmo { get; } = 0;
|
||||
public int? CurrentAmmo { get; } = 2;
|
||||
public int? CurrentAmmo { get; } = 1;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ 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;
|
||||
|
||||
@@ -21,14 +22,18 @@ public class BhopRound(IServiceProvider provider)
|
||||
.GetResult() ?? new BhopRoundConfig();
|
||||
|
||||
public override void ApplyRoundEffects() {
|
||||
Server.ExecuteCommand("sv_enablebunnyhopping 1");
|
||||
Server.ExecuteCommand("sv_autobunnyhopping 1");
|
||||
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.ExecuteCommand("sv_enablebunnyhopping 0");
|
||||
Server.ExecuteCommand("sv_autobunnyhopping 0");
|
||||
Server.NextWorldUpdate(() => {
|
||||
Server.ExecuteCommand("sv_enablebunnyhopping 0");
|
||||
Server.ExecuteCommand("sv_autobunnyhopping 0");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public class SpeedRound(IServiceProvider provider)
|
||||
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;
|
||||
@@ -43,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) {
|
||||
@@ -66,7 +68,11 @@ public class SpeedRound(IServiceProvider provider)
|
||||
EndReason.TIMEOUT(new InnocentRole(Provider)))));
|
||||
}
|
||||
|
||||
public override void OnGameState(GameStateUpdateEvent ev) { }
|
||||
public override void OnGameState(GameStateUpdateEvent ev) {
|
||||
if (ev.NewState != State.FINISHED) return;
|
||||
|
||||
endTimer?.Dispose();
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
|
||||
36
TTT/SpecialRound/Rounds/VanillaRound.cs
Normal file
36
TTT/SpecialRound/Rounds/VanillaRound.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ShopAPI.Events;
|
||||
using SpecialRound.lang;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Events;
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SpecialRound.Rounds;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.API.Extensions;
|
||||
|
||||
@@ -8,5 +9,9 @@ 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>();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
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;
|
||||
@@ -45,19 +47,23 @@ public class SpecialRoundStarter(IServiceProvider provider)
|
||||
if (Random.Shared.NextSingle() > config.SpecialRoundChance) return;
|
||||
|
||||
var specialRound = getSpecialRound();
|
||||
if (specialRound is null) return;
|
||||
|
||||
TryStartSpecialRound(specialRound);
|
||||
}
|
||||
|
||||
private AbstractSpecialRound? getSpecialRound() {
|
||||
return Provider.GetServices<AbstractSpecialRound>()
|
||||
private AbstractSpecialRound getSpecialRound() {
|
||||
return Provider.GetServices<ITerrorModule>()
|
||||
.OfType<AbstractSpecialRound>()
|
||||
.OrderBy(_ => Random.Shared.Next())
|
||||
.FirstOrDefault();
|
||||
.First();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
using TTT.Locale;
|
||||
using SpecialRoundAPI;
|
||||
using TTT.Locale;
|
||||
|
||||
namespace SpecialRound.lang;
|
||||
|
||||
public class RoundMsgs {
|
||||
public static IMsg SPECIAL_ROUND_STARTED(string name) {
|
||||
return MsgFactory.Create(nameof(SPECIAL_ROUND_STARTED), name);
|
||||
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)); }
|
||||
@@ -1,3 +1,4 @@
|
||||
SPECIAL_ROUND_STARTED: "%PREFIX%This round is a {purple}Special Round{grey}! This round is a: {yellow}{0}{grey} round!"
|
||||
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_BHOP: " {Yellow}BHOP{grey}: Bunny hopping is enabled! Hold jump to move faster!"
|
||||
SPECIAL_ROUND_VANILLA: " {green}VANILLA{grey}: The shop has been disabled!"
|
||||
@@ -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"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
API_ROUND_START: "%PREFIX% Round {yellow}#{0} {grey}has started!"
|
||||
API_ROUND_END: "%PREFIX% Round end! Logs are available at {blue}http://localhost/rounds/{0}{grey}."
|
||||
API_ROUND_END: "%PREFIX% Round end! Logs are available at {blue}http://ttt.localhost/round/{0}{grey}."
|
||||
Reference in New Issue
Block a user