2020-07-08 00:51:08 +02:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Flash;
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Content.Shared.Physics;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2020-07-08 00:51:08 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-02-18 09:09:07 +01:00
|
|
|
using Robust.Shared.Players;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Timing;
|
2020-07-08 00:51:08 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Flash.Components
|
2020-07-08 00:51:08 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public sealed class FlashableComponent : SharedFlashableComponent
|
|
|
|
|
{
|
2020-09-02 01:30:03 +02:00
|
|
|
[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)
|
|
|
|
|
{
|
2020-09-02 01:30:03 +02:00
|
|
|
_lastFlash = _gameTiming.CurTime;
|
2020-07-08 00:51:08 +02:00
|
|
|
_duration = duration;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2020-07-08 00:51:08 +02:00
|
|
|
{
|
|
|
|
|
return new FlashComponentState(_duration, _lastFlash);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
public static void FlashAreaHelper(IEntity source, float range, float duration, SoundSpecifier? sound = null)
|
2020-07-08 00:51:08 +02:00
|
|
|
{
|
2021-04-06 13:31:07 +10:00
|
|
|
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(source.Transform.Coordinates, range))
|
2020-07-08 00:51:08 +02:00
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
|
2021-03-08 04:09:59 +11:00
|
|
|
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
|
2020-07-08 00:51:08 +02:00
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
flashable.Flash(duration);
|
2020-07-08 00:51:08 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
if (sound != null)
|
2020-07-08 00:51:08 +02:00
|
|
|
{
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(source), sound.GetSound(), source.Transform.Coordinates);
|
2020-07-08 00:51:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|