mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-08 07:16:33 -08:00
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.
90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Commands;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using TTT.API;
|
|
using TTT.API.Command;
|
|
using TTT.API.Messages;
|
|
using TTT.API.Player;
|
|
using TTT.Game;
|
|
using TTT.Game.Commands;
|
|
using TTT.Game.lang;
|
|
|
|
namespace TTT.CS2.Command;
|
|
|
|
public class CS2CommandManager(IServiceProvider provider)
|
|
: CommandManager(provider), IPluginModule {
|
|
private const string COMMAND_PREFIX = "css_";
|
|
|
|
private readonly IPlayerConverter<CCSPlayerController> converter =
|
|
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
|
|
|
private readonly IMessenger messenger = provider
|
|
.GetRequiredService<IMessenger>();
|
|
|
|
private BasePlugin? plugin;
|
|
|
|
public void Start(BasePlugin? basePlugin, bool hotReload) {
|
|
plugin = basePlugin;
|
|
base.Start();
|
|
}
|
|
|
|
public override bool RegisterCommand(ICommand command) {
|
|
var registration = command.Aliases.All(alias
|
|
=> cmdMap.TryAdd(COMMAND_PREFIX + alias, command));
|
|
if (!registration) return false;
|
|
foreach (var alias in command.Aliases)
|
|
plugin?.AddCommand(COMMAND_PREFIX + alias,
|
|
command.Description ?? string.Empty, processInternal);
|
|
return true;
|
|
}
|
|
|
|
private void
|
|
processInternal(CCSPlayerController? executor, CommandInfo info) {
|
|
var cs2Info = new CS2CommandInfo(Provider, info);
|
|
var wrapper = executor == null ?
|
|
null :
|
|
converter.GetPlayer(executor) as IOnlinePlayer;
|
|
|
|
messenger.Debug($"Received command: {cs2Info.Args[0]} from {wrapper?.Id}");
|
|
|
|
if (cmdMap.TryGetValue(cs2Info.Args[0], out var command))
|
|
if (command.MustBeOnMainThread) {
|
|
processCommandSync(cs2Info, wrapper);
|
|
return;
|
|
}
|
|
|
|
Task.Run(async () => await processCommandAsync(cs2Info, wrapper));
|
|
}
|
|
|
|
private async Task<CommandResult> processCommandAsync(CS2CommandInfo cs2Info,
|
|
IOnlinePlayer? wrapper) {
|
|
try {
|
|
Console.WriteLine($"Processing command: {cs2Info.CommandString}");
|
|
return await ProcessCommand(cs2Info);
|
|
} catch (Exception e) {
|
|
var msg = e.Message;
|
|
cs2Info.ReplySync(Localizer[GameMsgs.GENERIC_ERROR(msg)]);
|
|
await Server.NextWorldUpdateAsync(() => {
|
|
Console.WriteLine(
|
|
$"Encountered an error when processing command: \"{cs2Info.CommandString}\" by {wrapper?.Id}");
|
|
Console.WriteLine(e);
|
|
});
|
|
return CommandResult.ERROR;
|
|
}
|
|
}
|
|
|
|
private void processCommandSync(CS2CommandInfo cs2Info,
|
|
IOnlinePlayer? wrapper) {
|
|
try { _ = ProcessCommand(cs2Info); } catch (Exception e) {
|
|
var msg = e.Message;
|
|
cs2Info.ReplySync(Localizer[GameMsgs.GENERIC_ERROR(msg)]);
|
|
Server.NextWorldUpdateAsync(() => {
|
|
Console.WriteLine(
|
|
$"Encountered an error when processing command: \"{cs2Info.CommandString}\" by {wrapper?.Id}");
|
|
Console.WriteLine(e);
|
|
})
|
|
.Wait();
|
|
}
|
|
}
|
|
} |