Optimise handheld lights (#2927)

* Optimise handheld lights

* Woops also these

* Might as well do shutdown too

* Also these

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-01-06 22:50:49 +11:00
committed by GitHub
parent 2bd4bf12a4
commit 482106e827
2 changed files with 62 additions and 2 deletions

View File

@@ -80,6 +80,12 @@ namespace Content.Server.GameObjects.Components.Interactable
Dirty();
}
public override void OnRemove()
{
base.OnRemove();
Owner.EntityManager.EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this));
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!ActionBlockerSystem.CanInteract(eventArgs.User)) return false;
@@ -125,6 +131,7 @@ namespace Content.Server.GameObjects.Components.Interactable
SetState(false);
Activated = false;
UpdateLightAction();
Owner.EntityManager.EventBus.QueueEvent(EventSource.Local, new DeactivateHandheldLightMessage(this));
if (makeNoise)
{
@@ -163,6 +170,7 @@ namespace Content.Server.GameObjects.Components.Interactable
Activated = true;
UpdateLightAction();
SetState(true);
Owner.EntityManager.EventBus.QueueEvent(EventSource.Local, new ActivateHandheldLightMessage(this));
if (TurnOnSound != null) EntitySystem.Get<AudioSystem>().PlayFromEntity(TurnOnSound, Owner);
return true;
@@ -283,4 +291,24 @@ namespace Content.Server.GameObjects.Components.Interactable
return lightComponent.ToggleStatus(args.Performer);
}
}
internal sealed class ActivateHandheldLightMessage : EntitySystemMessage
{
public HandheldLightComponent Component { get; }
public ActivateHandheldLightMessage(HandheldLightComponent component)
{
Component = component;
}
}
internal sealed class DeactivateHandheldLightMessage : EntitySystemMessage
{
public HandheldLightComponent Component { get; }
public DeactivateHandheldLightMessage(HandheldLightComponent component)
{
Component = component;
}
}
}