Biomass Reclaimer cleanup (#11551)

This commit is contained in:
0x6273
2022-10-04 03:55:15 +02:00
committed by GitHub
parent fb839f865e
commit 4792d840cf
2 changed files with 80 additions and 60 deletions

View File

@@ -10,39 +10,54 @@ namespace Content.Server.Medical.BiomassReclaimer
{ {
public CancellationTokenSource? CancelToken; public CancellationTokenSource? CancelToken;
[DataField("accumulator")] /// <summary>
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.
/// </summary>
[ViewVariables]
public float RandomMessTimer = 0f;
[DataField("randomMessAccumulator")] /// <summary>
public float RandomMessAccumulator = 0f; /// The interval for <see cref="RandomMessTimer"/>.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("randomMessInterval")]
public TimeSpan RandomMessInterval = TimeSpan.FromSeconds(5); public TimeSpan RandomMessInterval = TimeSpan.FromSeconds(5);
/// <summary> /// <summary>
/// This gets set for each mob it processes. /// This gets set for each mob it processes.
/// When accumulator hits this, spit out biomass. /// When it hits 0, spit out biomass.
/// </summary> /// </summary>
public float CurrentProcessingTime = 70f; [ViewVariables]
public float ProcessingTimer = default;
/// <summary> /// <summary>
/// This is calculated from the YieldPerUnitMass /// Amount of biomass that the mob being processed will yield.
/// and adjusted for genetic damage too. /// This is calculated from the YieldPerUnitMass.
/// </summary> /// </summary>
public float CurrentExpectedYield = 28f; [ViewVariables]
public uint CurrentExpectedYield = default;
public string BloodReagent = "Blood"; /// <summary>
/// The reagent that will be spilled while processing a mob.
/// </summary>
[ViewVariables]
public string? BloodReagent;
/// <summary>
/// Entities that can be randomly spawned while processing a mob.
/// </summary>
public List<EntitySpawnEntry> SpawnedEntities = new(); public List<EntitySpawnEntry> SpawnedEntities = new();
/// <summary> /// <summary>
/// How many units of biomass it produces for each unit of mass. /// How many units of biomass it produces for each unit of mass.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float YieldPerUnitMass = 0.4f; public float YieldPerUnitMass = default;
/// <summary> /// <summary>
/// The base yield when no components are upgraded /// The base yield per mass unit when no components are upgraded.
/// </summary> /// </summary>
[DataField("baseYieldPerUnitMass")] [ViewVariables, DataField("baseYieldPerUnitMass")]
public float BaseYieldPerUnitMass = 0.4f; public float BaseYieldPerUnitMass = 0.4f;
/// <summary> /// <summary>
@@ -52,18 +67,24 @@ namespace Content.Server.Medical.BiomassReclaimer
public string MachinePartYieldAmount = "Manipulator"; public string MachinePartYieldAmount = "Manipulator";
/// <summary> /// <summary>
/// Lower number = faster processing. /// How much the machine part quality affects the yield.
/// Good for machine upgrading I guess. /// Going up a tier will multiply the yield by this amount.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [DataField("partRatingYieldAmountMultiplier")]
public float ProcessingSpeedMultiplier = 0.4f; public float PartRatingYieldAmountMultiplier = 1.25f;
/// <summary> /// <summary>
/// The base multiplier of processing speed with no upgrades /// The time it takes to process a mob, per mass.
/// that is used with the weight to calculate the yield
/// </summary> /// </summary>
[DataField("baseProcessingSpeedMultiplier")] [ViewVariables(VVAccess.ReadWrite)]
public float BaseProcessingSpeedMultiplier = 0.4f; public float ProcessingTimePerUnitMass = default;
/// <summary>
/// The base time per mass unit that it takes to process a mob
/// when no components are upgraded.
/// </summary>
[ViewVariables, DataField("baseProcessingTimePerUnitMass")]
public float BaseProcessingTimePerUnitMass = 0.5f;
/// <summary> /// <summary>
/// The machine part that increses the processing speed. /// The machine part that increses the processing speed.
@@ -71,10 +92,17 @@ namespace Content.Server.Medical.BiomassReclaimer
[DataField("machinePartProcessSpeed", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))] [DataField("machinePartProcessSpeed", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartProcessingSpeed = "Laser"; public string MachinePartProcessingSpeed = "Laser";
/// <summary>
/// How much the machine part quality affects the yield.
/// Going up a tier will multiply the speed by this amount.
/// </summary>
[ViewVariables, DataField("partRatingSpeedMultiplier")]
public float PartRatingSpeedMultiplier = 1.35f;
/// <summary> /// <summary>
/// Will this refuse to gib a living mob? /// Will this refuse to gib a living mob?
/// </summary> /// </summary>
[DataField("safetyEnabled")] [ViewVariables(VVAccess.ReadWrite), DataField("safetyEnabled")]
public bool SafetyEnabled = true; public bool SafetyEnabled = true;
} }
} }

View File

