UseDelay + ItemCooldown merge (#22502)
This commit is contained in:
@@ -13,32 +13,21 @@ public sealed partial class RadiationCollectorComponent : Component
|
||||
/// <summary>
|
||||
/// How much joules will collector generate for each rad.
|
||||
/// </summary>
|
||||
[DataField("chargeModifier")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ChargeModifier = 30000f;
|
||||
|
||||
/// <summary>
|
||||
/// Cooldown time between users interaction.
|
||||
/// Is the machine enabled.
|
||||
/// </summary>
|
||||
[DataField("cooldown")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan Cooldown = TimeSpan.FromSeconds(0.81f);
|
||||
|
||||
/// <summary>
|
||||
/// Was machine activated by user?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField]
|
||||
[ViewVariables]
|
||||
public bool Enabled;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp when machine can be deactivated again.
|
||||
/// </summary>
|
||||
public TimeSpan CoolDownEnd;
|
||||
|
||||
/// <summary>
|
||||
/// List of gases that will react to the radiation passing through the collector
|
||||
/// </summary>
|
||||
[DataField("radiationReactiveGases")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public List<RadiationReactiveGas>? RadiationReactiveGases;
|
||||
}
|
||||
@@ -50,15 +39,15 @@ public sealed partial class RadiationCollectorComponent : Component
|
||||
public sealed partial class RadiationReactiveGas
|
||||
{
|
||||
/// <summary>
|
||||
/// The reactant gas
|
||||
/// The reactant gas
|
||||
/// </summary>
|
||||
[DataField("reactantPrototype", required: true)]
|
||||
public Gas Reactant = Gas.Plasma;
|
||||
[DataField(required: true)]
|
||||
public Gas ReactantPrototype;
|
||||
|
||||
/// <summary>
|
||||
/// Multipier for the amount of power produced by the radiation collector when using this gas
|
||||
/// </summary>
|
||||
[DataField("powerGenerationEfficiency")]
|
||||
[DataField]
|
||||
public float PowerGenerationEfficiency = 1f;
|
||||
|
||||
/// <summary>
|
||||
@@ -67,7 +56,7 @@ public sealed partial class RadiationReactiveGas
|
||||
/// /// <remarks>
|
||||
/// Set to zero if the reactant does not deplete
|
||||
/// </remarks>
|
||||
[DataField("reactantBreakdownRate")]
|
||||
[DataField]
|
||||
public float ReactantBreakdownRate = 1f;
|
||||
|
||||
/// <summary>
|
||||
@@ -76,12 +65,12 @@ public sealed partial class RadiationReactiveGas
|
||||
/// <remarks>
|
||||
/// Leave null if the reactant no byproduct gas is to be formed
|
||||
/// </remarks>
|
||||
[DataField("byproductPrototype")]
|
||||
public Gas? Byproduct = null;
|
||||
[DataField]
|
||||
public Gas? Byproduct;
|
||||
|
||||
/// <summary>
|
||||
/// The molar ratio of the byproduct gas generated from the reactant gas
|
||||
/// </summary>
|
||||
[DataField("molarRatio")]
|
||||
[DataField]
|
||||
public float MolarRatio = 1f;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Radiation.Events;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Server.Atmos;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Radiation.Events;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Timing;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Singularity.EntitySystems;
|
||||
|
||||
@@ -20,6 +23,10 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
[Dependency] private readonly BatterySystem _batterySystem = default!;
|
||||
|
||||
private const string GasTankContainer = "gas_tank";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -36,12 +43,11 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
private bool TryGetLoadedGasTank(EntityUid uid, [NotNullWhen(true)] out GasTankComponent? gasTankComponent)
|
||||
{
|
||||
gasTankComponent = null;
|
||||
var container = _containerSystem.EnsureContainer<ContainerSlot>(uid, "GasTank");
|
||||
|
||||
if (container.ContainedEntity == null)
|
||||
if (!_containerSystem.TryGetContainer(uid, GasTankContainer, out var container) || container.ContainedEntities.Count == 0)
|
||||
return false;
|
||||
|
||||
if (!EntityManager.TryGetComponent(container.ContainedEntity, out gasTankComponent))
|
||||
if (!EntityManager.TryGetComponent(container.ContainedEntities.First(), out gasTankComponent))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -61,13 +67,10 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
|
||||
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
|
||||
{
|
||||
var curTime = _gameTiming.CurTime;
|
||||
|
||||
if (curTime < component.CoolDownEnd)
|
||||
if (TryComp(uid, out UseDelayComponent? useDelay) && !_useDelay.TryResetDelay((uid, useDelay), true))
|
||||
return;
|
||||
|
||||
ToggleCollector(uid, args.User, component);
|
||||
component.CoolDownEnd = curTime + component.Cooldown;
|
||||
}
|
||||
|
||||
private void OnRadiation(EntityUid uid, RadiationCollectorComponent component, OnIrradiatedEvent args)
|
||||
@@ -82,7 +85,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
|
||||
foreach (var gas in component.RadiationReactiveGases)
|
||||
{
|
||||
float reactantMol = gasTankComponent.Air.GetMoles(gas.Reactant);
|
||||
float reactantMol = gasTankComponent.Air.GetMoles(gas.ReactantPrototype);
|
||||
float delta = args.TotalRads * reactantMol * gas.ReactantBreakdownRate;
|
||||
|
||||
// We need to offset the huge power gains possible when using very cold gases
|
||||
@@ -95,7 +98,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
|
||||
if (delta > 0)
|
||||
{
|
||||
gasTankComponent.Air.AdjustMoles(gas.Reactant, -Math.Min(delta, reactantMol));
|
||||
gasTankComponent.Air.AdjustMoles(gas.ReactantPrototype, -Math.Min(delta, reactantMol));
|
||||
}
|
||||
|
||||
if (gas.Byproduct != null)
|
||||
@@ -111,7 +114,7 @@ public sealed class RadiationCollectorSystem : EntitySystem
|
||||
// This still won't stop things being potentially hilariously unbalanced though.
|
||||
if (TryComp<BatteryComponent>(uid, out var batteryComponent))
|
||||
{
|
||||
batteryComponent.CurrentCharge += charge;
|
||||
_batterySystem.SetCharge(uid, charge, batteryComponent);
|
||||
}
|
||||
|
||||
// Update appearance
|
||||
|
||||
Reference in New Issue
Block a user