Remove ghost role component references (#15262)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using Content.Server.Mind.Commands;
|
||||
using Robust.Server.Player;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[Access(typeof(GhostRoleSystem))]
|
||||
public abstract class GhostRoleComponent : Component
|
||||
public sealed class GhostRoleComponent : Component
|
||||
{
|
||||
[DataField("name")] public string _roleName = "Unknown";
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
/// Whether the <see cref="MakeSentientCommand"/> should run on the mob.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("makeSentient")]
|
||||
protected bool MakeSentient = true;
|
||||
public bool MakeSentient = true;
|
||||
|
||||
/// <summary>
|
||||
/// The probability that this ghost role will be available after init.
|
||||
@@ -83,7 +83,5 @@ namespace Content.Server.Ghost.Roles.Components
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("reregister")]
|
||||
public bool ReregisterOnGhost { get; set; } = true;
|
||||
|
||||
public abstract bool Take(IPlayerSession session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,26 @@
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Content.Server.Ghost.Roles.Events;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows a ghost to take this role, spawning a new entity.
|
||||
/// </summary>
|
||||
[RegisterComponent, ComponentReference(typeof(GhostRoleComponent))]
|
||||
public sealed class GhostRoleMobSpawnerComponent : GhostRoleComponent
|
||||
[RegisterComponent]
|
||||
[Access(typeof(GhostRoleSystem))]
|
||||
public sealed class GhostRoleMobSpawnerComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("deleteOnSpawn")]
|
||||
private bool _deleteOnSpawn = true;
|
||||
public bool DeleteOnSpawn = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("availableTakeovers")]
|
||||
private int _availableTakeovers = 1;
|
||||
public int AvailableTakeovers = 1;
|
||||
|
||||
[ViewVariables]
|
||||
private int _currentTakeovers = 0;
|
||||
public int CurrentTakeovers = 0;
|
||||
|
||||
[CanBeNull]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? Prototype { get; private set; }
|
||||
|
||||
public override bool Take(IPlayerSession session)
|
||||
{
|
||||
if (Taken)
|
||||
return false;
|
||||
|
||||
if (string.IsNullOrEmpty(Prototype))
|
||||
throw new NullReferenceException("Prototype string cannot be null or empty!");
|
||||
|
||||
var mob = _entMan.SpawnEntity(Prototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
var xform = _entMan.GetComponent<TransformComponent>(mob);
|
||||
xform.AttachToGridOrMap();
|
||||
|
||||
var spawnedEvent = new GhostRoleSpawnerUsedEvent(Owner, mob);
|
||||
_entMan.EventBus.RaiseLocalEvent(mob, spawnedEvent, false);
|
||||
|
||||
if (MakeSentient)
|
||||
MakeSentientCommand.MakeSentient(mob, _entMan, AllowMovement, AllowSpeech);
|
||||
|
||||
mob.EnsureComponent<MindComponent>();
|
||||
|
||||
var ghostRoleSystem = EntitySystem.Get<GhostRoleSystem>();
|
||||
ghostRoleSystem.GhostRoleInternalCreateMindAndTransfer(session, Owner, mob, this);
|
||||
|
||||
if (++_currentTakeovers < _availableTakeovers)
|
||||
return true;
|
||||
|
||||
Taken = true;
|
||||
|
||||
if (_deleteOnSpawn)
|
||||
_entMan.QueueDeleteEntity(Owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,11 @@
|
||||
using Content.Server.Mind.Commands;
|
||||
using Content.Server.Mind.Components;
|
||||
using Robust.Server.Player;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows a ghost to take over the Owner entity.
|
||||
/// </summary>
|
||||
[RegisterComponent, ComponentReference(typeof(GhostRoleComponent))]
|
||||
public sealed class GhostTakeoverAvailableComponent : GhostRoleComponent
|
||||
[RegisterComponent]
|
||||
[Access(typeof(GhostRoleSystem))]
|
||||
public sealed class GhostTakeoverAvailableComponent : Component
|
||||
{
|
||||
public override bool Take(IPlayerSession session)
|
||||
{
|
||||
if (Taken)
|
||||
return false;
|
||||
|
||||
Taken = true;
|
||||
|
||||
var mind = Owner.EnsureComponent<MindComponent>();
|
||||
|
||||
if (mind.HasMind)
|
||||
return false;
|
||||
|
||||
if (MakeSentient)
|
||||
MakeSentientCommand.MakeSentient(Owner, IoCManager.Resolve<IEntityManager>(), AllowMovement, AllowSpeech);
|
||||
|
||||
var ghostRoleSystem = EntitySystem.Get<GhostRoleSystem>();
|
||||
ghostRoleSystem.GhostRoleInternalCreateMindAndTransfer(session, Owner, Owner, this);
|
||||
|
||||
ghostRoleSystem.UnregisterGhostRole(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Robust.Server.Player;
|
||||
|
||||
namespace Content.Server.Ghost.Roles.Components;
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct TakeGhostRoleEvent(IPlayerSession Player)
|
||||
{
|
||||
public bool TookRole { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user