mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* giant protoid cleanup * yml changes * ! --------- Co-authored-by: deltanedas <@deltanedas:goida.zip>
71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System.Linq;
|
|
using Content.Server.Store.Components;
|
|
using Content.Server.Administration;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.Store;
|
|
using Content.Shared.Store.Components;
|
|
using Robust.Shared.Console;
|
|
|
|
namespace Content.Server.Store.Systems;
|
|
|
|
public sealed partial class StoreSystem
|
|
{
|
|
[Dependency] private IConsoleHost _consoleHost = default!;
|
|
|
|
public void InitializeCommand()
|
|
{
|
|
_consoleHost.RegisterCommand("addcurrency", "Adds currency to the specified store", "addcurrency <uid> <currency prototype> <amount>",
|
|
AddCurrencyCommand,
|
|
AddCurrencyCommandCompletions);
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Fun)]
|
|
private void AddCurrencyCommand(IConsoleShell shell, string argstr, string[] args)
|
|
{
|
|
if (args.Length != 3)
|
|
{
|
|
shell.WriteError("Argument length must be 3");
|
|
return;
|
|
}
|
|
|
|
if (!NetEntity.TryParse(args[0], out var uidNet) || !TryGetEntity(uidNet, out var uid) || !float.TryParse(args[2], out var id))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var currency = args[1];
|
|
if (!ProtoMan.HasIndex<CurrencyPrototype>(currency))
|
|
{
|
|
shell.WriteError($"Unknown currency {currency}");
|
|
return;
|
|
}
|
|
|
|
if (!TryComp<StoreComponent>(uid, out var store))
|
|
return;
|
|
|
|
TryAddCurrency(new() { { currency, id } }, uid.Value, store);
|
|
}
|
|
|
|
private CompletionResult AddCurrencyCommandCompletions(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
var query = EntityQueryEnumerator<StoreComponent>();
|
|
var allStores = new List<string>();
|
|
while (query.MoveNext(out var storeuid, out _))
|
|
{
|
|
allStores.Add(storeuid.ToString());
|
|
}
|
|
return CompletionResult.FromHintOptions(allStores, "<uid>");
|
|
}
|
|
|
|
if (args.Length == 2 && NetEntity.TryParse(args[0], out var uidNet) && TryGetEntity(uidNet, out var uid))
|
|
{
|
|
if (TryComp<StoreComponent>(uid, out var store))
|
|
return CompletionResult.FromHintOptions(store.CurrencyWhitelist.Select(p => p.ToString()), "<currency prototype>");
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|