Adds InRangeUnobstructed method to InteractionSystem (#698)

* You cannot pickup items across walls, or pickup items when dead/in crit.

* Adds InRangeUnobstructed method to InteractionSystem.
Changes HandsSystem and ItemComponent to use it.
This commit is contained in:
Víctor Aguilera Puerto
2020-02-16 23:04:06 +01:00
committed by GitHub
parent c7a171cf14
commit 70c41f63b0
6 changed files with 88 additions and 9 deletions

View File

@@ -2,11 +2,14 @@
using Content.Server.Interfaces.GameObjects;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -24,6 +27,9 @@ namespace Content.Server.GameObjects
#pragma warning disable 649
[Dependency] private readonly IRobustRandom _robustRandom;
[Dependency] private readonly IPhysicsManager _physicsManager;
[Dependency] private readonly IMapManager _mapManager;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
private string _equippedPrefix;
@@ -64,8 +70,19 @@ namespace Content.Server.GameObjects
serializer.DataField(ref _equippedPrefix, "HeldPrefix", null);
}
public bool CanPickup(IEntity user)
{
var coords = Owner.Transform.GridPosition;
if (!ActionBlockerSystem.CanPickup(user)) return false;
return _entitySystemManager.GetEntitySystem<InteractionSystem>()
.InRangeUnobstructed(coords, user.Transform.GridPosition, ignoredEnt:Owner);
}
public bool AttackHand(AttackHandEventArgs eventArgs)
{
if (!CanPickup(eventArgs.User)) return false;
var hands = eventArgs.User.GetComponent<IHandsComponent>();
hands.PutInHand(this, hands.ActiveIndex, fallback: false);
return true;
@@ -85,7 +102,7 @@ namespace Content.Server.GameObjects
protected override VerbVisibility GetVisibility(IEntity user, ItemComponent component)
{
if (ContainerHelpers.IsInContainer(component.Owner))
if (ContainerHelpers.IsInContainer(component.Owner) || !component.CanPickup(user))
{
return VerbVisibility.Invisible;
}