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:
committed by
GitHub
parent
e8f769d189
commit
77fe21eb0d
64
Content.Client/Flash/FlashSystem.cs
Normal file
64
Content.Client/Flash/FlashSystem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Content.Shared.Flash;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Flash
|
||||
{
|
||||
public class FlashSystem : SharedFlashSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<FlashableComponent, ComponentHandleState>(OnFlashableHandleState);
|
||||
}
|
||||
|
||||
private void OnFlashableHandleState(EntityUid uid, FlashableComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not FlashableComponentState state)
|
||||
return;
|
||||
|
||||
// Yes, this code is awful. I'm just porting it to an entity system so don't blame me.
|
||||
if (_playerManager.LocalPlayer != null && _playerManager.LocalPlayer.Session.AttachedEntityUid != uid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.Time == default)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Few things here:
|
||||
// 1. If a shorter duration flash is applied then don't do anything
|
||||
// 2. If the client-side time is later than when the flash should've ended don't do anything
|
||||
var currentTime = _gameTiming.CurTime.TotalSeconds;
|
||||
var newEndTime = state.Time.TotalSeconds + state.Duration;
|
||||
var currentEndTime = component.LastFlash.TotalSeconds + component.Duration;
|
||||
|
||||
if (currentEndTime > newEndTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentTime > newEndTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.LastFlash = state.Time;
|
||||
component.Duration = state.Duration;
|
||||
|
||||
var overlay = _overlayManager.GetOverlay<FlashOverlay>();
|
||||
overlay.ReceiveFlash(component.Duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user