De-hardcode chemical metabolism of StomachComponent (#437)
* Move chemical reaction effects into Chemistry/ReactionEffects/ subfolder * Replace hardcoded StomachComponent metabolism with IMetabolizable The benefits of this approach are that reagent metabolism effects are not hardcoded into StomachComponent, and metabolism effects can be more easily chained together in yaml prototypes, and reagents can have different metabolism rates. One problem with this approach is that getting metabolism rates slower than 1u / second is impossible. Implementing #377 should resolve that problem. * Fix DefaultFood and DefaultDrink so they remove reagent regardless of Hunger/ThirstComponent presence Previously if neither of those were present the reagents wouldn't be removed from the stomach. This fixes that. * Additional comment on function * Make metabolizer interface implementations explicit Also removed some unused using statements * Make StomachComponent._reagentDeltas readonly * Fix misleading variable names and docs for metabolizables Changes one of the arguments for `IMetabolizable.Metabolize()` to be called `tickTime` instead of `frameTime` to more accurately reflect it's purpose. It's not really the frametime, but the time since the last metabolism tick. Also updated and expanded the docs to reflect this and to be more clear.
This commit is contained in:
committed by
Pieter-Jan Briers
parent
1f177a044d
commit
3ab8036363
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Content.Server.Explosions;
|
||||
using Content.Server.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.Chemistry.ReactionEffects
|
||||
{
|
||||
class ExplosionReactionEffect : IReactionEffect
|
||||
{
|
||||
private float _devastationRange;
|
||||
private float _heavyImpactRange;
|
||||
private float _lightImpactRange;
|
||||
private float _flashRange;
|
||||
|
||||
/// <summary>
|
||||
/// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount.
|
||||
/// </summary>
|
||||
private bool _scaled;
|
||||
/// <summary>
|
||||
/// Maximum scaling on ranges. For example, if it equals 5, then it won't scaled anywhere past
|
||||
/// 5 times the minimum reactant amount.
|
||||
/// </summary>
|
||||
private float _maxScale;
|
||||
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _devastationRange, "devastationRange", 1);
|
||||
serializer.DataField(ref _heavyImpactRange, "heavyImpactRange", 2);
|
||||
serializer.DataField(ref _lightImpactRange, "lightImpactRange", 3);
|
||||
serializer.DataField(ref _flashRange, "flashRange", 0);
|
||||
|
||||
serializer.DataField(ref _scaled, "scaled", false);
|
||||
serializer.DataField(ref _maxScale, "maxScale", 1);
|
||||
}
|
||||
|
||||
public void React(IEntity solutionEntity, int intensity)
|
||||
{
|
||||
float floatIntensity = intensity; //Use float to avoid truncation in scaling
|
||||
if (solutionEntity == null)
|
||||
return;
|
||||
if(!solutionEntity.TryGetComponent(out SolutionComponent solution))
|
||||
return;
|
||||
|
||||
//Handle scaling
|
||||
if (_scaled)
|
||||
{
|
||||
floatIntensity = Math.Min(floatIntensity, _maxScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
floatIntensity = 1;
|
||||
}
|
||||
|
||||
//Calculate intensities
|
||||
int finalDevastationRange = (int)Math.Round(_devastationRange * floatIntensity);
|
||||
int finalHeavyImpactRange = (int)Math.Round(_heavyImpactRange * floatIntensity);
|
||||
int finalLightImpactRange = (int)Math.Round(_lightImpactRange * floatIntensity);
|
||||
int finalFlashRange = (int)Math.Round(_flashRange * floatIntensity);
|
||||
ExplosionHelper.SpawnExplosion(solutionEntity.Transform.GridPosition, finalDevastationRange,
|
||||
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user