Refactors flashes to ECS, sunglasses protect you from being flashed. (#4579)

* Refactors flashes to ECS, sunglasses protect you from being flashed.

* VV ReadWrite for FlashImmunity Enabled.

* Use cached IEntityLookup.

* Consistent formatting.

* Fix flashbang duration.
Flash duration is a mess.

* Small area flash code cleanup.

* Flashable state is only sent to attached player.
This commit is contained in:
Vera Aguilera Puerto
2021-09-09 16:20:41 +02:00
committed by GitHub
parent e8f769d189
commit 77fe21eb0d
12 changed files with 228 additions and 132 deletions

View File

@@ -1,51 +1,12 @@
using System;
using Content.Shared.Flash;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Physics;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Players;
using Robust.Shared.Timing;
namespace Content.Server.Flash.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedFlashableComponent))]
[RegisterComponent, Friend(typeof(FlashSystem))]
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, SoundSpecifier? sound = null)
{
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(source.Transform.Coordinates, range))
{
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
flashable.Flash(duration);
}
if (sound != null)
{
SoundSystem.Play(Filter.Pvs(source), sound.GetSound(), source.Transform.Coordinates);
}
}
}
}