From 4792d840cf300544f862872e56077365a5bc2076 Mon Sep 17 00:00:00 2001 From: 0x6273 <0x40@keemail.me> Date: Tue, 4 Oct 2022 03:55:15 +0200 Subject: [PATCH] Biomass Reclaimer cleanup (#11551) --- .../BiomassReclaimerComponent.cs | 72 +++++++++++++------ .../BiomassReclaimerSystem.cs | 68 ++++++++---------- 2 files changed, 80 insertions(+), 60 deletions(-) diff --git a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs index dccdedf3d8..5a2fc7d8da 100644 --- a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs +++ b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerComponent.cs @@ -10,39 +10,54 @@ namespace Content.Server.Medical.BiomassReclaimer { public CancellationTokenSource? CancelToken; - [DataField("accumulator")] - public float Accumulator = 0f; + /// + /// This gets set for each mob it processes. + /// When it hits 0, there is a chance for the reclaimer to either spill blood or throw an item. + /// + [ViewVariables] + public float RandomMessTimer = 0f; - [DataField("randomMessAccumulator")] - public float RandomMessAccumulator = 0f; + /// + /// The interval for . + /// + [ViewVariables(VVAccess.ReadWrite), DataField("randomMessInterval")] public TimeSpan RandomMessInterval = TimeSpan.FromSeconds(5); /// /// This gets set for each mob it processes. - /// When accumulator hits this, spit out biomass. + /// When it hits 0, spit out biomass. /// - public float CurrentProcessingTime = 70f; + [ViewVariables] + public float ProcessingTimer = default; /// - /// This is calculated from the YieldPerUnitMass - /// and adjusted for genetic damage too. + /// Amount of biomass that the mob being processed will yield. + /// This is calculated from the YieldPerUnitMass. /// - public float CurrentExpectedYield = 28f; + [ViewVariables] + public uint CurrentExpectedYield = default; - public string BloodReagent = "Blood"; + /// + /// The reagent that will be spilled while processing a mob. + /// + [ViewVariables] + public string? BloodReagent; + /// + /// Entities that can be randomly spawned while processing a mob. + /// public List SpawnedEntities = new(); /// /// How many units of biomass it produces for each unit of mass. /// [ViewVariables(VVAccess.ReadWrite)] - public float YieldPerUnitMass = 0.4f; + public float YieldPerUnitMass = default; /// - /// The base yield when no components are upgraded + /// The base yield per mass unit when no components are upgraded. /// - [DataField("baseYieldPerUnitMass")] + [ViewVariables, DataField("baseYieldPerUnitMass")] public float BaseYieldPerUnitMass = 0.4f; /// @@ -52,18 +67,24 @@ namespace Content.Server.Medical.BiomassReclaimer public string MachinePartYieldAmount = "Manipulator"; /// - /// Lower number = faster processing. - /// Good for machine upgrading I guess. + /// How much the machine part quality affects the yield. + /// Going up a tier will multiply the yield by this amount. /// - [ViewVariables(VVAccess.ReadWrite)] - public float ProcessingSpeedMultiplier = 0.4f; + [DataField("partRatingYieldAmountMultiplier")] + public float PartRatingYieldAmountMultiplier = 1.25f; /// - /// The base multiplier of processing speed with no upgrades - /// that is used with the weight to calculate the yield + /// The time it takes to process a mob, per mass. /// - [DataField("baseProcessingSpeedMultiplier")] - public float BaseProcessingSpeedMultiplier = 0.4f; + [ViewVariables(VVAccess.ReadWrite)] + public float ProcessingTimePerUnitMass = default; + + /// + /// The base time per mass unit that it takes to process a mob + /// when no components are upgraded. + /// + [ViewVariables, DataField("baseProcessingTimePerUnitMass")] + public float BaseProcessingTimePerUnitMass = 0.5f; /// /// The machine part that increses the processing speed. @@ -71,10 +92,17 @@ namespace Content.Server.Medical.BiomassReclaimer [DataField("machinePartProcessSpeed", customTypeSerializer: typeof(PrototypeIdSerializer))] public string MachinePartProcessingSpeed = "Laser"; + /// + /// How much the machine part quality affects the yield. + /// Going up a tier will multiply the speed by this amount. + /// + [ViewVariables, DataField("partRatingSpeedMultiplier")] + public float PartRatingSpeedMultiplier = 1.35f; + /// /// Will this refuse to gib a living mob? /// - [DataField("safetyEnabled")] + [ViewVariables(VVAccess.ReadWrite), DataField("safetyEnabled")] public bool SafetyEnabled = true; } } diff --git a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs index a8119f34e7..3f4f49cf6c 100644 --- a/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs +++ b/Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs @@ -49,37 +49,34 @@ namespace Content.Server.Medical.BiomassReclaimer foreach (var (_, reclaimer) in EntityQuery()) { - reclaimer.Accumulator += frameTime; - reclaimer.RandomMessAccumulator += frameTime; + reclaimer.ProcessingTimer -= frameTime; + reclaimer.RandomMessTimer -= frameTime; - if (reclaimer.RandomMessAccumulator >= reclaimer.RandomMessInterval.TotalSeconds) + if (reclaimer.RandomMessTimer <= 0) { - if (_robustRandom.Prob(0.3f)) + if (_robustRandom.Prob(0.2f) && reclaimer.BloodReagent is not null) { - if (_robustRandom.Prob(0.7f)) - { - Solution blood = new(); - blood.AddReagent(reclaimer.BloodReagent, 50); - _spillableSystem.SpillAt(reclaimer.Owner, blood, "PuddleBlood"); - } - if (_robustRandom.Prob(0.1f) && reclaimer.SpawnedEntities.Count > 0) - { - var thrown = Spawn(_robustRandom.Pick(reclaimer.SpawnedEntities).PrototypeId, Transform(reclaimer.Owner).Coordinates); - Vector2 direction = (_robustRandom.Next(-30, 30), _robustRandom.Next(-30, 30)); - _throwing.TryThrow(thrown, direction, _robustRandom.Next(1, 10)); - } + Solution blood = new(); + blood.AddReagent(reclaimer.BloodReagent, 50); + _spillableSystem.SpillAt(reclaimer.Owner, blood, "PuddleBlood"); } - reclaimer.RandomMessAccumulator -= (float) reclaimer.RandomMessInterval.TotalSeconds; + if (_robustRandom.Prob(0.03f) && reclaimer.SpawnedEntities.Count > 0) + { + var thrown = Spawn(_robustRandom.Pick(reclaimer.SpawnedEntities).PrototypeId, Transform(reclaimer.Owner).Coordinates); + Vector2 direction = (_robustRandom.Next(-30, 30), _robustRandom.Next(-30, 30)); + _throwing.TryThrow(thrown, direction, _robustRandom.Next(1, 10)); + } + reclaimer.RandomMessTimer += (float) reclaimer.RandomMessInterval.TotalSeconds; } - if (reclaimer.Accumulator < reclaimer.CurrentProcessingTime) + if (reclaimer.ProcessingTimer > 0) { continue; } - reclaimer.Accumulator = 0; _stackSystem.SpawnMultiple((int) reclaimer.CurrentExpectedYield, 100, "Biomass", Transform(reclaimer.Owner).Coordinates); + reclaimer.BloodReagent = null; reclaimer.SpawnedEntities.Clear(); RemCompDeferred(reclaimer.Owner); } @@ -155,12 +152,13 @@ namespace Content.Server.Medical.BiomassReclaimer 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; + // Processing time slopes downwards with part rating. + component.ProcessingTimePerUnitMass = + component.BaseProcessingTimePerUnitMass / MathF.Pow(component.PartRatingSpeedMultiplier, laserRating - 1); - //linear increase by .1 per rating - component.YieldPerUnitMass = component.BaseYieldPerUnitMass + (manipRating - 1) * 0.1f; + // Yield slopes upwards with part rating. + component.YieldPerUnitMass = + component.BaseYieldPerUnitMass * MathF.Pow(component.PartRatingYieldAmountMultiplier, manipRating - 1); } private void OnReclaimSuccessful(ReclaimSuccessfulEvent args) @@ -179,8 +177,12 @@ namespace Content.Server.Medical.BiomassReclaimer return; reclaimer.CancelToken = null; } - private void StartProcessing(EntityUid toProcess, BiomassReclaimerComponent component) + + private void StartProcessing(EntityUid toProcess, BiomassReclaimerComponent component, PhysicsComponent? physics = null) { + if (!Resolve(toProcess, ref physics)) + return; + AddComp(component.Owner); if (TryComp(toProcess, out var stream)) @@ -192,19 +194,9 @@ namespace Content.Server.Medical.BiomassReclaimer component.SpawnedEntities = butcherableComponent.SpawnedEntities; } - component.CurrentExpectedYield = CalculateYield(toProcess, component); - component.CurrentProcessingTime = component.CurrentExpectedYield / component.YieldPerUnitMass * component.ProcessingSpeedMultiplier; - EntityManager.QueueDeleteEntity(toProcess); - } - private float CalculateYield(EntityUid uid, BiomassReclaimerComponent component) - { - if (!TryComp(uid, out var physics)) - { - Logger.Error("Somehow tried to extract biomass from " + uid + ", which has no physics component."); - return 0f; - } - - return (physics.FixturesMass * component.YieldPerUnitMass); + component.CurrentExpectedYield = (uint) Math.Max(0, physics.FixturesMass * component.YieldPerUnitMass); + component.ProcessingTimer = physics.FixturesMass * component.ProcessingTimePerUnitMass; + QueueDel(toProcess); } private bool CanGib(EntityUid uid, EntityUid dragged, BiomassReclaimerComponent component)