diff --git a/Content.Client/Commands/DebugCommands.cs b/Content.Client/Commands/DebugCommands.cs index 8fb0e75bb4..715dd99549 100644 --- a/Content.Client/Commands/DebugCommands.cs +++ b/Content.Client/Commands/DebugCommands.cs @@ -4,6 +4,7 @@ using Content.Shared.GameObjects.Components.Markers; using Robust.Client.Interfaces.Console; using Robust.Client.Interfaces.GameObjects.Components; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; @@ -48,8 +49,7 @@ namespace Content.Client.Commands public bool Execute(IDebugConsole console, params string[] args) { - IoCManager.Resolve() - .GetEntitySystem() + EntitySystem.Get() .EnableAll ^= true; return false; diff --git a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs index 03b5f088d3..94bfcf22ff 100644 --- a/Content.Client/GameObjects/Components/Sound/SoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/SoundComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Shared.GameObjects.Components.Sound; using Robust.Client.GameObjects.EntitySystems; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Network; using Robust.Shared.Interfaces.Random; @@ -9,6 +10,7 @@ using Robust.Shared.IoC; using Robust.Shared.Players; using Robust.Shared.Serialization; using Robust.Shared.Timers; +using Robust.Shared.Utility; namespace Content.Client.GameObjects.Components.Sound { @@ -54,7 +56,7 @@ namespace Content.Client.GameObjects.Components.Sound Timer.Spawn((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() => { if (!schedule.Play) return; // We make sure this hasn't changed. - if (_audioSystem == null) _audioSystem = IoCManager.Resolve().GetEntitySystem(); + if (_audioSystem == null) _audioSystem = EntitySystem.Get(); _audioStreams.Add(schedule,_audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams)); if (schedule.Times == 0) return; @@ -87,7 +89,7 @@ namespace Content.Client.GameObjects.Components.Sound public override void Initialize() { base.Initialize(); - IoCManager.Resolve().TryGetEntitySystem(out _audioSystem); + EntitySystem.TryGet(out _audioSystem); } public override void ExposeData(ObjectSerializer serializer) diff --git a/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs b/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs index a3436adcce..12c7ac72ee 100644 --- a/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Access/IdCardConsoleComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.Access; using Content.Shared.GameObjects.Components.Access; using Robust.Server.GameObjects.Components.Container; diff --git a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs index 3b555c725f..9104580303 100644 --- a/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Cargo/CargoConsoleComponent.cs @@ -14,6 +14,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Content.Server.Utility; using Robust.Shared.Map; namespace Content.Server.GameObjects.Components.Cargo diff --git a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs index 1b33bd2583..7fecdc0e45 100644 --- a/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/InjectorComponent.cs @@ -2,6 +2,7 @@ using Content.Server.GameObjects.Components.Metabolism; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry; using Robust.Shared.GameObjects; @@ -110,6 +111,8 @@ namespace Content.Server.GameObjects.Components.Chemistry /// void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + //Make sure we have the attacking entity if (eventArgs.Attacked == null || !_internalContents.Injector) { diff --git a/Content.Server/GameObjects/Components/Chemistry/PourableComponent.cs b/Content.Server/GameObjects/Components/Chemistry/PourableComponent.cs index f129e30321..f36ff18ffc 100644 --- a/Content.Server/GameObjects/Components/Chemistry/PourableComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/PourableComponent.cs @@ -4,12 +4,15 @@ using System.Text; using Content.Server.GameObjects.Components.Nutrition; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.Chemistry; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Chemistry { @@ -25,6 +28,7 @@ namespace Content.Server.GameObjects.Components.Chemistry #pragma warning disable 649 [Dependency] private readonly IServerNotifyManager _notifyManager; [Dependency] private readonly ILocalizationManager _localizationManager; + [Dependency] private readonly IEntitySystemManager _entitySystemManager; #pragma warning restore 649 public override string Name => "Pourable"; diff --git a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs index 829edbab1a..39584973fd 100644 --- a/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs +++ b/Content.Server/GameObjects/Components/Chemistry/ReagentDispenserComponent.cs @@ -5,6 +5,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.Components.Power; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry; using Robust.Server.GameObjects.Components.Container; diff --git a/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs b/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs index a3ce594242..f8ca433024 100644 --- a/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Command/CommunicationsConsoleComponent.cs @@ -1,6 +1,7 @@ using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameTicking; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Command; using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; diff --git a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs index be64cfb14f..146dabeaf8 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructionComponent.cs @@ -4,12 +4,14 @@ using Content.Server.GameObjects.Components.Interactable.Tools; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.Construction; using Content.Shared.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Random; @@ -18,6 +20,8 @@ using Robust.Shared.Localization; using Robust.Shared.ViewVariables; using static Content.Shared.Construction.ConstructionStepMaterial; using static Content.Shared.Construction.ConstructionStepTool; +using Robust.Shared.Utility; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Construction { @@ -46,18 +50,16 @@ namespace Content.Server.GameObjects.Components.Construction Sprite = Owner.GetComponent(); Transform = Owner.GetComponent(); - var systemman = IoCManager.Resolve(); } 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: Prototype.CanBuildInImpassable)) + // default interaction check for AttackBy allows inside blockers, so we will check if its blocked if + // we're not allowed to build on impassable stuff + if (Prototype.CanBuildInImpassable == false) { - _notifyManager.PopupMessage(Owner.Transform.GridPosition, playerEntity, - _localizationManager.GetString("You can't reach there!")); - return false; + if (!InteractionChecks.InRangeUnobstructed(eventArgs, false)) + return false; } var stage = Prototype.Stages[Stage]; @@ -124,7 +126,7 @@ namespace Content.Server.GameObjects.Components.Construction { return false; } - var sound = IoCManager.Resolve().GetEntitySystem(); + var sound = EntitySystem.Get(); switch (step) { diff --git a/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs b/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs index 314eaa59cd..53e1b83886 100644 --- a/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs +++ b/Content.Server/GameObjects/Components/Construction/ConstructorComponent.cs @@ -1,12 +1,14 @@ using System; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Construction; using Content.Shared.GameObjects.Components.Construction; using Content.Shared.Interfaces; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Network; @@ -16,6 +18,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Players; using Robust.Shared.Prototypes; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Construction { @@ -47,16 +50,13 @@ namespace Content.Server.GameObjects.Components.Construction { var prototype = _prototypeManager.Index(prototypeName); - var transform = Owner.Transform; - - var interactionSystem = _entitySystemManager.GetEntitySystem(); - if (!interactionSystem.InRangeUnobstructed(loc.ToMap(_mapManager), Owner.Transform.WorldPosition, ignoredEnt: Owner, insideBlockerValid: prototype.CanBuildInImpassable)) + if (!InteractionChecks.InRangeUnobstructed(Owner, loc.ToMapPos(_mapManager), + ignoredEnt: Owner, insideBlockerValid: prototype.CanBuildInImpassable)) { - _notifyManager.PopupMessage(transform.GridPosition, Owner, - _localizationManager.GetString("You can't reach there!")); return; } + if (prototype.Stages.Count < 2) { throw new InvalidOperationException($"Prototype '{prototypeName}' does not have enough stages."); diff --git a/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs b/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs index 3e064befc4..e917422964 100644 --- a/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs +++ b/Content.Server/GameObjects/Components/Doors/AirlockComponent.cs @@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.VendingMachines; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Doors; using Robust.Server.GameObjects; using Robust.Server.Interfaces.GameObjects; diff --git a/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs b/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs index 3e496bf08a..68d0c9847a 100644 --- a/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs +++ b/Content.Server/GameObjects/Components/Doors/ServerDoorComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.Components.Access; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Doors; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; diff --git a/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs b/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs index 98b9cf9891..6a0b47d9b8 100644 --- a/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/BucketComponent.cs @@ -2,6 +2,7 @@ using System; using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.Interfaces; using Robust.Shared.GameObjects; diff --git a/Content.Server/GameObjects/Components/Fluids/MopComponent.cs b/Content.Server/GameObjects/Components/Fluids/MopComponent.cs index 22f722ea9c..4a374c0ac4 100644 --- a/Content.Server/GameObjects/Components/Fluids/MopComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/MopComponent.cs @@ -2,6 +2,7 @@ using System; using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.Interfaces; using Robust.Shared.GameObjects; @@ -59,6 +60,8 @@ namespace Content.Server.GameObjects.Components.Fluids void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + Solution solution; if (eventArgs.Attacked == null) { diff --git a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs index 020f833e6e..3a3d06b8fa 100644 --- a/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs +++ b/Content.Server/GameObjects/Components/Fluids/PuddleComponent.cs @@ -9,6 +9,7 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.Transform; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; @@ -17,6 +18,7 @@ using Robust.Shared.Serialization; using Robust.Shared.Utility; using Robust.Shared.ViewVariables; using Timer = Robust.Shared.Timers.Timer; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Fluids { @@ -137,8 +139,7 @@ namespace Content.Server.GameObjects.Components.Fluids return true; } - var entitySystemManager = IoCManager.Resolve(); - entitySystemManager.GetEntitySystem().Play(_spillSound); + EntitySystem.Get().Play(_spillSound); return true; } diff --git a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs index 494a97c9d8..d1a01ef345 100644 --- a/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs +++ b/Content.Server/GameObjects/Components/Gravity/GravityGeneratorComponent.cs @@ -3,6 +3,7 @@ using Content.Server.GameObjects.Components.Interactable.Tools; using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Gravity; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Robust.Server.GameObjects; @@ -11,10 +12,12 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Gravity { @@ -101,6 +104,7 @@ namespace Content.Server.GameObjects.Components.Gravity public bool AttackBy(AttackByEventArgs eventArgs) { if (!eventArgs.AttackWith.TryGetComponent(out var welder)) return false; + if (welder.TryUse(5.0f)) { // Repair generator @@ -110,10 +114,9 @@ namespace Content.Server.GameObjects.Components.Gravity breakable.broken = false; _intact = true; - var entitySystemManager = IoCManager.Resolve(); var notifyManager = IoCManager.Resolve(); - entitySystemManager.GetEntitySystem().Play("/Audio/items/welder2.ogg", Owner); + EntitySystem.Get().Play("/Audio/items/welder2.ogg", Owner); notifyManager.PopupMessage(Owner, eventArgs.User, Loc.GetString("You repair the gravity generator with the welder")); return true; diff --git a/Content.Server/GameObjects/Components/Healing/HealingComponent.cs b/Content.Server/GameObjects/Components/Healing/HealingComponent.cs index 5fb3bdc7cc..6360facb39 100644 --- a/Content.Server/GameObjects/Components/Healing/HealingComponent.cs +++ b/Content.Server/GameObjects/Components/Healing/HealingComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; @@ -24,6 +25,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + if (eventArgs.Attacked == null) { return; diff --git a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs index 5f07b3d8b0..b35178f5bd 100644 --- a/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs +++ b/Content.Server/GameObjects/Components/Instruments/InstrumentComponent.cs @@ -3,6 +3,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects; using Content.Server.Mobs; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Instruments; using NFluidsynth; using Robust.Server.GameObjects; diff --git a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs index 575c14a83c..6aeb776312 100644 --- a/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/HandheldLightComponent.cs @@ -2,6 +2,7 @@ using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components; using Content.Shared.Interfaces; diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs index 8d052c9680..1bf0cf1231 100644 --- a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Maps; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; @@ -25,17 +26,11 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools public void AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); - var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); - float distance = coordinates.Distance(_mapManager, Owner.Transform.GridPosition); - - if (distance > InteractionSystem.InteractionRange) - { - return; - } - var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; if (tileDef.CanCrowbar) { diff --git a/Content.Server/GameObjects/Components/Items/DiceComponent.cs b/Content.Server/GameObjects/Components/Items/DiceComponent.cs index eda5569dd5..d85058fcb5 100644 --- a/Content.Server/GameObjects/Components/Items/DiceComponent.cs +++ b/Content.Server/GameObjects/Components/Items/DiceComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Audio; using Robust.Server.GameObjects; using Robust.Shared.Audio; diff --git a/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs b/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs index 143983abeb..f5b4cd2b8b 100644 --- a/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/FloorTileItemComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Maps; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; @@ -40,18 +41,11 @@ namespace Content.Server.GameObjects.Components.Items } public void AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + var attacked = eventArgs.Attacked; var mapGrid = _mapManager.GetGrid(eventArgs.ClickLocation.GridID); var tile = mapGrid.GetTileRef(eventArgs.ClickLocation); - - var coordinates = mapGrid.GridTileToLocal(tile.GridIndices); - float distance = coordinates.Distance(_mapManager, Owner.Transform.GridPosition); - - if (distance > InteractionSystem.InteractionRange) - { - return; - } - var tileDef = (ContentTileDefinition)_tileDefinitionManager[tile.Tile.TypeId]; if (tileDef.IsSubFloor && attacked == null && Stack.Use(1)) { @@ -63,7 +57,7 @@ namespace Content.Server.GameObjects.Components.Items } } - + } } diff --git a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs index ed37b1f088..23d6292743 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/EntityStorageComponent.cs @@ -3,6 +3,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Storage; using Robust.Server.GameObjects; diff --git a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs index f2470a8113..1b69ef420c 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ItemComponent.cs @@ -4,6 +4,7 @@ using Content.Server.GameObjects.Components.Destructible; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; using Content.Server.Throw; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Items; using Content.Shared.Physics; @@ -12,6 +13,7 @@ using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Map; @@ -23,6 +25,7 @@ using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Random; using Robust.Shared.Serialization; +using Robust.Shared.Utility; namespace Content.Server.GameObjects { @@ -35,7 +38,6 @@ namespace Content.Server.GameObjects #pragma warning disable 649 [Dependency] private readonly IRobustRandom _robustRandom; - [Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IMapManager _mapManager; #pragma warning restore 649 @@ -97,8 +99,7 @@ namespace Content.Server.GameObjects var userPos = user.Transform.MapPosition; var itemPos = Owner.Transform.WorldPosition; - return _entitySystemManager.GetEntitySystem() - .InRangeUnobstructed(userPos, itemPos, ignoredEnt: Owner, insideBlockerValid:true); + return InteractionChecks.InRangeUnobstructed(user, itemPos, ignoredEnt: Owner, insideBlockerValid:true); } public bool AttackHand(AttackHandEventArgs eventArgs) diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs index f0bdb1a615..fd19a8be39 100644 --- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs +++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs @@ -5,6 +5,7 @@ using Content.Server.GameObjects.Components; using Content.Server.GameObjects.Components.Items.Storage; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Storage; using Content.Shared.Interfaces; using Robust.Server.GameObjects; @@ -149,6 +150,8 @@ namespace Content.Server.GameObjects return false; } + + return PlayerInsertEntity(eventArgs.User); } diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index 4bec6bfd6a..b8341b8a32 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -21,6 +21,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.Localization; using Content.Server.Interfaces; +using Content.Server.Utility; using Robust.Shared.Audio; namespace Content.Server.GameObjects.Components.Kitchen @@ -177,6 +178,7 @@ namespace Content.Server.GameObjects.Components.Kitchen { return; } + UpdateUserInterface(); _userInterface.Open(actor.playerSession); diff --git a/Content.Server/GameObjects/Components/MagicMirrorComponent.cs b/Content.Server/GameObjects/Components/MagicMirrorComponent.cs index c245ef6aa3..76017269c8 100644 --- a/Content.Server/GameObjects/Components/MagicMirrorComponent.cs +++ b/Content.Server/GameObjects/Components/MagicMirrorComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.Interfaces; using Content.Shared.Preferences.Appearance; diff --git a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs index d1bdda9f79..d3ef519309 100644 --- a/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs +++ b/Content.Server/GameObjects/Components/Medical/MedicalScannerComponent.cs @@ -4,6 +4,7 @@ using Content.Server.GameObjects.EntitySystems; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Medical; using Content.Server.GameObjects.Components.Power; +using Content.Server.Utility; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; using Robust.Server.GameObjects.Components.UserInterface; @@ -120,8 +121,10 @@ namespace Content.Server.GameObjects.Components.Medical { return; } + if (!Powered) return; + _userInterface.Open(actor.playerSession); } diff --git a/Content.Server/GameObjects/Components/Mining/AsteroidRockComponent.cs b/Content.Server/GameObjects/Components/Mining/AsteroidRockComponent.cs index bc11b88107..265b86783c 100644 --- a/Content.Server/GameObjects/Components/Mining/AsteroidRockComponent.cs +++ b/Content.Server/GameObjects/Components/Mining/AsteroidRockComponent.cs @@ -1,6 +1,7 @@ using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.Components.Weapon.Melee; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Robust.Server.GameObjects; using Robust.Shared.Audio; diff --git a/Content.Server/GameObjects/Components/Movement/ServerPortalComponent.cs b/Content.Server/GameObjects/Components/Movement/ServerPortalComponent.cs index 582d0e04b9..9e1955decf 100644 --- a/Content.Server/GameObjects/Components/Movement/ServerPortalComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ServerPortalComponent.cs @@ -6,11 +6,13 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization; using Robust.Shared.Timers; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Movement { @@ -195,7 +197,7 @@ namespace Content.Server.GameObjects.Components.Movement if (!immuneEntities.Contains(entity)) { var position = _connectingTeleporter.Transform.GridPosition; - var soundPlayer = IoCManager.Resolve().GetEntitySystem(); + var soundPlayer = EntitySystem.Get(); // Departure // Do we need to rate-limit sounds to stop ear BLAST? diff --git a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs index 3b7d126f82..2a9d6a6780 100644 --- a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs @@ -7,6 +7,7 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Random; @@ -16,6 +17,7 @@ using Robust.Shared.Maths; using Robust.Shared.Serialization; using Robust.Shared.Timers; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Movement { @@ -141,7 +143,7 @@ namespace Content.Server.GameObjects.Components.Movement Timer.Spawn(TimeSpan.FromSeconds(_chargeTime + _cooldown), () => SetState(ItemTeleporterState.Off)); if (_cooldownSound != null) { - var soundPlayer = IoCManager.Resolve().GetEntitySystem(); + var soundPlayer = EntitySystem.Get(); soundPlayer.Play(_cooldownSound, Owner); } } @@ -227,7 +229,7 @@ namespace Content.Server.GameObjects.Components.Movement { // Messy maybe? GridCoordinates targetGrid = new GridCoordinates(vector, user.Transform.GridID); - var soundPlayer = IoCManager.Resolve().GetEntitySystem(); + var soundPlayer = EntitySystem.Get(); // If portals use those, otherwise just move em over if (_portalAliveTime > 0.0f) diff --git a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs index 8c611bb3f3..e3c5242a17 100644 --- a/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/DrinkComponent.cs @@ -3,6 +3,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.Interfaces; @@ -11,11 +12,13 @@ using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.Audio; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Nutrition { @@ -99,23 +102,25 @@ namespace Content.Server.GameObjects.Components.Nutrition void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + UseDrink(eventArgs.Attacked); } - private void UseDrink(IEntity user) + private void UseDrink(IEntity targetEntity) { - if (user == null) + if (targetEntity == null) { return; } if (UsesLeft() == 0 && !_despawnOnFinish) { - user.PopupMessage(user, _localizationManager.GetString("Empty")); + targetEntity.PopupMessage(targetEntity, _localizationManager.GetString("Empty")); return; } - if (user.TryGetComponent(out StomachComponent stomachComponent)) + if (targetEntity.TryGetComponent(out StomachComponent stomachComponent)) { _drinking = true; var transferAmount = ReagentUnit.Min(_transferAmount, _contents.CurrentVolume); @@ -125,17 +130,16 @@ namespace Content.Server.GameObjects.Components.Nutrition // When we split Finish gets called which may delete the can so need to use the entity system for sound if (_useSound != null) { - var entitySystemManager = IoCManager.Resolve(); - var audioSystem = entitySystemManager.GetEntitySystem(); + var audioSystem = EntitySystem.Get(); audioSystem.Play(_useSound, Owner, AudioParams.Default.WithVolume(-2f)); - user.PopupMessage(user, _localizationManager.GetString("Slurp")); + targetEntity.PopupMessage(targetEntity, _localizationManager.GetString("Slurp")); } } else { // Add it back in _contents.TryAddSolution(split); - user.PopupMessage(user, _localizationManager.GetString("Can't drink")); + targetEntity.PopupMessage(targetEntity, _localizationManager.GetString("Can't drink")); } _drinking = false; } diff --git a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs index a0039b14f9..8ea5cbe173 100644 --- a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs @@ -2,6 +2,7 @@ using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Nutrition; using Content.Shared.Interfaces; @@ -111,6 +112,8 @@ namespace Content.Server.GameObjects.Components.Nutrition void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + UseFood(eventArgs.Attacked); } diff --git a/Content.Server/GameObjects/Components/Paper/PaperComponent.cs b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs index 2162d3bcf7..064af4e78e 100644 --- a/Content.Server/GameObjects/Components/Paper/PaperComponent.cs +++ b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; diff --git a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs index 6c4cb1b619..15c518098e 100644 --- a/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs +++ b/Content.Server/GameObjects/Components/PlaceableSurfaceComponent.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Robust.Shared.GameObjects; using Robust.Shared.Serialization; diff --git a/Content.Server/GameObjects/Components/Power/ApcComponent.cs b/Content.Server/GameObjects/Components/Power/ApcComponent.cs index 5f99481eaf..da8e8b1337 100644 --- a/Content.Server/GameObjects/Components/Power/ApcComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Power; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; diff --git a/Content.Server/GameObjects/Components/Power/Chargers/PowerCellChargerComponent.cs b/Content.Server/GameObjects/Components/Power/Chargers/PowerCellChargerComponent.cs index 58341bd2ca..fd73b7503d 100644 --- a/Content.Server/GameObjects/Components/Power/Chargers/PowerCellChargerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/Chargers/PowerCellChargerComponent.cs @@ -1,5 +1,6 @@ using System; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Power; using Content.Shared.Interfaces; diff --git a/Content.Server/GameObjects/Components/Power/Chargers/WeaponCapacitorChargerComponent.cs b/Content.Server/GameObjects/Components/Power/Chargers/WeaponCapacitorChargerComponent.cs index d69c86eff3..40741df442 100644 --- a/Content.Server/GameObjects/Components/Power/Chargers/WeaponCapacitorChargerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/Chargers/WeaponCapacitorChargerComponent.cs @@ -1,6 +1,7 @@ using System; using Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Power; using Content.Shared.Interfaces; diff --git a/Content.Server/GameObjects/Components/Power/LightBulbComponent.cs b/Content.Server/GameObjects/Components/Power/LightBulbComponent.cs index f8fde7b236..4e61ede842 100644 --- a/Content.Server/GameObjects/Components/Power/LightBulbComponent.cs +++ b/Content.Server/GameObjects/Components/Power/LightBulbComponent.cs @@ -4,6 +4,7 @@ using Content.Shared.Audio; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; @@ -12,6 +13,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Power { @@ -126,7 +128,7 @@ namespace Content.Server.GameObjects.Components.Power var soundCollection = _prototypeManager.Index("glassbreak"); var file = _random.Pick(soundCollection.PickFiles); - IoCManager.Resolve().GetEntitySystem().Play(file, Owner); + EntitySystem.Get().Play(file, Owner); State = LightBulbState.Broken; } diff --git a/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs b/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs index 541b4f2f5a..342c3b44b1 100644 --- a/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PowerTransferComponent.cs @@ -2,6 +2,7 @@ using Content.Server.GameObjects.Components.Interactable.Tools; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components.Transform; diff --git a/Content.Server/GameObjects/Components/Power/PoweredLightComponent.cs b/Content.Server/GameObjects/Components/Power/PoweredLightComponent.cs index b6f9607890..cd789fbec5 100644 --- a/Content.Server/GameObjects/Components/Power/PoweredLightComponent.cs +++ b/Content.Server/GameObjects/Components/Power/PoweredLightComponent.cs @@ -1,6 +1,7 @@ using System; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.Container; diff --git a/Content.Server/GameObjects/Components/Power/Powernet.cs b/Content.Server/GameObjects/Components/Power/Powernet.cs index b244ef732b..76db36ae60 100644 --- a/Content.Server/GameObjects/Components/Power/Powernet.cs +++ b/Content.Server/GameObjects/Components/Power/Powernet.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using Content.Shared.GameObjects.EntitySystems; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Power { @@ -15,8 +17,7 @@ namespace Content.Server.GameObjects.Components.Power { public Powernet() { - var EntitySystemManager = IoCManager.Resolve(); - var powerSystem = EntitySystemManager.GetEntitySystem(); + var powerSystem = EntitySystem.Get(); powerSystem.Powernets.Add(this); Uid = powerSystem.NewUid(); } @@ -374,8 +375,7 @@ namespace Content.Server.GameObjects.Components.Power /// private void RemoveFromSystem() { - var EntitySystemManager = IoCManager.Resolve(); - EntitySystemManager.GetEntitySystem().Powernets.Remove(this); + EntitySystem.Get().Powernets.Remove(this); } #region Registration diff --git a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs index 9f313ae983..1897b71601 100644 --- a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Robust.Server.GameObjects; using Robust.Server.Interfaces.GameObjects; using Robust.Shared.GameObjects; @@ -25,6 +26,8 @@ namespace Content.Server.GameObjects.Components.Power /// public void AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GridID, out var grid)) return; diff --git a/Content.Server/GameObjects/Components/Research/LatheComponent.cs b/Content.Server/GameObjects/Components/Research/LatheComponent.cs index b97cc3a7cb..6847614f18 100644 --- a/Content.Server/GameObjects/Components/Research/LatheComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheComponent.cs @@ -8,6 +8,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Stack; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Materials; using Content.Shared.GameObjects.Components.Power; using Content.Shared.GameObjects.Components.Research; @@ -97,7 +98,7 @@ namespace Content.Server.GameObjects.Components.Research break; } - + } @@ -150,12 +151,13 @@ namespace Content.Server.GameObjects.Components.Research { return; } + OpenUserInterface(actor.playerSession); } bool IAttackBy.AttackBy(AttackByEventArgs eventArgs) { if (!Owner.TryGetComponent(out MaterialStorageComponent storage) - || !eventArgs.AttackWith.TryGetComponent(out MaterialComponent material)) return false; + || !eventArgs.AttackWith.TryGetComponent(out MaterialComponent material)) return false; var multiplier = 1; diff --git a/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs index f80ab8366f..ad63bb4bb7 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchClientComponent.cs @@ -1,4 +1,5 @@ using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Research; using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; @@ -60,7 +61,6 @@ namespace Content.Server.GameObjects.Components.Research return; OpenUserInterface(actor.playerSession); - return; } public void UpdateUserInterface() diff --git a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs index 89f3d2ddd4..ce9069758f 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchConsoleComponent.cs @@ -1,5 +1,6 @@ using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.Audio; using Content.Shared.GameObjects.Components.Research; using Content.Shared.Research; @@ -110,6 +111,7 @@ namespace Content.Server.GameObjects.Components.Research { return; } + OpenUserInterface(actor.playerSession); PlayKeyboardSound(); return; diff --git a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs index 2258c9af6b..476b6913c4 100644 --- a/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs +++ b/Content.Server/GameObjects/Components/Research/ResearchServerComponent.cs @@ -3,10 +3,12 @@ using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; using Content.Shared.Research; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Research { @@ -73,7 +75,7 @@ namespace Content.Server.GameObjects.Components.Research { base.Initialize(); Id = ServerCount++; - IoCManager.Resolve()?.GetEntitySystem()?.RegisterServer(this); + EntitySystem.Get()?.RegisterServer(this); Database = Owner.GetComponent(); Owner.TryGetComponent(out _powerDevice); } @@ -82,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Research protected override void Shutdown() { base.Shutdown(); - IoCManager.Resolve()?.GetEntitySystem()?.UnregisterServer(this); + EntitySystem.Get()?.UnregisterServer(this); } public override void ExposeData(ObjectSerializer serializer) diff --git a/Content.Server/GameObjects/Components/Stack/StackComponent.cs b/Content.Server/GameObjects/Components/Stack/StackComponent.cs index 3b4bae15c5..28fe570868 100644 --- a/Content.Server/GameObjects/Components/Stack/StackComponent.cs +++ b/Content.Server/GameObjects/Components/Stack/StackComponent.cs @@ -1,5 +1,6 @@ using System; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using Content.Shared.Interfaces; using Robust.Shared.GameObjects; diff --git a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs index 1a9823d8ae..352b3f9e65 100644 --- a/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs +++ b/Content.Server/GameObjects/Components/VendingMachines/VendingMachineComponent.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.VendingMachines; using Content.Shared.VendingMachines; using Robust.Server.GameObjects; diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Hitscan/HitscanWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Hitscan/HitscanWeaponComponent.cs index a725d53ef9..e2f417a0f0 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Hitscan/HitscanWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Hitscan/HitscanWeaponComponent.cs @@ -3,6 +3,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.Interfaces; using Content.Shared.Physics; @@ -10,6 +11,7 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.EntitySystemMessages; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Physics; using Robust.Shared.Interfaces.Timing; @@ -18,6 +20,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Serialization; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan { @@ -129,8 +132,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Hitscan Shaded = false }; - var mgr = IoCManager.Resolve(); - mgr.GetEntitySystem().CreateParticle(message); + EntitySystem.Get().CreateParticle(message); Owner.GetComponent().Play(_fireSound, AudioParams.Default.WithVolume(-5)); } } diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/AmmoBoxComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/AmmoBoxComponent.cs index 174d24a117..ec885c7e72 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/AmmoBoxComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/AmmoBoxComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Weapons.Ranged; using Content.Shared.Interfaces; using Robust.Server.GameObjects; diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs index 0fa594fa6b..fddd55a063 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Weapons.Ranged; using Content.Shared.Interfaces; using Robust.Server.GameObjects; diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs index 989ca86614..64a119f267 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Projectile/BallisticMagazineWeaponComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Weapons.Ranged; using Content.Shared.Interfaces; diff --git a/Content.Server/GameObjects/Components/WiresComponent.cs b/Content.Server/GameObjects/Components/WiresComponent.cs index d8c7a5b119..8c7eee7f1c 100644 --- a/Content.Server/GameObjects/Components/WiresComponent.cs +++ b/Content.Server/GameObjects/Components/WiresComponent.cs @@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.VendingMachines; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.GameObjects.Components; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -13,6 +14,7 @@ using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.Player; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Random; using Robust.Shared.IoC; @@ -20,6 +22,7 @@ using Robust.Shared.Localization; using Robust.Shared.Maths; using Robust.Shared.Random; using Robust.Shared.Utility; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components { @@ -108,7 +111,7 @@ namespace Content.Server.GameObjects.Components public override void Initialize() { base.Initialize(); - _audioSystem = IoCManager.Resolve().GetEntitySystem(); + _audioSystem = EntitySystem.Get(); _appearance = Owner.GetComponent(); _appearance.SetData(WiresVisuals.MaintenancePanelState, IsPanelOpen); _userInterface = Owner.GetComponent() @@ -235,8 +238,7 @@ namespace Content.Server.GameObjects.Components return; } - var interactionSystem = IoCManager.Resolve().GetEntitySystem(); - if (!interactionSystem.InRangeUnobstructed(player.Transform.MapPosition, Owner.Transform.WorldPosition, ignoredEnt: Owner)) + if (!EntitySystem.Get().InRangeUnobstructed(player.Transform.MapPosition, Owner.Transform.WorldPosition, ignoredEnt: Owner)) { _notifyManager.PopupMessage(Owner.Transform.GridPosition, player, _localizationManager.GetString("You can't reach there!")); return; @@ -302,8 +304,7 @@ namespace Content.Server.GameObjects.Components } IsPanelOpen = !IsPanelOpen; - IoCManager.Resolve() - .GetEntitySystem() + EntitySystem.Get() .Play(IsPanelOpen ? "/Audio/machines/screwdriveropen.ogg" : "/Audio/machines/screwdriverclose.ogg"); return true; } diff --git a/Content.Server/GameObjects/Components/WrenchableComponent.cs b/Content.Server/GameObjects/Components/WrenchableComponent.cs index 056a874900..37f46a02fb 100644 --- a/Content.Server/GameObjects/Components/WrenchableComponent.cs +++ b/Content.Server/GameObjects/Components/WrenchableComponent.cs @@ -1,10 +1,13 @@ using Content.Server.GameObjects.Components.Interactable.Tools; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Robust.Server.GameObjects; using Robust.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.Components { @@ -17,7 +20,7 @@ namespace Content.Server.GameObjects.Components public override void Initialize() { base.Initialize(); - _audioSystem = IoCManager.Resolve().GetEntitySystem(); + _audioSystem = EntitySystem.Get(); } public bool AttackBy(AttackByEventArgs eventArgs) diff --git a/Content.Server/GameObjects/EntitySystems/AiSystem.cs b/Content.Server/GameObjects/EntitySystems/AiSystem.cs index 61ad3d759f..2aadeb7e46 100644 --- a/Content.Server/GameObjects/EntitySystems/AiSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AiSystem.cs @@ -11,6 +11,7 @@ using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Reflection; using Robust.Shared.IoC; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.EntitySystems { @@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.EntitySystems var processorId = args[0]; var entId = new EntityUid(int.Parse(args[1])); var ent = IoCManager.Resolve().GetEntity(entId); - var aiSystem = IoCManager.Resolve().GetEntitySystem(); + var aiSystem = EntitySystem.Get(); if (!aiSystem.ProcessorTypeExists(processorId)) { diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index c5deb92514..f4530fbf1a 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -3,6 +3,7 @@ using System.Linq; using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Timing; using Content.Server.Interfaces.GameObjects; +using Content.Server.Utility; using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.Input; using Content.Shared.Physics; @@ -18,6 +19,7 @@ using Robust.Shared.Interfaces.GameObjects.Components; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Physics; using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -27,36 +29,53 @@ namespace Content.Server.GameObjects.EntitySystems { /// /// This interface gives components behavior when being clicked on or "attacked" by a user with an object in their hand + /// who is in range and has unobstructed reach of the target entity (allows inside blockers). /// public interface IAttackBy { /// - /// Called when using one object on another + /// Called when using one object on another when user is in range of the target entity. /// bool AttackBy(AttackByEventArgs eventArgs); } - public class AttackByEventArgs : EventArgs + public class AttackByEventArgs : EventArgs, ITargetedAttackEventArgs { public IEntity User { get; set; } public GridCoordinates ClickLocation { get; set; } public IEntity AttackWith { get; set; } + public IEntity Attacked { get; set; } + } + + public interface ITargetedAttackEventArgs + { + /// + /// Performer of the attack + /// + IEntity User { get; } + /// + /// Target of the attack + /// + IEntity Attacked { get; } + } /// /// This interface gives components behavior when being clicked on or "attacked" by a user with an empty hand + /// who is in range and has unobstructed reach of the target entity (allows inside blockers). /// public interface IAttackHand { /// - /// Called when a player directly interacts with an empty hand + /// Called when a player directly interacts with an empty hand when user is in range of the target entity. /// bool AttackHand(AttackHandEventArgs eventArgs); } - public class AttackHandEventArgs : EventArgs + public class AttackHandEventArgs : EventArgs, ITargetedAttackEventArgs { public IEntity User { get; set; } + public IEntity Attacked { get; set; } } /// @@ -80,8 +99,8 @@ namespace Content.Server.GameObjects.EntitySystems } /// - /// This interface gives components a behavior when clicking on another object and no interaction occurs - /// Doesn't pass what you clicked on as an argument, but if it becomes necessary we can add it later + /// This interface gives components a behavior when clicking on another object and no interaction occurs, + /// at any range. /// public interface IAfterAttack { @@ -116,19 +135,21 @@ namespace Content.Server.GameObjects.EntitySystems } /// - /// This interface gives components behavior when being activated in the world. + /// This interface gives components behavior when being activated in the world when the user + /// is in range and has unobstructed access to the target entity (allows inside blockers). /// public interface IActivate { /// - /// Called when this component is activated by another entity. + /// Called when this component is activated by another entity who is in range. /// void Activate(ActivateEventArgs eventArgs); } - public class ActivateEventArgs : EventArgs + public class ActivateEventArgs : EventArgs, ITargetedAttackEventArgs { public IEntity User { get; set; } + public IEntity Attacked { get; set; } } /// @@ -292,6 +313,7 @@ namespace Content.Server.GameObjects.EntitySystems #pragma warning disable 649 [Dependency] private readonly IMapManager _mapManager; [Dependency] private readonly IPhysicsManager _physicsManager; + [Dependency] private readonly ILocalizationManager _localizationManager; #pragma warning restore 649 public const float InteractionRange = 2; @@ -359,7 +381,12 @@ namespace Content.Server.GameObjects.EntitySystems return; } - activateComp.Activate(new ActivateEventArgs {User = user}); + // all activates should only fire when in range / unbostructed + var activateEventArgs = new ActivateEventArgs {User = user, Attacked = used}; + if (InteractionChecks.InRangeUnobstructed(activateEventArgs)) + { + activateComp.Activate(activateEventArgs); + } } private bool HandleWideAttack(ICommonSession session, GridCoordinates coords, EntityUid uid) @@ -556,15 +583,19 @@ namespace Content.Server.GameObjects.EntitySystems var attackBys = attacked.GetAllComponents().ToList(); var attackByEventArgs = new AttackByEventArgs { - User = user, ClickLocation = clickLocation, AttackWith = weapon + User = user, ClickLocation = clickLocation, AttackWith = weapon, Attacked = attacked }; - foreach (var attackBy in attackBys) + // all AttackBys should only happen when in range / unobstructed, so no range check is needed + if (InteractionChecks.InRangeUnobstructed(attackByEventArgs)) { - if (attackBy.AttackBy(attackByEventArgs)) + foreach (var attackBy in attackBys) { - // If an AttackBy returns a status completion we finish our attack - return; + if (attackBy.AttackBy(attackByEventArgs)) + { + // If an AttackBy returns a status completion we finish our attack + return; + } } } @@ -602,14 +633,18 @@ namespace Content.Server.GameObjects.EntitySystems } var attackHands = attacked.GetAllComponents().ToList(); - var attackHandEventArgs = new AttackHandEventArgs {User = user}; + var attackHandEventArgs = new AttackHandEventArgs {User = user, Attacked = attacked}; - foreach (var attackHand in attackHands) + // all attackHands should only fire when in range / unbostructed + if (InteractionChecks.InRangeUnobstructed(attackHandEventArgs)) { - if (attackHand.AttackHand(attackHandEventArgs)) + foreach (var attackHand in attackHands) { - // If an AttackHand returns a status completion we finish our attack - return; + if (attackHand.AttackHand(attackHandEventArgs)) + { + // If an AttackHand returns a status completion we finish our attack + return; + } } } diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index 855084abba..79b6c9a757 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -30,6 +30,7 @@ using Robust.Shared.Map; using Robust.Shared.Maths; using Robust.Shared.Physics; using Robust.Shared.Players; +using Robust.Shared.Utility; namespace Content.Server.GameObjects.EntitySystems { @@ -105,7 +106,7 @@ namespace Content.Server.GameObjects.EntitySystems if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp)) return; - var interactionSystem = IoCManager.Resolve().GetEntitySystem(); + var interactionSystem = EntitySystem.Get(); var oldItem = handsComp.GetActiveHand; @@ -133,9 +134,8 @@ namespace Content.Server.GameObjects.EntitySystems if (handsComp.GetActiveHand == null) return false; - var interactionSystem = _entitySystemManager.GetEntitySystem(); - if(interactionSystem.InRangeUnobstructed(coords.ToMap(_mapManager), ent.Transform.WorldPosition, ignoredEnt: ent)) + if(EntitySystem.Get().InRangeUnobstructed(coords.ToMap(_mapManager), ent.Transform.WorldPosition, ignoredEnt: ent)) if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange)) { handsComp.Drop(handsComp.ActiveIndex, coords); diff --git a/Content.Server/Health/BodySystem/BodyScanner/BodyScannerComponent.cs b/Content.Server/Health/BodySystem/BodyScanner/BodyScannerComponent.cs index bcd47e7afa..f28f683e9b 100644 --- a/Content.Server/Health/BodySystem/BodyScanner/BodyScannerComponent.cs +++ b/Content.Server/Health/BodySystem/BodyScanner/BodyScannerComponent.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Content.Server.Utility; using Content.Shared.BodySystem; @@ -41,6 +42,7 @@ namespace Content.Server.BodySystem { return; } + if (actor.playerSession.AttachedEntity.TryGetComponent(out BodyManagerComponent attempt)) { _userInterface.SetState(PrepareBodyScannerInterfaceState(attempt.Template, attempt.PartDictionary)); diff --git a/Content.Server/Health/BodySystem/Surgery/ServerSurgeryToolComponent.cs b/Content.Server/Health/BodySystem/Surgery/ServerSurgeryToolComponent.cs index 07bca79b8c..7f8c5d7274 100644 --- a/Content.Server/Health/BodySystem/Surgery/ServerSurgeryToolComponent.cs +++ b/Content.Server/Health/BodySystem/Surgery/ServerSurgeryToolComponent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Server.BodySystem; using Content.Server.GameObjects.EntitySystems; +using Content.Server.Utility; using Content.Shared.BodySystem; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Items; @@ -42,6 +43,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee void IAfterAttack.AfterAttack(AfterAttackEventArgs eventArgs) { + if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return; + if (eventArgs.Attacked == null) return; if (eventArgs.Attacked.TryGetComponent(out BodySystem.BodyManagerComponent bodyManager)) diff --git a/Content.Server/Utility/InteractionChecks.cs b/Content.Server/Utility/InteractionChecks.cs new file mode 100644 index 0000000000..f78824f0f6 --- /dev/null +++ b/Content.Server/Utility/InteractionChecks.cs @@ -0,0 +1,100 @@ +using System; +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.Interfaces; +using Content.Shared.Physics; +using Robust.Shared.GameObjects.Systems; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.Interfaces.Map; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Map; +using Robust.Shared.Maths; + +namespace Content.Server.Utility +{ + /// + /// Convenient methods for checking for various conditions commonly needed + /// for interactions. + /// + public static class InteractionChecks + { + + /// + /// Default interaction check for targeted attack interaction types. + /// Same as , but defaults to allow inside blockers. + /// Validates that attacker is in range of the attacked entity. Additionally shows a popup if + /// validation fails. + /// + public static bool InRangeUnobstructed(ITargetedAttackEventArgs eventArgs, bool insideBlockerValid = true) + { + if (!EntitySystem.Get().InRangeUnobstructed(eventArgs.User.Transform.MapPosition, + eventArgs.Attacked.Transform.WorldPosition, ignoredEnt: eventArgs.Attacked, insideBlockerValid: insideBlockerValid)) + { + var localizationManager = IoCManager.Resolve(); + eventArgs.Attacked.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!")); + return false; + } + + return true; + } + + /// + /// Default interaction check for after attack interaction types. + /// Same as , but defaults to allow inside blockers. + /// Validates that attacker is in range of the attacked entity, if there is such an entity. + /// If there is no attacked entity, validates that they are in range of the clicked position. + /// Additionally shows a popup if validation fails. + /// + public static bool InRangeUnobstructed(AfterAttackEventArgs eventArgs, bool insideBlockerValid = true) + { + if (eventArgs.Attacked != null) + { + if (!EntitySystem.Get().InRangeUnobstructed(eventArgs.User.Transform.MapPosition, + eventArgs.Attacked.Transform.WorldPosition, ignoredEnt: eventArgs.Attacked, insideBlockerValid: insideBlockerValid)) + { + var localizationManager = IoCManager.Resolve(); + eventArgs.Attacked.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!")); + return false; + } + } + else + { + var mapManager = IoCManager.Resolve(); + if (!EntitySystem.Get().InRangeUnobstructed(eventArgs.User.Transform.MapPosition, + eventArgs.ClickLocation.ToMapPos(mapManager), ignoredEnt: eventArgs.User, insideBlockerValid: insideBlockerValid)) + { + var localizationManager = IoCManager.Resolve(); + eventArgs.User.PopupMessage(eventArgs.User, localizationManager.GetString("You can't reach there!")); + return false; + } + } + + + return true; + } + + /// + /// Convenient static alternative to , which also + /// shows a popup message if not in range. + /// + public static bool InRangeUnobstructed(IEntity user, Vector2 targetWorldCoords, + float range = SharedInteractionSystem.InteractionRange, + int collisionMask = (int) CollisionGroup.Impassable, IEntity ignoredEnt = null, + bool insideBlockerValid = false) + { + var interactionSystem = EntitySystem.Get(); + if (!interactionSystem.InRangeUnobstructed(user.Transform.MapPosition, targetWorldCoords, range, collisionMask, + ignoredEnt, insideBlockerValid)) + { + var localizationManager = IoCManager.Resolve(); + user.PopupMessage(user, localizationManager.GetString("You can't reach there!")); + return false; + } + + return true; + } + + + + } +} diff --git a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs index 756968907d..f75efd385b 100644 --- a/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs +++ b/Content.Shared/GameObjects/EntitySystems/ExamineSystemShared.cs @@ -3,7 +3,7 @@ using Content.Shared.GameObjects.Components.Mobs; using JetBrains.Annotations; using Robust.Shared.GameObjects.Systems; using Robust.Shared.Interfaces.GameObjects; -using Robust.Shared.IoC; +using Robust.Shared.Utility; namespace Content.Shared.GameObjects.EntitySystems { @@ -30,8 +30,7 @@ namespace Content.Shared.GameObjects.EntitySystems return false; } - return IoCManager.Resolve() - .GetEntitySystem() + return EntitySystem.Get() .InRangeUnobstructed(examiner.Transform.MapPosition, examined.Transform.MapPosition.Position, ExamineRange, predicate: entity => entity == examiner || entity == examined, insideBlockerValid:true); } diff --git a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs index 47a613a91c..77bc6965c4 100644 --- a/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs +++ b/Content.Shared/GameObjects/EntitySystems/SharedInteractionSystem.cs @@ -37,7 +37,6 @@ namespace Content.Server.GameObjects.EntitySystems /// maximum distance between the two sets of coordinates. /// the mask to check for collisions /// . - /// Map manager containing the two GridIds. /// if coordinates inside obstructions count as obstructed or not /// True if the two points are within a given range without being obstructed. public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange, @@ -78,7 +77,6 @@ namespace Content.Server.GameObjects.EntitySystems /// maximum distance between the two sets of coordinates. /// the mask to check for collisions /// the entity to be ignored when checking for collisions. - /// Map manager containing the two GridIds. /// if coordinates inside obstructions count as obstructed or not /// True if the two points are within a given range without being obstructed. public bool InRangeUnobstructed(MapCoordinates coords, Vector2 otherCoords, float range = InteractionRange,