Refactor ghost boo to ECS (#4511)
* Moved ghost boo to ecs * Fixed small light exception * No need to inject EM * Moved cooldown and time to fields Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Ghost;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Actions.Behaviors;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
@@ -30,22 +28,19 @@ namespace Content.Server.Light.Components
|
||||
/// Component that represents a wall light. It has a light bulb that can be replaced when broken.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit, IGhostBooAffected
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public override string Name => "PoweredLight";
|
||||
|
||||
private static readonly TimeSpan _thunkDelay = TimeSpan.FromSeconds(2);
|
||||
// time to blink light when ghost made boo nearby
|
||||
private static readonly TimeSpan ghostBlinkingTime = TimeSpan.FromSeconds(10);
|
||||
private static readonly TimeSpan ghostBlinkingCooldown = TimeSpan.FromSeconds(60);
|
||||
|
||||
[ComponentDependency]
|
||||
private readonly AppearanceComponent? _appearance;
|
||||
|
||||
private TimeSpan _lastThunk;
|
||||
private TimeSpan? _lastGhostBlink;
|
||||
public TimeSpan? LastGhostBlink;
|
||||
|
||||
[DataField("burnHandSound")]
|
||||
private SoundSpecifier _burnHandSound = new SoundPathSpecifier("/Audio/Effects/lightburn.ogg");
|
||||
@@ -64,11 +59,20 @@ namespace Content.Server.Light.Components
|
||||
private bool _currentLit;
|
||||
|
||||
[ViewVariables]
|
||||
private bool _isBlinking;
|
||||
public bool IsBlinking;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("ignoreGhostsBoo")]
|
||||
private bool _ignoreGhostsBoo;
|
||||
public bool IgnoreGhostsBoo;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("ghostBlinkingTime")]
|
||||
public TimeSpan GhostBlinkingTime = TimeSpan.FromSeconds(10);
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("ghostBlinkingCooldown")]
|
||||
public TimeSpan GhostBlinkingCooldown = TimeSpan.FromSeconds(60);
|
||||
|
||||
|
||||
[DataField("bulb")] private LightBulbType _bulbType = LightBulbType.Tube;
|
||||
public LightBulbType BulbType => _bulbType;
|
||||
@@ -312,36 +316,6 @@ namespace Content.Server.Light.Components
|
||||
UpdateLight();
|
||||
}
|
||||
|
||||
public void ToggleBlinkingLight(bool isNowBlinking)
|
||||
{
|
||||
if (_isBlinking == isNowBlinking)
|
||||
return;
|
||||
|
||||
_isBlinking = isNowBlinking;
|
||||
_appearance?.SetData(PoweredLightVisuals.Blinking, _isBlinking);
|
||||
}
|
||||
|
||||
public bool AffectedByGhostBoo(InstantActionEventArgs args)
|
||||
{
|
||||
if (_ignoreGhostsBoo)
|
||||
return false;
|
||||
|
||||
// check cooldown first to prevent abuse
|
||||
var time = _gameTiming.CurTime;
|
||||
if (_lastGhostBlink != null)
|
||||
{
|
||||
if (time <= _lastGhostBlink + ghostBlinkingCooldown)
|
||||
return false;
|
||||
}
|
||||
_lastGhostBlink = time;
|
||||
|
||||
ToggleBlinkingLight(true);
|
||||
Owner.SpawnTimer(ghostBlinkingTime, () =>
|
||||
{
|
||||
ToggleBlinkingLight(false);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user