2021-10-03 07:05:52 +03:00
|
|
|
using Content.Server.Light.Events;
|
2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Actions;
|
2023-05-07 02:08:03 -04:00
|
|
|
using Content.Shared.Decals;
|
|
|
|
|
using Content.Shared.Emag.Systems;
|
2021-10-03 07:05:52 +03:00
|
|
|
using Content.Shared.Light;
|
2023-09-04 06:31:10 +01:00
|
|
|
using Content.Shared.Light.Components;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind.Components;
|
2022-02-26 18:24:08 +13:00
|
|
|
using Content.Shared.Toggleable;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2023-05-07 02:08:03 -04:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
2023-02-26 18:48:57 +11:00
|
|
|
using Robust.Shared.Utility;
|
2021-10-03 07:05:52 +03:00
|
|
|
|
|
|
|
|
namespace Content.Server.Light.EntitySystems
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class UnpoweredFlashlightSystem : EntitySystem
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-09-11 19:18:06 +10:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2023-05-07 02:08:03 -04:00
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2022-02-26 18:24:08 +13:00
|
|
|
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
2023-10-08 06:08:13 +11:00
|
|
|
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-05-07 02:08:03 -04:00
|
|
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
2023-09-11 19:18:06 +10:00
|
|
|
[Dependency] private readonly SharedPointLightSystem _light = default!;
|
2022-02-26 18:24:08 +13:00
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
2022-04-14 16:17:34 +12:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
2022-02-26 18:24:08 +13:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
2022-08-31 22:09:20 -04:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(OnMindAdded);
|
2023-05-07 02:08:03 -04:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GotEmaggedEvent>(OnGotEmagged);
|
2023-10-08 06:08:13 +11:00
|
|
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, MapInitEvent>(OnMapInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMapInit(EntityUid uid, UnpoweredFlashlightComponent component, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
_actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
|
|
|
|
Dirty(uid, component);
|
2022-02-26 18:24:08 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
ToggleLight(uid, component);
|
2022-02-26 18:24:08 +13:00
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-14 16:17:34 +12:00
|
|
|
private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetItemActionsEvent args)
|
2022-02-26 18:24:08 +13:00
|
|
|
{
|
2023-09-08 18:16:05 -07:00
|
|
|
args.AddAction(ref component.ToggleActionEntity, component.ToggleAction);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddToggleLightVerbs(EntityUid uid, UnpoweredFlashlightComponent component, GetVerbsEvent<ActivationVerb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
|
|
|
|
if (!args.CanAccess || !args.CanInteract)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-05-07 02:08:03 -04:00
|
|
|
ActivationVerb verb = new()
|
|
|
|
|
{
|
|
|
|
|
Text = Loc.GetString("toggle-flashlight-verb-get-data-text"),
|
|
|
|
|
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
|
|
|
|
|
Act = () => ToggleLight(uid, component),
|
|
|
|
|
Priority = -1 // For things like PDA's, Open-UI and other verbs that should be higher priority.
|
|
|
|
|
};
|
2021-10-05 14:29:03 +11:00
|
|
|
|
|
|
|
|
args.Verbs.Add(verb);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 22:09:20 -04:00
|
|
|
private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args)
|
|
|
|
|
{
|
2023-09-08 18:16:05 -07:00
|
|
|
_actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
2022-08-31 22:09:20 -04:00
|
|
|
}
|
2023-05-07 02:08:03 -04:00
|
|
|
|
|
|
|
|
private void OnGotEmagged(EntityUid uid, UnpoweredFlashlightComponent component, ref GotEmaggedEvent args)
|
|
|
|
|
{
|
2023-09-11 19:18:06 +10:00
|
|
|
if (!_light.TryGetLight(uid, out var light))
|
2023-05-07 02:08:03 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_prototypeManager.TryIndex<ColorPalettePrototype>(component.EmaggedColorsPrototype, out var possibleColors))
|
|
|
|
|
{
|
|
|
|
|
var pick = _random.Pick(possibleColors.Colors.Values);
|
2023-09-11 19:18:06 +10:00
|
|
|
_light.SetColor(uid, pick, light);
|
2023-05-07 02:08:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args.Repeatable = true;
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 17:34:53 +01:00
|
|
|
public void ToggleLight(EntityUid uid, UnpoweredFlashlightComponent flashlight)
|
2021-10-03 07:05:52 +03:00
|
|
|
{
|
2023-09-11 19:18:06 +10:00
|
|
|
if (!_light.TryGetLight(uid, out var light))
|
2021-10-03 07:05:52 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
flashlight.LightOn = !flashlight.LightOn;
|
2023-09-11 19:18:06 +10:00
|
|
|
_light.SetEnabled(uid, flashlight.LightOn, light);
|
2021-10-03 07:05:52 +03:00
|
|
|
|
2023-05-07 02:08:03 -04:00
|
|
|
_appearance.SetData(uid, UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn);
|
2021-10-03 07:05:52 +03:00
|
|
|
|
2023-05-07 02:08:03 -04:00
|
|
|
_audioSystem.PlayPvs(flashlight.ToggleSound, uid);
|
2021-10-03 07:05:52 +03:00
|
|
|
|
2023-05-07 02:08:03 -04:00
|
|
|
RaiseLocalEvent(uid, new LightToggleEvent(flashlight.LightOn), true);
|
2023-09-08 18:16:05 -07:00
|
|
|
_actionsSystem.SetToggled(flashlight.ToggleActionEntity, flashlight.LightOn);
|
2021-10-03 07:05:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|