Prevent Holoparasites from attacking their host (#6019)

This commit is contained in:
ShadowCommander
2022-01-04 01:22:28 -08:00
committed by GitHub
parent 5249ea057a
commit b335ef5e7f
5 changed files with 21 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ using Content.Shared.Audio;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.MobState; using Content.Shared.MobState;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -48,6 +49,8 @@ namespace Content.Server.Guardian
SubscribeLocalEvent<GuardianHostComponent, MoveEvent>(OnHostMove); SubscribeLocalEvent<GuardianHostComponent, MoveEvent>(OnHostMove);
SubscribeLocalEvent<GuardianHostComponent, MobStateChangedEvent>(OnHostStateChange); SubscribeLocalEvent<GuardianHostComponent, MobStateChangedEvent>(OnHostStateChange);
SubscribeLocalEvent<GuardianHostComponent, ComponentShutdown>(OnHostShutdown); SubscribeLocalEvent<GuardianHostComponent, ComponentShutdown>(OnHostShutdown);
SubscribeLocalEvent<GuardianComponent, AttackAttemptEvent>(OnGuardianAttackAttempt);
} }
private void OnGuardianUnplayer(EntityUid uid, GuardianComponent component, PlayerDetachedEvent args) private void OnGuardianUnplayer(EntityUid uid, GuardianComponent component, PlayerDetachedEvent args)
@@ -79,6 +82,15 @@ namespace Content.Server.Guardian
EntityManager.QueueDeleteEntity(component.HostedGuardian.Value); EntityManager.QueueDeleteEntity(component.HostedGuardian.Value);
} }
private void OnGuardianAttackAttempt(EntityUid uid, GuardianComponent component, AttackAttemptEvent args)
{
if (args.Cancelled || args.Target != component.Host)
return;
_popupSystem.PopupCursor(Loc.GetString("guardian-attack-host"), Filter.Entities(uid));
args.Cancel();
}
public void ToggleGuardian(GuardianHostComponent hostComponent) public void ToggleGuardian(GuardianHostComponent hostComponent)
{ {
if (hostComponent.HostedGuardian == null || if (hostComponent.HostedGuardian == null ||

View File

@@ -299,7 +299,7 @@ namespace Content.Server.Interaction
if (!ValidateInteractAndFace(user, coordinates)) if (!ValidateInteractAndFace(user, coordinates))
return; return;
if (!_actionBlockerSystem.CanAttack(user)) if (!_actionBlockerSystem.CanAttack(user, target))
return; return;
if (!wideAttack) if (!wideAttack)

View File

@@ -82,9 +82,9 @@ namespace Content.Shared.ActionBlocker
return !ev.Cancelled; return !ev.Cancelled;
} }
public bool CanAttack(EntityUid uid) public bool CanAttack(EntityUid uid, EntityUid? target = null)
{ {
var ev = new AttackAttemptEvent(uid); var ev = new AttackAttemptEvent(uid, target);
RaiseLocalEvent(uid, ev); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;

View File

@@ -4,11 +4,13 @@ namespace Content.Shared.Interaction.Events
{ {
public class AttackAttemptEvent : CancellableEntityEventArgs public class AttackAttemptEvent : CancellableEntityEventArgs
{ {
public AttackAttemptEvent(EntityUid uid) public EntityUid Uid { get; }
public EntityUid? Target { get; }
public AttackAttemptEvent(EntityUid uid, EntityUid? target = null)
{ {
Uid = uid; Uid = uid;
Target = target;
} }
public EntityUid Uid { get; }
} }
} }

View File

@@ -20,4 +20,5 @@ guardian-entity-taking-damage = Your guardian is taking damage!
guardian-host-critical-warn = YOUR HOST IS WOUNDED! guardian-host-critical-warn = YOUR HOST IS WOUNDED!
guardian-host-death-warn = YOUR FORM SUCCUMBS TO NONEXISTENCE! guardian-host-death-warn = YOUR FORM SUCCUMBS TO NONEXISTENCE!
guardian-death-warn = YOUR BODY IS PIERCED BY SUBATOMIC PAIN AS IT DISINTEGRATES! guardian-death-warn = YOUR BODY IS PIERCED BY SUBATOMIC PAIN AS IT DISINTEGRATES!
guardian-attack-host = You cannot attack your host.