Make CloningSystem properly reset and not use static (#2448)
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.GameObjects.Components.Observer;
|
using Content.Server.GameObjects.Components.Observer;
|
||||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||||
@@ -19,6 +17,7 @@ using Robust.Server.GameObjects.Components.UserInterface;
|
|||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -76,12 +75,12 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
HandleGhostReturn);
|
HandleGhostReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(float frametime)
|
public void Update(float frameTime)
|
||||||
{
|
{
|
||||||
if (_bodyContainer.ContainedEntity != null &&
|
if (_bodyContainer.ContainedEntity != null &&
|
||||||
Powered)
|
Powered)
|
||||||
{
|
{
|
||||||
_cloningProgress += frametime;
|
_cloningProgress += frameTime;
|
||||||
_cloningProgress = MathHelper.Clamp(_cloningProgress, 0f, _cloningTime);
|
_cloningProgress = MathHelper.Clamp(_cloningProgress, 0f, _cloningTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +121,9 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
|
|
||||||
private CloningPodBoundUserInterfaceState GetUserInterfaceState()
|
private CloningPodBoundUserInterfaceState GetUserInterfaceState()
|
||||||
{
|
{
|
||||||
return new CloningPodBoundUserInterfaceState(CloningSystem.getIdToUser(), _cloningProgress,
|
var idToUser = EntitySystem.Get<CloningSystem>().GetIdToUser();
|
||||||
|
|
||||||
|
return new CloningPodBoundUserInterfaceState(idToUser, _cloningProgress,
|
||||||
(_status == CloningPodStatus.Cloning));
|
(_status == CloningPodStatus.Cloning));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,11 +153,12 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
switch (message.Button)
|
switch (message.Button)
|
||||||
{
|
{
|
||||||
case UiButton.Clone:
|
case UiButton.Clone:
|
||||||
|
|
||||||
if (message.ScanId == null) return;
|
if (message.ScanId == null) return;
|
||||||
|
|
||||||
|
var cloningSystem = EntitySystem.Get<CloningSystem>();
|
||||||
|
|
||||||
if (_bodyContainer.ContainedEntity != null ||
|
if (_bodyContainer.ContainedEntity != null ||
|
||||||
!CloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind))
|
!cloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ using Robust.Server.GameObjects.Components.UserInterface;
|
|||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Timing;
|
using Robust.Shared.Interfaces.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -126,9 +127,12 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, true);
|
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cloningSystem = EntitySystem.Get<CloningSystem>();
|
||||||
|
var scanned = _bodyContainer.ContainedEntity.TryGetComponent(out MindComponent? mindComponent) &&
|
||||||
|
mindComponent.Mind != null &&
|
||||||
|
cloningSystem.HasDnaScan(mindComponent.Mind);
|
||||||
|
|
||||||
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types,
|
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, scanned);
|
||||||
CloningSystem.HasDnaScan(_bodyContainer.ContainedEntity.GetComponent<MindComponent>().Mind));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateUserInterface()
|
private void UpdateUserInterface()
|
||||||
@@ -261,7 +265,8 @@ namespace Content.Server.GameObjects.Components.Medical
|
|||||||
if (_bodyContainer.ContainedEntity != null)
|
if (_bodyContainer.ContainedEntity != null)
|
||||||
{
|
{
|
||||||
//TODO: Show a 'ERROR: Body is completely devoid of soul' if no Mind owns the entity.
|
//TODO: Show a 'ERROR: Body is completely devoid of soul' if no Mind owns the entity.
|
||||||
CloningSystem.AddToDnaScans(_playerManager
|
var cloningSystem = EntitySystem.Get<CloningSystem>();
|
||||||
|
cloningSystem.AddToDnaScans(_playerManager
|
||||||
.GetPlayersBy(playerSession =>
|
.GetPlayersBy(playerSession =>
|
||||||
{
|
{
|
||||||
var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity;
|
var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity;
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.GameObjects.Components.Medical;
|
using Content.Server.GameObjects.Components.Medical;
|
||||||
using Content.Server.Mobs;
|
using Content.Server.Mobs;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
internal sealed class CloningSystem : EntitySystem
|
internal sealed class CloningSystem : EntitySystem, IResettingEntitySystem
|
||||||
{
|
{
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
@@ -16,9 +17,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<int, Mind> Minds = new Dictionary<int, Mind>();
|
public readonly Dictionary<int, Mind> Minds = new Dictionary<int, Mind>();
|
||||||
|
|
||||||
public static void AddToDnaScans(Mind mind)
|
public void AddToDnaScans(Mind mind)
|
||||||
{
|
{
|
||||||
if (!Minds.ContainsValue(mind))
|
if (!Minds.ContainsValue(mind))
|
||||||
{
|
{
|
||||||
@@ -26,14 +27,19 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HasDnaScan(Mind mind)
|
public bool HasDnaScan(Mind mind)
|
||||||
{
|
{
|
||||||
return Minds.ContainsValue(mind);
|
return Minds.ContainsValue(mind);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<int, string> getIdToUser()
|
public Dictionary<int, string> GetIdToUser()
|
||||||
{
|
{
|
||||||
return Minds.ToDictionary(m => m.Key, m => m.Value.CharacterName);
|
return Minds.ToDictionary(m => m.Key, m => m.Value.CharacterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
Minds.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user