diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index 016ea7e781..40bb9eb6f0 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -1,9 +1,9 @@ using System.Linq; using Content.Server.Flash.Components; using Content.Server.Light.EntitySystems; +using Content.Server.Popups; using Content.Server.Stunnable; using Content.Shared.Examine; -using Content.Shared.Eye.Blinding; using Content.Shared.Eye.Blinding.Components; using Content.Shared.Flash; using Content.Shared.IdentityManagement; @@ -29,9 +29,11 @@ namespace Content.Server.Flash [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!; - [Dependency] private readonly MetaDataSystem _metaSystem = default!; + [Dependency] private readonly AudioSystem _audio = default!; [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly TagSystem _tagSystem = default!; + [Dependency] private readonly PopupSystem _popup = default!; + [Dependency] private readonly AppearanceSystem _appearance = default!; public override void Initialize() { @@ -51,7 +53,7 @@ namespace Content.Server.Flash { if (!args.IsHit || !args.HitEntities.Any() || - !UseFlash(comp, args.User)) + !UseFlash(uid, comp, args.User)) { return; } @@ -65,46 +67,37 @@ namespace Content.Server.Flash private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args) { - if (args.Handled || !UseFlash(comp, args.User)) + if (args.Handled || !UseFlash(uid, comp, args.User)) return; args.Handled = true; FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true); } - private bool UseFlash(FlashComponent comp, EntityUid user) + private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user) { - if (comp.HasUses) + if (!comp.HasUses || comp.Flashing) + return false; + + comp.Uses--; + _audio.PlayPvs(comp.Sound, uid); + comp.Flashing = true; + _appearance.SetData(uid, FlashVisuals.Flashing, true); + + if (comp.Uses == 0) { - // TODO flash visualizer - if (!EntityManager.TryGetComponent(comp.Owner, out var sprite)) - return false; - - if (--comp.Uses == 0) - { - sprite.LayerSetState(0, "burnt"); - - _tagSystem.AddTag(comp.Owner, "Trash"); - comp.Owner.PopupMessage(user, Loc.GetString("flash-component-becomes-empty")); - } - else if (!comp.Flashing) - { - int animLayer = sprite.AddLayerWithState("flashing"); - comp.Flashing = true; - - comp.Owner.SpawnTimer(400, () => - { - sprite.RemoveLayer(animLayer); - comp.Flashing = false; - }); - } - - SoundSystem.Play(comp.Sound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioParams.Default); - - return true; + _appearance.SetData(uid, FlashVisuals.Burnt, true); + _tagSystem.AddTag(uid, "Trash"); + _popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user); } - return false; + uid.SpawnTimer(400, () => + { + _appearance.SetData(uid, FlashVisuals.Flashing, false); + comp.Flashing = false; + }); + + return true; } public void Flash(EntityUid target, EntityUid? user, EntityUid? used, float flashDuration, float slowTo, bool displayPopup = true, FlashableComponent? flashable = null) diff --git a/Content.Shared/Flash/FlashableComponent.cs b/Content.Shared/Flash/FlashableComponent.cs index 74dec8bf0b..c51933e0a6 100644 --- a/Content.Shared/Flash/FlashableComponent.cs +++ b/Content.Shared/Flash/FlashableComponent.cs @@ -24,4 +24,13 @@ namespace Content.Shared.Flash Time = time; } } + + [Serializable, NetSerializable] + public enum FlashVisuals : byte + { + BaseLayer, + LightLayer, + Burnt, + Flashing, + } } diff --git a/Resources/Prototypes/Entities/Objects/Tools/lantern.yml b/Resources/Prototypes/Entities/Objects/Tools/lantern.yml index b3c32d64d8..2262675d35 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/lantern.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/lantern.yml @@ -65,6 +65,18 @@ id: lanternextrabright description: Blinding. components: + - type: Sprite + sprite: Objects/Tools/lantern.rsi + layers: + - state: lantern + map: [ "enum.FlashVisuals.BaseLayer" ] + - state: lantern-on + shader: unshaded + visible: false + map: [ "light" ] + - state: flashing + map: [ "enum.FlashVisuals.LightLayer" ] + visible: false - type: PointLight enabled: false radius: 5 @@ -72,3 +84,13 @@ color: "#FFC458" - type: Flash uses: 15 + - type: Appearance + - type: GenericVisualizer + visuals: + enum.FlashVisuals.Burnt: + enum.FlashVisuals.BaseLayer: + True: {state: burnt} + enum.FlashVisuals.Flashing: + enum.FlashVisuals.LightLayer: + True: {visible: true} + False: {visible: false} diff --git a/Resources/Prototypes/Entities/Objects/Weapons/security.yml b/Resources/Prototypes/Entities/Objects/Weapons/security.yml index 3bfec3d583..8e3e333090 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/security.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/security.yml @@ -53,7 +53,13 @@ components: - type: Sprite sprite: Objects/Weapons/Melee/flash.rsi - state: flash + layers: + - state: flash + map: [ "enum.FlashVisuals.BaseLayer" ] + - state: flashing + map: [ "enum.FlashVisuals.LightLayer" ] + visible: false + shader: unshaded - type: Flash - type: MeleeWeapon damage: @@ -66,6 +72,16 @@ - type: ItemCooldown - type: StaticPrice price: 40 + - type: Appearance + - type: GenericVisualizer + visuals: + enum.FlashVisuals.Burnt: + enum.FlashVisuals.BaseLayer: + True: {state: burnt} + enum.FlashVisuals.Flashing: + enum.FlashVisuals.LightLayer: + True: {visible: true} + False: {visible: false} - type: entity name: portable flasher