From 6a6486e270056e2eb2dc7a19846912e64d28857a Mon Sep 17 00:00:00 2001 From: Regalis Date: Sun, 26 Mar 2017 22:47:08 +0300 Subject: [PATCH] Server doesn't create an entityevent if the health of a character changes very little, husk infection isn't updated after the infected character dies, clients can't create a "huskified" human NPC until the server says so --- Subsurface/Source/Characters/Character.cs | 14 ++++++++++---- Subsurface/Source/Characters/HuskInfection.cs | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index c08a3b995..be72137b6 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -90,7 +90,7 @@ namespace Barotrauma protected float oxygen, oxygenAvailable; protected float drowningTime; - private float health; + private float health, lastSentHealth; protected float minHealth, maxHealth; protected Item closestItem; @@ -301,7 +301,13 @@ namespace Barotrauma health = newHealth; if (GameMain.Server != null) - GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); + { + if (Math.Abs(health - lastSentHealth) > (maxHealth - minHealth) / 255.0f || Math.Sign(health) != Math.Sign(lastSentHealth)) + { + GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status }); + lastSentHealth = health; + } + } } } @@ -1325,10 +1331,10 @@ namespace Barotrauma item.Submarine = Submarine; } } + + if (isDead) return; if (huskInfection != null) huskInfection.Update(deltaTime, this); - - if (isDead) return; if (GameMain.NetworkMember != null) { diff --git a/Subsurface/Source/Characters/HuskInfection.cs b/Subsurface/Source/Characters/HuskInfection.cs index c14bfb7fc..95c9525d6 100644 --- a/Subsurface/Source/Characters/HuskInfection.cs +++ b/Subsurface/Source/Characters/HuskInfection.cs @@ -151,6 +151,8 @@ namespace Barotrauma private void CharacterDead(Character character, CauseOfDeath causeOfDeath) { + if (GameMain.Client != null) return; + var husk = Character.Create( Path.Combine("Content", "Characters", "Human", "humanhusk.xml"), character.WorldPosition, @@ -177,6 +179,7 @@ namespace Barotrauma character.Enabled = false; + Entity.Spawner.AddToRemoveQueue(character); Entity.Spawner.AddToSpawnedList(husk); } }