Add make ghost role verb (#3204)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user