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

@@ -49,37 +49,34 @@ namespace Content.Server.Medical.BiomassReclaimer
foreach (var (_, reclaimer) in EntityQuery<ActiveBiomassReclaimerComponent, BiomassReclaimerComponent>())
{
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<ActiveBiomassReclaimerComponent>(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<ActiveBiomassReclaimerComponent>(component.Owner);
if (TryComp<BloodstreamComponent>(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<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);
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)