From 0c14926e6858239aa5acdcee9a5435da48796c7f Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Tue, 27 Sep 2022 04:00:30 -0400 Subject: [PATCH] biomass reclaimer machine part upgrade support (#11545) * biomass reclaimer upgrade * readonly struct --- .../BiomassReclaimerComponent.cs | 33 ++++++++++++++-- .../BiomassReclaimerSystem.cs | 38 +++++++++++++------ 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs index 740ac4cb92..dccdedf3d8 100644 --- a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs +++ b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs @@ -1,5 +1,7 @@ using Content.Shared.Storage; using System.Threading; +using Content.Shared.Construction.Prototypes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; namespace Content.Server.Medical.BiomassReclaimer { @@ -34,15 +36,40 @@ namespace Content.Server.Medical.BiomassReclaimer /// /// How many units of biomass it produces for each unit of mass. /// - [DataField("yieldPerUnitMass")] + [ViewVariables(VVAccess.ReadWrite)] public float YieldPerUnitMass = 0.4f; + /// + /// The base yield when no components are upgraded + /// + [DataField("baseYieldPerUnitMass")] + public float BaseYieldPerUnitMass = 0.4f; + + /// + /// Machine part whose rating modifies the yield per mass. + /// + [DataField("machinePartYieldAmount", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartYieldAmount = "Manipulator"; + /// /// Lower number = faster processing. /// Good for machine upgrading I guess. - /// - public float ProcessingSpeedMultiplier = 0.5f; + /// + [ViewVariables(VVAccess.ReadWrite)] + public float ProcessingSpeedMultiplier = 0.4f; + /// + /// The base multiplier of processing speed with no upgrades + /// that is used with the weight to calculate the yield + /// + [DataField("baseProcessingSpeedMultiplier")] + public float BaseProcessingSpeedMultiplier = 0.4f; + + /// + /// The machine part that increses the processing speed. + /// + [DataField("machinePartProcessSpeed", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string MachinePartProcessingSpeed = "Laser"; /// /// Will this refuse to gib a living mob? diff --git a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs index 56d17b2af0..a8119f34e7 100644 --- a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs +++ b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs @@ -15,6 +15,7 @@ using Content.Server.Power.Components; using Content.Server.Fluids.EntitySystems; using Content.Server.Body.Components; using Content.Server.Climbing; +using Content.Server.Construction; using Content.Server.DoAfter; using Content.Server.Humanoid; using Content.Server.Mind.Components; @@ -91,6 +92,7 @@ namespace Content.Server.Medical.BiomassReclaimer SubscribeLocalEvent(OnUnanchorAttempt); SubscribeLocalEvent(OnAfterInteractUsing); SubscribeLocalEvent(OnClimbedOn); + SubscribeLocalEvent(OnRefreshParts); SubscribeLocalEvent(OnReclaimSuccessful); SubscribeLocalEvent(OnReclaimCancelled); } @@ -148,6 +150,19 @@ namespace Content.Server.Medical.BiomassReclaimer StartProcessing(args.Climber, component); } + private void OnRefreshParts(EntityUid uid, BiomassReclaimerComponent component, RefreshPartsEvent args) + { + var laserRating = args.PartRatings[component.MachinePartProcessingSpeed]; + var manipRating = args.PartRatings[component.MachinePartYieldAmount]; + + //sloping down from 1/2 multiplier + component.ProcessingSpeedMultiplier = + component.BaseProcessingSpeedMultiplier * MathF.Pow(0.65f, laserRating - 1) + 0.1f; + + //linear increase by .1 per rating + component.YieldPerUnitMass = component.BaseYieldPerUnitMass + (manipRating - 1) * 0.1f; + } + private void OnReclaimSuccessful(ReclaimSuccessfulEvent args) { if (!TryComp(args.Reclaimer, out var reclaimer)) @@ -210,19 +225,20 @@ namespace Content.Server.Medical.BiomassReclaimer return false; // Reject souled bodies in easy mode. - if (_configManager.GetCVar(CCVars.BiomassEasyMode) && HasComp(dragged) && + if (_configManager.GetCVar(CCVars.BiomassEasyMode) && + HasComp(dragged) && TryComp(dragged, out var mindComp)) - { - if (mindComp.Mind?.UserId != null && _playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out var client)) - return false; - } + { + if (mindComp.Mind?.UserId != null && _playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out _)) + return false; + } return true; } - private sealed class ReclaimCancelledEvent : EntityEventArgs + private readonly struct ReclaimCancelledEvent { - public EntityUid Reclaimer; + public readonly EntityUid Reclaimer; public ReclaimCancelledEvent(EntityUid reclaimer) { @@ -230,11 +246,11 @@ namespace Content.Server.Medical.BiomassReclaimer } } - private sealed class ReclaimSuccessfulEvent : EntityEventArgs + private readonly struct ReclaimSuccessfulEvent { - public EntityUid User; - public EntityUid Target; - public EntityUid Reclaimer; + public readonly EntityUid User; + public readonly EntityUid Target; + public readonly EntityUid Reclaimer; public ReclaimSuccessfulEvent(EntityUid user, EntityUid target, EntityUid reclaimer) { User = user;