@@ -49,37 +49,34 @@ namespace Content.Server.Medical.BiomassReclaimer
foreach (var (_, reclaimer) in EntityQuery<ActiveBiomassReclaimerComponent, BiomassReclaimerComponent>()) foreach (var (_, reclaimer) in EntityQuery<ActiveBiomassReclaimerComponent, BiomassReclaimerComponent>())
{ {
reclaimer.Accumulator += frameTime; reclaimer.ProcessingTimer -= frameTime;
reclaimer.RandomMessAccumulator += 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(); Solution blood = new();
blood.AddReagent(reclaimer.BloodReagent, 50); blood.AddReagent(reclaimer.BloodReagent, 50);
_spillableSystem.SpillAt(reclaimer.Owner, blood, "PuddleBlood"); _spillableSystem.SpillAt(reclaimer.Owner, blood, "PuddleBlood");
} }
if (_robustRandom.Prob(0.1f) && reclaimer.SpawnedEntities.Count > 0) if (_robustRandom.Prob(0.03f) && reclaimer.SpawnedEntities.Count > 0)
{ {
var thrown = Spawn(_robustRandom.Pick(reclaimer.SpawnedEntities).PrototypeId, Transform(reclaimer.Owner).Coordinates); var thrown = Spawn(_robustRandom.Pick(reclaimer.SpawnedEntities).PrototypeId, Transform(reclaimer.Owner).Coordinates);
Vector2 direction = (_robustRandom.Next(-30, 30), _robustRandom.Next(-30, 30)); Vector2 direction = (_robustRandom.Next(-30, 30), _robustRandom.Next(-30, 30));
_throwing.TryThrow(thrown, direction, _robustRandom.Next(1, 10)); _throwing.TryThrow(thrown, direction, _robustRandom.Next(1, 10));
} }
} reclaimer.RandomMessTimer += (float) reclaimer.RandomMessInterval.TotalSeconds;
reclaimer.RandomMessAccumulator -= (float) reclaimer.RandomMessInterval.TotalSeconds;
} }
if (reclaimer.Accumulator < reclaimer.CurrentProcessingTime) if (reclaimer.ProcessingTimer > 0)
{ {
continue; continue;
} }
reclaimer.Accumulator = 0;
_stackSystem.SpawnMultiple((int) reclaimer.CurrentExpectedYield, 100, "Biomass", Transform(reclaimer.Owner).Coordinates); _stackSystem.SpawnMultiple((int) reclaimer.CurrentExpectedYield, 100, "Biomass", Transform(reclaimer.Owner).Coordinates);
reclaimer.BloodReagent = null;
reclaimer.SpawnedEntities.Clear(); reclaimer.SpawnedEntities.Clear();
RemCompDeferred<ActiveBiomassReclaimerComponent>(reclaimer.Owner); RemCompDeferred<ActiveBiomassReclaimerComponent>(reclaimer.Owner);
} }
@@ -155,12 +152,13 @@ namespace Content.Server.Medical.BiomassReclaimer
var laserRating = args.PartRatings[component.MachinePartProcessingSpeed]; var laserRating = args.PartRatings[component.MachinePartProcessingSpeed];
var manipRating = args.PartRatings[component.MachinePartYieldAmount]; var manipRating = args.PartRatings[component.MachinePartYieldAmount];
//sloping down from 1/2 multiplier // Processing time slopes downwards with part rating.
component.ProcessingSpeedMultiplier = component.ProcessingTimePerUnitMass =
component.BaseProcessingSpeedMultiplier * MathF.Pow(0.65f, laserRating - 1) + 0.1f; component.BaseProcessingTimePerUnitMass / MathF.Pow(component.PartRatingSpeedMultiplier, laserRating - 1);
//linear increase by .1 per rating // Yield slopes upwards with part rating.
component.YieldPerUnitMass = component.BaseYieldPerUnitMass + (manipRating - 1) * 0.1f; component.YieldPerUnitMass =
component.BaseYieldPerUnitMass * MathF.Pow(component.PartRatingYieldAmountMultiplier, manipRating - 1);
} }
private void OnReclaimSuccessful(ReclaimSuccessfulEvent args) private void OnReclaimSuccessful(ReclaimSuccessfulEvent args)
@@ -179,8 +177,12 @@ namespace Content.Server.Medical.BiomassReclaimer
return; return;
reclaimer.CancelToken = null; 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<ActiveBiomassReclaimerComponent>(component.Owner); AddComp<ActiveBiomassReclaimerComponent>(component.Owner);
if (TryComp<BloodstreamComponent>(toProcess, out var stream)) if (TryComp<BloodstreamComponent>(toProcess, out var stream))
@@ -192,19 +194,9 @@ namespace Content.Server.Medical.BiomassReclaimer
component.SpawnedEntities = butcherableComponent.SpawnedEntities; component.SpawnedEntities = butcherableComponent.SpawnedEntities;
} }
component.CurrentExpectedYield = CalculateYield(toProcess, component); component.CurrentExpectedYield = (uint) Math.Max(0, physics.FixturesMass * component.YieldPerUnitMass);
component.CurrentProcessingTime = component.CurrentExpectedYield / component.YieldPerUnitMass * component.ProcessingSpeedMultiplier; component.ProcessingTimer = physics.FixturesMass * component.ProcessingTimePerUnitMass;
EntityManager.QueueDeleteEntity(toProcess); QueueDel(toProcess);
}
private float CalculateYield(EntityUid uid, BiomassReclaimerComponent component)
{
if (!TryComp<PhysicsComponent>(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);
} }
private bool CanGib(EntityUid uid, EntityUid dragged, BiomassReclaimerComponent component) private bool CanGib(EntityUid uid, EntityUid dragged, BiomassReclaimerComponent component)