Files
tbd-station-14/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs
Pieter-Jan Briers 1eb0fbd8d0 Revert "Physics (#3452)"
This reverts commit 3e64fd56a1.
2021-02-28 18:49:48 +01:00

50 lines
1.6 KiB
C#

using System;
using Content.Shared.GameObjects.Components.Weapons;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Players;
using Robust.Shared.Timing;
namespace Content.Server.GameObjects.Components.Weapon
{
[RegisterComponent]
public sealed class FlashableComponent : SharedFlashableComponent
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
private double _duration;
private TimeSpan _lastFlash;
public void Flash(double duration)
{
_lastFlash = _gameTiming.CurTime;
_duration = duration;
Dirty();
}
public override ComponentState GetComponentState(ICommonSession player)
{
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))
{
if (!source.InRangeUnobstructed(entity, range, popup: true))
continue;
if(entity.TryGetComponent(out FlashableComponent flashable))
flashable.Flash(duration);
}
if (!string.IsNullOrEmpty(sound))
{
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<AudioSystem>().PlayAtCoords(sound, source.Transform.Coordinates);
}
}
}
}