Cloning error messages and prediction based timing (#4013)
* Cloning error messages and prediction based timing * Cloning error messages & prediction based timing: Fix problems mentioned in reviews
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Medical;
|
||||
@@ -6,16 +7,23 @@ using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using static Content.Shared.GameObjects.Components.Medical.SharedCloningPodComponent;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
internal sealed class CloningSystem : EntitySystem, IResettingEntitySystem
|
||||
{
|
||||
public readonly Dictionary<int, Mind> Minds = new();
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
public readonly Dictionary<Mind, int> MindToId = new();
|
||||
public readonly Dictionary<int, ClonerDNAEntry> IdToDNA = new();
|
||||
private int _nextAllocatedMindId = 0;
|
||||
private float _quickAndDirtyUserUpdatePreventerTimer = 0.0f;
|
||||
public readonly Dictionary<Mind, EntityUid> ClonesWaitingForMind = new();
|
||||
|
||||
public override void Initialize()
|
||||
@@ -42,8 +50,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
mindComp.Mind != null)
|
||||
return;
|
||||
|
||||
mind?.TransferTo(entity);
|
||||
mind?.UnVisit();
|
||||
mind.TransferTo(entity);
|
||||
mind.UnVisit();
|
||||
ClonesWaitingForMind.Remove(mind);
|
||||
}
|
||||
|
||||
private void HandleActivate(EntityUid uid, CloningPodComponent component, ActivateInWorldEvent args)
|
||||
@@ -75,6 +84,13 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
foreach (var (cloning, power) in ComponentManager.EntityQuery<CloningPodComponent, PowerReceiverComponent>(true))
|
||||
{
|
||||
if (cloning.UiKnownPowerState != power.Powered)
|
||||
{
|
||||
// Must be *before* update
|
||||
cloning.UiKnownPowerState = power.Powered;
|
||||
UpdateUserInterface(cloning);
|
||||
}
|
||||
|
||||
if (!power.Powered)
|
||||
return;
|
||||
|
||||
@@ -88,8 +104,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
cloning.Eject();
|
||||
}
|
||||
|
||||
UpdateUserInterface(cloning);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,32 +113,65 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
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));
|
||||
}
|
||||
|
||||
public void AddToDnaScans(Mind mind)
|
||||
public void AddToDnaScans(ClonerDNAEntry dna)
|
||||
{
|
||||
if (!Minds.ContainsValue(mind))
|
||||
if (!MindToId.ContainsKey(dna.Mind))
|
||||
{
|
||||
Minds.Add(Minds.Count, mind);
|
||||
int id = _nextAllocatedMindId++;
|
||||
MindToId.Add(dna.Mind, id);
|
||||
IdToDNA.Add(id, dna);
|
||||
}
|
||||
OnChangeMadeToDnaScans();
|
||||
}
|
||||
|
||||
public void OnChangeMadeToDnaScans()
|
||||
{
|
||||
foreach (var cloning in ComponentManager.EntityQuery<CloningPodComponent>(true))
|
||||
UpdateUserInterface(cloning);
|
||||
}
|
||||
|
||||
public bool HasDnaScan(Mind mind)
|
||||
{
|
||||
return Minds.ContainsValue(mind);
|
||||
return MindToId.ContainsKey(mind);
|
||||
}
|
||||
|
||||
public Dictionary<int, string?> GetIdToUser()
|
||||
{
|
||||
return Minds.ToDictionary(m => m.Key, m => m.Value.CharacterName);
|
||||
return IdToDNA.ToDictionary(m => m.Key, m => m.Value.Mind.CharacterName);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Minds.Clear();
|
||||
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.
|
||||
struct ClonerDNAEntry {
|
||||
public Mind Mind;
|
||||
public HumanoidCharacterProfile Profile;
|
||||
public ClonerDNAEntry(Mind m, HumanoidCharacterProfile hcp)
|
||||
{
|
||||
Mind = m;
|
||||
Profile = hcp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user