Remove server-side sprite references from Flash system (#15893)
This commit is contained in:
@@ -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<SpriteComponent?>(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)
|
||||
|
||||
Reference in New Issue
Block a user