2021-02-01 10:19:43 -06:00
|
|
|
#nullable enable
|
2020-10-28 19:19:47 +01:00
|
|
|
using System;
|
|
|
|
|
using Content.Server.Utility;
|
|
|
|
|
using Content.Shared.GameObjects.Components;
|
|
|
|
|
using Content.Shared.GameObjects.Components.Singularity;
|
|
|
|
|
using Content.Shared.Interfaces;
|
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
2021-03-31 12:41:23 -07:00
|
|
|
using Robust.Shared.Physics;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Timing;
|
2021-05-28 10:44:13 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-10-28 19:19:47 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
|
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-05-28 10:44:13 +01:00
|
|
|
public class RadiationCollectorComponent : Component, IInteractHand, IRadiationAct
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
|
|
|
|
|
public override string Name => "RadiationCollector";
|
|
|
|
|
private bool _enabled;
|
|
|
|
|
private TimeSpan _coolDownEnd;
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool Collecting {
|
|
|
|
|
get => _enabled;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_enabled == value) return;
|
|
|
|
|
_enabled = value;
|
|
|
|
|
SetAppearance(_enabled ? RadiationCollectorVisualState.Activating : RadiationCollectorVisualState.Deactivating);
|
|
|
|
|
}
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
[ComponentDependency] private readonly BatteryComponent? _batteryComponent = default!;
|
|
|
|
|
[ComponentDependency] private readonly BatteryDischargerComponent? _batteryDischargerComponent = default!;
|
|
|
|
|
|
2020-10-28 19:19:47 +01:00
|
|
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
var curTime = _gameTiming.CurTime;
|
|
|
|
|
|
|
|
|
|
if(curTime < _coolDownEnd)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (!_enabled)
|
|
|
|
|
{
|
2021-05-28 10:44:13 +01:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("radiation-collector-component-use-on"));
|
|
|
|
|
Collecting = true;
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-28 10:44:13 +01:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("radiation-collector-component-use-off"));
|
|
|
|
|
Collecting = false;
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_coolDownEnd = curTime + TimeSpan.FromSeconds(0.81f);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void IRadiationAct.RadiationAct(float frameTime, SharedRadiationPulseComponent radiation)
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
if (!_enabled) return;
|
|
|
|
|
|
2021-05-28 10:44:13 +01:00
|
|
|
// 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 (_batteryComponent != null)
|
|
|
|
|
{
|
|
|
|
|
_batteryComponent!.CurrentCharge += frameTime * radiation.RadsPerSecond * 3000f;
|
|
|
|
|
if (_batteryDischargerComponent != null)
|
|
|
|
|
{
|
|
|
|
|
// The battery discharger is controlled like this to ensure it won't drain the entire battery in a single tick.
|
|
|
|
|
// If that occurs then the battery discharger ends up shutting down.
|
|
|
|
|
_batteryDischargerComponent!.ActiveSupplyRate = (int) Math.Max(1, _batteryComponent!.CurrentCharge);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-28 19:19:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void SetAppearance(RadiationCollectorVisualState state)
|
|
|
|
|
{
|
2021-02-01 10:19:43 -06:00
|
|
|
if (Owner.TryGetComponent<AppearanceComponent>(out var appearance))
|
2020-10-28 19:19:47 +01:00
|
|
|
{
|
|
|
|
|
appearance.SetData(RadiationCollectorVisuals.VisualState, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|