Remove IRadiationAct (#7757)
* Move radiation collector to ECS * Damagable system * Remove IRadiationAct * Add small helper field * Update Content.Server/Radiation/Systems/RadiationSystem.cs Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> * Delete comment * Fixed total rads Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
@@ -1,52 +1,37 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Radiation;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Server.Singularity.EntitySystems;
|
||||
|
||||
namespace Content.Server.Singularity.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates electricity from radiation.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class RadiationCollectorComponent : Component, IRadiationAct
|
||||
[Friend(typeof(RadiationCollectorSystem))]
|
||||
public sealed class RadiationCollectorComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
public bool Enabled;
|
||||
public TimeSpan CoolDownEnd;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Collecting {
|
||||
get => Enabled;
|
||||
set
|
||||
{
|
||||
if (Enabled == value) return;
|
||||
Enabled = value;
|
||||
SetAppearance(Enabled ? RadiationCollectorVisualState.Activating : RadiationCollectorVisualState.Deactivating);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How much joules will collector generate for each rad.
|
||||
/// </summary>
|
||||
[DataField("chargeModifier")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float ChargeModifier = 30000f;
|
||||
|
||||
void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
||||
{
|
||||
if (!Enabled) return;
|
||||
/// <summary>
|
||||
/// Cooldown time between users interaction.
|
||||
/// </summary>
|
||||
[DataField("cooldown")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan Cooldown = TimeSpan.FromSeconds(0.81f);
|
||||
|
||||
// No idea if this is even vaguely accurate to the previous logic.
|
||||
// The maths is copied from that logic even though it works differently.
|
||||
// But the previous logic would also make the radiation collectors never ever stop providing energy.
|
||||
// And since frameTime was used there, I'm assuming that this is what the intent was.
|
||||
// This still won't stop things being potentially hilarously unbalanced though.
|
||||
if (_entMan.TryGetComponent<BatteryComponent>(Owner, out var batteryComponent))
|
||||
{
|
||||
batteryComponent.CurrentCharge += frameTime * radiation.RadsPerSecond * ChargeModifier;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Was machine activated by user?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public bool Enabled;
|
||||
|
||||
public void SetAppearance(RadiationCollectorVisualState state)
|
||||
{
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent<AppearanceComponent?>(Owner, out var appearance))
|
||||
{
|
||||
appearance.SetData(RadiationCollectorVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Timestamp when machine can be deactivated again.
|
||||
/// </summary>
|
||||
public TimeSpan CoolDownEnd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using Content.Server.Singularity.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Radiation.Events;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
@@ -15,6 +17,7 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RadiationCollectorComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<RadiationCollectorComponent, OnIrradiatedEvent>(OnRadiation);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, RadiationCollectorComponent component, InteractHandEvent args)
|
||||
@@ -24,18 +27,58 @@ namespace Content.Server.Singularity.EntitySystems
|
||||
if(curTime < component.CoolDownEnd)
|
||||
return;
|
||||
|
||||
if (!component.Enabled)
|
||||
ToggleCollector(uid, args.User, component);
|
||||
component.CoolDownEnd = curTime + component.Cooldown;
|
||||
}
|
||||
|
||||
private void OnRadiation(EntityUid uid, RadiationCollectorComponent component, OnIrradiatedEvent args)
|
||||
{
|
||||
if (!component.Enabled) return;
|
||||
|
||||
// No idea if this is even vaguely accurate to the previous logic.
|
||||
// The maths is copied from that logic even though it works differently.
|
||||
// But the previous logic would also make the radiation collectors never ever stop providing energy.
|
||||
// And since frameTime was used there, I'm assuming that this is what the intent was.
|
||||
// This still won't stop things being potentially hilariously unbalanced though.
|
||||
if (TryComp<BatteryComponent>(uid, out var batteryComponent))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("radiation-collector-component-use-on"), uid, Filter.Pvs(args.User));
|
||||
component.Collecting = true;
|
||||
var charge = args.TotalRads * component.ChargeModifier;
|
||||
batteryComponent.CurrentCharge += charge;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
public void ToggleCollector(EntityUid uid, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
SetCollectorEnabled(uid, !component.Enabled, user, component);
|
||||
}
|
||||
|
||||
public void SetCollectorEnabled(EntityUid uid, bool enabled, EntityUid? user = null, RadiationCollectorComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
component.Enabled = enabled;
|
||||
|
||||
// Show message to the player
|
||||
if (user != null)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("radiation-collector-component-use-off"), uid, Filter.Pvs(args.User));
|
||||
component.Collecting = false;
|
||||
var msg = component.Enabled ? "radiation-collector-component-use-on" : "radiation-collector-component-use-off";
|
||||
_popupSystem.PopupEntity(Loc.GetString(msg), uid, Filter.Pvs(user.Value));
|
||||
|
||||
}
|
||||
|
||||
component.CoolDownEnd = curTime + TimeSpan.FromSeconds(0.81f);
|
||||
// Update appearance
|
||||
UpdateAppearance(uid, component);
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, RadiationCollectorComponent? component, AppearanceComponent? appearance = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref appearance))
|
||||
return;
|
||||
|
||||
var state = component.Enabled ? RadiationCollectorVisualState.Active : RadiationCollectorVisualState.Deactive;
|
||||
appearance.SetData(RadiationCollectorVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Content.Server.Singularity
|
||||
}
|
||||
foreach (var comp in entityManager.EntityQuery<RadiationCollectorComponent>())
|
||||
{
|
||||
comp.Collecting = true;
|
||||
EntitySystem.Get<RadiationCollectorSystem>().SetCollectorEnabled(comp.Owner, true, null, comp);
|
||||
}
|
||||
foreach (var comp in entityManager.EntityQuery<ParticleAcceleratorControlBoxComponent>())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user