Files

59 lines
2.6 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Body.Components;
using Content.Shared.Body.Systems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Forensics;
2021-11-30 16:47:21 -07:00
namespace Content.Server.Body.Systems;
public sealed class BloodstreamSystem : SharedBloodstreamSystem
2021-11-30 16:47:21 -07:00
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BloodstreamComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<BloodstreamComponent, GenerateDnaEvent>(OnDnaGenerated);
2022-04-05 04:02:33 +12:00
}
// not sure if we can move this to shared or not
// it would certainly help if SolutionContainer was documented
// but since we usually don't add the component dynamically to entities we can keep this unpredicted for now
private void OnComponentInit(Entity<BloodstreamComponent> entity, ref ComponentInit args)
2021-11-30 16:47:21 -07:00
{
if (!SolutionContainer.EnsureSolution(entity.Owner,
entity.Comp.ChemicalSolutionName,
out var chemicalSolution) ||
!SolutionContainer.EnsureSolution(entity.Owner,
entity.Comp.BloodSolutionName,
out var bloodSolution) ||
!SolutionContainer.EnsureSolution(entity.Owner,
entity.Comp.BloodTemporarySolutionName,
out var tempSolution))
return;
2022-02-17 15:00:41 -07:00
chemicalSolution.MaxVolume = entity.Comp.ChemicalMaxVolume;
bloodSolution.MaxVolume = entity.Comp.BloodMaxVolume;
tempSolution.MaxVolume = entity.Comp.BleedPuddleThreshold * 4; // give some leeway, for chemstream as well
2022-02-17 15:00:41 -07:00
// Fill blood solution with BLOOD
// The DNA string might not be initialized yet, but the reagent data gets updated in the GenerateDnaEvent subscription
bloodSolution.AddReagent(new ReagentId(entity.Comp.BloodReagent, GetEntityBloodData(entity.Owner)), entity.Comp.BloodMaxVolume - bloodSolution.Volume);
2022-02-17 15:00:41 -07:00
}
// forensics is not predicted yet
private void OnDnaGenerated(Entity<BloodstreamComponent> entity, ref GenerateDnaEvent args)
{
if (SolutionContainer.ResolveSolution(entity.Owner, entity.Comp.BloodSolutionName, ref entity.Comp.BloodSolution, out var bloodSolution))
{
foreach (var reagent in bloodSolution.Contents)
{
List<ReagentData> reagentData = reagent.Reagent.EnsureReagentData();
reagentData.RemoveAll(x => x is DnaData);
reagentData.AddRange(GetEntityBloodData(entity.Owner));
}
}
else
Log.Error("Unable to set bloodstream DNA, solution entity could not be resolved");
}
2021-11-30 16:47:21 -07:00
}