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 null
parent afe534f8c6
commit bde4d81e76
No known key found for this signature in database
GPG Key ID: 212F05528FD678BE
1 changed files with 9 additions and 1 deletions

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);