Make CloningSystem properly reset and not use static (#2448)

This commit is contained in:
DrSmugleaf
2020-10-30 01:05:18 +01:00
committed by GitHub
parent 75c6ba7e01
commit a2de32d4c4
3 changed files with 28 additions and 15 deletions

View File

@@ -1,7 +1,5 @@
#nullable enable
using System;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
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.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -76,12 +75,12 @@ namespace Content.Server.GameObjects.Components.Medical
HandleGhostReturn);
}
public void Update(float frametime)
public void Update(float frameTime)
{
if (_bodyContainer.ContainedEntity != null &&
Powered)
{
_cloningProgress += frametime;
_cloningProgress += frameTime;
_cloningProgress = MathHelper.Clamp(_cloningProgress, 0f, _cloningTime);
}
@@ -122,7 +121,9 @@ namespace Content.Server.GameObjects.Components.Medical
private CloningPodBoundUserInterfaceState GetUserInterfaceState()
{
return new CloningPodBoundUserInterfaceState(CloningSystem.getIdToUser(), _cloningProgress,
var idToUser = EntitySystem.Get<CloningSystem>().GetIdToUser();
return new CloningPodBoundUserInterfaceState(idToUser, _cloningProgress,
(_status == CloningPodStatus.Cloning));
}
@@ -152,11 +153,12 @@ namespace Content.Server.GameObjects.Components.Medical
switch (message.Button)
{
case UiButton.Clone:
if (message.ScanId == null) return;
var cloningSystem = EntitySystem.Get<CloningSystem>();
if (_bodyContainer.ContainedEntity != null ||
!CloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind))
!cloningSystem.Minds.TryGetValue(message.ScanId.Value, out var mind))
{
return;
}

View File

@@ -20,6 +20,7 @@ using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -126,9 +127,12 @@ namespace Content.Server.GameObjects.Components.Medical
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,
CloningSystem.HasDnaScan(_bodyContainer.ContainedEntity.GetComponent<MindComponent>().Mind));
return new MedicalScannerBoundUserInterfaceState(body.Uid, classes, types, scanned);
}
private void UpdateUserInterface()
@@ -261,7 +265,8 @@ namespace Content.Server.GameObjects.Components.Medical
if (_bodyContainer.ContainedEntity != null)
{
//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 =>
{
var mindOwnedMob = playerSession.ContentData()?.Mind?.OwnedEntity;

View File

@@ -2,11 +2,12 @@
using System.Linq;
using Content.Server.GameObjects.Components.Medical;
using Content.Server.Mobs;
using Content.Shared.GameTicking;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
internal sealed class CloningSystem : EntitySystem
internal sealed class CloningSystem : EntitySystem, IResettingEntitySystem
{
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))
{
@@ -26,14 +27,19 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
public static bool HasDnaScan(Mind mind)
public bool HasDnaScan(Mind 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);
}
public void Reset()
{
Minds.Clear();
}
}
}