Prevent subfloor melee attacks (#12899)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2022-12-17 14:47:15 +11:00
committed by GitHub
parent 127d0e93da
commit 8bc5f29f9f
4 changed files with 40 additions and 3 deletions

View File

@@ -156,7 +156,17 @@ namespace Content.Shared.ActionBlocker
var ev = new AttackAttemptEvent(uid, target);
RaiseLocalEvent(uid, ev);
return !ev.Cancelled;
if (ev.Cancelled)
return false;
if (target != null)
{
var tev = new GettingAttackedAttemptEvent();
RaiseLocalEvent(target.Value, ref tev);
return !tev.Cancelled;
}
return true;
}
public bool CanChangeDirection(EntityUid uid)

View File

@@ -0,0 +1,7 @@
namespace Content.Shared.Interaction.Events;
/// <summary>
/// Raised directed on the target entity when being attacked.
/// </summary>
[ByRefEvent]
public record struct GettingAttackedAttemptEvent(bool Cancelled);

View File

@@ -31,6 +31,13 @@ namespace Content.Shared.SubFloor
// Like 80% sure this doesn't need to handle re-anchoring.
SubscribeLocalEvent<SubFloorHideComponent, AnchorStateChangedEvent>(HandleAnchorChanged);
SubscribeLocalEvent<SubFloorHideComponent, GettingInteractedWithAttemptEvent>(OnInteractionAttempt);
SubscribeLocalEvent<SubFloorHideComponent, GettingAttackedAttemptEvent>(OnAttackAttempt);
}
private void OnAttackAttempt(EntityUid uid, SubFloorHideComponent component, ref GettingAttackedAttemptEvent args)
{
if (component.BlockInteractions && component.IsUnderCover)
args.Cancelled = true;
}
private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, GettingInteractedWithAttemptEvent args)

View File

@@ -295,8 +295,21 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
if (!CombatMode.IsInCombatMode(user))
return;
if (!Blocker.CanAttack(user))
return;
switch (attack)
{
case LightAttackEvent light:
if (!Blocker.CanAttack(user, light.Target))
return;
break;
case DisarmAttackEvent disarm:
if (!Blocker.CanAttack(user, disarm.Target))
return;
break;
default:
if (!Blocker.CanAttack(user))
return;
break;
}
// Windup time checked elsewhere.