2021-10-03 07:05:52 +03:00
|
|
|
using Content.Server.Administration;
|
|
|
|
|
using Content.Shared.Administration;
|
|
|
|
|
using Content.Shared.CCVar;
|
2022-08-17 00:34:25 -04:00
|
|
|
using Content.Shared.FixedPoint;
|
2021-10-03 07:05:52 +03:00
|
|
|
using Robust.Server.Player;
|
|
|
|
|
using Robust.Shared.Configuration;
|
|
|
|
|
using Robust.Shared.Console;
|
2023-10-28 09:59:53 +11:00
|
|
|
using Robust.Shared.Player;
|
2021-10-03 07:05:52 +03:00
|
|
|
|
|
|
|
|
namespace Content.Server.Traitor.Uplink.Commands
|
|
|
|
|
{
|
2022-09-14 17:02:38 -07:00
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AddUplinkCommand : IConsoleCommand
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2024-01-03 19:04:31 -05:00
|
|
|
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
|
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
2021-10-03 07:05:52 +03:00
|
|
|
public string Command => "adduplink";
|
|
|
|
|
|
2022-07-15 13:14:37 +12:00
|
|
|
public string Description => Loc.GetString("add-uplink-command-description");
|
2021-10-03 07:05:52 +03:00
|
|
|
|
2022-07-15 13:14:37 +12:00
|
|
|
public string Help => Loc.GetString("add-uplink-command-help");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
|
|
|
{
|
|
|
|
|
return args.Length switch
|
|
|
|
|
{
|
|
|
|
|
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(), Loc.GetString("add-uplink-command-completion-1")),
|
|
|
|
|
2 => CompletionResult.FromHint(Loc.GetString("add-uplink-command-completion-2")),
|
|
|
|
|
_ => CompletionResult.Empty
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-10-03 07:05:52 +03:00
|
|
|
|
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
|
|
|
{
|
2022-07-15 13:14:37 +12:00
|
|
|
if (args.Length > 2)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-28 09:59:53 +11:00
|
|
|
ICommonSession? session;
|
2022-07-15 13:14:37 +12:00
|
|
|
if (args.Length > 0)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2022-07-15 13:14:37 +12:00
|
|
|
// Get player entity
|
2024-01-03 19:04:31 -05:00
|
|
|
if (!_playerManager.TryGetSessionByUsername(args[0], out session))
|
2022-07-15 13:14:37 +12:00
|
|
|
{
|
|
|
|
|
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
2022-07-15 13:14:37 +12:00
|
|
|
else
|
|
|
|
|
{
|
2023-10-28 09:59:53 +11:00
|
|
|
session = shell.Player;
|
2022-07-15 13:14:37 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (session?.AttachedEntity is not { } user)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2022-07-15 13:14:37 +12:00
|
|
|
shell.WriteLine(Loc.GetString("add-uplink-command-error-1"));
|
2021-10-03 07:05:52 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get target item
|
2021-12-06 00:52:58 +01:00
|
|
|
EntityUid? uplinkEntity = null;
|
2021-10-03 07:05:52 +03:00
|
|
|
if (args.Length >= 2)
|
|
|
|
|
{
|
|
|
|
|
if (!int.TryParse(args[1], out var itemID))
|
|
|
|
|
{
|
|
|
|
|
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
var eNet = new NetEntity(itemID);
|
|
|
|
|
|
|
|
|
|
if (!_entManager.TryGetEntity(eNet, out var eUid))
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
|
|
|
|
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 00:52:58 +01:00
|
|
|
uplinkEntity = eUid;
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get TC count
|
2024-01-03 19:04:31 -05:00
|
|
|
var tcCount = _cfgManager.GetCVar(CCVars.TraitorStartingBalance);
|
|
|
|
|
Logger.Debug(_entManager.ToPrettyString(user));
|
2021-10-03 07:05:52 +03:00
|
|
|
// Finally add uplink
|
2024-01-03 19:04:31 -05:00
|
|
|
var uplinkSys = _entManager.System<UplinkSystem>();
|
2022-08-17 00:34:25 -04:00
|
|
|
if (!uplinkSys.AddUplink(user, FixedPoint2.New(tcCount), uplinkEntity: uplinkEntity))
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2022-07-15 13:14:37 +12:00
|
|
|
shell.WriteLine(Loc.GetString("add-uplink-command-error-2"));
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|