2021-02-12 04:35:56 +01:00
|
|
|
|
using System;
|
2021-02-14 13:34:02 +01:00
|
|
|
|
using Content.Server.Commands;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
using Content.Server.GameObjects.Components.Mobs;
|
|
|
|
|
|
using Content.Server.Players;
|
|
|
|
|
|
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-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-02-12 04:35:56 +01:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
2021-02-16 09:51:27 +01:00
|
|
|
|
namespace Content.Server.GameObjects.Components.Observer.GhostRoles
|
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))]
|
|
|
|
|
|
public class GhostRoleMobSpawnerComponent : GhostRoleComponent
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "GhostRoleMobSpawner";
|
|
|
|
|
|
|
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("makeSentient")]
|
2021-02-14 13:34:02 +01:00
|
|
|
|
private bool _makeSentient = 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)]
|
|
|
|
|
|
[DataField("prototype")]
|
|
|
|
|
|
public string Prototype { get; private set; }
|
2021-02-12 04:35:56 +01:00
|
|
|
|
|
|
|
|
|
|
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 = Owner.EntityManager.SpawnEntity(Prototype, Owner.Transform.Coordinates);
|
|
|
|
|
|
|
2021-02-14 13:34:02 +01:00
|
|
|
|
if(_makeSentient)
|
|
|
|
|
|
MakeSentientCommand.MakeSentient(mob);
|
|
|
|
|
|
|
2021-02-12 04:35:56 +01:00
|
|
|
|
mob.EnsureComponent<MindComponent>();
|
2021-02-14 13:34:02 +01:00
|
|
|
|
|
2021-02-12 04:35:56 +01:00
|
|
|
|
session.ContentData().Mind.TransferTo(mob);
|
|
|
|
|
|
|
|
|
|
|
|
if (++_currentTakeovers < _availableTakeovers) return true;
|
|
|
|
|
|
|
|
|
|
|
|
Taken = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (_deleteOnSpawn)
|
|
|
|
|
|
Owner.Delete();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|