mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
* Replace instances of SolutionContainerSystem with SharedSolutionContainerSystem * guap * More fixes * Wait you can do that? --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com> (cherry picked from commit ef1fadf2752789ffc4f59309e2dd7490aee6f4e7)
51 lines
2.2 KiB
C#
51 lines
2.2 KiB
C#
using Content.Server.Body.Components;
|
|
using Content.Server.Body.Systems;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Chemistry.EntitySystems;
|
|
using Content.Shared.Chemistry.Reagent;
|
|
using Content.Shared.Contests;
|
|
using Content.Shared.HeightAdjust;
|
|
using Robust.Shared.Configuration;
|
|
|
|
namespace Content.Server.HeightAdjust;
|
|
|
|
public sealed class BloodstreamAdjustSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly BloodstreamSystem _bloodstream = default!;
|
|
[Dependency] private readonly IConfigurationManager _config = default!;
|
|
[Dependency] private readonly ContestsSystem _contests = default!;
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<BloodstreamAffectedByMassComponent, MapInitEvent>((uid, comp, _) => TryAdjustBloodstream((uid, comp)));
|
|
SubscribeLocalEvent<BloodstreamAffectedByMassComponent, HeightAdjustedEvent>((uid, comp, _) => TryAdjustBloodstream((uid, comp)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adjusts the bloodstream of the specified entity based on the settings provided by the component.
|
|
/// </summary>
|
|
public bool TryAdjustBloodstream(Entity<BloodstreamAffectedByMassComponent> ent)
|
|
{
|
|
if (!TryComp<BloodstreamComponent>(ent, out var bloodstream)
|
|
|| !_solutionContainer.TryGetSolution(ent.Owner, bloodstream.BloodSolutionName, out var bloodSolutionEnt)
|
|
|| bloodstream.BloodMaxVolume == 0
|
|
|| !_config.GetCVar(CCVars.HeightAdjustModifiesBloodstream))
|
|
return false;
|
|
|
|
var bloodSolution = bloodSolutionEnt.Value.Comp.Solution;
|
|
|
|
var factor = Math.Pow(_contests.MassContest(ent, bypassClamp: true, rangeFactor: 4f), ent.Comp.Power);
|
|
factor = Math.Clamp(factor, ent.Comp.Min, ent.Comp.Max);
|
|
|
|
var newVolume = bloodstream.BloodMaxVolume * factor;
|
|
var newBloodLevel = bloodSolution.FillFraction * newVolume;
|
|
bloodSolution.MaxVolume = newVolume;
|
|
bloodSolution.SetContents([new ReagentQuantity(bloodstream.BloodReagent, newBloodLevel, null)], false);
|
|
|
|
_bloodstream.SetBloodMaxVolume(ent.Owner, newVolume, bloodstream);
|
|
|
|
return true;
|
|
}
|
|
}
|