From 5b1798cb503c063f4bfa7c0e5538d344532a781b Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 30 Nov 2017 17:07:37 +0200 Subject: [PATCH] Fixed monsters not taking damage when they're far enough from the host's camera (or the main sub when using the dedicated server). The limbs of the monsters were disabled when 8000 units away, causing them to become invincible because the collider does not register damage. Closes #50 --- .../Source/Characters/AICharacter.cs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs b/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs index c12fa49e0..4ccc10788 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AICharacter.cs @@ -1,10 +1,17 @@ using Microsoft.Xna.Framework; -using System; namespace Barotrauma { partial class AICharacter : Character { + //characters that are further than this from the camera (and all clients) + //have all their limb physics bodies disabled + const float EnableSimplePhysicsDist = 10000.0f; + const float DisableSimplePhysicsDist = EnableSimplePhysicsDist * 0.9f; + + const float EnableSimplePhysicsDistSqr = EnableSimplePhysicsDist * EnableSimplePhysicsDist; + const float DisableSimplePhysicsDistSqr = DisableSimplePhysicsDist * DisableSimplePhysicsDist; + private AIController aiController; public override AIController AIController @@ -32,17 +39,34 @@ namespace Barotrauma if (!IsRemotePlayer) { - float dist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition); - if (dist > 8000.0f * 8000.0f) + float characterDist = Vector2.DistanceSquared(cam.WorldViewCenter, WorldPosition); + if (GameMain.Server != null) + { + //get the distance from the closest player to this character + foreach (Character c in CharacterList) + { + if (c != this && (c.IsRemotePlayer || c == GameMain.Server.Character)) + { + float dist = Vector2.DistanceSquared(c.WorldPosition, WorldPosition); + if (dist < characterDist) + { + characterDist = dist; + if (characterDist < DisableSimplePhysicsDistSqr) break; + } + } + } + } + + if (characterDist > EnableSimplePhysicsDistSqr) { AnimController.SimplePhysicsEnabled = true; } - else if (dist < 7000.0f * 7000.0f) + else if (characterDist < DisableSimplePhysicsDistSqr) { AnimController.SimplePhysicsEnabled = false; } } - + if (IsDead || Health <= 0.0f || IsUnconscious || Stun > 0.0f) return; if (Controlled == this || !aiController.Enabled) return;