From 6c6ef3911d8b1bef9739ded62789fdc0a961117a Mon Sep 17 00:00:00 2001 From: py01 <60152240+collinlunn@users.noreply.github.com> Date: Tue, 3 Mar 2020 10:03:58 -0600 Subject: [PATCH] =?UTF-8?q?InRangeUnobstructed=20check=20for=20constructio?= =?UTF-8?q?n=20start=20and=20step=20progre=E2=80=A6=20(#773)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Construction/ConstructionComponent.cs | 12 ++++++++++-- .../Components/Construction/ConstructorComponent.cs | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs index 7e10507e50..4124a7a219 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs @@ -31,9 +31,10 @@ namespace Content.Server.GameObjects.Components.Construction SpriteComponent Sprite; ITransformComponent Transform; - #pragma warning disable 649 +#pragma warning disable 649 [Dependency] private IRobustRandom _random; - #pragma warning restore 649 + [Dependency] private readonly IEntitySystemManager _entitySystemManager; +#pragma warning restore 649 public override void Initialize() { @@ -46,6 +47,13 @@ namespace Content.Server.GameObjects.Components.Construction public bool AttackBy(AttackByEventArgs eventArgs) { + var playerEntity = eventArgs.User; + var interactionSystem = _entitySystemManager.GetEntitySystem(); + if (!interactionSystem.InRangeUnobstructed(playerEntity.Transform.MapPosition, Owner.Transform.WorldPosition, ignoredEnt: Owner, insideBlockerValid: true)) + { + return false; + } + var stage = Prototype.Stages[Stage]; if (TryProcessStep(stage.Forward, eventArgs.AttackWith)) diff --git a/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs index 6dc83b2640..3ef1905fc6 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs @@ -1,4 +1,4 @@ -using System; +using System; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Construction; @@ -29,7 +29,6 @@ namespace Content.Server.GameObjects.Components.Construction public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null) { base.HandleMessage(message, netChannel, component); - switch (message) { case TryStartStructureConstructionMessage tryStart: @@ -43,7 +42,9 @@ namespace Content.Server.GameObjects.Components.Construction var prototype = _prototypeManager.Index(prototypeName); var transform = Owner.Transform; - if (!loc.InRange(_mapManager, transform.GridPosition, InteractionSystem.InteractionRange)) + + var interactionSystem = _entitySystemManager.GetEntitySystem(); + if (!interactionSystem.InRangeUnobstructed(loc.ToMap(_mapManager), Owner.Transform.WorldPosition, ignoredEnt: Owner, insideBlockerValid: true)) { return; }