Add make ghost role verb (#3204)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Observer
|
||||
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class GhostRolesEntry : VBoxContainer
|
||||
@@ -1,9 +1,10 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Observer
|
||||
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class GhostRolesEui : BaseEui
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Observer
|
||||
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class GhostRolesWindow : SS14Window
|
||||
@@ -0,0 +1,76 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class MakeGhostRoleEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
|
||||
private readonly MakeGhostRoleWindow _window;
|
||||
|
||||
public MakeGhostRoleEui()
|
||||
{
|
||||
_window = new MakeGhostRoleWindow();
|
||||
|
||||
_window.OnClose += OnClose;
|
||||
_window.OnMake += OnMake;
|
||||
}
|
||||
|
||||
public override void HandleState(EuiStateBase state)
|
||||
{
|
||||
if (state is not MakeGhostRoleEuiState uiState)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_window.SetEntity(uiState.EntityUid);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
private void OnMake(EntityUid uid, string name, string description, bool makeSentient)
|
||||
{
|
||||
var player = _playerManager.LocalPlayer;
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var makeGhostRoleCommand =
|
||||
$"makeghostrole " +
|
||||
$"\"{CommandParsing.Escape(uid.ToString())}\" " +
|
||||
$"\"{CommandParsing.Escape(name)}\" " +
|
||||
$"\"{CommandParsing.Escape(description)}\"";
|
||||
|
||||
_consoleHost.ExecuteCommand(player.Session, makeGhostRoleCommand);
|
||||
|
||||
if (makeSentient)
|
||||
{
|
||||
var makeSentientCommand = $"makesentient \"{CommandParsing.Escape(uid.ToString())}\"";
|
||||
_consoleHost.ExecuteCommand(player.Session, makeSentientCommand);
|
||||
}
|
||||
|
||||
_window.Close();
|
||||
}
|
||||
|
||||
private void OnClose()
|
||||
{
|
||||
base.Closed();
|
||||
SendMessage(new MakeGhostRoleWindowClosedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<cc:SS14Window Title="Make Ghost Role"
|
||||
xmlns:cc="clr-namespace:Robust.Client.UserInterface.CustomControls;assembly=Robust.Client"
|
||||
xmlns:c="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client">
|
||||
|
||||
<c:VBoxContainer>
|
||||
<c:HBoxContainer>
|
||||
<c:Label Name="RoleEntityLabel" Text="Entity" />
|
||||
<c:Label Name="RoleEntity" Text="" />
|
||||
</c:HBoxContainer>
|
||||
<c:HBoxContainer>
|
||||
<c:Label Name="RoleNameLabel" Text="Role Name" />
|
||||
<c:LineEdit Name="RoleName" SizeFlagsHorizontal="FillExpand"/>
|
||||
</c:HBoxContainer>
|
||||
<c:HBoxContainer>
|
||||
<c:Label Name="RoleDescriptionLabel" Text="Role Description" />
|
||||
<c:LineEdit Name="RoleDescription" SizeFlagsHorizontal="FillExpand"/>
|
||||
</c:HBoxContainer>
|
||||
<c:HBoxContainer>
|
||||
<c:Label Name="MakeSentientLabel" Text="Make Sentient" />
|
||||
<c:CheckBox Name="MakeSentientCheckbox" />
|
||||
</c:HBoxContainer>
|
||||
<c:HBoxContainer>
|
||||
<c:Button Name="MakeButton" Text="Make" />
|
||||
</c:HBoxContainer>
|
||||
</c:VBoxContainer>
|
||||
|
||||
</cc:SS14Window>
|
||||
@@ -0,0 +1,49 @@
|
||||
#nullable enable
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class MakeGhostRoleWindow : SS14Window
|
||||
{
|
||||
public delegate void MakeRole(EntityUid uid, string name, string description, bool makeSentient);
|
||||
|
||||
public MakeGhostRoleWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
MakeSentientLabel.CustomMinimumSize = (150, 0);
|
||||
RoleEntityLabel.CustomMinimumSize = (150, 0);
|
||||
RoleNameLabel.CustomMinimumSize = (150, 0);
|
||||
RoleName.CustomMinimumSize = (300, 0);
|
||||
RoleDescriptionLabel.CustomMinimumSize = (150, 0);
|
||||
RoleDescription.CustomMinimumSize = (300, 0);
|
||||
|
||||
MakeButton.OnPressed += OnPressed;
|
||||
}
|
||||
|
||||
private EntityUid? EntityUid { get; set; }
|
||||
|
||||
public event MakeRole? OnMake;
|
||||
|
||||
public void SetEntity(EntityUid uid)
|
||||
{
|
||||
EntityUid = uid;
|
||||
RoleEntity.Text = $"{uid}";
|
||||
}
|
||||
|
||||
private void OnPressed(ButtonEventArgs args)
|
||||
{
|
||||
if (EntityUid == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnMake?.Invoke(EntityUid.Value, RoleName.Text, RoleDescription.Text, MakeSentientCheckbox.Pressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Content.Server/Commands/GhostRoles/MakeGhostRoleCommand.cs
Normal file
63
Content.Server/Commands/GhostRoles/MakeGhostRoleCommand.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Observer.GhostRoles;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Commands.GhostRoles
|
||||
{
|
||||
[AdminCommand(AdminFlags.Fun)]
|
||||
public class MakeGhostRoleCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "makeghostrole";
|
||||
public string Description => "Turns an entity into a ghost role.";
|
||||
public string Help => $"Usage: {Command} <entity uid> <name> <description>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 3)
|
||||
{
|
||||
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
if (!EntityUid.TryParse(args[0], out var uid))
|
||||
{
|
||||
shell.WriteLine($"{args[0]} is not a valid entity uid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityManager.TryGetEntity(uid, out var entity))
|
||||
{
|
||||
shell.WriteLine($"No entity found with uid {uid}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out MindComponent? mind) &&
|
||||
mind.HasMind)
|
||||
{
|
||||
shell.WriteLine($"Entity {entity.Name} with id {uid} already has a mind.");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[1];
|
||||
var description = args[2];
|
||||
|
||||
if (entity.EnsureComponent(out GhostTakeoverAvailableComponent takeOver))
|
||||
{
|
||||
shell.WriteLine($"Entity {entity.Name} with id {uid} already has a {nameof(GhostTakeoverAvailableComponent)}");
|
||||
return;
|
||||
}
|
||||
|
||||
takeOver.RoleName = name;
|
||||
takeOver.RoleDescription = description;
|
||||
|
||||
shell.WriteLine($"Made entity {entity.Name} a ghost role.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
public abstract class GhostRoleComponent : Component
|
||||
{
|
||||
@@ -16,11 +16,8 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string RoleName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _roleName;
|
||||
}
|
||||
private set
|
||||
get => _roleName;
|
||||
set
|
||||
{
|
||||
_roleName = value;
|
||||
EntitySystem.Get<GhostRoleSystem>().UpdateAllEui();
|
||||
@@ -30,11 +27,8 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string RoleDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return _roleDescription;
|
||||
}
|
||||
private set
|
||||
get => _roleDescription;
|
||||
set
|
||||
{
|
||||
_roleDescription = value;
|
||||
EntitySystem.Get<GhostRoleSystem>().UpdateAllEui();
|
||||
@@ -8,7 +8,7 @@ using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows a ghost to take this role, spawning a new entity.
|
||||
@@ -1,10 +1,10 @@
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
public class GhostRolesEui : BaseEui
|
||||
{
|
||||
@@ -5,7 +5,7 @@ using Content.Server.Players;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows a ghost to take over the Owner entity.
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
public class MakeGhostRoleEui : BaseEui
|
||||
{
|
||||
public MakeGhostRoleEui(EntityUid entityUid)
|
||||
{
|
||||
EntityUid = entityUid;
|
||||
}
|
||||
|
||||
public EntityUid EntityUid { get; }
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
return new MakeGhostRoleEuiState(EntityUid);
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
{
|
||||
base.HandleMessage(msg);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case MakeGhostRoleWindowClosedMessage _:
|
||||
Closed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Closed()
|
||||
{
|
||||
base.Closed();
|
||||
|
||||
EntitySystem.Get<GhostRoleSystem>().CloseMakeGhostRoleEui(Player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ using System.Collections.Generic;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Eui;
|
||||
using Content.Server.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Server.GameObjects.Components.Observer.GhostRoles;
|
||||
using Content.Shared.GameObjects.Components.Observer.GhostRoles;
|
||||
using Content.Shared.GameTicking;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -22,6 +23,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
private uint _nextRoleIdentifier = 0;
|
||||
private readonly Dictionary<uint, GhostRoleComponent> _ghostRoles = new();
|
||||
private readonly Dictionary<IPlayerSession, GhostRolesEui> _openUis = new();
|
||||
private readonly Dictionary<IPlayerSession, MakeGhostRoleEui> _openMakeGhostRoleUis = new();
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyCollection<GhostRoleComponent> GhostRoles => _ghostRoles.Values;
|
||||
@@ -49,6 +51,19 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
eui.StateDirty();
|
||||
}
|
||||
|
||||
public void OpenMakeGhostRoleEui(IPlayerSession session, EntityUid uid)
|
||||
{
|
||||
if (session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
if (_openMakeGhostRoleUis.ContainsKey(session))
|
||||
CloseEui(session);
|
||||
|
||||
var eui = _openMakeGhostRoleUis[session] = new MakeGhostRoleEui(uid);
|
||||
_euiManager.OpenEui(eui, session);
|
||||
eui.StateDirty();
|
||||
}
|
||||
|
||||
public void CloseEui(IPlayerSession session)
|
||||
{
|
||||
if (!_openUis.ContainsKey(session)) return;
|
||||
@@ -58,6 +73,14 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
eui?.Close();
|
||||
}
|
||||
|
||||
public void CloseMakeGhostRoleEui(IPlayerSession session)
|
||||
{
|
||||
if (_openMakeGhostRoleUis.Remove(session, out var eui))
|
||||
{
|
||||
eui?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAllEui()
|
||||
{
|
||||
foreach (var eui in _openUis.Values)
|
||||
|
||||
62
Content.Server/GlobalVerbs/MakeGhostRoleVerb.cs
Normal file
62
Content.Server/GlobalVerbs/MakeGhostRoleVerb.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.GlobalVerbs
|
||||
{
|
||||
[GlobalVerb]
|
||||
public class MakeGhostRoleVerb : GlobalVerb
|
||||
{
|
||||
public override bool RequireInteractionRange => false;
|
||||
public override bool BlockedByContainers => false;
|
||||
|
||||
public override void GetData(IEntity user, IEntity target, VerbData data)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
|
||||
if (target.TryGetComponent(out MindComponent? mind) &&
|
||||
mind.HasMind)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out IActorComponent? actor) ||
|
||||
!groupController.CanCommand(actor.playerSession, "makeghostrole"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
data.Visibility = VerbVisibility.Visible;
|
||||
data.Text = Loc.GetString("Make Ghost Role");
|
||||
data.CategoryData = VerbCategories.Debug;
|
||||
}
|
||||
|
||||
public override void Activate(IEntity user, IEntity target)
|
||||
{
|
||||
var groupController = IoCManager.Resolve<IConGroupController>();
|
||||
|
||||
if (target.TryGetComponent(out MindComponent? mind) &&
|
||||
mind.HasMind)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.TryGetComponent(out IActorComponent? actor) ||
|
||||
!groupController.CanCommand(actor.playerSession, "makeghostrole"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var ghostRoleSystem = EntitySystem.Get<GhostRoleSystem>();
|
||||
ghostRoleSystem.OpenMakeGhostRoleEui(actor.playerSession, target.Uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Observer
|
||||
namespace Content.Shared.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[NetSerializable, Serializable]
|
||||
public struct GhostRoleInfo
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class MakeGhostRoleEuiState : EuiStateBase
|
||||
{
|
||||
public MakeGhostRoleEuiState(EntityUid entityUid)
|
||||
{
|
||||
EntityUid = entityUid;
|
||||
}
|
||||
|
||||
public EntityUid EntityUid { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Observer.GhostRoles
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class MakeGhostRoleWindowClosedMessage : EuiMessageBase
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user