StoreSystem.Command.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Linq;
  2. using Content.Server.Store.Components;
  3. using Content.Shared.FixedPoint;
  4. using Content.Server.Administration;
  5. using Content.Shared.Administration;
  6. using Content.Shared.Store.Components;
  7. using Robust.Shared.Console;
  8. namespace Content.Server.Store.Systems;
  9. public sealed partial class StoreSystem
  10. {
  11. [Dependency] private readonly IConsoleHost _consoleHost = default!;
  12. public void InitializeCommand()
  13. {
  14. _consoleHost.RegisterCommand("addcurrency", "Adds currency to the specified store", "addcurrency <uid> <currency prototype> <amount>",
  15. AddCurrencyCommand,
  16. AddCurrencyCommandCompletions);
  17. }
  18. [AdminCommand(AdminFlags.Fun)]
  19. private void AddCurrencyCommand(IConsoleShell shell, string argstr, string[] args)
  20. {
  21. if (args.Length != 3)
  22. {
  23. shell.WriteError("Argument length must be 3");
  24. return;
  25. }
  26. if (!NetEntity.TryParse(args[0], out var uidNet) || !TryGetEntity(uidNet, out var uid) || !float.TryParse(args[2], out var id))
  27. {
  28. return;
  29. }
  30. if (!TryComp<StoreComponent>(uid, out var store))
  31. return;
  32. var currency = new Dictionary<string, FixedPoint2>
  33. {
  34. { args[1], id }
  35. };
  36. TryAddCurrency(currency, uid.Value, store);
  37. }
  38. private CompletionResult AddCurrencyCommandCompletions(IConsoleShell shell, string[] args)
  39. {
  40. if (args.Length == 1)
  41. {
  42. var query = EntityQueryEnumerator<StoreComponent>();
  43. var allStores = new List<string>();
  44. while (query.MoveNext(out var storeuid, out _))
  45. {
  46. allStores.Add(storeuid.ToString());
  47. }
  48. return CompletionResult.FromHintOptions(allStores, "<uid>");
  49. }
  50. if (args.Length == 2 && NetEntity.TryParse(args[0], out var uidNet) && TryGetEntity(uidNet, out var uid))
  51. {
  52. if (TryComp<StoreComponent>(uid, out var store))
  53. return CompletionResult.FromHintOptions(store.CurrencyWhitelist.Select(p => p.ToString()), "<currency prototype>");
  54. }
  55. return CompletionResult.Empty;
  56. }
  57. }