Flash overlay rework and bugfixes (#27369)

This commit is contained in:
slarticodefast
2024-06-02 06:17:53 +02:00
committed by GitHub
parent f5bc921bdd
commit 1283989346
18 changed files with 187 additions and 208 deletions

View File

@@ -9,18 +9,17 @@ using Content.Shared.Charges.Systems;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Flash;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Physics;
using Content.Shared.Tag;
using Content.Shared.Traits.Assorted;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.StatusEffect;
using Content.Shared.Examine;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
namespace Content.Server.Flash
@@ -31,14 +30,14 @@ namespace Content.Server.Flash
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly SharedChargesSystem _charges = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly ExamineSystemShared _examine = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly StunSystem _stun = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
public override void Initialize()
{
@@ -46,7 +45,7 @@ namespace Content.Server.Flash
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
// ran before toggling light for extra-bright lantern
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new []{ typeof(HandheldLightSystem) });
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new[] { typeof(HandheldLightSystem) });
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
SubscribeLocalEvent<FlashImmunityComponent, FlashAttemptEvent>(OnFlashImmunityFlashAttempt);
SubscribeLocalEvent<PermanentBlindnessComponent, FlashAttemptEvent>(OnPermanentBlindnessFlashAttempt);
@@ -114,19 +113,35 @@ namespace Content.Server.Flash
float flashDuration,
float slowTo,
bool displayPopup = true,
FlashableComponent? flashable = null,
bool melee = false,
TimeSpan? stunDuration = null)
{
if (!Resolve(target, ref flashable, false))
return;
var attempt = new FlashAttemptEvent(target, user, used);
RaiseLocalEvent(target, attempt, true);
if (attempt.Cancelled)
return;
// don't paralyze, slowdown or convert to rev if the target is immune to flashes
if (!_statusEffectsSystem.TryAddStatusEffect<FlashedComponent>(target, FlashedKey, TimeSpan.FromSeconds(flashDuration / 1000f), true))
return;
if (stunDuration != null)
{
_stun.TryParalyze(target, stunDuration.Value, true);
}
else
{
_stun.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration / 1000f), true,
slowTo, slowTo);
}
if (displayPopup && user != null && target != user && Exists(user.Value))
{
_popup.PopupEntity(Loc.GetString("flash-component-user-blinds-you",
("user", Identity.Entity(user.Value, EntityManager))), target, target);
}
if (melee)
{
var ev = new AfterFlashedEvent(target, user, used);
@@ -135,48 +150,31 @@ namespace Content.Server.Flash
if (used != null)
RaiseLocalEvent(used.Value, ref ev);
}
flashable.LastFlash = _timing.CurTime;
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
Dirty(target, flashable);
if (stunDuration != null)
{
_stun.TryParalyze(target, stunDuration.Value, true);
}
else
{
_stun.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
slowTo, slowTo);
}
if (displayPopup && user != null && target != user && Exists(user.Value))
{
_popup.PopupEntity(Loc.GetString("flash-component-user-blinds-you",
("user", Identity.Entity(user.Value, EntityManager))), target, target);
}
}
public void FlashArea(Entity<FlashComponent?> source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null)
{
var transform = Transform(source);
var mapPosition = _transform.GetMapCoordinates(transform);
var flashableQuery = GetEntityQuery<FlashableComponent>();
var statusEffectsQuery = GetEntityQuery<StatusEffectsComponent>();
var damagedByFlashingQuery = GetEntityQuery<DamagedByFlashingComponent>();
foreach (var entity in _entityLookup.GetEntitiesInRange(transform.Coordinates, range))
{
if (!_random.Prob(probability))
continue;
if (!flashableQuery.TryGetComponent(entity, out var flashable))
// Is the entity affected by the flash either through status effects or by taking damage?
if (!statusEffectsQuery.HasComponent(entity) && !damagedByFlashingQuery.HasComponent(entity))
continue;
// Check for unobstructed entities while ignoring the mobs with flashable components.
if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, flashable.CollisionGroup, predicate: (e) => flashableQuery.HasComponent(e) || e == source.Owner))
// Check for entites in view
// put damagedByFlashingComponent in the predicate because shadow anomalies block vision.
if (!_examine.InRangeUnOccluded(entity, mapPosition, range, predicate: (e) => damagedByFlashingQuery.HasComponent(e)))
continue;
// They shouldn't have flash removed in between right?
Flash(entity, user, source, duration, slowTo, displayPopup, flashableQuery.GetComponent(entity));
Flash(entity, user, source, duration, slowTo, displayPopup);
}
_audio.PlayPvs(sound, source, AudioParams.Default.WithVolume(1f).WithMaxDistance(3f));
@@ -195,13 +193,15 @@ namespace Content.Server.Flash
private void OnFlashImmunityFlashAttempt(EntityUid uid, FlashImmunityComponent component, FlashAttemptEvent args)
{
if(component.Enabled)
if (component.Enabled)
args.Cancel();
}
private void OnPermanentBlindnessFlashAttempt(EntityUid uid, PermanentBlindnessComponent component, FlashAttemptEvent args)
{
args.Cancel();
// check for total blindness
if (component.Blindness == 0)
args.Cancel();
}
private void OnTemporaryBlindnessFlashAttempt(EntityUid uid, TemporaryBlindnessComponent component, FlashAttemptEvent args)
@@ -210,6 +210,10 @@ namespace Content.Server.Flash
}
}
/// <summary>
/// Called before a flash is used to check if the attempt is cancelled by blindness, items or FlashImmunityComponent.
/// Raised on the target hit by the flash, the user of the flash and the flash used.
/// </summary>
public sealed class FlashAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid Target;
@@ -224,8 +228,8 @@ namespace Content.Server.Flash
}
}
/// <summary>
/// Called after a flash is used via melee on another person to check for rev conversion.
/// Raised on the user of the flash, the target hit by the flash, and the flash used.
/// Called after a flash is used via melee on another person to check for rev conversion.
/// Raised on the target hit by the flash, the user of the flash and the flash used.
/// </summary>
[ByRefEvent]
public readonly struct AfterFlashedEvent
@@ -241,6 +245,4 @@ namespace Content.Server.Flash
Used = used;
}
}
}