using Content.Server.Light.Events; using Content.Shared.Actions; using Content.Shared.Decals; using Content.Shared.Emag.Systems; using Content.Shared.Light; using Content.Shared.Light.Components; using Content.Shared.Mind.Components; using Content.Shared.Toggleable; using Content.Shared.Verbs; using Robust.Server.GameObjects; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Utility; namespace Content.Server.Light.EntitySystems { public sealed class UnpoweredFlashlightSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly SharedAudioSystem _audioSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent>(AddToggleLightVerbs); SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); SubscribeLocalEvent(OnMindAdded); SubscribeLocalEvent(OnGotEmagged); } private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args) { if (args.Handled) return; ToggleLight(uid, component); args.Handled = true; } private void OnGetActions(EntityUid uid, UnpoweredFlashlightComponent component, GetItemActionsEvent args) { args.AddAction(ref component.ToggleActionEntity, component.ToggleAction); } private void AddToggleLightVerbs(EntityUid uid, UnpoweredFlashlightComponent component, GetVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) return; 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. }; args.Verbs.Add(verb); } private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args) { _actionsSystem.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); } private void OnGotEmagged(EntityUid uid, UnpoweredFlashlightComponent component, ref GotEmaggedEvent args) { if (!TryComp(uid, out var light)) return; if (_prototypeManager.TryIndex(component.EmaggedColorsPrototype, out var possibleColors)) { var pick = _random.Pick(possibleColors.Colors.Values); light.Color = pick; } args.Repeatable = true; args.Handled = true; } public void ToggleLight(EntityUid uid, UnpoweredFlashlightComponent flashlight) { if (!TryComp(uid, out var light)) return; flashlight.LightOn = !flashlight.LightOn; light.Enabled = flashlight.LightOn; _appearance.SetData(uid, UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn); _audioSystem.PlayPvs(flashlight.ToggleSound, uid); RaiseLocalEvent(uid, new LightToggleEvent(flashlight.LightOn), true); _actionsSystem.SetToggled(flashlight.ToggleActionEntity, flashlight.LightOn); } } }