From 34c65693133fecba104b9c090ee712c72e638139 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 29 Jun 2016 17:26:26 +0300 Subject: [PATCH] Server can inflict impact damage on clients, character oxygen level syncing bugfix, hulls send a networkevent when oxygen level changes by >=5%, limb velocities aren't reset when receiving a network update --- Subsurface/Content/Items/MiniMap/item.xml | 3 +- .../Animation/HumanoidAnimController.cs | 2 +- .../Source/Characters/Animation/Ragdoll.cs | 2 +- Subsurface/Source/Characters/Character.cs | 3 +- Subsurface/Source/Map/Hull.cs | 23 ++++++--- Subsurface/Source/Physics/PhysicsBody.cs | 50 +++++++++---------- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/Subsurface/Content/Items/MiniMap/item.xml b/Subsurface/Content/Items/MiniMap/item.xml index 7511ae36b..a5cb84fb9 100644 --- a/Subsurface/Content/Items/MiniMap/item.xml +++ b/Subsurface/Content/Items/MiniMap/item.xml @@ -1,7 +1,8 @@  + linkable="true" + pickdistance="150"> diff --git a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs index ca39e4aee..f1e758669 100644 --- a/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Subsurface/Source/Characters/Animation/HumanoidAnimController.cs @@ -815,7 +815,7 @@ namespace Barotrauma // - moving sideways // - reached the top or bottom of the ladder if (notClimbing || - (TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition * 1.5f) || + (TargetMovement.Y < 0.0f && ConvertUnits.ToSimUnits(trigger.Height) + handPos.Y < HeadPosition) || (TargetMovement.Y > 0.0f && handPos.Y > 0.1f)) { Anim = Animation.None; diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index de4362d40..769d44ca9 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -407,7 +407,7 @@ namespace Barotrauma if (impact > l.impactTolerance) { - if (!character.IsNetworkPlayer) + if (!character.IsNetworkPlayer || GameMain.Server != null) { character.AddDamage(CauseOfDeath.Damage, impact - l.impactTolerance * 0.1f, null); diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index ab9eab0ad..aa6d60c8f 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1520,7 +1520,7 @@ namespace Barotrauma message.Write(keys[(int)InputType.Run].Held); - message.Write(keys[(int)InputType.Crouch].Held); + message.Write(((HumanoidAnimController)AnimController).Crouching); if (secondaryHeld) @@ -1685,6 +1685,7 @@ namespace Barotrauma if (allOk) { bleeding = 0.0f; + Oxygen = 100.0f; AnimController.StunTimer = 0.0f; return; } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index 645edc985..9b9fb22eb 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -62,7 +62,7 @@ namespace Barotrauma float[] leftDelta; float[] rightDelta; - private float lastSentVolume; + private float lastSentVolume, lastSentOxygen; private float lastNetworkUpdate; public List ConnectedGaps; @@ -395,12 +395,13 @@ namespace Barotrauma } //update client hulls if the amount of water has changed by >10% - if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f) + //or if oxygen percentage has changed by 5% + if (Math.Abs(lastSentVolume - volume) > FullVolume * 0.1f || + Math.Abs(lastSentOxygen - OxygenPercentage) > 5f) { - new Networking.NetworkEvent(ID, false); - lastSentVolume = volume; + new Networking.NetworkEvent(ID, false); } - + if (!update) { lethalPressure = 0.0f; @@ -758,6 +759,7 @@ namespace Barotrauma public override bool FillNetworkData(Networking.NetworkEventType type, NetBuffer message, object data) { message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6); + message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8); message.Write((byte)fireSources.Count, 4); for (int i = 0; i < Math.Min(fireSources.Count, 16); i++) @@ -773,6 +775,10 @@ namespace Barotrauma message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 6); } + + lastSentVolume = volume; + lastSentOxygen = OxygenPercentage; + return true; } @@ -783,19 +789,24 @@ namespace Barotrauma if (sendingTime < lastNetworkUpdate) return; float newVolume = this.volume; + float newOxygen = this.OxygenPercentage; try { float newPercentage = message.ReadRangedSingle(0.0f, 1.5f, 6); newVolume = newPercentage * FullVolume; + + newOxygen = message.ReadRangedSingle(0.0f, 100.0f, 8); } - catch + catch (Exception e) { + DebugConsole.Log("Failed to read network message for Hull {" + ID + "}! " + e.Message); return; } Volume = newVolume; + OxygenPercentage = newOxygen; int fireSourceCount = message.ReadByte(4); diff --git a/Subsurface/Source/Physics/PhysicsBody.cs b/Subsurface/Source/Physics/PhysicsBody.cs index 2af44a175..0bde1b41d 100644 --- a/Subsurface/Source/Physics/PhysicsBody.cs +++ b/Subsurface/Source/Physics/PhysicsBody.cs @@ -27,9 +27,9 @@ namespace Barotrauma protected float prevRotation; protected Vector2 targetPosition; - protected Vector2 targetVelocity; + //protected Vector2 targetVelocity; protected float targetRotation; - protected float targetAngularVelocity; + //protected float targetAngularVelocity; private Vector2 drawPosition; private float drawRotation; @@ -64,16 +64,16 @@ namespace Barotrauma } } - public Vector2 TargetVelocity - { - get { return targetVelocity; } - set - { - if (!MathUtils.IsValid(value)) return; - targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f); - targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f); - } - } + //public Vector2 TargetVelocity + //{ + // get { return targetVelocity; } + // set + // { + // if (!MathUtils.IsValid(value)) return; + // targetVelocity.X = MathHelper.Clamp(value.X, -100.0f, 100.0f); + // targetVelocity.Y = MathHelper.Clamp(value.Y, -100.0f, 100.0f); + // } + //} public float TargetRotation { @@ -85,15 +85,15 @@ namespace Barotrauma } } - public float TargetAngularVelocity - { - get { return targetAngularVelocity; } - set - { - if (!MathUtils.IsValid(value)) return; - targetAngularVelocity = value; - } - } + //public float TargetAngularVelocity + //{ + // get { return targetAngularVelocity; } + // set + // { + // if (!MathUtils.IsValid(value)) return; + // targetAngularVelocity = value; + // } + //} public Vector2 DrawPosition { @@ -314,8 +314,8 @@ namespace Barotrauma } body.SetTransform(targetPosition, targetRotation == 0.0f ? body.Rotation : targetRotation); - body.LinearVelocity = targetVelocity; - body.AngularVelocity = targetAngularVelocity; + //body.LinearVelocity = targetVelocity; + //body.AngularVelocity = targetAngularVelocity; targetPosition = Vector2.Zero; } @@ -415,10 +415,10 @@ namespace Barotrauma return; targetPosition = newTargetPos; - TargetVelocity = newTargetVel; + LinearVelocity = newTargetVel; targetRotation = newTargetRotation; - targetAngularVelocity = newTargetAngularVel; + AngularVelocity = newTargetAngularVel; lastNetworkUpdateTime = sendingTime; }