Compare commits

...

16 Commits

Author SHA1 Message Date
MSWS
64889de2fa Clarify module classname 2025-10-20 19:32:31 -07:00
MSWS
7a6676e6ac Fix reload module 2025-10-20 19:30:00 -07:00
MSWS
49227e6d37 fix: Update RTD Credit reward to use locale 2025-10-20 19:27:37 -07:00
MSWS
0748114c9a Merge branch 'main' into dev 2025-10-20 18:57:55 -07:00
MSWS
346984f394 Update colors 2025-10-20 18:56:58 -07:00
MSWS
6316f39819 refactor: Refactor config initialization pattern
Refactor configuration initialization and improve code readability across multiple modules

- **GameHandlers/RoundStart_GameStartHandler.cs**: Change `config` initialization to a property to streamline retrieval and improve formatting for better readability.
- **Shop/Items/Traitor/C4/C4ShopItem.cs**: Refactor `config` to enable lazy loading through the Service Provider and remove the `readonly` keyword.
- **Karma/KarmaStorage.cs**: Simplify code by removing the lazy-loaded property `_configStorage` and directly using `_config`.
- **Game/RoundBasedGame.cs**: Implement lazy loading for configuration retrieval, update player initialization logic, and improve method structure for clarity.
- **Shop/Listeners/RoleAssignCreditor.cs**: Change `config` to a read-only property for lazy loading and enhance performance with delayed instantiation.
2025-10-20 18:52:44 -07:00
Isaac
bdef55428c Balance Changes, make Configs Hot Load 2025-10-19 22:15:54 -07:00
MSWS
9f45b919e1 Fix ragdolls misbehaving after multiple carriers 2025-10-19 21:29:36 -07:00
MSWS
7d75b867f9 Merge branch 'feat/rtd' 2025-10-19 19:06:54 -07:00
MSWS
35b15c4578 Inherit from IListener 2025-10-19 18:42:10 -07:00
Isaac
9b99adca3f feat: RTD System (#130) 2025-10-19 18:18:41 -07:00
MSWS
3802610b1c feat: Implement player muting system for gameplay control
```markdown
Implement player muting feature and enhance game mechanics

- Add `RTD_MUTED` message in `RtdMsgs.cs` utilizing the existing message creation method.
- Enhance `PlayerMuter.cs` by checking game state before muting players and implementing event handler to unmute players when the game finishes.
- Update `TraitorChatHandler.cs` to handle muted players in chat and prevent dead players from participating in traitor chat.
- Introduce `MuteReward` class in `MuteReward.cs` to mute players for the next round and manage muted player voice events.
- Modify `RewardGenerator.cs` to include `MuteReward` and adjust reward probabilities, enhancing the reward system.

These changes collectively introduce and integrate a system for managing player muting, ensuring robust gameplay dynamics and clarity for players during active game sessions.
```
2025-10-19 18:16:38 -07:00
MSWS
171250382e feat: Introduce RTD feature with reward system +semver:minor
Introduce RTD Project and Enhance Codebase with Localization and Config Improvements

- Introduce a new RTD project with multiple enhancements to reward and command systems:
  - Add new interfaces and classes for `IRtdReward`, `IRewardGenerator`, and several types of rewards like `ShopItemReward`, `CreditReward`, `HealthReward`, and `WeaponReward`.
  - Implement new command functionality through `RtdCommand` and `RtdStatsCommand`.
- Strengthen the code architecture by refactoring configuration access:
  - Convert `config` fields to properties using expression-bodied members across various items and listeners, promoting improved readability and potential lazy loading.
- Integrate localization features:
  - Add and standardize import statements for `TTT.Game.lang` to support upcoming language and localization developments across different game modules.
  - Create new language configuration files, like `en.yml`, and introduce classes such as `RtdMsgs` for localized message handling.
- Improve game mechanics:
  - Enhance poison effect handling within `PoisonShotsListener` with periodic damage application and improved player interaction updates.
  - Extend the `IIconManager` to offer additional player visibility options, enhancing game dynamics through methods like `RevealToAll`.
- Optimize plugin and module management:
  - Add logging features with `ShopPurchaseLogger` and new logging statements for plugin module registration.
  - Ensure cohesive project structure by updating project files and solution configuration for the new RTD module.
- Refactor utility and helper functions for better clarity:
  - Introduce utility classes like `WeaponTranslations` to map internal to user-friendly weapon names.
  - Clean up and streamline namespaces for clarity and consistency, especially within utilities like `GrenadeDataHelper`.

This commit collectively enhances the system's modularity, readability, and capability for future localization and extensibility.
2025-10-19 17:45:58 -07:00
Isaac
9c693059ea Revert "Refresh AliveSpoofer per map" (#129)
This reverts commit 9d3ecbe7fb.
2025-10-19 15:42:57 -07:00
Isaac
05aeb53a3c Refresh AliveSpoofer per map (#127) 2025-10-18 01:18:30 -07:00
Isaac
c545a10d6f Bug and crash fixes (#126) 2025-10-17 22:05:21 -07:00
76 changed files with 818 additions and 82 deletions

View File

@@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Karma", "TTT\Karma\Karma.cs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShopAPI", "TTT\ShopAPI\ShopAPI.csproj", "{16F720B5-9D45-47BF-8C80-4F91005E36D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RTD", "TTT\RTD\RTD.csproj", "{8A426E84-45DA-4558-A218-E042F1AC60B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -72,6 +74,10 @@ Global
{16F720B5-9D45-47BF-8C80-4F91005E36D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16F720B5-9D45-47BF-8C80-4F91005E36D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16F720B5-9D45-47BF-8C80-4F91005E36D1}.Release|Any CPU.Build.0 = Release|Any CPU
{8A426E84-45DA-4558-A218-E042F1AC60B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A426E84-45DA-4558-A218-E042F1AC60B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A426E84-45DA-4558-A218-E042F1AC60B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A426E84-45DA-4558-A218-E042F1AC60B2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection

View File

@@ -12,6 +12,7 @@ public interface IIconManager {
void AddVisiblePlayer(int client, int player);
void RemoveVisiblePlayer(int client, int player);
void SetVisiblePlayers(IOnlinePlayer online, ulong playersBitmask);
void RevealToAll(IOnlinePlayer online);
void ClearAllVisibility();
}

3
TTT/API/Player/IMuted.cs Normal file
View File

@@ -0,0 +1,3 @@
namespace TTT.API.Player;
public interface IMuted : ISet<string> { }

View File

@@ -8,6 +8,7 @@ using TTT.API.Messages;
using TTT.API.Player;
using TTT.Game;
using TTT.Game.Commands;
using TTT.Game.lang;
namespace TTT.CS2.Command;

View File

@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using Microsoft.Extensions.DependencyInjection;
using TTT.API;
using TTT.API.Command;
@@ -6,7 +7,7 @@ using TTT.API.Player;
namespace TTT.CS2.Command.Test;
public class ReloadModule(IServiceProvider provider) : ICommand, IPluginModule {
public class ReloadModuleCommand(IServiceProvider provider) : ICommand, IPluginModule {
public void Dispose() { }
public void Start() { }
private BasePlugin? plugin;
@@ -49,9 +50,11 @@ public class ReloadModule(IServiceProvider provider) : ICommand, IPluginModule {
if (module is not IPluginModule pluginModule)
return Task.FromResult(CommandResult.SUCCESS);
info.ReplySync("Hotloading plugin module '{moduleName}'...");
pluginModule.Start(plugin, true);
info.ReplySync("Plugin module '{moduleName}' hotloaded successfully.");
Server.NextWorldUpdate(() => {
info.ReplySync($"Hotloading plugin module '{moduleName}'...");
pluginModule.Start(plugin, true);
info.ReplySync($"Plugin module '{moduleName}' hotloaded successfully.");
});
return Task.FromResult(CommandResult.SUCCESS);
}

View File

@@ -27,7 +27,7 @@ public class TestCommand(IServiceProvider provider) : ICommand, IPluginModule {
subCommands.Add("emitsound", new EmitSoundCommand(provider));
subCommands.Add("credits", new CreditsCommand(provider));
subCommands.Add("spec", new SpecCommand(provider));
subCommands.Add("reload", new ReloadModule(provider));
subCommands.Add("reload", new ReloadModuleCommand(provider));
}
public Task<CommandResult>

View File

@@ -10,6 +10,7 @@ using TTT.CS2.Roles;
using TTT.CS2.Utils;
using TTT.Game;
using TTT.Game.Events.Game;
using TTT.Game.lang;
using TTT.Game.Roles;
namespace TTT.CS2.Game;

View File

@@ -4,9 +4,12 @@ using CounterStrikeSharp.API.Core.Attributes.Registration;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using TTT.API;
using TTT.API.Events;
using TTT.API.Game;
using TTT.API.Messages;
using TTT.API.Player;
using TTT.CS2.lang;
using TTT.Game.Events.Game;
using TTT.Locale;
namespace TTT.CS2.GameHandlers;
@@ -21,6 +24,9 @@ public class PlayerMuter(IServiceProvider provider) : IPluginModule {
private readonly IMessenger messenger =
provider.GetRequiredService<IMessenger>();
private readonly IGameManager game =
provider.GetRequiredService<IGameManager>();
public void Dispose() { }
public void Start() { }
@@ -36,6 +42,8 @@ public class PlayerMuter(IServiceProvider provider) : IPluginModule {
if (player.Pawn.Value is { Health: > 0 }) return;
if (game.ActiveGame is not { State: State.IN_PROGRESS }) return;
if ((player.VoiceFlags & VoiceFlags.Muted) != VoiceFlags.Muted) {
var apiPlayer = converter.GetPlayer(player);
messenger.Message(apiPlayer, locale[CS2Msgs.DEAD_MUTE_REMINDER]);
@@ -52,4 +60,14 @@ public class PlayerMuter(IServiceProvider provider) : IPluginModule {
player.VoiceFlags &= ~VoiceFlags.Muted;
return HookResult.Continue;
}
[UsedImplicitly]
[EventHandler]
public void OnGameEvent(GameStateUpdateEvent ev) {
if (ev.NewState != State.FINISHED) return;
foreach (var p in Utilities.GetPlayers()) {
p.VoiceFlags &= ~VoiceFlags.Muted;
}
}
}

View File

@@ -90,9 +90,13 @@ public class PropMover(IServiceProvider provider) : IPluginModule {
if (!released.HasFlag(PlayerButtons.Use)) return;
playersPressingE.Remove(player);
if (!heldItem.Ragdoll.IsValid) return;
heldItem.Ragdoll.AcceptInput("EnableMotion");
if (heldItem.Beam != null && heldItem.Beam.IsValid)
heldItem.Beam.AcceptInput("Kill");
// Check if any other players are still holding this ragdoll
foreach (var (_, info) in playersPressingE)
if (info.Ragdoll == heldItem.Ragdoll)
return;
heldItem.Ragdoll.AcceptInput("EnableMotion");
}
private void refreshHeld() {

View File

@@ -75,6 +75,12 @@ public class RoleIconsHandler(IServiceProvider provider)
SetVisiblePlayers(gamePlayer.Slot, playersBitmask);
}
public void RevealToAll(IOnlinePlayer online) {
var gamePlayer = players.GetPlayer(online);
if (gamePlayer == null || !gamePlayer.IsValid) return;
RevealToAll(gamePlayer.Slot);
}
public void ClearAllVisibility() {
Array.Clear(visibilities, 0, visibilities.Length);
}

View File

@@ -12,9 +12,11 @@ namespace TTT.CS2.GameHandlers;
public class RoundStart_GameStartHandler(IServiceProvider provider)
: IPluginModule {
private readonly TTTConfig config =
provider.GetService<IStorage<TTTConfig>>()?.Load().GetAwaiter().GetResult()
?? new TTTConfig();
private TTTConfig config
=> provider.GetService<IStorage<TTTConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private readonly IPlayerFinder finder =
provider.GetRequiredService<IPlayerFinder>();

View File

@@ -8,6 +8,7 @@ using TTT.API.Game;
using TTT.API.Messages;
using TTT.API.Player;
using TTT.API.Role;
using TTT.CS2.Extensions;
using TTT.CS2.lang;
using TTT.CS2.ThirdParties.eGO;
using TTT.Game.Roles;
@@ -31,6 +32,8 @@ public class TraitorChatHandler(IServiceProvider provider) : IPluginModule {
private readonly IRoleAssigner roles =
provider.GetRequiredService<IRoleAssigner>();
private readonly IMuted? mutedPlayers = provider.GetService<IMuted>();
private IActain? maulService;
public void Start(BasePlugin? plugin) {
@@ -42,8 +45,10 @@ public class TraitorChatHandler(IServiceProvider provider) : IPluginModule {
}
plugin?.AddCommandListener("say_team", onSay);
plugin?.AddCommandListener("say", onSay);
} catch (KeyNotFoundException) {
plugin?.AddCommandListener("say_team", onSay);
plugin?.AddCommandListener("say", onSay);
}
}
@@ -57,6 +62,12 @@ public class TraitorChatHandler(IServiceProvider provider) : IPluginModule {
private void OnChatShare(CCSPlayerController? player, CommandInfo info,
ref bool canceled) {
if (player == null) return;
if (mutedPlayers != null
&& mutedPlayers.Contains(player.SteamID.ToString())) {
canceled = true;
return;
}
if (!info.GetArg(0).Equals("say_team", StringComparison.OrdinalIgnoreCase))
return;
if (player.Team == CsTeam.CounterTerrorist) return;
@@ -68,10 +79,18 @@ public class TraitorChatHandler(IServiceProvider provider) : IPluginModule {
private HookResult onSay(CCSPlayerController? player,
CommandInfo commandInfo) {
if (mutedPlayers != null
&& mutedPlayers.Contains(player?.SteamID.ToString() ?? ""))
return HookResult.Handled;
if (commandInfo.GetArg(0).Equals("say", StringComparison.OrdinalIgnoreCase))
return HookResult.Continue;
if (player == null
|| game.ActiveGame is not { State: State.IN_PROGRESS or State.FINISHED }
|| converter.GetPlayer(player) is not IOnlinePlayer apiPlayer
|| !roles.GetRoles(apiPlayer).Any(r => r is TraitorRole))
|| !roles.GetRoles(apiPlayer).Any(r => r is TraitorRole)
|| player.GetHealth() <= 0)
return HookResult.Continue;
var teammates = game.ActiveGame?.Players.Where(p

View File

@@ -17,8 +17,8 @@ public class BodyPaintListener(IServiceProvider provider)
private readonly IBodyTracker bodies =
provider.GetRequiredService<IBodyTracker>();
private readonly BodyPaintConfig config =
provider.GetService<IStorage<BodyPaintConfig>>()
private BodyPaintConfig config
=> Provider.GetService<IStorage<BodyPaintConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new BodyPaintConfig();

View File

@@ -18,9 +18,11 @@ public static class CamoServiceCollection {
}
public class CamouflageItem(IServiceProvider provider) : BaseItem(provider) {
private readonly CamoConfig config =
provider.GetService<IStorage<CamoConfig>>()?.Load().GetAwaiter().GetResult()
?? new CamoConfig();
private CamoConfig config
=> Provider.GetService<IStorage<CamoConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new CamoConfig();
private readonly IPlayerConverter<CCSPlayerController> converter =
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();

View File

@@ -13,6 +13,7 @@ using TTT.API;
using TTT.API.Player;
using TTT.API.Role;
using TTT.API.Storage;
using TTT.CS2.Utils;
namespace TTT.CS2.Items.ClusterGrenade;

View File

@@ -28,12 +28,12 @@ namespace TTT.CS2.Items.Compass;
/// </summary>
public abstract class AbstractCompassItem<TRole> : RoleRestrictedItem<TRole>,
IListener, IPluginModule where TRole : class, IRole {
protected readonly CompassConfig config;
protected CompassConfig _Config { get; }
protected readonly IPlayerConverter<CCSPlayerController> Converter;
protected readonly ISet<IPlayer> Owners = new HashSet<IPlayer>();
protected AbstractCompassItem(IServiceProvider provider) : base(provider) {
config = provider.GetService<IStorage<CompassConfig>>()
_Config = provider.GetService<IStorage<CompassConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new CompassConfig();
@@ -42,7 +42,7 @@ public abstract class AbstractCompassItem<TRole> : RoleRestrictedItem<TRole>,
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
}
public override ShopItemConfig Config => config;
public override ShopItemConfig Config => _Config;
public void Start(BasePlugin? plugin) {
base.Start();
@@ -80,6 +80,7 @@ public abstract class AbstractCompassItem<TRole> : RoleRestrictedItem<TRole>,
foreach (var player in Owners.OfType<IOnlinePlayer>()) {
var gamePlayer = Converter.GetPlayer(player);
if (gamePlayer == null) continue;
if (!player.IsAlive) continue;
ShowCompass(gamePlayer, player);
}
}
@@ -95,7 +96,7 @@ public abstract class AbstractCompassItem<TRole> : RoleRestrictedItem<TRole>,
if (targets.Count == 0) return;
var (nearest, distance) = GetNearestVector(src, targets);
if (nearest == null || distance > config.MaxRange) return;
if (nearest == null || distance > _Config.MaxRange) return;
var normalizedYaw = AdjustGameAngle(viewer.PlayerPawn.Value.EyeAngles.Y);
@@ -120,8 +121,8 @@ public abstract class AbstractCompassItem<TRole> : RoleRestrictedItem<TRole>,
}
private string GenerateCompass(float pointing, float target) {
return TextCompass.GenerateCompass(config.CompassFOV, config.CompassLength,
pointing, targetDir: target);
return TextCompass.GenerateCompass(_Config.CompassFOV,
_Config.CompassLength, pointing, targetDir: target);
}
private static string GetDistanceDescription(float distance) {

View File

@@ -1,6 +1,7 @@
using TTT.API.Player;
using TTT.API.Role;
using TTT.Game;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.CS2.Items.DNA;

View File

@@ -24,8 +24,8 @@ public class PoisonShotsListener(IServiceProvider provider)
: BaseListener(provider), IPluginModule {
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
private readonly PoisonShotsConfig config =
provider.GetService<IStorage<PoisonShotsConfig>>()
private PoisonShotsConfig config
=> Provider.GetService<IStorage<PoisonShotsConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new PoisonShotsConfig();

View File

@@ -10,6 +10,7 @@ using TTT.CS2.Events;
using TTT.CS2.Extensions;
using TTT.Game;
using TTT.Game.Events.Body;
using TTT.Game.lang;
using TTT.Game.Listeners;
using TTT.Game.Roles;
@@ -57,7 +58,8 @@ public class BodyPickupListener(IServiceProvider provider)
if (ragdoll.IsValid) ragdoll.SetColor(primary.Color);
var online = converter.GetPlayer(ev.Body.OfPlayer);
if (online is not { IsValid: true }) return;
if (online is not { IsValid: true } || online.Team == CsTeam.Spectator)
return;
if (primary is InnocentRole) online.SwitchTeam(CsTeam.CounterTerrorist);

View File

@@ -127,6 +127,7 @@ public class RoundTimerListener(IServiceProvider provider)
var role = Roles.GetRoles(player).FirstOrDefault();
if (role == null) continue;
csPlayer.SetClan(role.Name, false);
if (csPlayer.Team == CsTeam.Spectator) continue;
if (role is InnocentRole) csPlayer.SwitchTeam(CsTeam.CounterTerrorist);
}

View File

@@ -56,7 +56,7 @@ public class CS2AliveSpoofer : IAliveSpoofer, IPluginModule {
[UsedImplicitly]
[GameEventHandler]
public HookResult OnDisconnect(EventPlayerDisconnect ev) {
public HookResult OnDisconnect(EventPlayerDisconnect ev, GameEventInfo _) {
if (ev.Userid == null) return HookResult.Continue;
_fakeAlivePlayers.Remove(ev.Userid);
return HookResult.Continue;

View File

@@ -2,10 +2,8 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using TTT.CS2.RayTrace.Class;
using Address = TTT.CS2.Utils.Address;
namespace TTT.CS2.Items.ClusterGrenade;
namespace TTT.CS2.Utils;
public class GrenadeDataHelper {
private static readonly CHEGrenadeProjectile_CreateDelegate

View File

@@ -0,0 +1,127 @@
namespace TTT.CS2.Utils;
public static class WeaponTranslations {
public static string GetFriendlyWeaponName(string designerName) {
switch (designerName) {
case "weapon_ak47":
return "AK-47";
case "weapon_aug":
return "AUG";
case "weapon_awp":
return "AWP";
case "weapon_bizon":
return "Bizon";
case "weapon_cz75a":
return "CZ75";
case "weapon_deagle":
return "Desert Eagle";
case "weapon_elite":
return "Dualies";
case "weapon_famas":
return "Famas";
case "weapon_fiveseven":
return "Five Seven";
case "weapon_g3sg1":
return "G3SG1";
case "weapon_galilar":
return "Galil";
case "weapon_glock":
return "Glock 18";
case "weapon_hkp2000":
return "HPK2000";
case "weapon_m249":
return "M249";
case "weapon_m4a1":
return "M4A1";
case "weapon_m4a1_silencer":
return "M4A1-S";
case "weapon_m4a4":
return "M4A4";
case "weapon_mac10":
return "MAC10";
case "weapon_mag7":
return "MAG7";
case "weapon_mp5sd":
return "MP5SD";
case "weapon_mp7":
return "MP7";
case "weapon_mp9":
return "MP9";
case "weapon_negev":
return "Negev";
case "weapon_nova":
return "Nova";
case "weapon_p250":
return "P250";
case "weapon_p90":
return "P90";
case "weapon_revolver":
return "Revolver";
case "weapon_sawedoff":
return "Sawed Off";
case "weapon_scar20":
return "Scar20";
case "weapon_sg553":
return "SG553";
case "weapon_sg556":
return "SG556";
case "weapon_ssg08":
return "SSG08";
case "weapon_taser":
return "Zeus";
case "weapon_tec9":
return "Tec9";
case "weapon_ump45":
return "UMP45";
case "weapon_usp_silencer":
return "USPS";
case "weapon_xm1014":
return "XM1014";
case "item_kevlar":
return "Kevlar";
case "item_assaultsuit":
return "Kevlar Helmet";
case "weapon_snowball":
return "Snowball";
case "weapon_shield":
return "Shield";
case "weapon_c4":
return "Bomb";
case "weapon_healthshot":
return "Healthshot";
case "weapon_breachcharge":
return "Breach Charge";
case "weapon_tablet":
return "Tablet";
case "weapon_bumpmine":
return "Bumpmine";
case "weapon_smokegrenade":
return "Smoke Grenade";
case "weapon_flashbang":
return "Flashbang";
case "weapon_hegrenade":
return "HE Grenade";
case "weapon_molotov":
return "Molotov";
case "weapon_incgrenade":
return "Incendiary Grenade";
case "weapon_decoy":
return "Decoy Grenade";
case "weapon_tagrenade":
return "TAGrenade";
case "weapon_frag":
return "Frag Grenade";
case "weapon_firebomb":
return "Firebomb";
case "weapon_diversion":
return "Diversion";
case "weapon_knife_t":
case "weapon_knife":
return "Knife";
default: {
var name = designerName.Replace("weapon_", "");
return char.ToUpper(name[0]) + name[1..];
}
}
}
}

View File

@@ -1,6 +1,7 @@
using TTT.API.Player;
using TTT.API.Role;
using TTT.Game;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.CS2.lang;

View File

@@ -2,8 +2,8 @@ ROLE_SPECTATOR: "Spectator"
TRAITOR_CHAT_FORMAT: "{darkred}[TRAITORS] {red}{0}: {default}{1}"
TASER_SCANNED: "%PREFIX%You scanned {0}{grey}, they are %an% {1}{grey}!"
DNA_PREFIX: "{darkblue}D{blue}N{lightblue}A{grey} | {grey}"
AFK_WARNING: "%PREFIX%You will be moved to Spectator mode in {0} second%s% for being AFK."
AFK_MOVED: "%PREFIX%You have been moved to Spectator mode for being AFK."
AFK_WARNING: "%PREFIX%You will be moved to spectators in {yellow}{{0} second%s%{grey} for being AFK."
AFK_MOVED: "%PREFIX%You were moved to spectators for being AFK."
DEAD_MUTE_REMINDER: "%PREFIX%You are dead and cannot be heard."

View File

@@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection;
using TTT.API;
using TTT.API.Command;
using TTT.API.Player;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Commands;

View File

@@ -3,6 +3,7 @@ using TTT.API.Command;
using TTT.API.Game;
using TTT.API.Messages;
using TTT.API.Player;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Commands;

View File

@@ -4,6 +4,7 @@ using TTT.API;
using TTT.API.Command;
using TTT.API.Events;
using TTT.API.Player;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Commands;

View File

@@ -11,11 +11,11 @@ namespace TTT.Game.Listeners;
public class GameRestartListener(IServiceProvider provider)
: BaseListener(provider) {
private readonly TTTConfig config = provider
.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private TTTConfig config
=> Provider.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private readonly IScheduler scheduler =
provider.GetRequiredService<IScheduler>();

View File

@@ -1,6 +1,7 @@
using JetBrains.Annotations;
using TTT.API.Events;
using TTT.Game.Events.Player;
using TTT.Game.lang;
namespace TTT.Game.Listeners;

View File

@@ -9,9 +9,11 @@ namespace TTT.Game.Listeners;
public class PlayerJoinStarting(IServiceProvider provider)
: BaseListener(provider) {
private readonly TTTConfig config =
provider.GetService<IStorage<TTTConfig>>()?.Load().GetAwaiter().GetResult()
?? new TTTConfig();
private TTTConfig config
=> Provider.GetService<IStorage<TTTConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
[EventHandler]
[UsedImplicitly]

View File

@@ -3,6 +3,7 @@ using JetBrains.Annotations;
using TTT.API.Events;
using TTT.API.Game;
using TTT.Game.Events.Game;
using TTT.Game.lang;
using TTT.Game.Roles;
namespace TTT.Game.Listeners;

View File

@@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
using TTT.API.Game;
using TTT.API.Messages;
using TTT.API.Player;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Loggers;

View File

@@ -4,16 +4,17 @@ using TTT.API.Messages;
using TTT.API.Player;
using TTT.API.Role;
using TTT.API.Storage;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Roles;
public abstract class BaseRole(IServiceProvider provider) : IRole {
protected readonly TTTConfig Config = provider
.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
protected TTTConfig Config
=> Provider.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
protected readonly IInventoryManager Inventory =
provider.GetRequiredService<IInventoryManager>();

View File

@@ -1,5 +1,6 @@
using System.Drawing;
using TTT.API.Player;
using TTT.Game.lang;
namespace TTT.Game.Roles;

View File

@@ -1,6 +1,7 @@
using System.Drawing;
using Microsoft.Extensions.DependencyInjection;
using TTT.API.Player;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Game.Roles;

View File

@@ -1,5 +1,6 @@
using System.Drawing;
using TTT.API.Player;
using TTT.Game.lang;
namespace TTT.Game.Roles;

View File

@@ -8,6 +8,7 @@ using TTT.API.Player;
using TTT.API.Role;
using TTT.API.Storage;
using TTT.Game.Events.Game;
using TTT.Game.lang;
using TTT.Game.Loggers;
using TTT.Game.Roles;
using TTT.Locale;
@@ -15,11 +16,11 @@ using TTT.Locale;
namespace TTT.Game;
public class RoundBasedGame(IServiceProvider provider) : IGame {
private readonly TTTConfig config = provider
.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private TTTConfig config
=> provider.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
protected readonly IMsgLocalizer Locale =
provider.GetRequiredService<IMsgLocalizer>();

View File

@@ -4,7 +4,7 @@ using TTT.API.Role;
using TTT.Game.Roles;
using TTT.Locale;
namespace TTT.Game;
namespace TTT.Game.lang;
public static class GameMsgs {
public static IMsg PREFIX => MsgFactory.Create(nameof(PREFIX));

View File

@@ -15,8 +15,8 @@ namespace TTT.Karma;
public class KarmaListener(IServiceProvider provider) : BaseListener(provider) {
private readonly Dictionary<string, int> badKills = new();
private readonly KarmaConfig config =
provider.GetService<IStorage<KarmaConfig>>()
private KarmaConfig config
=> Provider.GetService<IStorage<KarmaConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new KarmaConfig();

View File

@@ -19,12 +19,6 @@ public sealed class KarmaStorage(IServiceProvider provider) : IKarmaService {
private const bool EnableCache = true;
private readonly IEventBus _bus = provider.GetRequiredService<IEventBus>();
private KarmaConfig _configStorage
=> provider.GetService<IStorage<KarmaConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new KarmaConfig();
private readonly SemaphoreSlim _flushGate = new(1, 1);
// Cache keyed by stable player id to avoid relying on IPlayer equality

View File

@@ -12,6 +12,7 @@
<ProjectReference Include="..\CS2\CS2.csproj"/>
<ProjectReference Include="..\Karma\Karma.csproj"/>
<ProjectReference Include="..\Shop\Shop.csproj"/>
<ProjectReference Include="..\RTD\RTD.csproj"/>
</ItemGroup>
<ItemGroup>

View File

@@ -36,6 +36,8 @@ public class TTT(IServiceProvider provider) : BasePlugin {
$"Found {pluginModules.Count} plugin modules, loading...");
foreach (var module in pluginModules) {
Logger.LogInformation(
$"Registering {module.Version} {module.Id} {module.GetType().Namespace}");
module.Start(this, hotReload);
RegisterAllAttributes(module);
loadedModules.Add(module);

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using TTT.CS2;
using TTT.Game;
using TTT.Karma;
using TTT.RTD;
using TTT.Shop;
namespace TTT.Plugin;
@@ -16,5 +17,6 @@ public class TTTServiceCollection : IPluginServiceCollection<TTT> {
serviceCollection.AddGameServices();
serviceCollection.AddCS2Services();
serviceCollection.AddShopServices();
serviceCollection.AddRtdServices();
}
}

View File

@@ -0,0 +1,5 @@
namespace TTT.RTD;
public interface IRewardGenerator : IReadOnlyCollection<(IRtdReward, float)> {
IRtdReward GetReward();
}

10
TTT/RTD/IRtdReward.cs Normal file
View File

@@ -0,0 +1,10 @@
using TTT.API;
using TTT.API.Player;
namespace TTT.RTD;
public interface IRtdReward : ITerrorModule {
string Name { get; }
string Description { get; }
void GrantReward(IOnlinePlayer player);
}

5
TTT/RTD/Muted.cs Normal file
View File

@@ -0,0 +1,5 @@
using TTT.API.Player;
namespace TTT.RTD;
public class Muted : HashSet<string>, IMuted { }

18
TTT/RTD/RTD.csproj Normal file
View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>TTT.RTD</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\API\API.csproj" />
<ProjectReference Include="..\CS2\CS2.csproj" />
<ProjectReference Include="..\Game\Game.csproj" />
<ProjectReference Include="..\ShopAPI\ShopAPI.csproj" />
<ProjectReference Include="..\Shop\Shop.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,82 @@
using System.Collections;
using CounterStrikeSharp.API.Core;
using TTT.API;
using TTT.CS2.Items.Armor;
using TTT.CS2.Items.Camouflage;
using TTT.CS2.Items.Station;
using TTT.RTD.Rewards;
using TTT.Shop.Items;
using TTT.Shop.Items.Detective.Stickers;
using TTT.Shop.Items.Taser;
namespace TTT.RTD;
public class RewardGenerator(IServiceProvider provider)
: IRewardGenerator, IPluginModule {
private readonly List<(IRtdReward, float)> rewards = new();
private const float PROB_LOTTERY = 1 / 5000f;
private const float PROB_EXTREMELY_LOW = 1 / 800f;
private const float PROB_VERY_LOW = 1 / 100f;
private const float PROB_LOW = 1 / 20f;
private const float PROB_MEDIUM = 1 / 10f;
private const float PROB_OFTEN = 1 / 5f;
private const float PROB_VERY_OFTEN = 1 / 2f;
public IEnumerator<(IRtdReward, float)> GetEnumerator() {
return rewards.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public int Count => rewards.Count;
public IRtdReward GetReward() {
var totalWeight = 0f;
foreach (var (_, weight) in rewards) { totalWeight += weight; }
var randomValue = Random.Shared.NextSingle() * totalWeight;
var cumulativeWeight = 0f;
foreach (var (reward, weight) in rewards) {
cumulativeWeight += weight;
if (randomValue <= cumulativeWeight) { return reward; }
}
return rewards[^1].Item1;
}
public void Start() {
rewards.AddRange([
(new CreditReward(provider, 5), PROB_OFTEN),
(new CreditReward(provider, -5), PROB_OFTEN),
(new WeaponReward(provider, "weapon_flashbang"), PROB_MEDIUM),
(new CreditReward(provider, -10), PROB_LOW),
(new HealthReward(provider, 150), PROB_LOW),
(new CreditReward(provider, -50), PROB_VERY_LOW),
(new CreditReward(provider, 50), PROB_VERY_LOW),
(new HealthReward(provider, 50), PROB_VERY_LOW),
(new ShopItemReward<CamouflageItem>(provider), PROB_VERY_LOW),
(new ShopItemReward<ArmorItem>(provider), PROB_VERY_LOW),
(new ShopItemReward<TaserItem>(provider), PROB_VERY_LOW),
(new ShopItemReward<Stickers>(provider), PROB_VERY_LOW),
(new ShopItemReward<OneShotDeagleItem>(provider), PROB_VERY_LOW),
(new ProvenReward(provider), PROB_VERY_LOW),
(new MuteReward(provider), PROB_VERY_LOW),
(new ShopItemReward<HealthStation>(provider), PROB_EXTREMELY_LOW),
(new HealthReward(provider, 1), PROB_EXTREMELY_LOW),
(new CreditReward(provider, 100), PROB_EXTREMELY_LOW),
(new HealthReward(provider, 200), PROB_EXTREMELY_LOW),
]);
rewards.ForEach(r => r.Item1.Start());
}
public void Start(BasePlugin? plugin) {
Start();
foreach (var (reward, _) in rewards) {
if (reward is IPluginModule module) { module.Start(plugin); }
}
}
public void Dispose() { }
}

View File

@@ -0,0 +1,22 @@
using CounterStrikeSharp.API;
using Microsoft.Extensions.DependencyInjection;
using ShopAPI;
using TTT.API.Player;
using TTT.RTD.lang;
using TTT.Shop;
namespace TTT.RTD.Rewards;
public class CreditReward(IServiceProvider provider, int amo)
: RoundStartReward(provider) {
public override string Name => Locale[RtdMsgs.CREDITS_REWARD(amo)];
public override string Description
=> Locale[RtdMsgs.CREDITS_REWARD_DESC(amo)];
private readonly IShop shop = provider.GetRequiredService<IShop>();
public override void GiveOnRound(IOnlinePlayer player) {
shop.AddBalance(player, amo, "RTD Reward");
}
}

View File

@@ -0,0 +1,15 @@
using TTT.API.Player;
namespace TTT.RTD.Rewards;
public class HealthReward(IServiceProvider provider, int health)
: RoundStartReward(provider) {
public override string Name => $"{health} HP";
public override string Description
=> $"you will start next round with {health} HP";
public override void GiveOnRound(IOnlinePlayer player) {
player.Health = health;
}
}

View File

@@ -0,0 +1,50 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using Microsoft.Extensions.DependencyInjection;
using TTT.API;
using TTT.API.Game;
using TTT.API.Messages;
using TTT.API.Player;
using TTT.Game.Events.Game;
using TTT.Locale;
using TTT.RTD.lang;
namespace TTT.RTD.Rewards;
public class MuteReward(IServiceProvider provider)
: RoundStartReward(provider), IPluginModule {
public override string Name => "Mute";
public override string Description
=> "you will not be able to communicate next round";
private readonly IMuted mutedPlayers = provider.GetRequiredService<IMuted>();
private readonly IMsgLocalizer locale =
provider.GetRequiredService<IMsgLocalizer>();
public override void GiveOnRound(IOnlinePlayer player) {
mutedPlayers.Add(player.Id);
}
public void Start(BasePlugin? plugin) {
plugin?.RegisterListener<Listeners.OnClientVoice>(onVoice);
}
private void onVoice(int playerSlot) {
var player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null) return;
if ((player.VoiceFlags & VoiceFlags.Muted) == VoiceFlags.Muted) return;
if (mutedPlayers.Contains(player.SteamID.ToString())) {
player.VoiceFlags |= VoiceFlags.Muted;
player.PrintToChat(locale[RtdMsgs.RTD_MUTED]);
}
}
public override void OnRoundStart(GameStateUpdateEvent ev) {
if (ev.NewState == State.FINISHED) mutedPlayers.Clear();
base.OnRoundStart(ev);
}
}

View File

@@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using TTT.API.Player;
using TTT.API.Role;
using TTT.Game.Roles;
namespace TTT.RTD.Rewards;
public class ProvenReward(IServiceProvider provider)
: RoundStartReward(provider) {
private readonly IRoleAssigner roles =
provider.GetRequiredService<IRoleAssigner>();
private readonly IIconManager icons =
provider.GetRequiredService<IIconManager>();
public override string Name => "Proven If Inno";
public override string Description
=> "you will be shown innocent if assigned next round";
public override void GiveOnRound(IOnlinePlayer player) {
if (!roles.GetRoles(player).OfType<InnocentRole>().Any()) return;
icons.RevealToAll(player);
}
}

View File

@@ -0,0 +1,21 @@
using Microsoft.Extensions.DependencyInjection;
using ShopAPI;
using TTT.API.Player;
namespace TTT.RTD.Rewards;
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 Description
=> $"you will receive {("aeiou".Contains(Name.ToLower()[0]) ? "an" : "a")} {typeof(TItem).Name} next round";
public override void GiveOnRound(IOnlinePlayer player) {
var instance = shop.Items.OfType<TItem>().FirstOrDefault();
if (instance == null) return;
shop.GiveItem(player, instance);
}
}

View File

@@ -0,0 +1,27 @@
using Microsoft.Extensions.DependencyInjection;
using TTT.API.Player;
using TTT.CS2.Utils;
using TTT.Game.Roles;
namespace TTT.RTD.Rewards;
public class WeaponReward(IServiceProvider provider, string weapon,
int? amo = null, int? reserve = null) : RoundStartReward(provider) {
private readonly IInventoryManager inventory =
provider.GetRequiredService<IInventoryManager>();
public override string Name
=> WeaponTranslations.GetFriendlyWeaponName(weapon);
public override string Description
=> $"you will receive {(weapon.ToLower().StartsWith('a') ? "an" : "a")} {WeaponTranslations.GetFriendlyWeaponName(weapon)} next round{ammoDesc}";
private string ammoDesc
=> amo != null && reserve != null ? $" with {amo}/{reserve} ammo" :
amo != null ? $" with {amo} ammo" :
reserve != null ? $" with {reserve} reserve ammo" : "";
public override void GiveOnRound(IOnlinePlayer player) {
inventory.GiveWeapon(player, new BaseWeapon(weapon, amo, reserve));
}
}

View File

@@ -0,0 +1,41 @@
using CounterStrikeSharp.API;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using TTT.API.Events;
using TTT.API.Game;
using TTT.API.Player;
using TTT.Game.Events.Game;
using TTT.Locale;
namespace TTT.RTD;
public abstract class RoundStartReward(IServiceProvider provider)
: IRtdReward, IListener {
private readonly ISet<IOnlinePlayer> givenPlayers =
new HashSet<IOnlinePlayer>();
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
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>();
[UsedImplicitly]
[EventHandler(Priority = Priority.LOW)]
public virtual void OnRoundStart(GameStateUpdateEvent ev) {
if (ev.NewState != State.IN_PROGRESS) return;
foreach (var player in givenPlayers) GiveOnRound(player);
givenPlayers.Clear();
}
public void Start() { bus.RegisterListener(this); }
public void Dispose() { bus.UnregisterListener(this); }
}

86
TTT/RTD/RtdCommand.cs Normal file
View File

@@ -0,0 +1,86 @@
using JetBrains.Annotations;
using TTT.API;
using TTT.API.Command;
using TTT.API.Events;
using TTT.API.Game;
using TTT.API.Player;
using TTT.CS2.Utils;
using TTT.Game.Events.Game;
using TTT.Locale;
using TTT.RTD.lang;
namespace TTT.RTD;
public class RTDCommand(IRewardGenerator generator, IPermissionManager perms,
IMsgLocalizer locale) : ICommand, IPluginModule, IListener {
private bool inBetweenRounds = true;
private Dictionary<string, IRtdReward> playerRewards = new();
public bool MustBeOnMainThread => true;
public string Id => "rtd";
public Task<CommandResult>
Execute(IOnlinePlayer? executor, ICommandInfo info) {
if (executor == null) return Task.FromResult(CommandResult.PLAYER_ONLY);
var bypass = perms.HasFlags(executor, "@css/root") && info.ArgCount == 2;
#if DEBUG
bypass = true;
#endif
if (!bypass && playerRewards.TryGetValue(executor.Id, out var existing)) {
info.ReplySync(locale[RtdMsgs.RTD_ALREADY_ROLLED(existing)]);
return Task.FromResult(CommandResult.SUCCESS);
}
if (!bypass) {
if (!inBetweenRounds && !RoundUtil.IsWarmup() && executor.IsAlive) {
info.ReplySync(locale[RtdMsgs.RTD_CANNOT_ROLL_YET]);
return Task.FromResult(CommandResult.SUCCESS);
}
}
var reward = generator.GetReward();
if (bypass) {
if (!int.TryParse(info.Args[1], out var slot)) {
info.ReplySync("Invalid parameter: must be an integer.");
return Task.FromResult(CommandResult.SUCCESS);
}
if (slot != -1) {
var rewards = generator.ToList();
if (slot < 0 || slot >= rewards.Count) {
info.ReplySync(
$"Invalid parameter: must be between 0 and {rewards.Count - 1}.");
return Task.FromResult(CommandResult.SUCCESS);
}
reward = generator.ToList()[slot].Item1;
}
}
info.ReplySync(locale[RtdMsgs.RTD_ROLLED(reward)]);
reward.GrantReward(executor);
playerRewards[executor.Id] = reward;
return Task.FromResult(CommandResult.SUCCESS);
}
[UsedImplicitly]
[EventHandler]
public void OnGameState(GameStateUpdateEvent ev) {
switch (ev.NewState) {
case State.FINISHED:
inBetweenRounds = true;
break;
case State.IN_PROGRESS:
inBetweenRounds = false;
playerRewards.Clear();
break;
}
}
public void Dispose() { }
public void Start() { }
}

View File

@@ -0,0 +1,14 @@
using Microsoft.Extensions.DependencyInjection;
using TTT.API.Extensions;
using TTT.API.Player;
namespace TTT.RTD;
public static class RtdServiceExtensions {
public static void AddRtdServices(this IServiceCollection services) {
services.AddModBehavior<IRewardGenerator, RewardGenerator>();
services.AddModBehavior<RtdStatsCommand>();
services.AddModBehavior<RTDCommand>();
services.AddSingleton<IMuted, Muted>();
}
}

View File

@@ -0,0 +1,29 @@
using CounterStrikeSharp.API.Modules.Utils;
using TTT.API.Command;
using TTT.API.Player;
namespace TTT.RTD;
public class RtdStatsCommand(IRewardGenerator generator) : ICommand {
public void Dispose() { }
public void Start() { }
public string Id => "rtdstats";
public Task<CommandResult>
Execute(IOnlinePlayer? executor, ICommandInfo info) {
if (executor == null) return Task.FromResult(CommandResult.PLAYER_ONLY);
var rewards = generator.ToList();
var total = rewards.Sum(r => r.Item2);
var index = 0;
foreach (var (reward, prob) in rewards) {
var percent = (prob / total) * 100;
info.ReplySync(
$" {ChatColors.Orange}{index}. {ChatColors.Default}{reward.Name}{ChatColors.Grey}: {ChatColors.Yellow}{percent:0.00}%");
index++;
}
return Task.FromResult(CommandResult.SUCCESS);
}
}

23
TTT/RTD/lang/RtdMsgs.cs Normal file
View File

@@ -0,0 +1,23 @@
using TTT.Locale;
namespace TTT.RTD.lang;
public class RtdMsgs {
public static IMsg RTD_ALREADY_ROLLED(IRtdReward reward)
=> MsgFactory.Create(nameof(RTD_ALREADY_ROLLED), reward.Name);
public static IMsg RTD_CANNOT_ROLL_YET
=> MsgFactory.Create(nameof(RTD_CANNOT_ROLL_YET));
public static IMsg RTD_ROLLED(IRtdReward reward)
=> MsgFactory.Create(nameof(RTD_ROLLED), reward.Name, reward.Description);
public static IMsg RTD_MUTED
=> MsgFactory.Create(nameof(RTD_MUTED));
public static IMsg CREDITS_REWARD(int amo)
=> MsgFactory.Create(nameof(CREDITS_REWARD), amo);
public static IMsg CREDITS_REWARD_DESC(int amo)
=> MsgFactory.Create(nameof(CREDITS_REWARD_DESC), amo);
}

7
TTT/RTD/lang/en.yml Normal file
View File

@@ -0,0 +1,7 @@
RTD_PREFIX: "{lightred}RTD | {grey}"
RTD_ALREADY_ROLLED: "%RTD_PREFIX%You already rolled {default}{0}{grey}."
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}%CREDITS_NAME%%s%{grey} next round"

View File

@@ -13,7 +13,7 @@ public class BalanceCommand(IServiceProvider provider) : ICommand {
private readonly IShop shop = provider.GetRequiredService<IShop>();
public string Id => "balance";
public string[] Aliases => [Id, "bal", "credits", "money"];
public string[] Aliases => [Id, "bal", "credits", "money", "points"];
public void Dispose() { }
public void Start() { }

View File

@@ -4,6 +4,7 @@ using ShopAPI;
using TTT.API.Command;
using TTT.API.Player;
using TTT.Game;
using TTT.Game.lang;
using TTT.Locale;
namespace TTT.Shop.Commands;

View File

@@ -15,9 +15,11 @@ public static class M4A1ServiceCollection {
}
public class M4A1ShopItem(IServiceProvider provider) : BaseItem(provider) {
private readonly M4A1Config config =
provider.GetService<IStorage<M4A1Config>>()?.Load().GetAwaiter().GetResult()
?? new M4A1Config();
private M4A1Config config
=> Provider.GetService<IStorage<M4A1Config>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new M4A1Config();
public override string Name => Locale[M4A1Msgs.SHOP_ITEM_M4A1];
public override string Description => Locale[M4A1Msgs.SHOP_ITEM_M4A1_DESC];

View File

@@ -14,8 +14,8 @@ namespace TTT.Shop.Items;
public class DeagleDamageListener(IServiceProvider provider)
: BaseListener(provider) {
private readonly OneShotDeagleConfig config =
provider.GetService<IStorage<OneShotDeagleConfig>>()
private OneShotDeagleConfig config
=> Provider.GetService<IStorage<OneShotDeagleConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new OneShotDeagleConfig();

View File

@@ -15,8 +15,8 @@ public static class TaserServiceCollection {
}
public class TaserItem(IServiceProvider provider) : BaseItem(provider) {
private readonly TaserConfig config =
provider.GetService<IStorage<TaserConfig>>()
private TaserConfig config
=> Provider.GetService<IStorage<TaserConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new TaserConfig();

View File

@@ -21,10 +21,11 @@ public static class C4ServiceCollection {
public class C4ShopItem(IServiceProvider provider)
: RoleRestrictedItem<TraitorRole>(provider), IListener {
private readonly C4Config config = provider.GetService<IStorage<C4Config>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new C4Config();
private C4Config config
=> Provider.GetService<IStorage<C4Config>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new C4Config();
private readonly IPlayerFinder finder =
provider.GetRequiredService<IPlayerFinder>();

View File

@@ -18,8 +18,8 @@ public static class GlovesServiceCollection {
public class GlovesItem(IServiceProvider provider)
: RoleRestrictedItem<TraitorRole>(provider) {
private readonly GlovesConfig config =
provider.GetService<IStorage<GlovesConfig>>()
private GlovesConfig config
=> Provider.GetService<IStorage<GlovesConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new GlovesConfig();

View File

@@ -14,8 +14,8 @@ namespace TTT.Shop.Items.Traitor.Gloves;
public class GlovesListener(IServiceProvider provider)
: BaseListener(provider) {
private readonly GlovesConfig config =
provider.GetService<IStorage<GlovesConfig>>()
private GlovesConfig config
=> Provider.GetService<IStorage<GlovesConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new GlovesConfig();

View File

@@ -13,9 +13,11 @@ namespace TTT.Shop.Listeners;
public class RoleAssignCreditor(IServiceProvider provider)
: BaseListener(provider) {
private readonly ShopConfig config =
provider.GetService<IStorage<ShopConfig>>()?.Load().GetAwaiter().GetResult()
?? new ShopConfig(provider);
private ShopConfig config
=> Provider.GetService<IStorage<ShopConfig>>()
?.Load()
.GetAwaiter()
.GetResult() ?? new ShopConfig(Provider);
private KarmaConfig karmaConfig
=> Provider.GetService<IStorage<KarmaConfig>>()

View File

@@ -0,0 +1,17 @@
using JetBrains.Annotations;
using ShopAPI.Events;
using TTT.API.Events;
using TTT.Game.Listeners;
using TTT.Shop.Logs;
namespace TTT.Shop.Listeners;
public class ShopPurchaseLogger(IServiceProvider provider)
: BaseListener(provider) {
[UsedImplicitly]
[EventHandler(Priority = Priority.MONITOR, IgnoreCanceled = true)]
public void OnShopPurchase(PlayerPurchaseItemEvent ev) {
Games.ActiveGame?.Logger.LogAction(new PurchaseAction(Roles, ev.Player,
ev.Item));
}
}

View File

@@ -0,0 +1,20 @@
using ShopAPI;
using TTT.API.Game;
using TTT.API.Player;
using TTT.API.Role;
namespace TTT.Shop.Logs;
public class PurchaseAction(IRoleAssigner roles, IPlayer purchaser,
IShopItem item) : IAction {
public IPlayer Player { get; } = purchaser;
public IPlayer? Other { get; }
public IRole? PlayerRole { get; } =
roles.GetRoles(purchaser).FirstOrDefault();
public IRole? OtherRole { get; }
public string Id { get; } = "ttt.shop.action.purchase";
public string Verb { get; } = "purchased";
public string Details { get; } = item.Name;
}

View File

@@ -37,6 +37,7 @@ public static class ShopServiceCollection {
collection.AddModBehavior<IItemSorter, ShopCommand>();
collection.AddModBehavior<BuyCommand>();
collection.AddModBehavior<BalanceCommand>();
collection.AddModBehavior<ShopPurchaseLogger>();
collection.AddArmorServices();
collection.AddBodyCompassServices();

View File

@@ -4,6 +4,7 @@ using TTT.API.Game;
using TTT.API.Player;
using TTT.Game;
using TTT.Game.Commands;
using TTT.Game.lang;
using TTT.Locale;
using Xunit;

View File

@@ -10,11 +10,11 @@ namespace TTT.Test.Game.Listeners;
public class GameRestartingTest(IServiceProvider provider)
: GameTest(provider) {
private readonly TTTConfig config = provider
.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private TTTConfig config
=> Provider.GetRequiredService<IStorage<TTTConfig>>()
.Load()
.GetAwaiter()
.GetResult() ?? new TTTConfig();
private readonly TestScheduler scheduler =
provider.GetRequiredService<TestScheduler>();

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using TTT.API.Player;
using TTT.API.Role;
using TTT.Game;
using TTT.Game.lang;
using TTT.Locale;
using Xunit;