Skip to content

Commit

Permalink
simplify repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Oct 26, 2024
1 parent 6dead32 commit 0b02455
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Content.Server/Psionics/PsionicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ private void OnMobstateChanged(EntityUid uid, PsionicComponent component, MobSta
}
}

/// <summary>
/// When a caster with active summons is attacked, aggro their familiars to the attacker.
/// </summary>
private void OnDamageChanged(EntityUid uid, PsionicComponent component, DamageChangedEvent args)
{
if (component.Familiars.Count <= 0
Expand All @@ -282,15 +285,12 @@ private void OnDamageChanged(EntityUid uid, PsionicComponent component, DamageCh
|| args.Origin is not { } origin)
return;

foreach (var familiar in component.Familiars)
{
if (!TryComp<NPCRetaliationComponent>(familiar, out var retaliationComponent))
continue;

_retaliationSystem.TryRetaliate(familiar, origin, retaliationComponent);
}
SetFamiliarTarget(origin, component);
}

/// <summary>
/// When a caster with active summons attempts to attack something, aggro their familiars to the target.
/// </summary>
private void OnAttackAttempt(EntityUid uid, PsionicComponent component, AttackAttemptEvent args)
{
if (component.Familiars.Count <= 0
Expand All @@ -299,6 +299,11 @@ private void OnAttackAttempt(EntityUid uid, PsionicComponent component, AttackAt
|| component.Familiars.Contains(target))
return;

SetFamiliarTarget(target, component);
}

private void SetFamiliarTarget(EntityUid target, PsionicComponent component)
{
foreach (var familiar in component.Familiars)
{
if (!TryComp<NPCRetaliationComponent>(familiar, out var retaliationComponent))
Expand Down

0 comments on commit 0b02455

Please sign in to comment.