Get rid of the OverlayEffectsComponent stuff (#3010)

* Get rid of the OverlayEffectsComponent stuff because it just ended up creating workarounds for it's bugs, without removing any functionality

* Flashes and Flashbangs use the same code now (the Flashable path because it's better)
This commit is contained in:
20kdc
2021-01-24 08:17:45 +00:00
committed by GitHub
parent 329d599107
commit e53ae365a3
21 changed files with 65 additions and 659 deletions

View File

@@ -1,33 +0,0 @@
using Content.Server.Administration;
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
namespace Content.Server.Commands.Mobs
{
[AdminCommand(AdminFlags.Debug)]
public class AddOverlayCommand : IClientCommand
{
public string Command => "addoverlay";
public string Description => "Adds an overlay by its ID";
public string Help => "addoverlay <id>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, "Expected 1 argument.");
return;
}
if (player?.AttachedEntity != null)
{
if (player.AttachedEntity.TryGetComponent(out ServerOverlayEffectsComponent overlayEffectsComponent))
{
overlayEffectsComponent.AddOverlay(args[0]);
}
}
}
}
}

View File

@@ -1,33 +0,0 @@
using Content.Server.Administration;
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
namespace Content.Server.Commands.Mobs
{
[AdminCommand(AdminFlags.Debug)]
public class RemoveOverlayCommand : IClientCommand
{
public string Command => "rmoverlay";
public string Description => "Removes an overlay by its ID";
public string Help => "rmoverlay <id>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, "Expected 1 argument.");
return;
}
if (player?.AttachedEntity != null)
{
if (player.AttachedEntity.TryGetComponent(out ServerOverlayEffectsComponent overlayEffectsComponent))
{
overlayEffectsComponent.RemoveOverlay(args[0]);
}
}
}
}
}

View File

@@ -1,95 +0,0 @@
using System;
using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Mobs;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Mobs
{
[RegisterComponent]
[ComponentReference(typeof(SharedOverlayEffectsComponent))]
public sealed class ServerOverlayEffectsComponent : SharedOverlayEffectsComponent
{
public ServerOverlayEffectsComponent()
{
NetSyncEnabled = false;
}
[ViewVariables(VVAccess.ReadWrite)]
public List<OverlayContainer> ActiveOverlays { get; } = new();
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null)
{
if (Owner.TryGetComponent(out IActorComponent actor) && message is ResendOverlaysMessage)
{
if (actor.playerSession.ConnectedClient == netChannel)
{
SyncClient();
}
}
}
public void AddOverlay(string id) => AddOverlay(new OverlayContainer(id));
public void AddOverlay(SharedOverlayID id) => AddOverlay(new OverlayContainer(id));
public void AddOverlay(OverlayContainer container)
{
if (!ActiveOverlays.Contains(container))
{
ActiveOverlays.Add(container);
SyncClient();
}
}
public void RemoveOverlay(SharedOverlayID id) => RemoveOverlay(id.ToString());
public void RemoveOverlay(string id) => RemoveOverlay(new OverlayContainer(id));
public void RemoveOverlay(OverlayContainer container)
{
if (ActiveOverlays.Remove(container))
{
SyncClient();
}
}
public bool TryModifyOverlay(string id, Action<OverlayContainer> modifications)
{
var overlay = ActiveOverlays.Find(c => c.ID == id);
if (overlay == null)
{
return false;
}
modifications(overlay);
SyncClient();
return true;
}
public void ClearOverlays()
{
if (ActiveOverlays.Count == 0)
{
return;
}
ActiveOverlays.Clear();
SyncClient();
}
private void SyncClient()
{
if (Owner.TryGetComponent(out IActorComponent actor))
{
if (actor.playerSession.ConnectedClient.IsConnected)
{
SendNetworkMessage(new OverlayEffectComponentMessage(ActiveOverlays), actor.playerSession.ConnectedClient);
}
}
}
}
}

View File

@@ -20,11 +20,6 @@ namespace Content.Server.GameObjects.Components.Mobs.State
appearance.SetData(DamageStateVisuals.State, DamageState.Critical);
}
if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
{
overlay.AddOverlay(SharedOverlayID.GradientCircleMaskOverlay);
}
if (entity.TryGetComponent(out StunnableComponent stun))
{
stun.CancelAll();
@@ -36,11 +31,6 @@ namespace Content.Server.GameObjects.Components.Mobs.State
public override void ExitState(IEntity entity)
{
base.ExitState(entity);
if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
{
overlay.ClearOverlays();
}
}
}
}

