From 0f513f64fb94f42fe758b941e1694fd0e5699ee2 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 25 Oct 2021 15:22:57 +1100 Subject: [PATCH] Rotate DefaultGrid on round start (#4957) * Rotate DefaultGrid on round start Not ideal long-term but good for bugspotting short-term. * Fix buckle test Because gridtraversal was being triggered the pos was being fucked when moving back * Fix buckle * Buckle offset --- .../Tests/Buckle/BuckleTest.cs | 6 +++--- .../Buckle/Components/BuckleComponent.cs | 18 +++--------------- Content.Server/GameTicking/GameTicker.CVars.cs | 4 ++++ .../GameTicking/GameTicker.RoundFlow.cs | 10 +++++++++- Content.Shared/CCVar/CCVars.cs | 6 ++++++ 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs index 8f1fde6b2f..4dba1073d7 100644 --- a/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs +++ b/Content.IntegrationTests/Tests/Buckle/BuckleTest.cs @@ -103,7 +103,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.False(actionBlocker.CanMove(human)); Assert.False(actionBlocker.CanChangeDirection(human)); Assert.False(EffectBlockerSystem.CanFall(human)); - Assert.That(human.Transform.WorldPosition, Is.EqualTo(chair.Transform.WorldPosition)); + Assert.That((human.Transform.WorldPosition - chair.Transform.WorldPosition).Length, Is.LessThanOrEqualTo(buckle.BuckleOffset.Length)); // Side effects of buckling for the strap Assert.That(strap.BuckledEntities, Does.Contain(human)); @@ -333,7 +333,7 @@ namespace Content.IntegrationTests.Tests.Buckle Assert.True(buckle.Buckled); // Move the buckled entity away - human.Transform.LocalPosition += (100, 0); + human.Transform.WorldPosition += (100, 0); }); await WaitUntil(server, () => !buckle.Buckled, 10); @@ -343,7 +343,7 @@ namespace Content.IntegrationTests.Tests.Buckle await server.WaitAssertion(() => { // Move the now unbuckled entity back onto the chair - human.Transform.LocalPosition -= (100, 0); + human.Transform.WorldPosition -= (100, 0); // Buckle Assert.True(buckle.TryBuckle(human, chair)); diff --git a/Content.Server/Buckle/Components/BuckleComponent.cs b/Content.Server/Buckle/Components/BuckleComponent.cs index 9f941cedc5..b181d6b685 100644 --- a/Content.Server/Buckle/Components/BuckleComponent.cs +++ b/Content.Server/Buckle/Components/BuckleComponent.cs @@ -122,33 +122,21 @@ namespace Content.Server.Buckle.Components var strapTransform = strap.Owner.Transform; ownTransform.AttachParent(strapTransform); + ownTransform.LocalRotation = Angle.Zero; switch (strap.Position) { case StrapPosition.None: - ownTransform.WorldRotation = strapTransform.WorldRotation; break; case StrapPosition.Stand: EntitySystem.Get().Stand(Owner.Uid); - ownTransform.WorldRotation = strapTransform.WorldRotation; break; case StrapPosition.Down: EntitySystem.Get().Down(Owner.Uid, false, false); - ownTransform.LocalRotation = Angle.Zero; break; } - // Assign BuckleOffset first, before causing a MoveEvent to fire - if (strapTransform.WorldRotation.GetCardinalDir() == Direction.North) - { - BuckleOffset = (0, 0.15f); - ownTransform.WorldPosition = strapTransform.WorldPosition + BuckleOffset; - } - else - { - BuckleOffset = Vector2.Zero; - ownTransform.WorldPosition = strapTransform.WorldPosition; - } + ownTransform.LocalPosition = Vector2.Zero + BuckleOffset; } public bool CanBuckle(IEntity? user, IEntity to, [NotNullWhen(true)] out StrapComponent? strap) @@ -403,7 +391,7 @@ namespace Content.Server.Buckle.Components int? drawDepth = null; if (BuckledTo != null && - Owner.Transform.WorldRotation.GetCardinalDir() == Direction.North && + BuckledTo.Owner.Transform.LocalRotation.GetCardinalDir() == Direction.North && BuckledTo.SpriteComponent != null) { drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; diff --git a/Content.Server/GameTicking/GameTicker.CVars.cs b/Content.Server/GameTicking/GameTicker.CVars.cs index a00299df4b..58cdc6d9cc 100644 --- a/Content.Server/GameTicking/GameTicker.CVars.cs +++ b/Content.Server/GameTicking/GameTicker.CVars.cs @@ -24,6 +24,9 @@ namespace Content.Server.GameTicking [ViewVariables] public bool StationOffset { get; private set; } = false; + [ViewVariables] + public bool StationRotation { get; private set; } = false; + [ViewVariables] public float MaxStationOffset { get; private set; } = 0f; @@ -36,6 +39,7 @@ namespace Content.Server.GameTicking _configurationManager.OnValueChanged(CCVars.GameDisallowLateJoins, value => { DisallowLateJoin = value; UpdateLateJoinStatus(); UpdateJobsAvailable(); }, true); _configurationManager.OnValueChanged(CCVars.StationOffset, value => StationOffset = value, true); + _configurationManager.OnValueChanged(CCVars.StationRotation, value => StationRotation = value, true); _configurationManager.OnValueChanged(CCVars.MaxStationOffset, value => MaxStationOffset = value, true); } } diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index e8e33bcb73..f9bcbcdf81 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -8,6 +8,7 @@ using Content.Shared.GameTicking; using Content.Shared.Preferences; using Prometheus; using Robust.Server.Player; +using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; @@ -63,12 +64,19 @@ namespace Content.Server.GameTicking throw new InvalidOperationException($"No grid found for map {map}"); } + var stationXform = EntityManager.GetComponent(grid.GridEntityId); + if (StationOffset) { // Apply a random offset to the station grid entity. var x = _robustRandom.NextFloat() * MaxStationOffset * 2 - MaxStationOffset; var y = _robustRandom.NextFloat() * MaxStationOffset * 2 - MaxStationOffset; - EntityManager.GetEntity(grid.GridEntityId).Transform.LocalPosition = new Vector2(x, y); + stationXform.LocalPosition = new Vector2(x, y); + } + + if (StationRotation) + { + stationXform.LocalRotation = _robustRandom.NextFloat(MathF.Tau); } DefaultGridId = grid.Index; diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index a844896c50..309761dfde 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -90,6 +90,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef MaxStationOffset = CVarDef.Create("game.maxstationoffset", 1000.0f); + /// + /// Whether a random rotation will be applied to the station on roundstart. + /// + public static readonly CVarDef StationRotation = + CVarDef.Create("game.station_rotation", true); + /// /// When enabled, guests will be assigned permanent UIDs and will have their preferences stored. ///