Allow solutions to store extra reagent data (#19323)

This commit is contained in:
Leon Friedrich
2023-09-05 09:55:10 +12:00
committed by GitHub
parent a6b81058d0
commit e4ca6f4fb9
52 changed files with 932 additions and 538 deletions

View File

@@ -1,11 +1,20 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
namespace Content.Server.Power.Components;
[RegisterComponent]
public sealed partial class RiggableComponent : Component
{
public const string SolutionName = "battery";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("isRigged")]
public bool IsRigged;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("solution")]
public string Solution = "battery";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("reagent")]
public ReagentQuantity RequiredQuantity = new("Plasma", FixedPoint2.New(5), null);
}

View File

@@ -4,6 +4,7 @@ using Content.Server.Explosion.EntitySystems;
using Content.Server.Kitchen.Components;
using Content.Server.Power.Components;
using Content.Server.Stunnable.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Database;
using Content.Shared.Rejuvenate;
@@ -47,27 +48,19 @@ public sealed class RiggableSystem : EntitySystem
private void OnSolutionChanged(EntityUid uid, RiggableComponent component, SolutionChangedEvent args)
{
if (TryComp<BatteryComponent>(uid, out var battery))
{
IsRigged(uid, args);
}
if (args.SolutionId != component.Solution)
return;
if (component.IsRigged)
var wasRigged = component.IsRigged;
var quantity = args.Solution.GetReagentQuantity(component.RequiredQuantity.Reagent);
component.IsRigged = quantity >= component.RequiredQuantity.Quantity;
if (component.IsRigged && !wasRigged)
{
_adminLogger.Add(LogType.Explosion, LogImpact.Medium, $"{ToPrettyString(uid)} has been rigged up to explode when used.");
}
}
public void IsRigged(EntityUid uid, SolutionChangedEvent args)
{
if (TryComp<RiggableComponent>(uid, out var riggableComp))
{
riggableComp.IsRigged = _solutionsSystem.TryGetSolution(uid, RiggableComponent.SolutionName, out var solution)
&& solution.TryGetReagent("Plasma", out var plasma)
&& plasma >= 5;
}
}
public void Explode(EntityUid uid, BatteryComponent? battery = null, EntityUid? cause = null)
{
if (!Resolve(uid, ref battery))

View File

@@ -81,7 +81,7 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
foreach (var reagentQuantity in solution)
{
if (reagentQuantity.ReagentId != component.Reagent)
if (reagentQuantity.Reagent.Prototype != component.Reagent)
{
args.Clogged = true;
return;
@@ -94,7 +94,7 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
if (!_solutionContainer.TryGetSolution(uid, component.Solution, out var solution))
return;
var availableReagent = solution.GetReagentQuantity(component.Reagent).Value;
var availableReagent = solution.GetTotalPrototypeQuantity(component.Reagent).Value;
var toRemove = RemoveFractionalFuel(
ref component.FractionalReagent,
args.FuelUsed,
@@ -112,8 +112,8 @@ public sealed class GeneratorSystem : SharedGeneratorSystem
if (!_solutionContainer.TryGetSolution(uid, component.Solution, out var solution))
return;
var reagent = component.FractionalReagent * FixedPoint2.Epsilon.Float()
+ solution.GetReagentQuantity(component.Reagent).Float();
var availableReagent = solution.GetTotalPrototypeQuantity(component.Reagent).Float();
var reagent = component.FractionalReagent * FixedPoint2.Epsilon.Float() + availableReagent;
args.Fuel = reagent * component.Multiplier;
}