View File

@@ -26,11 +26,6 @@ namespace Content.Server.GameObjects.Components.Mobs.State
status.ShowAlert(AlertType.HumanDead);
}
if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlayComponent))
{
overlayComponent.AddOverlay(SharedOverlayID.CircleMaskOverlay);
}
if (entity.TryGetComponent(out StunnableComponent stun))
{
stun.CancelAll();
@@ -52,11 +47,6 @@ namespace Content.Server.GameObjects.Components.Mobs.State
{
physics.CanCollide = true;
}
if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlay))
{
overlay.ClearOverlays();
}
}
}
}

View File

@@ -8,15 +8,5 @@ namespace Content.Server.GameObjects.Components.Mobs.State
[ComponentReference(typeof(IMobStateComponent))]
public class MobStateComponent : SharedMobStateComponent
{
public override void OnRemove()
{
// TODO: Might want to add an OnRemove() to IMobState since those are where these components are being used
if (Owner.TryGetComponent(out ServerOverlayEffectsComponent overlay))
{
overlay.ClearOverlays();
}
base.OnRemove();
}
}
}

View File

@@ -4,13 +4,17 @@ using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Network.NetMessages;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
@@ -128,22 +132,12 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
}
// TODO: Check if target can be flashed (e.g. things like sunglasses would block a flash)
// TODO: Merge with the code in FlashableComponent
private void Flash(IEntity entity, IEntity user, int flashDuration)
{
if (entity.TryGetComponent(out ServerOverlayEffectsComponent overlayEffectsComponent))
if (entity.TryGetComponent(out FlashableComponent flashable))
{
if (!overlayEffectsComponent.TryModifyOverlay(nameof(SharedOverlayID.FlashOverlay),
overlay =>
{
if (overlay.TryGetOverlayParameter<TimedOverlayParameter>(out var timed))
{
timed.Length += flashDuration;
}
}))
{
var container = new OverlayContainer(SharedOverlayID.FlashOverlay, new TimedOverlayParameter(flashDuration));
overlayEffectsComponent.AddOverlay(container);
}
flashable.Flash(flashDuration / 1000d);
}
if (entity.TryGetComponent(out StunnableComponent stunnableComponent))

View File

@@ -1,35 +0,0 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
internal sealed class TimedOverlayRemovalSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var component in ComponentManager.EntityQuery<ServerOverlayEffectsComponent>())
{
foreach (var overlay in component.ActiveOverlays.ToArray())
{
if (overlay.TryGetOverlayParameter<TimedOverlayParameter>(out var parameter))
{
if (parameter.StartedAt + parameter.Length <= _gameTiming.CurTime.TotalMilliseconds)
{
component.RemoveOverlay(overlay);
}
}
}
}
}
}
}

View File

@@ -85,12 +85,6 @@ namespace Content.Server.GameTicking
var ghostComponent = ghost.GetComponent<GhostComponent>();
ghostComponent.CanReturnToBody = canReturn;
if (playerEntity != null &&
playerEntity.TryGetComponent(out ServerOverlayEffectsComponent? overlayComponent))
{
overlayComponent.RemoveOverlay(SharedOverlayID.CircleMaskOverlay);
}
if (canReturn)
mind.Visit(ghost);
else

View File

@@ -1,6 +1,7 @@
using Content.Server.Administration;
using Content.Server.Interfaces;
using Content.Shared;
using Content.Shared.Network.NetMessages;
using Content.Shared.Administration;
using Content.Shared.Interfaces;
using Robust.Server.Interfaces.Console;

View File

@@ -51,25 +51,11 @@ namespace Content.Server.StationEvents
public override void Startup()
{
ResetTimeUntilPulse();
var componentManager = IoCManager.Resolve<IComponentManager>();
foreach (var overlay in componentManager.EntityQuery<ServerOverlayEffectsComponent>())
{
overlay.AddOverlay(SharedOverlayID.RadiationPulseOverlay);
}
base.Startup();
}
public override void Shutdown()
{
var componentManager = IoCManager.Resolve<IComponentManager>();
foreach (var overlay in componentManager.EntityQuery<ServerOverlayEffectsComponent>())
{
overlay.RemoveOverlay(SharedOverlayID.RadiationPulseOverlay);
}
base.Shutdown();
}