Files
tbd-station-14/Content.Server/GameObjects/Components/Weapon/FlashableComponent.cs
Acruid 9459400002 SoundSystem Improvements (#3697)
* Refactor all audio to use the new SoundSystem.

* Update submodule

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2021-03-21 17:12:03 +01:00

52 lines
1.6 KiB
C#

using System;
using Content.Shared.GameObjects.Components.Weapons;
using Content.Shared.Physics;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Player;
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 source.EntityManager.GetEntitiesInRange(source.Transform.Coordinates, range))
{
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
flashable.Flash(duration);
}
if (!string.IsNullOrEmpty(sound))
{
SoundSystem.Play(Filter.Pvs(source), sound, source.Transform.Coordinates);
}
}
}
}