From 50e6b26514cf061e887c7d5e1496123147fe22f3 Mon Sep 17 00:00:00 2001 From: Aviu00 <93730715+Aviu00@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:48:39 +0900 Subject: [PATCH] - fix: Shooting now uses grid velocity. (#8) --- Content.Server/Magic/MagicSystem.cs | 13 +++++++++++-- Content.Server/Weapons/Ranged/Systems/GunSystem.cs | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Content.Server/Magic/MagicSystem.cs b/Content.Server/Magic/MagicSystem.cs index d8febe0d1f..bb11c1f014 100644 --- a/Content.Server/Magic/MagicSystem.cs +++ b/Content.Server/Magic/MagicSystem.cs @@ -21,6 +21,7 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Map; +using Robust.Shared.Physics.Components; using Robust.Shared.Random; using Robust.Shared.Serialization.Manager; using Robust.Shared.Spawners; @@ -164,16 +165,24 @@ public sealed class MagicSystem : EntitySystem Speak(ev); var xform = Transform(ev.Performer); - var userVelocity = _physics.GetMapLinearVelocity(ev.Performer); + + // var userVelocity = _physics.GetMapLinearVelocity(ev.Performer); WD EDIT foreach (var pos in GetSpawnPositions(xform, ev.Pos)) { // If applicable, this ensures the projectile is parented to grid on spawn, instead of the map. var mapPos = pos.ToMap(EntityManager); - var spawnCoords = _mapManager.TryFindGridAt(mapPos, out var gridUid, out _) + var spawnCoords = _mapManager.TryFindGridAt(mapPos, out var gridUid, out var grid) // WD EDIT ? pos.WithEntityId(gridUid, EntityManager) : new(_mapManager.GetMapEntityId(mapPos.MapId), mapPos.Position); + // WD EDIT + var userVelocity = Vector2.Zero; + + if (grid != null && TryComp(gridUid, out PhysicsComponent? physics)) + userVelocity = physics.LinearVelocity; + // WD EDIT + var ent = Spawn(ev.Prototype, spawnCoords); var direction = ev.Target.ToMapPos(EntityManager, _transformSystem) - spawnCoords.ToMapPos(EntityManager, _transformSystem); diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 810f5d0990..91eb717fb5 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -115,7 +115,14 @@ public sealed partial class GunSystem : SharedGunSystem // Update shot based on the recoil toMap = fromMap.Position + angle.ToVec() * mapDirection.Length(); mapDirection = toMap - fromMap.Position; - var gunVelocity = Physics.GetMapLinearVelocity(gunUid); + + // WD EDIT START + // var gunVelocity = Physics.GetMapLinearVelocity(gunUid); + var gunVelocity = Vector2.Zero; + + if (grid != null && TryComp(gridUid, out PhysicsComponent? physics)) + gunVelocity = physics.LinearVelocity; + // WD EDIT END // I must be high because this was getting tripped even when true. // DebugTools.Assert(direction != Vector2.Zero);