2021-02-12 04:35:56 +01:00
|
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.Mind.Commands;
|
|
|
|
|
|
using Content.Server.Mind.Components;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-12 10:45:22 +01:00
|
|
|
|
using Robust.Server.Player;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 11:11:52 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
2022-01-11 14:12:19 +11:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2022-01-11 14:12:19 +11:00
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Ghost.Roles.Components
|
2021-02-12 04:35:56 +01:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Allows a ghost to take this role, spawning a new entity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[RegisterComponent, ComponentReference(typeof(GhostRoleComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class GhostRoleMobSpawnerComponent : GhostRoleComponent
|
2021-02-12 04:35:56 +01:00
|
|
|
|
{
|
2021-12-08 17:17:12 +01:00
|
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("deleteOnSpawn")]
|
2021-02-12 04:35:56 +01:00
|
|
|
|
private bool _deleteOnSpawn = true;
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("availableTakeovers")]
|
2021-02-12 04:35:56 +01:00
|
|
|
|
private int _availableTakeovers = 1;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
private int _currentTakeovers = 0;
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[CanBeNull]
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2022-01-11 14:12:19 +11:00
|
|
|
|
[DataField("prototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
2021-03-16 15:50:20 +01:00
|
|
|
|
public string? Prototype { get; private set; }
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
public override bool Take(IPlayerSession session)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Taken)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2021-12-03 20:31:14 +11:00
|
|
|
|
if (string.IsNullOrEmpty(Prototype))
|
2021-02-12 04:35:56 +01:00
|
|
|
|
throw new NullReferenceException("Prototype string cannot be null or empty!");
|
|
|
|
|
|
|
2021-12-08 17:17:12 +01:00
|
|
|
|
var mob = _entMan.SpawnEntity(Prototype, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
2021-12-03 20:31:14 +11:00
|
|
|
|
if (MakeSentient)
|
2021-12-08 17:17:12 +01:00
|
|
|
|
MakeSentientCommand.MakeSentient(mob, _entMan);
|
2021-02-14 13:34:02 +01:00
|
|
|
|
|
2021-02-12 04:35:56 +01:00
|
|
|
|
mob.EnsureComponent<MindComponent>();
|
2021-02-14 13:34:02 +01:00
|
|
|
|
|
2021-11-15 18:14:34 +00:00
|
|
|
|
var ghostRoleSystem = EntitySystem.Get<GhostRoleSystem>();
|
2021-12-07 21:54:00 +11:00
|
|
|
|
ghostRoleSystem.GhostRoleInternalCreateMindAndTransfer(session, Owner, mob, this);
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
2021-10-23 10:56:37 +02:00
|
|
|
|
if (++_currentTakeovers < _availableTakeovers)
|
|
|
|
|
|
return true;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
Taken = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (_deleteOnSpawn)
|
2021-12-08 17:17:12 +01:00
|
|
|
|
_entMan.DeleteEntity(Owner);
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|