From 212b7074a87c79d7d8063302cf7f2a44dab51121 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 3 Apr 2019 16:22:54 +0300 Subject: [PATCH] (8bcb4dfd5) Refined cable holders, added variants for 1-3 cables (background still missing) --- .../Source/Items/Components/Door.cs | 100 +++++++++--------- .../Items/Components/Signal/LightComponent.cs | 4 + 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs index 73826cd2c..c6ca050f5 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs @@ -396,25 +396,70 @@ namespace Barotrauma.Items.Components } int dir = IsHorizontal ? Math.Sign(c.SimPosition.Y - item.SimPosition.Y) : Math.Sign(c.SimPosition.X - item.SimPosition.X); + List bodies = c.AnimController.Limbs.Select(l => l.body).ToList(); + bodies.Add(c.AnimController.Collider); + bool soundPlayed = false; foreach (Limb limb in c.AnimController.Limbs) { - if (PushBodyOutOfDoorway(c, limb.body, dir, simPos, simSize) && !soundPlayed) + float diff = 0.0f; + if (!MathUtils.IsValid(body.SimPosition)) + { + DebugConsole.ThrowError("Failed to push a limb out of a doorway - position of the body (character \"" + c.Name + "\") is not valid (" + body.SimPosition + ")"); + GameAnalyticsManager.AddErrorEventOnce("PushCharactersAway:LimbPosInvalid", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Failed to push a character out of a doorway - position of the character \"" + c.Name + "\" is not valid (" + body.SimPosition + ")." + + " Removed: " + c.Removed + + " Remoteplayer: " + c.IsRemotePlayer); + continue; + } + + if (IsHorizontal) + { + if (body.SimPosition.X < simPos.X || body.SimPosition.X > simPos.X + simSize.X) continue; + diff = body.SimPosition.Y - item.SimPosition.Y; + } + else + { + if (body.SimPosition.Y > simPos.Y || body.SimPosition.Y < simPos.Y - simSize.Y) continue; + diff = body.SimPosition.X - item.SimPosition.X; + } + + if (Math.Sign(diff) != dir) { #if CLIENT SoundPlayer.PlayDamageSound("LimbBlunt", 1.0f, limb.body); #endif - soundPlayed = true; + + if (IsHorizontal) + { + body.SetTransform(new Vector2(body.SimPosition.X, item.SimPosition.Y + dir * simSize.Y * 2.0f), body.Rotation); + body.ApplyLinearImpulse(new Vector2(isOpen ? 0.0f : 1.0f, dir * 2.0f)); + } + else + { + body.SetTransform(new Vector2(item.SimPosition.X + dir * simSize.X * 1.2f, body.SimPosition.Y), body.Rotation); + body.ApplyLinearImpulse(new Vector2(dir * 0.5f, isOpen ? 0.0f : -1.0f)); + } + } + + if (IsHorizontal) + { + if (Math.Abs(body.SimPosition.Y - item.SimPosition.Y) > simSize.Y * 0.5f) continue; + + body.ApplyLinearImpulse(new Vector2(isOpen ? 0.0f : 1.0f, dir * 0.5f)); } } PushBodyOutOfDoorway(c, c.AnimController.Collider, dir, simPos, simSize); } } - private bool PushBodyOutOfDoorway(Character c, PhysicsBody body, int dir, Vector2 doorRectSimPos, Vector2 doorRectSimSize) + public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f) { - float diff = 0.0f; - if (!MathUtils.IsValid(body.SimPosition)) + if (isStuck) return; + + bool wasOpen = PredictedState == null ? isOpen : PredictedState.Value; + + if (connection.Name == "toggle") { DebugConsole.ThrowError("Failed to push a limb out of a doorway - position of the body (character \"" + c.Name + "\") is not valid (" + body.SimPosition + ")"); GameAnalyticsManager.AddErrorEventOnce("PushCharactersAway:LimbPosInvalid", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, @@ -435,51 +480,6 @@ namespace Barotrauma.Items.Components diff = body.SimPosition.X - item.SimPosition.X; } - //if the limb is at a different side of the door than the character (collider), - //immediately teleport it to the correct side - if (Math.Sign(diff) != dir) - { - if (IsHorizontal) - { - body.SetTransform(new Vector2(body.SimPosition.X, item.SimPosition.Y + dir * doorRectSimSize.Y * 2.0f), body.Rotation); - } - else - { - body.SetTransform(new Vector2(item.SimPosition.X + dir * doorRectSimSize.X * 1.2f, body.SimPosition.Y), body.Rotation); - } - } - - //apply an impulse to push the limb further from the door - if (IsHorizontal) - { - if (Math.Abs(body.SimPosition.Y - item.SimPosition.Y) > doorRectSimSize.Y * 0.5f) { return false; } - body.ApplyLinearImpulse(new Vector2(isOpen ? 0.0f : 1.0f, dir * 2.0f), maxVelocity: NetConfig.MaxPhysicsBodyVelocity); - } - else - { - if (Math.Abs(body.SimPosition.X - item.SimPosition.X) > doorRectSimSize.X * 0.5f) { return false; } - body.ApplyLinearImpulse(new Vector2(dir * 2.0f, isOpen ? 0.0f : -1.0f), maxVelocity: NetConfig.MaxPhysicsBodyVelocity); - } - - c.SetStun(0.2f); - return true; - } - - public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f) - { - if (isStuck) return; - - bool wasOpen = PredictedState == null ? isOpen : PredictedState.Value; - - if (connection.Name == "toggle") - { - SetState(!wasOpen, false, true); - } - else if (connection.Name == "set_state") - { - SetState(signal != "0", false, true); - } - #if SERVER if (sender != null && wasOpen != isOpen) { diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs index 7845f609c..eebf1146a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/LightComponent.cs @@ -26,6 +26,10 @@ namespace Barotrauma.Items.Components private float blinkTimer; + private bool itemLoaded; + + private float blinkTimer; + public PhysicsBody ParentBody; [Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f), Serialize(100.0f, true)]