From ea6824a60d0c4a4289af0ee7114b71ed68c0ac35 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sat, 13 Feb 2016 23:26:50 +0200 Subject: [PATCH] Disable aiming with holdable items when using a (railgun) controller, syncing ViewTargetID properly between clients, dropping connected wires when a button is picked up, placing large InterestingPositions on the main path through the level --- .../Source/Characters/Animation/Ragdoll.cs | 2 +- Subsurface/Source/Characters/Character.cs | 19 +++++-- .../Items/Components/Holdable/Holdable.cs | 3 + .../Items/Components/Holdable/Pickable.cs | 44 +++++++++------ .../Items/Components/Machines/Controller.cs | 53 +++++++++++++----- Subsurface/Source/Map/Levels/Level.cs | 10 ++-- Subsurface_Solution.v12.suo | Bin 828928 -> 828928 bytes 7 files changed, 88 insertions(+), 43 deletions(-) diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index f43ac934f..06efb4e9d 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -301,7 +301,7 @@ namespace Barotrauma { Structure structure = f2.Body.UserData as Structure; - if (f2.Body.UserData as SubmarineBody != null) return true; + if (f2.Body.UserData as Submarine != null && character.Submarine == f2.Body.UserData as Submarine) return false; //always collides with bodies other than structures if (structure == null) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index bdbf8fc3c..df18d9434 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -106,6 +106,8 @@ namespace Barotrauma private float[] soundRange; //which AIstate each sound is for private AIController.AiState[] soundStates; + + private Entity viewTarget; private CharacterInfo info; @@ -1380,15 +1382,21 @@ namespace Barotrauma if (secondaryHeld) { + if (Character.controlled==this) + { + viewTarget = Lights.LightManager.ViewTarget == null ? this : Lights.LightManager.ViewTarget; + } + if (viewTarget == null) viewTarget = this; + Vector2 relativeCursorPosition = cursorPosition; - relativeCursorPosition -= Lights.LightManager.ViewTarget == null ? Position : Lights.LightManager.ViewTarget.Position; + relativeCursorPosition -= viewTarget.Position; if (relativeCursorPosition.Length()>500.0f) { relativeCursorPosition = Vector2.Normalize(relativeCursorPosition) * 495.0f; } - message.Write(Lights.LightManager.ViewTarget == null ? (ushort)0 : Lights.LightManager.ViewTarget.ID); + message.Write(viewTarget.ID); message.WriteRangedSingle(relativeCursorPosition.X, -500.0f, 500.0f, 8); message.WriteRangedSingle(relativeCursorPosition.Y, -500.0f, 500.0f, 8); @@ -1556,13 +1564,14 @@ namespace Barotrauma float dir = 1.0f; Vector2 pos = Vector2.Zero; - ushort viewTargetId = 0; + ushort viewTargetID = 0; + viewTarget = null; try { if (secondaryKeyState) { - viewTargetId = message.ReadUInt16(); + viewTargetID = message.ReadUInt16(); relativeCursorPos = new Vector2( message.ReadRangedSingle(-500.0f, 500.0f, 8), @@ -1600,7 +1609,7 @@ namespace Barotrauma { cursorPosition = MathUtils.IsValid(relativeCursorPos) ? relativeCursorPos : Vector2.Zero; - Entity viewTarget = viewTargetId == 0 ? this : Entity.FindEntityByID(viewTargetId); + viewTarget = viewTargetID == 0 ? this : Entity.FindEntityByID(viewTargetID); if (viewTarget == null) viewTarget = this; cursorPosition += viewTarget.Position; diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index 668ce26f1..5831f5eda 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -110,6 +110,7 @@ namespace Barotrauma.Items.Components public override void Drop(Character dropper) { + DropConnectedWires(dropper); if (body != null) item.body = body; @@ -246,6 +247,8 @@ namespace Barotrauma.Items.Components item.Submarine = picker.Submarine; + if (picker.SelectedConstruction != null && picker.SelectedConstruction.GetComponent() != null) return; + //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); diff --git a/Subsurface/Source/Items/Components/Holdable/Pickable.cs b/Subsurface/Source/Items/Components/Holdable/Pickable.cs index 3589ba016..3dcca4999 100644 --- a/Subsurface/Source/Items/Components/Holdable/Pickable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Pickable.cs @@ -97,20 +97,7 @@ namespace Barotrauma.Items.Components } item.linkedTo.Clear(); - var connectionPanel = item.GetComponent(); - if (connectionPanel != null) - { - foreach (Connection c in connectionPanel.Connections) - { - foreach (Wire w in c.Wires) - { - if (w == null) continue; - - w.Item.Drop(picker); - w.Item.SetTransform(picker.SimPosition, 0.0f); - } - } - } + DropConnectedWires(picker); ApplyStatusEffects(ActionType.OnPicked, 1.0f, picker); @@ -134,7 +121,9 @@ namespace Barotrauma.Items.Components pickTimer = 0.0f; while (pickTimer < requiredTime) { - if (picker.IsKeyHit(InputType.Aim) || !item.IsInPickRange(picker.WorldPosition)) + if (picker.IsKeyDown(InputType.Aim) || + !item.IsInPickRange(picker.WorldPosition) || + picker.Stun > 0.0f || picker.IsDead) { StopPicking(picker); yield return CoroutineStatus.Success; @@ -159,7 +148,7 @@ namespace Barotrauma.Items.Components StopPicking(picker); - OnPicked(picker); + if (!picker.IsNetworkPlayer) OnPicked(picker); yield return CoroutineStatus.Success; } @@ -170,6 +159,25 @@ namespace Barotrauma.Items.Components pickTimer = 0.0f; } + protected void DropConnectedWires(Character character) + { + if (character == null) return; + + var connectionPanel = item.GetComponent(); + if (connectionPanel == null) return; + + foreach (Connection c in connectionPanel.Connections) + { + foreach (Wire w in c.Wires) + { + if (w == null) continue; + + w.Item.Drop(character); + w.Item.SetTransform(character.SimPosition, 0.0f); + } + } + } + public override void Draw(SpriteBatch spriteBatch, bool editing = false) { @@ -198,7 +206,9 @@ namespace Barotrauma.Items.Components //} } - if (picker==null || picker.Inventory == null) return; + if (picker == null || picker.Inventory == null) return; + + DropConnectedWires(picker); item.Submarine = picker.Submarine; diff --git a/Subsurface/Source/Items/Components/Machines/Controller.cs b/Subsurface/Source/Items/Components/Machines/Controller.cs index 6f6fbe473..646a15cbf 100644 --- a/Subsurface/Source/Items/Components/Machines/Controller.cs +++ b/Subsurface/Source/Items/Components/Machines/Controller.cs @@ -68,13 +68,14 @@ namespace Barotrauma.Items.Components this.cam = cam; if (character == null + || character.IsDead + || character.Stun > 0.0f || character.SelectedConstruction != item - || Vector2.Distance(character.Position, item.Position) > item.PickDistance * 1.5f) + || Vector2.Distance(character.Position, item.Position) > item.PickDistance * 2.0f) { if (character != null) { - character.SelectedConstruction = null; - character.AnimController.Anim = AnimController.Animation.None; + CancelUsing(character); character = null; } IsActive = false; @@ -119,15 +120,13 @@ namespace Barotrauma.Items.Components limb.Disabled = true; - FixedMouseJoint fmj = limb.pullJoint; - if (fmj == null) continue; + if (limb.pullJoint == null) continue; Vector2 position = ConvertUnits.ToSimUnits(lb.position + new Vector2(item.Rect.X, item.Rect.Y)); - fmj.Enabled = true; - fmj.WorldAnchorB = position; + limb.pullJoint.Enabled = true; + limb.pullJoint.WorldAnchorB = position; } - item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out"); } public override bool Use(float deltaTime, Character activator = null) @@ -153,6 +152,8 @@ namespace Barotrauma.Items.Components return; } + if (character!=null) item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out"); + foreach (Connection c in item.Connections) { if (c.Name != "position_out") continue; @@ -183,20 +184,42 @@ namespace Barotrauma.Items.Components return true; } + private void CancelUsing(Character character) + { + foreach (LimbPos lb in limbPositions) + { + Limb limb = character.AnimController.GetLimb(lb.limbType); + if (limb == null) continue; + + limb.Disabled = false; + + limb.pullJoint.Enabled = false; + } + + character.AnimController.Anim = AnimController.Animation.None; + } + public override bool Select(Character activator = null) { - if (character!=null && character.SelectedConstruction == item) - { - character = null; - IsActive = false; - if (activator != null) activator.AnimController.Anim = AnimController.Animation.None; + if (activator == null) return false; - return true; + //someone already using the item + if (character != null) + { + if (character == activator) + { + IsActive = false; + CancelUsing(character); + character = null; + } + else + { + return false; + } } else { character = activator; - if (activator == null) return false; IsActive = true; } diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 7c7f34af5..4e1b7e858 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -166,11 +166,11 @@ namespace Barotrauma for (float x = startPosition.X; x < endPosition.X; x += Rand.Range(5000.0f, 10000.0f, false)) { pathNodes.Add(new Vector2(x, Rand.Range(pathBorders.Y, pathBorders.Bottom, false))); + } - //if (x > borders.Center.X) - //{ - // positionsOfInterest.Add(pathNodes.Last()); - //} + for (int i = 2; i < pathNodes.Count; i+=3 ) + { + positionsOfInterest.Add(new InterestingPosition(pathNodes[i], true)); } pathNodes.Add(endPosition); @@ -1021,7 +1021,7 @@ namespace Barotrauma var positionsWithSpace = positionsOfInterest.FindAll(p => (bool)preferLarge == p.IsLarge); if (!positionsWithSpace.Any()) return Size * 0.5f; - return positionsWithSpace[Rand.Int(positionsOfInterest.Count, !useSyncedRand)].Position; + return positionsWithSpace[Rand.Int(positionsWithSpace.Count, !useSyncedRand)].Position; } } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 09dc59b9c56baa4add4b40b2d7fb551ae0556efd..8e982b8c9a525fc57ebcf5769ac01dab11dced8c 100644 GIT binary patch delta 1438 zcmcgrZERCj818${X?JheLN~@%aGRwo8~Q`$+BgD*l}sICvlN85Ewc>#2sV?r1c;DP zx)7>~MqSU?n=E5aJ}v}}vfgDk5wkFYL}OiMVpMK$nP0z*OZd934ZL4zr4xQ zbKmE@?{nV1&$+2wT`E`iYD}%R*=z~0*|gr)J3${g@)Ov7yMNg;sCThEz@Y3BHR6wa zJ}(DFt;kWLoDxy^QdZa-#iSKJp$=voo%YmYKUhVMJP69p%Y(|re`MJQv(6I69%i!C zwNF$ts_b@^GYN9QRp~9Hct2r?6w7H%5@HVPFxNI#$>eHx0?x^k?kd-5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