* some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable™️ * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge™️ * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using Content.Server.Administration.UI;
|
|
using Content.Server.EUI;
|
|
using Content.Server.Preferences.Managers;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.PDA;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Roles;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Prototypes;
|
|
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
|
|
|
|
namespace Content.Server.Administration.Commands
|
|
{
|
|
[AdminCommand(AdminFlags.Admin)]
|
|
class SetOutfitCommand : IConsoleCommand
|
|
{
|
|
public string Command => "setoutfit";
|
|
|
|
public string Description => Loc.GetString("set-outfit-command-description", ("requiredComponent", nameof(InventoryComponent)));
|
|
|
|
public string Help => Loc.GetString("set-outfit-command-help-text", ("command",Command));
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length < 1)
|
|
{
|
|
shell.WriteLine(Loc.GetString("shell-wrong-arguments-number"));
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args[0], out var entityUid))
|
|
{
|
|
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
|
return;
|
|
}
|
|
|
|
var entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
var target = new EntityUid(entityUid);
|
|
|
|
if (!target.IsValid() || !entityManager.EntityExists(target))
|
|
{
|
|
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
|
return;
|
|
}
|
|
|
|
if (!entityManager.TryGetComponent<InventoryComponent?>(target, out var inventoryComponent))
|
|
{
|
|
shell.WriteLine(Loc.GetString("shell-target-entity-does-not-have-message",("missing", "inventory")));
|
|
return;
|
|
}
|
|
|
|
if (args.Length == 1)
|
|
{
|
|
if (shell.Player is not IPlayerSession player)
|
|
{
|
|
shell.WriteError(Loc.GetString("set-outfit-command-is-not-player-error"));
|
|
return;
|
|
}
|
|
|
|
var eui = IoCManager.Resolve<EuiManager>();
|
|
var ui = new SetOutfitEui(target);
|
|
eui.OpenEui(ui, player);
|
|
return;
|
|
}
|
|
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
|
if (!prototypeManager.TryIndex<StartingGearPrototype>(args[1], out var startingGear))
|
|
{
|
|
shell.WriteLine(Loc.GetString("set-outfit-command-invalid-outfit-id-error"));
|
|
return;
|
|
}
|
|
|
|
HumanoidCharacterProfile? profile = null;
|
|
// Check if we are setting the outfit of a player to respect the preferences
|
|
if (entityManager.TryGetComponent<ActorComponent?>(target, out var actorComponent))
|
|
{
|
|
var userId = actorComponent.PlayerSession.UserId;
|
|
var preferencesManager = IoCManager.Resolve<IServerPreferencesManager>();
|
|
var prefs = preferencesManager.GetPreferences(userId);
|
|
profile = prefs.SelectedCharacter as HumanoidCharacterProfile;
|
|
}
|
|
|
|
var invSystem = EntitySystem.Get<InventorySystem>();
|
|
if (invSystem.TryGetSlots(target, out var slotDefinitions, inventoryComponent))
|
|
{
|
|
foreach (var slot in slotDefinitions)
|
|
{
|
|
invSystem.TryUnequip(target, slot.Name, true, true, inventoryComponent);
|
|
var gearStr = startingGear.GetGear(slot.Name, profile);
|
|
if (gearStr == string.Empty)
|
|
{
|
|
continue;
|
|
}
|
|
var equipmentEntity = entityManager.SpawnEntity(gearStr, entityManager.GetComponent<TransformComponent>(target).Coordinates);
|
|
if (slot.Name == "id" &&
|
|
entityManager.TryGetComponent<PDAComponent?>(equipmentEntity, out var pdaComponent) &&
|
|
pdaComponent.ContainedID != null)
|
|
{
|
|
pdaComponent.ContainedID.FullName = entityManager.GetComponent<MetaDataComponent>(target).EntityName;
|
|
}
|
|
|
|
invSystem.TryEquip(target, equipmentEntity, slot.Name, true, inventory: inventoryComponent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|