Add setoutfit command (#2874)
* Add setoutfit command * Adds setoutfit as a verb and adds a proper UI to the command * Removes from AdminMenuWindow * Changes the SetOutfit verb to be a component verb instead of a global verb * Addresses reviews * Remove empty method * Remove on server aswell
This commit is contained in:
85
Content.Server/Administration/Commands/SetOutfitCommand.cs
Normal file
85
Content.Server/Administration/Commands/SetOutfitCommand.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
class SetOutfitCommand : IClientCommand
|
||||
{
|
||||
public string Command => "setoutfit";
|
||||
|
||||
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 void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Wrong number of arguments."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var entityUid))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("EntityUid must be a number."));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var eUid = new EntityUid(entityUid);
|
||||
|
||||
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Invalid entity ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = entityManager.GetEntity(eUid);
|
||||
|
||||
if (!target.TryGetComponent<InventoryComponent>(out var inventoryComponent))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Target entity does not have an inventory!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
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.SendText(player, Loc.GetString("Invalid outfit id"));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var slot in inventoryComponent.Slots)
|
||||
{
|
||||
inventoryComponent.ForceUnequip(slot);
|
||||
var gearStr = startingGear.GetGear(slot, null);
|
||||
if (gearStr != "")
|
||||
{
|
||||
var equipmentEntity = entityManager.SpawnEntity(gearStr, target.Transform.Coordinates);
|
||||
inventoryComponent.Equip(slot, equipmentEntity.GetComponent<ItemComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Commands;
|
||||
using Content.Server.GameObjects.Components.Items.Clothing;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.EntitySystems.Click;
|
||||
@@ -9,8 +10,13 @@ using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
@@ -32,8 +38,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private readonly Dictionary<Slots, ContainerSlot> _slotContainers = new();
|
||||
[ViewVariables] private readonly Dictionary<Slots, ContainerSlot> _slotContainers = new();
|
||||
|
||||
private KeyValuePair<Slots, (EntityUid entity, bool fits)>? _hoverEntity;
|
||||
|
||||
@@ -102,7 +107,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
bool IEffectBlocker.CanSlip()
|
||||
{
|
||||
if(Owner.TryGetComponent(out InventoryComponent inventoryComponent) &&
|
||||
if (Owner.TryGetComponent(out InventoryComponent inventoryComponent) &&
|
||||
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes)
|
||||
)
|
||||
{
|
||||
@@ -273,9 +278,11 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return pass && _slotContainers[slot].CanInsert(item.Owner);
|
||||
}
|
||||
|
||||
public bool CanEquip(Slots slot, ItemComponent item, bool mobCheck = true) => CanEquip(slot, item, mobCheck, out var _);
|
||||
public bool CanEquip(Slots slot, ItemComponent item, bool mobCheck = true) =>
|
||||
CanEquip(slot, item, mobCheck, out var _);
|
||||
|
||||
public bool CanEquip(Slots slot, IEntity entity, bool mobCheck = true) => CanEquip(slot, entity.GetComponent<ItemComponent>(), mobCheck);
|
||||
public bool CanEquip(Slots slot, IEntity entity, bool mobCheck = true) =>
|
||||
CanEquip(slot, entity.GetComponent<ItemComponent>(), mobCheck);
|
||||
|
||||
/// <summary>
|
||||
/// Drops the item in a slot.
|
||||
@@ -466,14 +473,15 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
if (activeHand != null)
|
||||
{
|
||||
await interactionSystem.Interaction(Owner, activeHand.Owner, itemContainedInSlot.Owner,
|
||||
new EntityCoordinates());
|
||||
await interactionSystem.Interaction(Owner, activeHand.Owner, itemContainedInSlot.Owner,
|
||||
new EntityCoordinates());
|
||||
}
|
||||
else if (Unequip(msg.Inventoryslot))
|
||||
{
|
||||
hands.PutInHand(itemContainedInSlot);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ClientInventoryUpdate.Hover:
|
||||
@@ -590,5 +598,45 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class SetOutfitVerb : Verb<InventoryComponent>
|
||||
{
|
||||
public override bool RequireInteractionRange => false;
|
||||
public override bool BlockedByContainers => false;
|
||||
|
||||
protected override void GetData(IEntity user, InventoryComponent component, VerbData data)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
if (!CanCommand(user))
|
||||
return;
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Set Outfit");
|
||||
data.CategoryData = VerbCategories.Debug;
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, InventoryComponent component)
|
||||
{
|
||||
if (!CanCommand(user))
|
||||
return;
|
||||
|
||||
var target = component.Owner;
|
||||
|
||||
var entityId = target.Uid.ToString();
|
||||
|
||||
var command = new SetOutfitCommand();
|
||||
var shell = IoCManager.Resolve<IConsoleShell>();
|
||||
var args = new string[] {entityId};
|
||||
command.Execute(shell, user.PlayerSession(), args);
|
||||
}
|
||||
|
||||
private static bool CanCommand(IEntity user)
|
||||
{
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
return user.TryGetComponent<IActorComponent>(out var player) &&
|
||||
groupController.CanCommand(player.playerSession, "setoutfit");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
Content.Server/SetOutfitEui.cs
Normal file
55
Content.Server/SetOutfitEui.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Database;
|
||||
using Content.Server.Eui;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Eui;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.IoC;
|
||||
using System;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
|
||||
namespace Content.Server
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SetOutfitEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
private readonly IEntity _target;
|
||||
public SetOutfitEui(IEntity entity)
|
||||
{
|
||||
_target = entity;
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
|
||||
StateDirty();
|
||||
_adminManager.OnPermsChanged += AdminManagerOnPermsChanged;
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
return new SetOutfitEuiState
|
||||
{
|
||||
TargetEntityId = _target.Uid
|
||||
};
|
||||
}
|
||||
|
||||
private void AdminManagerOnPermsChanged(AdminPermsChangedEventArgs obj)
|
||||
{
|
||||
// Close UI if user loses +FUN.
|
||||
if (obj.Player == Player && !UserAdminFlagCheck(AdminFlags.Fun))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
private bool UserAdminFlagCheck(AdminFlags flags)
|
||||
{
|
||||
return _adminManager.HasAdminFlag(Player, flags);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user