1
0

AnomalyCoreSystem.cs 874 B

123456789101112131415161718192021222324252627
  1. using Content.Server.Cargo.Systems;
  2. using Content.Shared.Anomaly.Components;
  3. using Robust.Shared.Timing;
  4. namespace Content.Server.Anomaly.Effects;
  5. /// <summary>
  6. /// This component reduces the value of the entity during decay
  7. /// </summary>
  8. public sealed class AnomalyCoreSystem : EntitySystem
  9. {
  10. [Dependency] private readonly IGameTiming _gameTiming = default!;
  11. public override void Initialize()
  12. {
  13. SubscribeLocalEvent<AnomalyCoreComponent, PriceCalculationEvent>(OnGetPrice);
  14. }
  15. private void OnGetPrice(Entity<AnomalyCoreComponent> core, ref PriceCalculationEvent args)
  16. {
  17. var timeLeft = core.Comp.DecayMoment - _gameTiming.CurTime;
  18. var lerp = timeLeft.TotalSeconds / core.Comp.TimeToDecay;
  19. lerp = Math.Clamp(lerp, 0, 1);
  20. args.Price = MathHelper.Lerp(core.Comp.EndPrice, core.Comp.StartPrice, lerp);
  21. }
  22. }