Anomaly Cores (#21306)

* add first anomaly core

* meme

* 5 min to 10 min
fix yml

* fix

* Update doc

* no static price
This commit is contained in:
Ed
2023-11-01 02:20:52 +03:00
committed by GitHub
parent 3a4c40c29b
commit 96ff529c82
31 changed files with 596 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
using Content.Server.Anomaly.Components;
using Content.Server.Cargo.Systems;
using Content.Shared.Anomaly;
using Robust.Shared.Timing;
namespace Content.Server.Anomaly.Effects;
/// <summary>
/// This component reduces the value of the entity during decay
/// </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);
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;
}
}