Files
tbd-station-14/Content.Server/Traitor/Uplink/Commands/AddUplinkCommand.cs
Alex Evgrashin e5df8dbee3 Moving PDA to ECS (#4538)
* Moved pen slot to separate component

* Moved it all to more generic item slot class

* Add sounds

* Item slots now supports many slots

* Some clean-up

* Refactored slots a bit

* Moving ID card out

* Moving pda to system

* Moving PDA owner to ECS

* Moved PDA flashlight to separate component

* Toggle lights work through events

* Fixing UI

* Moving uplink to separate component

* Continue moving uplink to separate component

* More cleaning

* Removing pda shared

* Nuked shared pda component

* Fixed flashlight

* Pen slot now showed in UI

* Light toggle now shows correctly in UI

* Small refactoring of item slots

* Added contained entity

* Fixed tests

* Finished with PDA

* Moving PDA uplink to separate window

* Adding-removing uplink should show new button

* Working on a better debug

* Debug command to add uplink

* Uplink send state to UI

* Almost working UI

* Uplink correcty updates when you buy-sell items

* Ups

* Moved localization to separate file

* Minor fixes

* Removed item slots methods events

* Removed PDA owner name

* Removed one uplink event

* Deleted all uplink events

* Removed flashlight events

* Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Item slots system review

* Flashlight review

* PDA to XAML

* Move UplinkMenu to seperate class, fix WeightedColors methods

* Move UI to XAML

* Moved events to entity id

* Address review

* Removed uplink extensions

* Minor fix

* Moved item slots to shared

* My bad Robust...

* Fixed pda sound

* Fixed pda tests

* Fixed pda test again

Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Visne <vincefvanwijk@gmail.com>
2021-10-03 15:05:52 +11:00

94 lines
3.3 KiB
C#

using Content.Server.Administration;
using Content.Server.PDA.Managers;
using Content.Server.Traitor.Uplink.Components;
using Content.Server.Traitor.Uplink.Systems;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Traitor.Uplink;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Traitor.Uplink.Commands
{
[AdminCommand(AdminFlags.Fun)]
public class AddUplinkCommand : IConsoleCommand
{
public string Command => "adduplink";
public string Description => "Creates uplink on selected item and link it to users account";
public string Help => "Usage: adduplink <username> <item-id>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
// Get player entity
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[0], out var session))
{
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return;
}
if (session.AttachedEntity == null)
{
shell.WriteLine(Loc.GetString("Selected player doesn't controll any entity"));
return;
}
var user = session.AttachedEntity;
// Get target item
IEntity? uplinkEntity = null;
var entityManager = IoCManager.Resolve<IEntityManager>();
if (args.Length >= 2)
{
if (!int.TryParse(args[1], out var itemID))
{
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
var eUid = new EntityUid(itemID);
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
{
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
return;
}
uplinkEntity = entityManager.GetEntity(eUid);
}
// Get TC count
var configManager = IoCManager.Resolve<IConfigurationManager>();
var tcCount = configManager.GetCVar(CCVars.TraitorStartingBalance);
// Get account
var uplinkManager = IoCManager.Resolve<IUplinkManager>();
if (!uplinkManager.TryGetAccount(user.Uid, out UplinkAccount? uplinkAccount))
{
uplinkAccount = new UplinkAccount(user.Uid, tcCount);
if (!uplinkManager.AddNewAccount(uplinkAccount))
{
shell.WriteLine(Loc.GetString("Can't create new uplink account"));
return;
}
}
// Finally add uplink
if (!entityManager.EntitySysManager.GetEntitySystem<UplinkSystem>()
.AddUplink(user, uplinkAccount!, uplinkEntity))
{
shell.WriteLine(Loc.GetString("Failed to add uplink to the player"));
return;
}
}
}
}