Add CanAttack check if target is in a container (#27689)

This commit is contained in:
metalgearsloth
2024-05-09 16:00:16 +10:00
committed by GitHub
parent a7b86f724e
commit a2329889aa

View File

@@ -169,8 +169,16 @@ namespace Content.Shared.ActionBlocker
public bool CanAttack(EntityUid uid, EntityUid? target = null, Entity<MeleeWeaponComponent>? weapon = null, bool disarm = false)
{
// If target is in a container can we attack
if (target != null && _container.IsEntityInContainer(target.Value))
{
return false;
}
_container.TryGetOuterContainer(uid, Transform(uid), out var outerContainer);
if (target != null && target != outerContainer?.Owner && _container.IsEntityInContainer(uid))
// If we're in a container can we attack the target.
if (target != null && target != outerContainer?.Owner && _container.IsEntityInContainer(uid))
{
var containerEv = new CanAttackFromContainerEvent(uid, target);
RaiseLocalEvent(uid, containerEv);