AICharacte syncing bugfixes, cleanbuild removes the temp save folder, minor networkevent optimizations (enum max value == GetValues().Length-1)
This commit is contained in:
@@ -554,7 +554,7 @@ namespace Barotrauma
|
||||
|
||||
public override void FillNetworkData(NetBuffer message)
|
||||
{
|
||||
message.Write((byte)state);
|
||||
message.WriteRangedInteger(0, Enum.GetValues(typeof(AiState)).Length-1, (int)state);
|
||||
|
||||
bool wallAttack = (wallAttackPos != Vector2.Zero && state == AiState.Attack);
|
||||
|
||||
@@ -594,7 +594,7 @@ namespace Barotrauma
|
||||
try
|
||||
{
|
||||
|
||||
newState = (AiState)(message.ReadByte());
|
||||
newState = (AiState)message.ReadRangedInteger(0, Enum.GetValues(typeof(AiState)).Length - 1);
|
||||
|
||||
//bool wallAttack = message.ReadBoolean();
|
||||
|
||||
@@ -619,7 +619,15 @@ namespace Barotrauma
|
||||
targetID = message.ReadUInt16();
|
||||
}
|
||||
|
||||
catch { return; }
|
||||
catch (Exception e)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Failed to read enemy ai update message", e);
|
||||
#endif
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//wallAttackPos = newWallAttackPos;
|
||||
|
||||
|
||||
@@ -92,19 +92,11 @@ namespace Barotrauma
|
||||
case NetworkEventType.KillCharacter:
|
||||
return true;
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
//if (RefLimb.ignoreCollisions) continue;
|
||||
|
||||
//if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||
|
||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||
|
||||
|
||||
message.Write(AnimController.RefLimb.Rotation);
|
||||
// i++;
|
||||
//}
|
||||
message.Write(AnimController.RefLimb.Rotation);
|
||||
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer, 0.0f, 60.0f), 0.0f, 60.0f, 8);
|
||||
message.Write((byte)((health / maxHealth) * 255.0f));
|
||||
@@ -115,30 +107,23 @@ namespace Barotrauma
|
||||
aiController.FillNetworkData(message);
|
||||
return true;
|
||||
case NetworkEventType.EntityUpdate:
|
||||
//if (Submarine == null)
|
||||
//{
|
||||
// if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
|
||||
//}
|
||||
|
||||
|
||||
message.Write(AnimController.TargetDir == Direction.Right);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -1.0f, 1.0f), -1.0f, 1.0f, 8);
|
||||
|
||||
message.Write(Submarine != null);
|
||||
|
||||
|
||||
message.Write(AnimController.RefLimb.SimPosition.X);
|
||||
message.Write(AnimController.RefLimb.SimPosition.Y);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
default:
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("AICharacter network event had a wrong type ("+type+")");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||
@@ -152,33 +137,27 @@ namespace Barotrauma
|
||||
Kill(CauseOfDeath.Damage, true);
|
||||
return;
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
//foreach (Limb limb in AnimController.Limbs)
|
||||
//{
|
||||
// if (limb.ignoreCollisions) continue;
|
||||
|
||||
Vector2 limbPos = AnimController.RefLimb.SimPosition;
|
||||
float rotation = AnimController.RefLimb.Rotation;
|
||||
Vector2 limbPos = AnimController.RefLimb.SimPosition;
|
||||
float rotation = AnimController.RefLimb.Rotation;
|
||||
|
||||
try
|
||||
{
|
||||
limbPos.X = message.ReadFloat();
|
||||
limbPos.Y = message.ReadFloat();
|
||||
try
|
||||
{
|
||||
limbPos.X = message.ReadFloat();
|
||||
limbPos.Y = message.ReadFloat();
|
||||
|
||||
rotation = message.ReadFloat();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
rotation = message.ReadFloat();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (AnimController.RefLimb.body != null)
|
||||
{
|
||||
//AnimController.RefLimb.body.TargetVelocity = limb.body.LinearVelocity;
|
||||
AnimController.RefLimb.body.TargetPosition = limbPos;// +vel * (float)(deltaTime / 60.0);
|
||||
AnimController.RefLimb.body.TargetRotation = rotation;// +angularVel * (float)(deltaTime / 60.0);
|
||||
//limb.body.TargetAngularVelocity = limb.body.AngularVelocity;
|
||||
}
|
||||
//}
|
||||
if (AnimController.RefLimb.body != null)
|
||||
{
|
||||
AnimController.RefLimb.body.TargetPosition = limbPos;
|
||||
AnimController.RefLimb.body.TargetRotation = rotation;
|
||||
}
|
||||
|
||||
float newStunTimer = 0.0f, newHealth = 0.0f, newBleeding = 0.0f;
|
||||
|
||||
@@ -190,7 +169,14 @@ namespace Barotrauma
|
||||
|
||||
newBleeding = message.ReadRangedSingle(0.0f, 5.0f, 8);
|
||||
}
|
||||
catch { return; }
|
||||
catch (Exception e)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Failed to read AICharacter update message", e);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
AnimController.StunTimer = newStunTimer;
|
||||
health = newHealth;
|
||||
@@ -231,9 +217,9 @@ namespace Barotrauma
|
||||
|
||||
AnimController.TargetDir = (targetDir) ? Direction.Right : Direction.Left;
|
||||
AnimController.TargetMovement = targetMovement;
|
||||
|
||||
AnimController.TargetMovement = AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
|
||||
|
||||
|
||||
AnimController.RefLimb.body.TargetPosition =
|
||||
AnimController.EstimateCurrPosition(pos, (float)(NetTime.Now) - sendingTime);
|
||||
|
||||
if (inSub)
|
||||
{
|
||||
|
||||
@@ -1393,17 +1393,17 @@ namespace Barotrauma
|
||||
if (inventory == null) return false;
|
||||
return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||
case NetworkEventType.ImportantEntityUpdate:
|
||||
if (health>0.0f)
|
||||
if (health > 0.0f)
|
||||
{
|
||||
message.Write(Math.Max((byte)((health / maxHealth) * 255.0f), (byte)1));
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Write((byte)0);
|
||||
message.WriteRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length, (int)lastAttackCauseOfDeath);
|
||||
message.WriteRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length-1, (int)lastAttackCauseOfDeath);
|
||||
}
|
||||
|
||||
if (AnimController.StunTimer<=0.0f && bleeding<=0.0f && oxygen>99.0f)
|
||||
if (AnimController.StunTimer <= 0.0f && bleeding <= 0.0f && oxygen > 99.0f)
|
||||
{
|
||||
message.Write(true);
|
||||
}
|
||||
@@ -1566,7 +1566,7 @@ namespace Barotrauma
|
||||
|
||||
if (health == 0.0f)
|
||||
{
|
||||
causeOfDeath = (CauseOfDeath)message.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length);
|
||||
causeOfDeath = (CauseOfDeath)message.ReadRangedInteger(0, Enum.GetValues(typeof(CauseOfDeath)).Length-1);
|
||||
Kill(causeOfDeath, true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user