Actionblocker cleanup (#11371)

Doesn't fix the CanInteract shenanigans but fixed an unnecessary cast + removed a bunch of broadcasts.
This commit is contained in:
metalgearsloth 2022-09-17 15:29:01 +10:00 committed by GitHub
parent c380577156
commit 6ac4c38263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

View File

@ -43,8 +43,8 @@ namespace Content.Shared.ActionBlocker
var ev = new UpdateCanMoveEvent(uid); var ev = new UpdateCanMoveEvent(uid);
RaiseLocalEvent(uid, ev); RaiseLocalEvent(uid, ev);
if (component.CanMove == ev.Cancelled && component is Component comp) if (component.CanMove == ev.Cancelled)
Dirty(comp); Dirty(component);
component.CanMove = !ev.Cancelled; component.CanMove = !ev.Cancelled;
return !ev.Cancelled; return !ev.Cancelled;
@ -64,7 +64,7 @@ namespace Content.Shared.ActionBlocker
public bool CanInteract(EntityUid user, EntityUid? target) public bool CanInteract(EntityUid user, EntityUid? target)
{ {
var ev = new InteractionAttemptEvent(user, target); var ev = new InteractionAttemptEvent(user, target);
RaiseLocalEvent(user, ev, true); RaiseLocalEvent(user, ev);
if (ev.Cancelled) if (ev.Cancelled)
return false; return false;
@ -73,7 +73,7 @@ namespace Content.Shared.ActionBlocker
return true; return true;
var targetEv = new GettingInteractedWithAttemptEvent(user, target); var targetEv = new GettingInteractedWithAttemptEvent(user, target);
RaiseLocalEvent(target.Value, targetEv, true); RaiseLocalEvent(target.Value, targetEv);
if (!targetEv.Cancelled) if (!targetEv.Cancelled)
InteractWithItem(user, target.Value); InteractWithItem(user, target.Value);
@ -92,7 +92,7 @@ namespace Content.Shared.ActionBlocker
public bool CanUseHeldEntity(EntityUid user) public bool CanUseHeldEntity(EntityUid user)
{ {
var ev = new UseAttemptEvent(user); var ev = new UseAttemptEvent(user);
RaiseLocalEvent(user, ev, true); RaiseLocalEvent(user, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
@ -100,13 +100,14 @@ namespace Content.Shared.ActionBlocker
public bool CanThrow(EntityUid user, EntityUid itemUid) public bool CanThrow(EntityUid user, EntityUid itemUid)
{ {
var ev = new ThrowAttemptEvent(user, itemUid); var ev = new ThrowAttemptEvent(user, itemUid);
RaiseLocalEvent(user, ev, true); RaiseLocalEvent(user, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
public bool CanSpeak(EntityUid uid) public bool CanSpeak(EntityUid uid)
{ {
// This one is used as broadcast
var ev = new SpeakAttemptEvent(uid); var ev = new SpeakAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev, true);
@ -116,7 +117,7 @@ namespace Content.Shared.ActionBlocker
public bool CanDrop(EntityUid uid) public bool CanDrop(EntityUid uid)
{ {
var ev = new DropAttemptEvent(uid); var ev = new DropAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
@ -124,13 +125,13 @@ namespace Content.Shared.ActionBlocker
public bool CanPickup(EntityUid user, EntityUid item) public bool CanPickup(EntityUid user, EntityUid item)
{ {
var userEv = new PickupAttemptEvent(user, item); var userEv = new PickupAttemptEvent(user, item);
RaiseLocalEvent(user, userEv, false); RaiseLocalEvent(user, userEv);
if (userEv.Cancelled) if (userEv.Cancelled)
return false; return false;
var itemEv = new GettingPickedUpAttemptEvent(user, item); var itemEv = new GettingPickedUpAttemptEvent(user, item);
RaiseLocalEvent(item, itemEv, false); RaiseLocalEvent(item, itemEv);
if (!itemEv.Cancelled) if (!itemEv.Cancelled)
InteractWithItem(user, item); InteractWithItem(user, item);
@ -141,6 +142,7 @@ namespace Content.Shared.ActionBlocker
public bool CanEmote(EntityUid uid) public bool CanEmote(EntityUid uid)
{ {
// This one is used as broadcast
var ev = new EmoteAttemptEvent(uid); var ev = new EmoteAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev, true);
@ -150,7 +152,7 @@ namespace Content.Shared.ActionBlocker
public bool CanAttack(EntityUid uid, EntityUid? target = null) public bool CanAttack(EntityUid uid, EntityUid? target = null)
{ {
var ev = new AttackAttemptEvent(uid, target); var ev = new AttackAttemptEvent(uid, target);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
@ -158,7 +160,7 @@ namespace Content.Shared.ActionBlocker
public bool CanChangeDirection(EntityUid uid) public bool CanChangeDirection(EntityUid uid)
{ {
var ev = new ChangeDirectionAttemptEvent(uid); var ev = new ChangeDirectionAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
@ -166,7 +168,7 @@ namespace Content.Shared.ActionBlocker
public bool CanShiver(EntityUid uid) public bool CanShiver(EntityUid uid)
{ {
var ev = new ShiverAttemptEvent(uid); var ev = new ShiverAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }
@ -174,7 +176,7 @@ namespace Content.Shared.ActionBlocker
public bool CanSweat(EntityUid uid) public bool CanSweat(EntityUid uid)
{ {
var ev = new SweatAttemptEvent(uid); var ev = new SweatAttemptEvent(uid);
RaiseLocalEvent(uid, ev, true); RaiseLocalEvent(uid, ev);
return !ev.Cancelled; return !ev.Cancelled;
} }