Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash buff #25730

Merged
merged 8 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Content.Server/Flash/FlashSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent a
args.Handled = true;
foreach (var e in args.HitEntities)
{
Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo, melee: true);
Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo, melee: true, stunDuration: comp.MeleeStunDuration);
}
}

Expand Down Expand Up @@ -115,7 +115,8 @@ public void Flash(EntityUid target,
float slowTo,
bool displayPopup = true,
FlashableComponent? flashable = null,
bool melee = false)
bool melee = false,
TimeSpan? stunDuration = null)
{
if (!Resolve(target, ref flashable, false))
return;
Expand All @@ -139,43 +140,46 @@ public void Flash(EntityUid target,
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
Dirty(target, flashable);

_stun.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
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(EntityUid source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, float probability = 1f, SoundSpecifier? sound = null)
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 = EntityManager.GetComponent<TransformComponent>(source);
var transform = Transform(source);
var mapPosition = _transform.GetMapCoordinates(transform);
var flashableQuery = GetEntityQuery<FlashableComponent>();

foreach (var entity in _entityLookup.GetEntitiesInRange(transform.Coordinates, range))
{
if (!flashableQuery.TryGetComponent(entity, out var flashable))
if (!_random.Prob(probability))
continue;

if (!_random.Prob(probability))
if (!flashableQuery.TryGetComponent(entity, out var flashable))
continue;

// Check for unobstructed entities while ignoring the mobs with flashable components.
if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, flashable.CollisionGroup, (e) => e == source))
if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, flashable.CollisionGroup, predicate: (e) => flashableQuery.HasComponent(e) || e == source.Owner))
continue;

// They shouldn't have flash removed in between right?
Flash(entity, user, source, duration, slowTo, displayPopup, flashableQuery.GetComponent(entity));
}

if (sound != null)
{
_audio.PlayPvs(sound, source, AudioParams.Default.WithVolume(1f).WithMaxDistance(3f));
}
_audio.PlayPvs(sound, source, AudioParams.Default.WithVolume(1f).WithMaxDistance(3f));
}

private void OnInventoryFlashAttempt(EntityUid uid, InventoryComponent component, FlashAttemptEvent args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ private void OnPostFlash(EntityUid uid, HeadRevolutionaryComponent comp, ref Aft

_npcFaction.AddFaction(ev.Target, RevolutionaryNpcFaction);
var revComp = EnsureComp<RevolutionaryComponent>(ev.Target);
_stun.TryParalyze(ev.Target, comp.StunTime, true);

if (ev.User != null)
{
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Flash/Components/FlashComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public sealed partial class FlashComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
public int FlashDuration { get; set; } = 5000;

/// <summary>
/// How long a target is stunned when a melee flash is used.
/// If null, melee flashes will not stun at all
/// </summary>
[DataField]
public TimeSpan? MeleeStunDuration = TimeSpan.FromSeconds(1.5);

[DataField("range")]
[ViewVariables(VVAccess.ReadWrite)]
public float Range { get; set; } = 7f;
Expand Down
Loading