From a692899f5b989f304d3a08ab9b75e6357ef40523 Mon Sep 17 00:00:00 2001 From: Acruid Date: Sat, 25 Jan 2020 01:39:14 -0800 Subject: [PATCH] GridCoordinates API changes. --- Content.Client/State/GameScreen.cs | 5 ++--- Content.Server/Explosions/ExplosionHelper.cs | 4 +--- .../Components/Movement/ServerTeleporterComponent.cs | 11 +++++------ .../Components/Power/WirePlacerComponent.cs | 2 +- .../Components/Weapon/Melee/MeleeWeaponComponent.cs | 3 +-- .../EntitySystems/Click/InteractionSystem.cs | 4 ++-- .../GameObjects/EntitySystems/HandsSystem.cs | 2 +- RobustToolbox | 2 +- 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Content.Client/State/GameScreen.cs b/Content.Client/State/GameScreen.cs index 2ddd2a670c..d7e7af0583 100644 --- a/Content.Client/State/GameScreen.cs +++ b/Content.Client/State/GameScreen.cs @@ -109,9 +109,8 @@ namespace Content.Client.State public IList GetEntitiesUnderPosition(GridCoordinates coordinates) { // Find all the entities intersecting our click - var worldCoords = coordinates.ToWorld(_mapManager); - var entities = _entityManager.GetEntitiesIntersecting(_mapManager.GetGrid(coordinates.GridID).ParentMapId, - worldCoords.Position); + var mapCoords = coordinates.ToMap(_mapManager); + var entities = _entityManager.GetEntitiesIntersecting(mapCoords.MapId, mapCoords.Position); // Check the entities against whether or not we can click them var foundEntities = new List<(IEntity clicked, int drawDepth)>(); diff --git a/Content.Server/Explosions/ExplosionHelper.cs b/Content.Server/Explosions/ExplosionHelper.cs index 7ca0b329d2..89213971ee 100644 --- a/Content.Server/Explosions/ExplosionHelper.cs +++ b/Content.Server/Explosions/ExplosionHelper.cs @@ -119,8 +119,6 @@ namespace Content.Server.Explosions // Knock back cameras of all players in the area. var playerManager = IoCManager.Resolve(); - //var selfPos = Owner.Transform.WorldPosition; //vec2 - var selfPos = coords.ToWorld(mapManager).Position; foreach (var player in playerManager.GetAllPlayers()) { if (player.AttachedEntity == null @@ -131,7 +129,7 @@ namespace Content.Server.Explosions } var playerPos = player.AttachedEntity.Transform.WorldPosition; - var delta = selfPos - playerPos; + var delta = coords.ToMapPos(mapManager) - playerPos; var distance = delta.LengthSquared; var effect = 1 / (1 + 0.2f * distance); diff --git a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs index 94fa985dcb..3b7d126f82 100644 --- a/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs +++ b/Content.Server/GameObjects/Components/Movement/ServerTeleporterComponent.cs @@ -86,8 +86,7 @@ namespace Content.Server.GameObjects.Components.Movement { if (_teleporterType == TeleporterType.Directed) { - var userTarget = eventArgs.ClickLocation.ToWorld(_mapManager); - TryDirectedTeleport(eventArgs.User, userTarget); + TryDirectedTeleport(eventArgs.User, eventArgs.ClickLocation.ToMap(_mapManager)); } if (_teleporterType == TeleporterType.Random) @@ -96,10 +95,10 @@ namespace Content.Server.GameObjects.Components.Movement } } - public void TryDirectedTeleport(IEntity user, GridCoordinates grid) + public void TryDirectedTeleport(IEntity user, MapCoordinates mapCoords) { // Checks - if (user.Transform.GridPosition.Distance(_mapManager, grid) > _range) + if ((user.Transform.WorldPosition - mapCoords.Position).LengthSquared > (_range * _range)) { return; } @@ -110,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Movement } if (_avoidCollidable) { - foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(grid)) + foreach (var entity in _serverEntityManager.GetEntitiesIntersecting(mapCoords)) { // Added this component to avoid stacking portals and causing shenanigans // TODO: Doesn't do a great job of stopping stacking portals for directed @@ -132,7 +131,7 @@ namespace Content.Server.GameObjects.Components.Movement return; } - Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, new Vector2(grid.X, grid.Y))); + Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, mapCoords.Position)); StartCooldown(); } diff --git a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs index c6d77d42a8..9f313ae983 100644 --- a/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs +++ b/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs @@ -28,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Power if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GridID, out var grid)) return; - var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation.ToWorld(_mapManager), SnapGridOffset.Center); + var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center); var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center); if(grid.GetTileRef(snapPos).Tile.IsEmpty) diff --git a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs index 991aa578a0..2d2aa67edc 100644 --- a/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Melee/MeleeWeaponComponent.cs @@ -83,8 +83,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee return; } var location = eventArgs.User.Transform.GridPosition; - var angle = new Angle(eventArgs.ClickLocation.ToWorld(_mapManager).Position - - location.ToWorld(_mapManager).Position); + var angle = new Angle(eventArgs.ClickLocation.ToMapPos(_mapManager) - location.ToMapPos(_mapManager)); // This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes. var entities = ArcRayCast(eventArgs.User.Transform.WorldPosition, angle, eventArgs.User); diff --git a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs index 4fc865182a..6ec19ed9b3 100644 --- a/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/Click/InteractionSystem.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Timing; @@ -408,7 +408,7 @@ namespace Content.Server.GameObjects.EntitySystems // Check if ClickLocation is in object bounds here, if not lets log as warning and see why if (attacked.TryGetComponent(out ICollidableComponent collideComp)) { - if (!collideComp.WorldAABB.Contains(coordinates.ToWorld(_mapManager).Position)) + if (!collideComp.WorldAABB.Contains(coordinates.ToMapPos(_mapManager))) { Logger.WarningS("system.interaction", $"Player {player.Name} clicked {attacked.Name} outside of its bounding box component somehow"); diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs index 5042016753..1612977b76 100644 --- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs @@ -198,7 +198,7 @@ namespace Content.Server.GameObjects.EntitySystems projComp.IgnoreEntity(plyEnt); var transform = plyEnt.Transform; - var dirVec = (coords.ToWorld(_mapManager).Position - transform.WorldPosition).Normalized; + var dirVec = (coords.ToMapPos(_mapManager) - transform.WorldPosition).Normalized; if (!throwEnt.TryGetComponent(out PhysicsComponent physComp)) physComp = throwEnt.AddComponent(); diff --git a/RobustToolbox b/RobustToolbox index 9f956cef95..4eb29a9e80 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 9f956cef958c5c9d38de3f5b57af016d3e174f14 +Subproject commit 4eb29a9e801c53f86c27231cd262f4dcd0e824bd