@@ -1,6 +1,5 @@
|
||||
using Content.Server.Anomaly.Components;
|
||||
using Content.Server.Cargo.Systems;
|
||||
using Content.Shared.Anomaly;
|
||||
using Content.Shared.Anomaly.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Anomaly.Effects;
|
||||
@@ -10,47 +9,19 @@ namespace Content.Server.Anomaly.Effects;
|
||||
/// </summary>
|
||||
public sealed class AnomalyCoreSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<AnomalyCoreComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<AnomalyCoreComponent, PriceCalculationEvent>(OnGetPrice);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<AnomalyCoreComponent> core, ref MapInitEvent args)
|
||||
{
|
||||
core.Comp.DecayMoment = _gameTiming.CurTime + TimeSpan.FromSeconds(core.Comp.TimeToDecay);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<AnomalyCoreComponent>();
|
||||
while (query.MoveNext(out var uid, out var component))
|
||||
{
|
||||
if (component.IsDecayed)
|
||||
continue;
|
||||
|
||||
//When time runs out, we completely decompose
|
||||
if (component.DecayMoment < _gameTiming.CurTime)
|
||||
Decay(uid, component);
|
||||
}
|
||||
}
|
||||
private void OnGetPrice(Entity<AnomalyCoreComponent> core, ref PriceCalculationEvent args)
|
||||
{
|
||||
var timeLeft = core.Comp.DecayMoment - _gameTiming.CurTime;
|
||||
var lerp = (double) (timeLeft.TotalSeconds / core.Comp.TimeToDecay);
|
||||
var lerp = timeLeft.TotalSeconds / core.Comp.TimeToDecay;
|
||||
lerp = Math.Clamp(lerp, 0, 1);
|
||||
|
||||
args.Price = MathHelper.Lerp(core.Comp.EndPrice, core.Comp.StartPrice, lerp);
|
||||
}
|
||||
|
||||
private void Decay(EntityUid uid, AnomalyCoreComponent component)
|
||||
{
|
||||
_appearance.SetData(uid, AnomalyCoreVisuals.Decaying, false);
|
||||
component.IsDecayed = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user