59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
using System;
|
|
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
|
|
using Content.Shared.Xenoarchaeology.XenoArtifacts;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Xenoarchaeology.XenoArtifacts;
|
|
|
|
public class RandomArtifactSpriteSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly IGameTiming _time = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<RandomArtifactSpriteComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<RandomArtifactSpriteComponent, ArtifactActivatedEvent>(OnActivated);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var query = EntityManager.EntityQuery<RandomArtifactSpriteComponent, AppearanceComponent>();
|
|
foreach (var (component, appearance) in query)
|
|
{
|
|
if (component.ActivationStart == null)
|
|
return;
|
|
|
|
var timeDif = _time.CurTime - component.ActivationStart.Value;
|
|
if (timeDif.Seconds >= component.ActivationTime)
|
|
{
|
|
appearance.SetData(SharedArtifactsVisuals.IsActivated, false);
|
|
component.ActivationStart = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnInit(EntityUid uid, RandomArtifactSpriteComponent component, ComponentInit args)
|
|
{
|
|
if (!TryComp(uid, out AppearanceComponent? appearance))
|
|
return;
|
|
|
|
var randomSprite = _random.Next(component.MinSprite, component.MaxSprite + 1);
|
|
appearance.SetData(SharedArtifactsVisuals.SpriteIndex, randomSprite);
|
|
}
|
|
|
|
private void OnActivated(EntityUid uid, RandomArtifactSpriteComponent component, ArtifactActivatedEvent args)
|
|
{
|
|
if (!TryComp(uid, out AppearanceComponent? appearance))
|
|
return;
|
|
|
|
appearance.SetData(SharedArtifactsVisuals.IsActivated, true);
|
|
component.ActivationStart = _time.CurTime;
|
|
}
|
|
}
|