Refactor minds to be entities with components, make roles components (#19591)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2023-08-28 16:53:24 -07:00
committed by GitHub
parent e0ee397af7
commit 15c0211fb2
119 changed files with 1445 additions and 1289 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.EUI;
using Content.Server.Mind;
using Content.Shared.Cloning;
using Content.Shared.Eui;
@@ -6,11 +7,13 @@ namespace Content.Server.Cloning
{
public sealed class AcceptCloningEui : BaseEui
{
private readonly EntityUid _mindId;
private readonly MindComponent _mind;
private readonly CloningSystem _cloningSystem;
private readonly Mind.Mind _mind;
public AcceptCloningEui(Mind.Mind mind, CloningSystem cloningSys)
public AcceptCloningEui(EntityUid mindId, MindComponent mind, CloningSystem cloningSys)
{
_mindId = mindId;
_mind = mind;
_cloningSystem = cloningSys;
}
@@ -26,7 +29,7 @@ namespace Content.Server.Cloning
return;
}
_cloningSystem.TransferMindToClone(_mind);
_cloningSystem.TransferMindToClone(_mindId, _mind);
Close();
}
}

View File

@@ -1,23 +1,23 @@
using System.Linq;
using JetBrains.Annotations;
using Content.Server.Administration.Logs;
using Content.Server.Medical.Components;
using Content.Server.Cloning.Components;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Medical.Components;
using Content.Server.Mind;
using Content.Server.Power.Components;
using Content.Server.Mind.Components;
using Content.Server.UserInterface;
using Content.Server.Power.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Content.Shared.Cloning.CloningConsole;
using Content.Server.UserInterface;
using Content.Shared.Cloning;
using Content.Shared.Cloning.CloningConsole;
using Content.Shared.Database;
using Content.Shared.DeviceLinking;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.IdentityManagement;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
namespace Content.Server.Cloning
{
@@ -31,6 +31,8 @@ namespace Content.Server.Cloning
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -162,12 +164,10 @@ namespace Content.Server.Cloning
if (body is null)
return;
if (!TryComp<MindContainerComponent>(body, out var mindComp))
if (!_mindSystem.TryGetMind(body.Value, out var mindId, out var mind))
return;
var mind = mindComp.Mind;
if (mind == null || mind.UserId.HasValue == false || mind.Session == null)
if (mind.UserId.HasValue == false || mind.Session == null)
return;
if (_cloningSystem.TryCloning(cloningPodUid, body.Value, mind, cloningPod, scannerComp.CloningFailChanceMultiplier))
@@ -212,15 +212,15 @@ namespace Content.Server.Cloning
{
scanBodyInfo = MetaData(scanBody.Value).EntityName;
TryComp<MindContainerComponent>(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 _))
if (!_mindSystem.TryGetMind(scanBody.Value, out _, out var mind) ||
mind.UserId == null ||
!_playerManager.TryGetSessionById(mind.UserId.Value, out _))
{
clonerStatus = ClonerStatus.NoMindDetected;
}

View File

@@ -1,41 +1,40 @@
using Content.Shared.GameTicking;
using Content.Shared.Damage;
using Content.Shared.Examine;
using Content.Shared.Cloning;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Cloning.Components;
using Content.Server.Construction;
using Content.Server.DeviceLinking.Systems;
using Content.Server.EUI;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Humanoid;
using Content.Server.Jobs;
using Content.Server.Materials;
using Content.Server.Mind;
using Content.Server.Mind.Components;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.Roles.Jobs;
using Content.Server.Traits.Assorted;
using Content.Shared.Atmos;
using Content.Shared.CCVar;
using Content.Server.Cloning.Components;
using Content.Server.Mind.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Atmos.EntitySystems;
using Content.Server.EUI;
using Content.Server.Humanoid;
using Content.Shared.Chemistry.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Construction;
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Materials;
using Content.Server.Jobs;
using Content.Shared.Cloning;
using Content.Shared.Damage;
using Content.Shared.DeviceLinking.Events;
using Content.Shared.Emag.Components;
using Content.Server.Mind;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Zombies;
using Content.Shared.Mobs.Systems;
using Robust.Server.GameObjects;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
using Content.Shared.Emag.Systems;
using Content.Server.Popups;
using Content.Server.Traits.Assorted;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Cloning
{
@@ -62,8 +61,9 @@ namespace Content.Server.Cloning
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly JobSystem _jobs = default!;
public readonly Dictionary<Mind.Mind, EntityUid> ClonesWaitingForMind = new();
public readonly Dictionary<MindComponent, EntityUid> ClonesWaitingForMind = new();
public const float EasyModeCloningCost = 0.7f;
public override void Initialize()
@@ -102,7 +102,7 @@ namespace Content.Server.Cloning
args.AddPercentageUpgrade("cloning-pod-component-upgrade-biomass-requirement", component.BiomassRequirementMultiplier);
}
internal void TransferMindToClone(Mind.Mind mind)
internal void TransferMindToClone(EntityUid mindId, MindComponent mind)
{
if (!ClonesWaitingForMind.TryGetValue(mind, out var entity) ||
!EntityManager.EntityExists(entity) ||
@@ -110,8 +110,8 @@ namespace Content.Server.Cloning
mindComp.Mind != null)
return;
_mindSystem.TransferTo(mind, entity, ghostCheckOverride: true);
_mindSystem.UnVisit(mind);
_mindSystem.TransferTo(mindId, entity, ghostCheckOverride: true, mind: mind);
_mindSystem.UnVisit(mindId, mind);
ClonesWaitingForMind.Remove(mind);
}
@@ -154,7 +154,7 @@ namespace Content.Server.Cloning
args.PushMarkup(Loc.GetString("cloning-pod-biomass", ("number", _material.GetMaterialAmount(uid, component.RequiredMaterial))));
}
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod, float failChanceModifier = 1)
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, MindComponent mind, CloningPodComponent? clonePod, float failChanceModifier = 1)
{
if (!Resolve(uid, ref clonePod))
return false;
@@ -167,7 +167,7 @@ namespace Content.Server.Cloning
if (EntityManager.EntityExists(clone) &&
!_mobStateSystem.IsDead(clone) &&
TryComp<MindContainerComponent>(clone, out var cloneMindComp) &&
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind))
(cloneMindComp.Mind == null || cloneMindComp.Mind == mind.Owner))
return false; // Mind already has clone
ClonesWaitingForMind.Remove(mind);
@@ -253,16 +253,16 @@ namespace Content.Server.Cloning
clonePod.BodyContainer.Insert(mob);
ClonesWaitingForMind.Add(mind, mob);
UpdateStatus(uid, CloningPodStatus.NoMind, clonePod);
_euiManager.OpenEui(new AcceptCloningEui(mind, this), client);
var mindId = mind.Owner;
_euiManager.OpenEui(new AcceptCloningEui(mindId, mind, this), client);
AddComp<ActiveCloningPodComponent>(uid);
// TODO: Ideally, components like this should be on a mind entity so this isn't neccesary.
// Remove this when 'mind entities' are added.
// TODO: Ideally, components like this should be components on the mind entity so this isn't necessary.
// Add on special job components to the mob.
if (mind.CurrentJob != null)
if (_jobs.MindTryGetJob(mindId, out _, out var prototype))
{
foreach (var special in mind.CurrentJob.Prototype.Special)
foreach (var special in prototype.Special)
{
if (special is AddComponentSpecial)
special.AfterEquip(mob);

View File

@@ -1,10 +1,12 @@
using Content.Server.Mind;
namespace Content.Server.Cloning.Components
{
[RegisterComponent]
public sealed partial class BeingClonedComponent : Component
{
[ViewVariables]
public Mind.Mind? Mind = default;
public MindComponent? Mind = default;
[ViewVariables]
public EntityUid Parent;