@@ -1,16 +1,19 @@
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.Eui;
|
||||
using Content.Server.Cloning.Systems;
|
||||
|
||||
namespace Content.Server.Cloning
|
||||
{
|
||||
public sealed class AcceptCloningEui : BaseEui
|
||||
{
|
||||
private readonly CloningSystem _cloningSystem;
|
||||
private readonly Mind.Mind _mind;
|
||||
|
||||
public AcceptCloningEui(Mind.Mind mind)
|
||||
public AcceptCloningEui(Mind.Mind mind, CloningSystem cloningSys)
|
||||
{
|
||||
_mind = mind;
|
||||
_cloningSystem = cloningSys;
|
||||
}
|
||||
|
||||
public override void HandleMessage(EuiMessageBase msg)
|
||||
@@ -18,14 +21,13 @@ namespace Content.Server.Cloning
|
||||
base.HandleMessage(msg);
|
||||
|
||||
if (msg is not AcceptCloningChoiceMessage choice ||
|
||||
choice.Button == AcceptCloningUiButton.Deny ||
|
||||
!EntitySystem.TryGet<CloningSystem>(out var cloningSystem))
|
||||
choice.Button == AcceptCloningUiButton.Deny)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
cloningSystem.TransferMindToClone(_mind);
|
||||
_cloningSystem.TransferMindToClone(_mind);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
249
Content.Server/Cloning/CloningConsoleSystem.cs
Normal file
249
Content.Server/Cloning/CloningConsoleSystem.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Timing;
|
||||
using Content.Server.Medical.Components;
|
||||
using Content.Server.Cloning.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.MachineLinking.System;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Server.MobState;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Content.Shared.Cloning.CloningConsole;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.MachineLinking.Events;
|
||||
using Content.Shared.IdentityManagement;
|
||||
|
||||
namespace Content.Server.Cloning.Systems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class CloningConsoleSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly CloningSystem _cloningSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<CloningConsoleComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, UiButtonPressedMessage>(OnButtonPressed);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, AfterActivatableUIOpenEvent>(OnUIOpen);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, PowerChangedEvent>(OnPowerChanged);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, NewLinkEvent>(OnNewLink);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, PortDisconnectedEvent>(OnPortDisconnected);
|
||||
SubscribeLocalEvent<CloningConsoleComponent, AnchorStateChangedEvent>(OnAnchorChanged);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, CloningConsoleComponent component, ComponentInit args)
|
||||
{
|
||||
_signalSystem.EnsureTransmitterPorts(uid, CloningConsoleComponent.ScannerPort, CloningConsoleComponent.PodPort);
|
||||
}
|
||||
private void OnButtonPressed(EntityUid uid, CloningConsoleComponent consoleComponent, UiButtonPressedMessage args)
|
||||
{
|
||||
if (!_powerReceiverSystem.IsPowered(uid))
|
||||
return;
|
||||
|
||||
switch (args.Button)
|
||||
{
|
||||
case UiButton.Clone:
|
||||
if (consoleComponent.GeneticScanner != null && consoleComponent.CloningPod != null)
|
||||
TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, consoleComponent: consoleComponent);
|
||||
break;
|
||||
case UiButton.Eject:
|
||||
if (consoleComponent.CloningPod != null)
|
||||
TryEject(uid, consoleComponent.CloningPod.Value, consoleComponent: consoleComponent);
|
||||
break;
|
||||
}
|
||||
UpdateUserInterface(consoleComponent);
|
||||
}
|
||||
|
||||
private void OnPowerChanged(EntityUid uid, CloningConsoleComponent component, PowerChangedEvent args)
|
||||
{
|
||||
UpdateUserInterface(component);
|
||||
}
|
||||
|
||||
private void OnNewLink(EntityUid uid, CloningConsoleComponent component, NewLinkEvent args)
|
||||
{
|
||||
if (TryComp<MedicalScannerComponent>(args.Receiver, out var scanner) && args.TransmitterPort == CloningConsoleComponent.ScannerPort)
|
||||
{
|
||||
component.GeneticScanner = args.Receiver;
|
||||
scanner.ConnectedConsole = uid;
|
||||
}
|
||||
|
||||
if (TryComp<CloningPodComponent>(args.Receiver, out var pod) && args.TransmitterPort == CloningConsoleComponent.PodPort)
|
||||
{
|
||||
component.CloningPod = args.Receiver;
|
||||
pod.ConnectedConsole = uid;
|
||||
}
|
||||
RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component);
|
||||
}
|
||||
|
||||
private void OnPortDisconnected(EntityUid uid, CloningConsoleComponent component, PortDisconnectedEvent args)
|
||||
{
|
||||
if (args.Port == CloningConsoleComponent.ScannerPort)
|
||||
component.GeneticScanner = null;
|
||||
|
||||
if (args.Port == CloningConsoleComponent.PodPort)
|
||||
component.CloningPod = null;
|
||||
|
||||
UpdateUserInterface(component);
|
||||
}
|
||||
|
||||
private void OnUIOpen(EntityUid uid, CloningConsoleComponent component, AfterActivatableUIOpenEvent args)
|
||||
{
|
||||
UpdateUserInterface(component);
|
||||
}
|
||||
|
||||
private void OnAnchorChanged(EntityUid uid, CloningConsoleComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (args.Anchored)
|
||||
{
|
||||
RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component);
|
||||
return;
|
||||
}
|
||||
UpdateUserInterface(component);
|
||||
}
|
||||
|
||||
public void UpdateUserInterface(CloningConsoleComponent consoleComponent)
|
||||
{
|
||||
if (!_powerReceiverSystem.IsPowered(consoleComponent.Owner))
|
||||
{
|
||||
_uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key)?.CloseAll();
|
||||
return;
|
||||
}
|
||||
|
||||
var newState = GetUserInterfaceState(consoleComponent);
|
||||
|
||||
_uiSystem.GetUiOrNull(consoleComponent.Owner, CloningConsoleUiKey.Key)?.SetState(newState);
|
||||
}
|
||||
|
||||
public void TryEject(EntityUid uid, EntityUid clonePodUid, CloningPodComponent? cloningPod = null, CloningConsoleComponent? consoleComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref consoleComponent) || !Resolve(clonePodUid, ref cloningPod))
|
||||
return;
|
||||
|
||||
_cloningSystem.Eject(clonePodUid, cloningPod);
|
||||
}
|
||||
|
||||
public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null)
|
||||
{
|
||||
if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp))
|
||||
return;
|
||||
|
||||
if (!Transform(cloningPodUid).Anchored || !Transform(scannerUid).Anchored)
|
||||
return;
|
||||
|
||||
if (!consoleComponent.CloningPodInRange || !consoleComponent.GeneticScannerInRange)
|
||||
return;
|
||||
|
||||
if (scannerComp.BodyContainer.ContainedEntity is null)
|
||||
return;
|
||||
|
||||
if (!TryComp<MindComponent>(scannerComp.BodyContainer.ContainedEntity.Value, out var mindComp))
|
||||
return;
|
||||
|
||||
var mind = mindComp.Mind;
|
||||
|
||||
if (mind == null || mind.UserId.HasValue == false || mind.Session == null)
|
||||
return;
|
||||
|
||||
bool cloningSuccessful = _cloningSystem.TryCloning(cloningPodUid, scannerComp.BodyContainer.ContainedEntity.Value, mind, cloningPod);
|
||||
}
|
||||
|
||||
public void RecheckConnections(EntityUid console, EntityUid? cloningPod, EntityUid? scanner, CloningConsoleComponent? consoleComp = null)
|
||||
{
|
||||
if (!Resolve(console, ref consoleComp))
|
||||
return;
|
||||
|
||||
if (scanner != null)
|
||||
{
|
||||
Transform(scanner.Value).Coordinates.TryDistance(EntityManager, Transform((console)).Coordinates, out float scannerDistance);
|
||||
consoleComp.GeneticScannerInRange = scannerDistance <= consoleComp.MaxDistance;
|
||||
}
|
||||
if (cloningPod != null)
|
||||
{
|
||||
Transform(cloningPod.Value).Coordinates.TryDistance(EntityManager, Transform((console)).Coordinates, out float podDistance);
|
||||
consoleComp.CloningPodInRange = podDistance <= consoleComp.MaxDistance;
|
||||
}
|
||||
|
||||
UpdateUserInterface(consoleComp);
|
||||
}
|
||||
private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConsoleComponent consoleComponent)
|
||||
{
|
||||
ClonerStatus clonerStatus = ClonerStatus.Ready;
|
||||
|
||||
// genetic scanner info
|
||||
string scanBodyInfo = Loc.GetString("generic-unknown");
|
||||
bool scannerConnected = false;
|
||||
bool scannerInRange = consoleComponent.GeneticScannerInRange;
|
||||
if (consoleComponent.GeneticScanner != null && TryComp<MedicalScannerComponent>(consoleComponent.GeneticScanner, out var scanner)) {
|
||||
|
||||
scannerConnected = true;
|
||||
EntityUid? scanBody = scanner.BodyContainer.ContainedEntity;
|
||||
|
||||
// GET STATE
|
||||
if (scanBody == null || !HasComp<MobStateComponent>(scanBody))
|
||||
clonerStatus = ClonerStatus.ScannerEmpty;
|
||||
else
|
||||
{
|
||||
scanBodyInfo = MetaData(scanBody.Value).EntityName;
|
||||
|
||||
TryComp<MindComponent>(scanBody, out var mindComp);
|
||||
|
||||
if (!_mobStateSystem.IsDead(scanBody.Value))
|
||||
{
|
||||
clonerStatus = ClonerStatus.ScannerOccupantAlive;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mindComp == null || mindComp.Mind == null || mindComp.Mind.UserId == null || !_playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out var client))
|
||||
{
|
||||
clonerStatus = ClonerStatus.NoMindDetected;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cloning pod info
|
||||
var cloneBodyInfo = Loc.GetString("generic-unknown");
|
||||
bool clonerConnected = false;
|
||||
bool clonerMindPresent = false;
|
||||
bool clonerInRange = consoleComponent.CloningPodInRange;
|
||||
if (consoleComponent.CloningPod != null && TryComp<CloningPodComponent>(consoleComponent.CloningPod, out var clonePod)
|
||||
&& Transform(consoleComponent.CloningPod.Value).Anchored)
|
||||
{
|
||||
clonerConnected = true;
|
||||
EntityUid? cloneBody = clonePod.BodyContainer.ContainedEntity;
|
||||
|
||||
clonerMindPresent = clonePod.Status == CloningPodStatus.Cloning;
|
||||
if (cloneBody != null)
|
||||
{
|
||||
cloneBodyInfo = Identity.Name(cloneBody.Value, EntityManager);
|
||||
clonerStatus = ClonerStatus.ClonerOccupied;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clonerStatus = ClonerStatus.NoClonerDetected;
|
||||
}
|
||||
|
||||
return new CloningConsoleBoundUserInterfaceState(
|
||||
scanBodyInfo,
|
||||
cloneBodyInfo,
|
||||
clonerMindPresent,
|
||||
clonerStatus,
|
||||
scannerConnected,
|
||||
scannerInRange,
|
||||
clonerConnected,
|
||||
clonerInRange
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,63 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Cloning.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Shared.Timing;
|
||||
using static Content.Shared.Cloning.SharedCloningPodComponent;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Content.Shared.CharacterAppearance.Components;
|
||||
using Content.Shared.Species;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Server.EUI;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Server.Containers;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Server.MachineLinking.System;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Server.MobState;
|
||||
|
||||
namespace Content.Server.Cloning
|
||||
namespace Content.Server.Cloning.Systems
|
||||
{
|
||||
internal sealed class CloningSystem : EntitySystem
|
||||
public sealed class CloningSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
public readonly Dictionary<Mind.Mind, int> MindToId = new();
|
||||
public readonly Dictionary<int, ClonerDNAEntry> IdToDNA = new();
|
||||
private int _nextAllocatedMindId = 0;
|
||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = null!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly EuiManager _euiManager = null!;
|
||||
[Dependency] private readonly CloningConsoleSystem _cloningConsoleSystem = default!;
|
||||
[Dependency] private readonly SharedHumanoidAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly ContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
|
||||
public readonly Dictionary<Mind.Mind, EntityUid> ClonesWaitingForMind = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CloningPodComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
|
||||
SubscribeLocalEvent<BeingClonedComponent, MindAddedMessage>(HandleMindAdded);
|
||||
SubscribeLocalEvent<CloningPodComponent, PortDisconnectedEvent>(OnPortDisconnected);
|
||||
SubscribeLocalEvent<CloningPodComponent, AnchorStateChangedEvent>(OnAnchor);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, CloningPodComponent clonePod, ComponentInit args)
|
||||
{
|
||||
clonePod.BodyContainer = _containerSystem.EnsureContainer<ContainerSlot>(clonePod.Owner, $"{Name}-bodyContainer");
|
||||
_signalSystem.EnsureReceiverPorts(uid, CloningPodComponent.PodPort);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(CloningPodComponent clonePod)
|
||||
{
|
||||
if (TryComp<AppearanceComponent>(clonePod.Owner, out var appearance))
|
||||
appearance.SetData(CloningPodVisuals.Status, clonePod.Status);
|
||||
}
|
||||
|
||||
internal void TransferMindToClone(Mind.Mind mind)
|
||||
{
|
||||
if (!ClonesWaitingForMind.TryGetValue(mind, out var entity) ||
|
||||
!EntityManager.EntityExists(entity) ||
|
||||
!EntityManager.TryGetComponent(entity, out MindComponent? mindComp) ||
|
||||
!TryComp<MindComponent>(entity, out var mindComp) ||
|
||||
mindComp.Mind != null)
|
||||
return;
|
||||
|
||||
@@ -39,33 +66,94 @@ namespace Content.Server.Cloning
|
||||
ClonesWaitingForMind.Remove(mind);
|
||||
}
|
||||
|
||||
private void HandleMindAdded(EntityUid uid, BeingClonedComponent component, MindAddedMessage message)
|
||||
private void HandleMindAdded(EntityUid uid, BeingClonedComponent clonedComponent, MindAddedMessage message)
|
||||
{
|
||||
if (component.Parent == EntityUid.Invalid ||
|
||||
!EntityManager.EntityExists(component.Parent) ||
|
||||
!EntityManager.TryGetComponent<CloningPodComponent?>(component.Parent, out var cloningPodComponent) ||
|
||||
component.Owner != cloningPodComponent.BodyContainer?.ContainedEntity)
|
||||
if (clonedComponent.Parent == EntityUid.Invalid ||
|
||||
!EntityManager.EntityExists(clonedComponent.Parent) ||
|
||||
!TryComp<CloningPodComponent>(clonedComponent.Parent, out var cloningPodComponent) ||
|
||||
clonedComponent.Owner != cloningPodComponent.BodyContainer?.ContainedEntity)
|
||||
{
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(component.Owner);
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(clonedComponent.Owner);
|
||||
return;
|
||||
}
|
||||
UpdateStatus(CloningPodStatus.Cloning, cloningPodComponent);
|
||||
}
|
||||
|
||||
cloningPodComponent.UpdateStatus(CloningPodStatus.Cloning);
|
||||
private void OnPortDisconnected(EntityUid uid, CloningPodComponent pod, PortDisconnectedEvent args)
|
||||
{
|
||||
pod.ConnectedConsole = null;
|
||||
}
|
||||
|
||||
private void OnAnchor(EntityUid uid, CloningPodComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (component.ConnectedConsole == null || !TryComp<CloningConsoleComponent>(component.ConnectedConsole, out var console))
|
||||
return;
|
||||
|
||||
if (args.Anchored)
|
||||
{
|
||||
_cloningConsoleSystem.RecheckConnections(component.ConnectedConsole.Value, uid, console.GeneticScanner, console);
|
||||
return;
|
||||
}
|
||||
_cloningConsoleSystem.UpdateUserInterface(console);
|
||||
}
|
||||
|
||||
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod)
|
||||
{
|
||||
if (!Resolve(uid, ref clonePod) || bodyToClone == null)
|
||||
return false;
|
||||
|
||||
if (ClonesWaitingForMind.TryGetValue(mind, out var clone))
|
||||
{
|
||||
if (EntityManager.EntityExists(clone) &&
|
||||
!_mobStateSystem.IsDead(clone) &&
|
||||
TryComp<MindComponent>(clone, out var cloneMindComp) &&
|
||||
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
|
||||
return false; // Mind already has clone
|
||||
|
||||
ClonesWaitingForMind.Remove(mind);
|
||||
}
|
||||
|
||||
if (mind.OwnedEntity != null && !_mobStateSystem.IsDead(mind.OwnedEntity.Value))
|
||||
return false; // Body controlled by mind is not dead
|
||||
|
||||
// Yes, we still need to track down the client because we need to open the Eui
|
||||
if (mind.UserId == null || !_playerManager.TryGetSessionById(mind.UserId.Value, out var client))
|
||||
return false; // If we can't track down the client, we can't offer transfer. That'd be quite bad.
|
||||
|
||||
if (!TryComp<HumanoidAppearanceComponent>(bodyToClone, out var humanoid))
|
||||
return false; // whatever body was to be cloned, was not a humanoid
|
||||
|
||||
var speciesProto = _prototype.Index<SpeciesPrototype>(humanoid.Species).Prototype;
|
||||
var mob = Spawn(speciesProto, Transform(clonePod.Owner).MapPosition);
|
||||
_appearanceSystem.UpdateAppearance(mob, humanoid.Appearance);
|
||||
_appearanceSystem.UpdateSexGender(mob, humanoid.Sex, humanoid.Gender);
|
||||
|
||||
MetaData(mob).EntityName = MetaData(bodyToClone).EntityName;
|
||||
|
||||
var cloneMindReturn = EntityManager.AddComponent<BeingClonedComponent>(mob);
|
||||
cloneMindReturn.Mind = mind;
|
||||
cloneMindReturn.Parent = clonePod.Owner;
|
||||
clonePod.BodyContainer.Insert(mob);
|
||||
clonePod.CapturedMind = mind;
|
||||
ClonesWaitingForMind.Add(mind, mob);
|
||||
UpdateStatus(CloningPodStatus.NoMind, clonePod);
|
||||
_euiManager.OpenEui(new AcceptCloningEui(mind, this), client);
|
||||
|
||||
AddComp<ActiveCloningPodComponent>(uid);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void UpdateStatus(CloningPodStatus status, CloningPodComponent cloningPod)
|
||||
{
|
||||
cloningPod.Status = status;
|
||||
UpdateAppearance(cloningPod);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
// TODO: Make this stateful
|
||||
foreach (var (cloning, power) in EntityManager.EntityQuery<CloningPodComponent, ApcPowerReceiverComponent>())
|
||||
foreach (var (_, cloning) in EntityManager.EntityQuery<ActiveCloningPodComponent, CloningPodComponent>())
|
||||
{
|
||||
if (cloning.UiKnownPowerState != power.Powered)
|
||||
{
|
||||
// Must be *before* update
|
||||
cloning.UiKnownPowerState = power.Powered;
|
||||
UpdateUserInterface(cloning);
|
||||
}
|
||||
|
||||
if (!power.Powered)
|
||||
if (!_powerReceiverSystem.IsPowered(cloning.Owner))
|
||||
continue;
|
||||
|
||||
if (cloning.BodyContainer.ContainedEntity != null)
|
||||
@@ -76,77 +164,30 @@ namespace Content.Server.Cloning
|
||||
|
||||
if (cloning.CapturedMind?.Session?.AttachedEntity == cloning.BodyContainer.ContainedEntity)
|
||||
{
|
||||
cloning.Eject();
|
||||
Eject(cloning.Owner, cloning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUserInterface(CloningPodComponent comp)
|
||||
public void Eject(EntityUid uid, CloningPodComponent? clonePod)
|
||||
{
|
||||
var idToUser = GetIdToUser();
|
||||
comp.UserInterface?.SetState(
|
||||
new CloningPodBoundUserInterfaceState(
|
||||
idToUser,
|
||||
// now
|
||||
_timing.CurTime,
|
||||
// progress, time, progressing
|
||||
comp.CloningProgress,
|
||||
comp.CloningTime,
|
||||
// this is duplicate w/ the above check that actually updates progress
|
||||
// better here than on client though
|
||||
comp.UiKnownPowerState && (comp.BodyContainer.ContainedEntity != null),
|
||||
comp.Status == CloningPodStatus.Cloning));
|
||||
}
|
||||
if (!Resolve(uid, ref clonePod))
|
||||
return;
|
||||
|
||||
public void AddToDnaScans(ClonerDNAEntry dna)
|
||||
{
|
||||
if (!MindToId.ContainsKey(dna.Mind))
|
||||
{
|
||||
int id = _nextAllocatedMindId++;
|
||||
MindToId.Add(dna.Mind, id);
|
||||
IdToDNA.Add(id, dna);
|
||||
}
|
||||
OnChangeMadeToDnaScans();
|
||||
}
|
||||
if (clonePod.BodyContainer.ContainedEntity is not {Valid: true} entity || clonePod.CloningProgress < clonePod.CloningTime)
|
||||
return;
|
||||
|
||||
public void OnChangeMadeToDnaScans()
|
||||
{
|
||||
foreach (var cloning in EntityManager.EntityQuery<CloningPodComponent>())
|
||||
UpdateUserInterface(cloning);
|
||||
}
|
||||
|
||||
public bool HasDnaScan(Mind.Mind mind)
|
||||
{
|
||||
return MindToId.ContainsKey(mind);
|
||||
}
|
||||
|
||||
public Dictionary<int, string?> GetIdToUser()
|
||||
{
|
||||
return IdToDNA.ToDictionary(m => m.Key, m => m.Value.Mind.CharacterName);
|
||||
EntityManager.RemoveComponent<BeingClonedComponent>(entity);
|
||||
clonePod.BodyContainer.Remove(entity);
|
||||
clonePod.CapturedMind = null;
|
||||
clonePod.CloningProgress = 0f;
|
||||
UpdateStatus(CloningPodStatus.Idle, clonePod);
|
||||
RemCompDeferred<ActiveCloningPodComponent>(uid);
|
||||
}
|
||||
|
||||
public void Reset(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
MindToId.Clear();
|
||||
IdToDNA.Clear();
|
||||
ClonesWaitingForMind.Clear();
|
||||
_nextAllocatedMindId = 0;
|
||||
// We PROBABLY don't need to send out UI interface updates for the dna scan changes during a reset
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This needs to be moved to Content.Server.Mobs and made a global point of reference.
|
||||
// For example, GameTicker should be using this, and this should be using ICharacterProfile rather than HumanoidCharacterProfile.
|
||||
// It should carry a reference or copy of itself with the mobs that it affects.
|
||||
// See TODO in MedicalScannerComponent.
|
||||
public struct ClonerDNAEntry {
|
||||
public Mind.Mind Mind;
|
||||
public HumanoidCharacterProfile Profile;
|
||||
|
||||
public ClonerDNAEntry(Mind.Mind m, HumanoidCharacterProfile hcp)
|
||||
{
|
||||
Mind = m;
|
||||
Profile = hcp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.Cloning.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
/// <summary>
|
||||
/// Shrimply a tracking component for pods that are cloning.
|
||||
/// </summary>
|
||||
public sealed class ActiveCloningPodComponent : Component
|
||||
{}
|
||||
}
|
||||
24
Content.Server/Cloning/Components/CloningConsoleComponent.cs
Normal file
24
Content.Server/Cloning/Components/CloningConsoleComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Content.Server.Cloning.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class CloningConsoleComponent : Component
|
||||
{
|
||||
public const string ScannerPort = "MedicalScannerSender";
|
||||
|
||||
public const string PodPort = "CloningPodSender";
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? GeneticScanner = null;
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? CloningPod = null;
|
||||
|
||||
/// Maximum distance between console and one if its machines
|
||||
[DataField("maxDistance")]
|
||||
public float MaxDistance = 4f;
|
||||
|
||||
public bool GeneticScannerInRange = true;
|
||||
|
||||
public bool CloningPodInRange = true;
|
||||
}
|
||||
}
|
||||
@@ -1,208 +1,18 @@
|
||||
using Content.Server.Climbing;
|
||||
using Content.Server.EUI;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.CharacterAppearance.Systems;
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Species;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Cloning.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class CloningPodComponent : SharedCloningPodComponent
|
||||
public sealed class CloningPodComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
|
||||
[Dependency] private readonly EuiManager _euiManager = null!;
|
||||
|
||||
[ViewVariables]
|
||||
public BoundUserInterface? UserInterface =>
|
||||
Owner.GetUIOrNull(CloningPodUIKey.Key);
|
||||
|
||||
public const string PodPort = "CloningPodReceiver";
|
||||
[ViewVariables] public ContainerSlot BodyContainer = default!;
|
||||
[ViewVariables] public Mind.Mind? CapturedMind;
|
||||
[ViewVariables] public float CloningProgress = 0;
|
||||
[DataField("cloningTime")]
|
||||
[ViewVariables] public float CloningTime = 30f;
|
||||
// Used to prevent as many duplicate UI messages as possible
|
||||
[ViewVariables] public bool UiKnownPowerState = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("soundCloneStart")]
|
||||
public SoundSpecifier? CloneStartSound = new SoundPathSpecifier("/Audio/Machines/genetics.ogg");
|
||||
|
||||
[ViewVariables]
|
||||
public CloningPodStatus Status;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
BodyContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-bodyContainer");
|
||||
|
||||
//TODO: write this so that it checks for a change in power events for GORE POD cases
|
||||
EntitySystem.Get<CloningSystem>().UpdateUserInterface(this);
|
||||
}
|
||||
|
||||
protected override void OnRemove()
|
||||
{
|
||||
if (UserInterface != null)
|
||||
{
|
||||
UserInterface.OnReceiveMessage -= OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void UpdateAppearance()
|
||||
{
|
||||
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(CloningPodVisuals.Status, Status);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
{
|
||||
if (obj.Message is not CloningPodUiButtonPressedMessage message || obj.Session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
switch (message.Button)
|
||||
{
|
||||
case UiButton.Clone:
|
||||
if (BodyContainer.ContainedEntity != null)
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-occupied"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.ScanId == null)
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-no-selection"));
|
||||
return;
|
||||
}
|
||||
|
||||
var cloningSystem = EntitySystem.Get<CloningSystem>();
|
||||
|
||||
if (!cloningSystem.IdToDNA.TryGetValue(message.ScanId.Value, out var dna))
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-bad-selection"));
|
||||
return; // ScanId is not in database
|
||||
}
|
||||
|
||||
var mind = dna.Mind;
|
||||
|
||||
if (cloningSystem.ClonesWaitingForMind.TryGetValue(mind, out var clone))
|
||||
{
|
||||
if (_entities.EntityExists(clone) &&
|
||||
_entities.TryGetComponent<MobStateComponent?>(clone, out var cloneState) &&
|
||||
!cloneState.IsDead() &&
|
||||
_entities.TryGetComponent(clone, out MindComponent? cloneMindComp) &&
|
||||
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-cloning"));
|
||||
return; // Mind already has clone
|
||||
}
|
||||
|
||||
cloningSystem.ClonesWaitingForMind.Remove(mind);
|
||||
}
|
||||
|
||||
if (mind.OwnedEntity != null &&
|
||||
_entities.TryGetComponent<MobStateComponent?>(mind.OwnedEntity.Value, out var state) &&
|
||||
!state.IsDead())
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-already-alive"));
|
||||
return; // Body controlled by mind is not dead
|
||||
}
|
||||
|
||||
// Yes, we still need to track down the client because we need to open the Eui
|
||||
if (mind.UserId == null || !_playerManager.TryGetSessionById(mind.UserId.Value, out var client))
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-user-offline"));
|
||||
return; // If we can't track down the client, we can't offer transfer. That'd be quite bad.
|
||||
}
|
||||
|
||||
// Cloning confirmed now.
|
||||
|
||||
var speciesProto = _prototype.Index<SpeciesPrototype>(dna.Profile.Species).Prototype;
|
||||
var mob = _entities.SpawnEntity(speciesProto, _entities.GetComponent<TransformComponent>(Owner).MapPosition);
|
||||
|
||||
EntitySystem.Get<SharedHumanoidAppearanceSystem>().UpdateFromProfile(mob, dna.Profile);
|
||||
_entities.GetComponent<MetaDataComponent>(mob).EntityName = dna.Profile.Name;
|
||||
|
||||
// TODO: Ideally client knows about this and plays it on its own
|
||||
// Send them a sound to know it happened
|
||||
if (CloneStartSound != null)
|
||||
SoundSystem.Play(CloneStartSound.GetSound(), Filter.SinglePlayer(client));
|
||||
|
||||
var cloneMindReturn = _entities.AddComponent<BeingClonedComponent>(mob);
|
||||
cloneMindReturn.Mind = mind;
|
||||
cloneMindReturn.Parent = Owner;
|
||||
|
||||
BodyContainer.Insert(mob);
|
||||
CapturedMind = mind;
|
||||
cloningSystem.ClonesWaitingForMind.Add(mind, mob);
|
||||
|
||||
UpdateStatus(CloningPodStatus.NoMind);
|
||||
|
||||
var acceptMessage = new AcceptCloningEui(mind);
|
||||
_euiManager.OpenEui(acceptMessage, client);
|
||||
|
||||
break;
|
||||
|
||||
case UiButton.Eject:
|
||||
if (BodyContainer.ContainedEntity == null)
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-empty"));
|
||||
return;
|
||||
}
|
||||
if (CloningProgress < CloningTime)
|
||||
{
|
||||
obj.Session.AttachedEntity.Value.PopupMessageCursor(Loc.GetString("cloning-pod-component-msg-incomplete"));
|
||||
return;
|
||||
}
|
||||
Eject();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public void Eject()
|
||||
{
|
||||
if (BodyContainer.ContainedEntity is not {Valid: true} entity || CloningProgress < CloningTime)
|
||||
return;
|
||||
|
||||
_entities.RemoveComponent<BeingClonedComponent>(entity);
|
||||
BodyContainer.Remove(entity);
|
||||
CapturedMind = null;
|
||||
CloningProgress = 0f;
|
||||
UpdateStatus(CloningPodStatus.Idle);
|
||||
EntitySystem.Get<ClimbSystem>().ForciblySetClimbing(entity, Owner);
|
||||
}
|
||||
|
||||
public void UpdateStatus(CloningPodStatus status)
|
||||
{
|
||||
Status = status;
|
||||
UpdateAppearance();
|
||||
EntitySystem.Get<CloningSystem>().UpdateUserInterface(this);
|
||||
}
|
||||
[ViewVariables] public CloningPodStatus Status;
|
||||
public EntityUid? ConnectedConsole;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user