From 24f7b6ffc598f04679083ab8df5b920a6a6f56f5 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Tue, 18 Apr 2023 14:27:05 +0000 Subject: [PATCH] experimental welder fuel regeneration (#15475) * solution regeneration system * experimental welding tool regenerates 1u of fuel every second * pro * use a solution * added -> generated --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- .../SolutionRegenerationComponent.cs | 39 ++++++++++++++++++ .../SolutionRegenerationSystem.cs | 40 +++++++++++++++++++ .../Entities/Objects/Tools/welders.yml | 6 +++ 3 files changed, 85 insertions(+) create mode 100644 Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs create mode 100644 Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs diff --git a/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs b/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs new file mode 100644 index 0000000000..d84f9365c7 --- /dev/null +++ b/Content.Server/Chemistry/Components/SolutionRegenerationComponent.cs @@ -0,0 +1,39 @@ +using Content.Server.Chemistry.EntitySystems; +using Content.Shared.Chemistry.Components; +using Content.Shared.FixedPoint; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; + +namespace Content.Server.Chemistry.Components; + +/// +/// Passively increases a solution's quantity of a reagent. +/// +[RegisterComponent] +[Access(typeof(SolutionRegenerationSystem))] +public sealed class SolutionRegenerationComponent : Component +{ + /// + /// The name of the solution to add to. + /// + [DataField("solution", required: true), ViewVariables(VVAccess.ReadWrite)] + public string Solution = string.Empty; + + /// + /// The reagent(s) to be regenerated in the solution. + /// + [DataField("generated", required: true), ViewVariables(VVAccess.ReadWrite)] + public Solution Generated = default!; + + /// + /// How long it takes to regenerate once. + /// + [DataField("duration"), ViewVariables(VVAccess.ReadWrite)] + public TimeSpan Duration = TimeSpan.FromSeconds(1); + + /// + /// The time when the next regeneration will occur. + /// + [DataField("nextChargeTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)] + public TimeSpan NextRegenTime = TimeSpan.FromSeconds(0); +} diff --git a/Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs new file mode 100644 index 0000000000..d6d74820d1 --- /dev/null +++ b/Content.Server/Chemistry/EntitySystems/SolutionRegenerationSystem.cs @@ -0,0 +1,40 @@ +using Content.Server.Chemistry.Components; +using Content.Server.Chemistry.Components.SolutionManager; +using Robust.Shared.Timing; + +namespace Content.Server.Chemistry.EntitySystems; + +public sealed class SolutionRegenerationSystem : EntitySystem +{ + [Dependency] private readonly SolutionContainerSystem _solutionContainer = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnUnpaused); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var regen, out var manager)) + { + if (_timing.CurTime < regen.NextRegenTime) + continue; + + // timer ignores if its full, it's just a fixed cycle + regen.NextRegenTime = _timing.CurTime + regen.Duration; + if (_solutionContainer.TryGetSolution(uid, regen.Solution, out var solution, manager)) + _solutionContainer.TryAddSolution(uid, solution, regen.Generated); + } + } + + private void OnUnpaused(EntityUid uid, SolutionRegenerationComponent comp, ref EntityUnpausedEvent args) + { + comp.NextRegenTime += args.PausedTime; + } +} diff --git a/Resources/Prototypes/Entities/Objects/Tools/welders.yml b/Resources/Prototypes/Entities/Objects/Tools/welders.yml index 0834b192b0..4a38583c84 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/welders.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/welders.yml @@ -127,6 +127,12 @@ enabled: false radius: 1.5 color: lightblue + - type: SolutionRegeneration + solution: Welder + generated: + reagents: + - ReagentId: WeldingFuel + Quantity: 1 - type: entity name: emergency welding tool