Character death syncing, characters don't reselect items when they receive a network msg about an item they have already selected

This commit is contained in:
Regalis
2017-01-06 17:43:18 +02:00
parent beac45458e
commit 80e743916a
2 changed files with 65 additions and 35 deletions
+2 -2
View File
@@ -47,7 +47,7 @@ namespace Barotrauma
AnimController.SimplePhysicsEnabled = false; AnimController.SimplePhysicsEnabled = false;
} }
if (isDead || Health <= 0.0f) return; if (IsDead || Health <= 0.0f) return;
if (Controlled == this || !aiController.Enabled) return; if (Controlled == this || !aiController.Enabled) return;
@@ -76,7 +76,7 @@ namespace Barotrauma
{ {
base.DrawFront(spriteBatch,cam); base.DrawFront(spriteBatch,cam);
if (GameMain.DebugDraw && !isDead) aiController.DebugDraw(spriteBatch); if (GameMain.DebugDraw && !IsDead) aiController.DebugDraw(spriteBatch);
} }
public override void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker) public override void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker)
+34 -4
View File
@@ -130,7 +130,7 @@ namespace Barotrauma
private Dictionary<object, HUDProgressBar> hudProgressBars; private Dictionary<object, HUDProgressBar> hudProgressBars;
protected bool isDead; private bool isDead;
private CauseOfDeath lastAttackCauseOfDeath; private CauseOfDeath lastAttackCauseOfDeath;
private CauseOfDeath causeOfDeath; private CauseOfDeath causeOfDeath;
@@ -360,6 +360,8 @@ namespace Barotrauma
set set
{ {
if (!MathUtils.IsValid(value)) return; if (!MathUtils.IsValid(value)) return;
if (GameMain.Client != null) return;
float newBleeding = MathHelper.Clamp(value, 0.0f, 5.0f); float newBleeding = MathHelper.Clamp(value, 0.0f, 5.0f);
if (newBleeding == bleeding) return; if (newBleeding == bleeding) return;
@@ -1888,6 +1890,7 @@ namespace Barotrauma
PlaySound(CharacterSound.SoundType.Die); PlaySound(CharacterSound.SoundType.Die);
isDead = true; isDead = true;
this.causeOfDeath = causeOfDeath; this.causeOfDeath = causeOfDeath;
AnimController.movement = Vector2.Zero; AnimController.movement = Vector2.Zero;
AnimController.TargetMovement = Vector2.Zero; AnimController.TargetMovement = Vector2.Zero;
@@ -2154,8 +2157,11 @@ namespace Barotrauma
} }
else if (selectedEntity is Item) else if (selectedEntity is Item)
{ {
selectedConstruction = (Item)selectedEntity; var newSelectedConstruction = (Item)selectedEntity;
if (selectedConstruction != null) selectedConstruction.Pick(this, true, true); if (newSelectedConstruction != null && selectedConstruction != newSelectedConstruction)
{
newSelectedConstruction.Pick(this, true, true);
}
} }
} }
else else
@@ -2219,6 +2225,13 @@ namespace Barotrauma
return; return;
} }
msg.Write(isDead);
if (isDead)
{
msg.Write((byte)causeOfDeath);
}
else
{
msg.WriteRangedSingle(health, minHealth, maxHealth, 8); msg.WriteRangedSingle(health, minHealth, maxHealth, 8);
msg.Write(oxygen < 100.0f); msg.Write(oxygen < 100.0f);
@@ -2240,6 +2253,7 @@ namespace Barotrauma
msg.WriteRangedSingle(Stun, 0.0f, 60.0f, 8); msg.WriteRangedSingle(Stun, 0.0f, 60.0f, 8);
} }
} }
}
private void ReadStatus(NetBuffer msg) private void ReadStatus(NetBuffer msg)
{ {
@@ -2249,6 +2263,21 @@ namespace Barotrauma
return; return;
} }
bool isDead = msg.ReadBoolean();
if (isDead)
{
causeOfDeath = (CauseOfDeath)msg.ReadByte();
if (causeOfDeath == CauseOfDeath.Pressure)
{
Implode(true);
}
else
{
Kill(causeOfDeath, true);
}
}
else
{
health = msg.ReadRangedSingle(minHealth, maxHealth, 8); health = msg.ReadRangedSingle(minHealth, maxHealth, 8);
bool lowOxygen = msg.ReadBoolean(); bool lowOxygen = msg.ReadBoolean();
@@ -2260,7 +2289,7 @@ namespace Barotrauma
bool isBleeding = msg.ReadBoolean(); bool isBleeding = msg.ReadBoolean();
if (isBleeding) if (isBleeding)
{ {
Bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8); bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8);
} }
bool stunned = msg.ReadBoolean(); bool stunned = msg.ReadBoolean();
@@ -2270,6 +2299,7 @@ namespace Barotrauma
StartStun(newStunTimer, true); StartStun(newStunTimer, true);
} }
} }
}
public void WriteSpawnData(NetBuffer msg) public void WriteSpawnData(NetBuffer msg)
{ {