cloning machine upgrade support (#11588)

* cloning machine upgrade support

* foo
This commit is contained in:
Nemanja
2022-09-28 22:30:11 -04:00
committed by GitHub
parent b606ecb9cb
commit a9dd9257d8
2 changed files with 82 additions and 22 deletions

View File

@@ -17,6 +17,7 @@ using Content.Server.MobState;
using Content.Shared.Chemistry.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Materials;
using Content.Server.Stack;
@@ -31,7 +32,6 @@ using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
namespace Content.Server.Cloning.Systems
{
public sealed class CloningSystem : EntitySystem
@@ -48,6 +48,7 @@ namespace Content.Server.Cloning.Systems
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedStackSystem _stackSystem = default!;
[Dependency] private readonly StackSystem _serverStackSystem = default!;
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
@@ -63,6 +64,7 @@ namespace Content.Server.Cloning.Systems
base.Initialize();
SubscribeLocalEvent<CloningPodComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<CloningPodComponent, RefreshPartsEvent>(OnPartsRefreshed);
SubscribeLocalEvent<CloningPodComponent, MachineDeconstructedEvent>(OnDeconstruct);
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<BeingClonedComponent, MindAddedMessage>(HandleMindAdded);
@@ -77,17 +79,20 @@ namespace Content.Server.Cloning.Systems
_signalSystem.EnsureReceiverPorts(uid, CloningPodComponent.PodPort);
}
private void OnPartsRefreshed(EntityUid uid, CloningPodComponent component, RefreshPartsEvent args)
{
var materialRating = args.PartRatings[component.MachinePartMaterialUse];
var speedRating = args.PartRatings[component.MachinePartCloningSpeed];
component.BiomassRequirementMultiplier = MathF.Pow(component.PartRatingMaterialMultiplier, materialRating - 1);
component.CloningTime = component.BaseCloningTime * MathF.Pow(component.PartRatingSpeedMultiplier, speedRating - 1);
}
private void OnDeconstruct(EntityUid uid, CloningPodComponent component, MachineDeconstructedEvent args)
{
_serverStackSystem.SpawnMultiple(_material.GetMaterialAmount(uid, "Biomass"), 100, "Biomass", Transform(uid).Coordinates);
}
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) ||
@@ -106,7 +111,7 @@ namespace Content.Server.Cloning.Systems
if (clonedComponent.Parent == EntityUid.Invalid ||
!EntityManager.EntityExists(clonedComponent.Parent) ||
!TryComp<CloningPodComponent>(clonedComponent.Parent, out var cloningPodComponent) ||
clonedComponent.Owner != cloningPodComponent.BodyContainer?.ContainedEntity)
clonedComponent.Owner != cloningPodComponent.BodyContainer.ContainedEntity)
{
EntityManager.RemoveComponent<BeingClonedComponent>(clonedComponent.Owner);
return;
@@ -142,7 +147,7 @@ namespace Content.Server.Cloning.Systems
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod)
{
if (!Resolve(uid, ref clonePod) || bodyToClone == null)
if (!Resolve(uid, ref clonePod))
return false;
if (HasComp<ActiveCloningPodComponent>(uid))
@@ -175,7 +180,7 @@ namespace Content.Server.Cloning.Systems
if (!TryComp<PhysicsComponent>(bodyToClone, out var physics))
return false;
int cloningCost = (int) physics.FixturesMass;
var cloningCost = (int) Math.Round(physics.FixturesMass * clonePod.BiomassRequirementMultiplier);
if (_configManager.GetCVar(CCVars.BiomassEasyMode))
cloningCost = (int) Math.Round(cloningCost * EasyModeCloningCost);
@@ -221,7 +226,6 @@ namespace Content.Server.Cloning.Systems
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);
@@ -235,7 +239,7 @@ namespace Content.Server.Cloning.Systems
{
foreach (var special in mind.CurrentJob.Prototype.Special)
{
if (special.GetType() == typeof(AddComponentSpecial))
if (special is AddComponentSpecial)
special.AfterEquip(mob);
}
}
@@ -246,7 +250,7 @@ namespace Content.Server.Cloning.Systems
public void UpdateStatus(CloningPodStatus status, CloningPodComponent cloningPod)
{
cloningPod.Status = status;
UpdateAppearance(cloningPod);
_appearance.SetData(cloningPod.Owner, CloningPodVisuals.Status, cloningPod.Status);
}
public override void Update(float frameTime)
@@ -280,7 +284,6 @@ namespace Content.Server.Cloning.Systems
EntityManager.RemoveComponent<BeingClonedComponent>(entity);
clonePod.BodyContainer.Remove(entity);
clonePod.CapturedMind = null;
clonePod.CloningProgress = 0f;
clonePod.UsedBiomass = 0;
UpdateStatus(CloningPodStatus.Idle, clonePod);