Files
OldThink/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2020-07-08 00:51:08 +02:00
using System;
using Content.Shared.GameObjects.Components.Weapons;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
2020-07-08 00:51:08 +02:00
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Players;
using Robust.Shared.Timing;
2020-07-08 00:51:08 +02:00
namespace Content.Server.GameObjects.Components.Weapon
{
[RegisterComponent]
public sealed class FlashableComponent : SharedFlashableComponent
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
2020-07-08 00:51:08 +02:00
private double _duration;
private TimeSpan _lastFlash;
public void Flash(double duration)
{
_lastFlash = _gameTiming.CurTime;
2020-07-08 00:51:08 +02:00
_duration = duration;
Dirty();
}
public override ComponentState GetComponentState(ICommonSession player)
2020-07-08 00:51:08 +02:00
{
return new FlashComponentState(_duration, _lastFlash);
}
public static void FlashAreaHelper(IEntity source, float range, float duration, string sound = null)
{
foreach (var entity in IoCManager.Resolve<IEntityManager>().GetEntitiesInRange(source.Transform.Coordinates, range))
2020-07-08 00:51:08 +02:00
{
if (!source.InRangeUnobstructed(entity, range, popup: true))
2020-07-08 00:51:08 +02:00
continue;
if(entity.TryGetComponent(out FlashableComponent flashable))
flashable.Flash(duration);
}
if (!string.IsNullOrEmpty(sound))
{
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().PlayAtCoords(sound, source.Transform.Coordinates);
2020-07-08 00:51:08 +02:00
}
}
}
}