Fix outfit command not respecting preferences and not filling id's name (#3198)

This commit is contained in:
Leo
2021-02-14 11:39:53 -03:00
committed by GitHub
parent a8e9bf0488
commit ad611755dc

View File

@@ -1,8 +1,15 @@
#nullable enable
using Content.Server.Eui; using Content.Server.Eui;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.PDA;
using Content.Server.Interfaces;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.Preferences;
using Content.Shared.Roles; using Content.Shared.Roles;
using NFluidsynth;
using Robust.Server.GameObjects;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Console; using Robust.Shared.Console;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -17,7 +24,8 @@ namespace Content.Server.Administration.Commands
{ {
public string Command => "setoutfit"; public string Command => "setoutfit";
public string Description => Loc.GetString("Sets the outfit of the specified entity. The entity must have an InventoryComponent"); public string Description =>
Loc.GetString("Sets the outfit of the specified entity. The entity must have an InventoryComponent");
public string Help => Loc.GetString("Usage: {0} <entityUid> | {0} <entityUid> <outfitId>", Command); public string Help => Loc.GetString("Usage: {0} <entityUid> | {0} <entityUid> <outfitId>", Command);
@@ -55,9 +63,16 @@ namespace Content.Server.Administration.Commands
if (args.Length == 1) if (args.Length == 1)
{ {
if (!(shell.Player is IPlayerSession player))
{
shell.WriteError(
Loc.GetString(
"This does not work from the server console. You must pass the outfit id aswell."));
return;
}
var eui = IoCManager.Resolve<EuiManager>(); var eui = IoCManager.Resolve<EuiManager>();
var ui = new SetOutfitEui(target); var ui = new SetOutfitEui(target);
var player = shell.Player as IPlayerSession;
eui.OpenEui(ui, player); eui.OpenEui(ui, player);
return; return;
} }
@@ -69,17 +84,31 @@ namespace Content.Server.Administration.Commands
return; return;
} }
HumanoidCharacterProfile? profile = null;
// Check if we are setting the outfit of a player to respect the preferences
if (target.TryGetComponent<IActorComponent>(out var actorComponent))
{
var userId = actorComponent.playerSession.UserId;
var preferencesManager = IoCManager.Resolve<IServerPreferencesManager>();
var prefs = preferencesManager.GetPreferences(userId);
profile = prefs.SelectedCharacter as HumanoidCharacterProfile;
}
foreach (var slot in inventoryComponent.Slots) foreach (var slot in inventoryComponent.Slots)
{ {
inventoryComponent.ForceUnequip(slot); inventoryComponent.ForceUnequip(slot);
var gearStr = startingGear.GetGear(slot, null); var gearStr = startingGear.GetGear(slot, profile);
if (gearStr != "") if (gearStr == "") continue;
{
var equipmentEntity = entityManager.SpawnEntity(gearStr, target.Transform.Coordinates); var equipmentEntity = entityManager.SpawnEntity(gearStr, target.Transform.Coordinates);
if (slot == EquipmentSlotDefines.Slots.IDCARD &&
equipmentEntity.TryGetComponent<PDAComponent>(out var pdaComponent) &&
pdaComponent.ContainedID != null)
{
pdaComponent.ContainedID.FullName = target.Name;
}
inventoryComponent.Equip(slot, equipmentEntity.GetComponent<ItemComponent>(), false); inventoryComponent.Equip(slot, equipmentEntity.GetComponent<ItemComponent>(), false);
} }
} }
}
} }
} }