Multiplayer fixes

This commit is contained in:
Regalis
2015-12-12 16:23:01 +02:00
parent 17e8a2171f
commit 04cfca0ede
14 changed files with 46 additions and 37 deletions

View File

@@ -64,6 +64,8 @@ namespace Barotrauma
public EnemyAIController(Character c, string file) : base(c)
{
if (GameMain.Client != null && GameMain.Server == null) c.Enabled = false;
targetMemories = new Dictionary<AITarget, AITargetMemory>();
XDocument doc = ToolBox.TryLoadXml(file);

View File

@@ -42,7 +42,6 @@ namespace Barotrauma
public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false)
: base(file, position, characterInfo, isNetworkPlayer)
{
if (GameMain.Client != null && GameMain.Server == null) Enabled = false;
}
public void SetAI(AIController aiController)
@@ -98,10 +97,10 @@ namespace Barotrauma
//{
//if (RefLimb.ignoreCollisions) continue;
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false;
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
message.Write(AnimController.RefLimb.Rotation);
@@ -114,14 +113,14 @@ namespace Barotrauma
aiController.FillNetworkData(message);
return true;
case NetworkEventType.EntityUpdate:
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false;
if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.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(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
return true;
}
@@ -149,8 +148,8 @@ namespace Barotrauma
try
{
limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
limbPos.X = message.ReadFloat();
limbPos.Y = message.ReadFloat();
rotation = message.ReadFloat();
}
@@ -196,8 +195,8 @@ namespace Barotrauma
targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8);
targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8);
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
//vel.X = message.ReadFloat();
//vel.Y = message.ReadFloat();

View File

@@ -988,7 +988,7 @@ namespace Barotrauma
{
if (!Enabled) return;
Vector2 pos = ConvertUnits.ToDisplayUnits(AnimController.Limbs[0].SimPosition);
Vector2 pos = AnimController.Limbs[0].WorldPosition;
pos.Y = -pos.Y;
if (this == controlled) return;
@@ -1335,10 +1335,10 @@ namespace Barotrauma
message.Write(AnimController.Dir > 0.0f);
}
if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return true;
if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return true;
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
message.Write(AnimController.RefLimb.SimPosition.X);
message.Write(AnimController.RefLimb.SimPosition.Y);
return true;
default:
@@ -1505,8 +1505,8 @@ namespace Barotrauma
}
try
{
pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16);
pos.X = message.ReadFloat();
pos.Y = message.ReadFloat();
}
catch

View File

@@ -54,7 +54,7 @@ namespace Barotrauma
if (character.ClosestCharacter != null && (character.ClosestCharacter.IsDead || character.ClosestCharacter.Stun > 0.0f))
{
Vector2 startPos = character.Position + (character.ClosestCharacter.Position - character.Position) * 0.7f;
Vector2 startPos = character.Position + (character.ClosestCharacter.WorldPosition - character.WorldPosition) * 0.7f;
startPos = cam.WorldToScreen(startPos);
Vector2 textPos = startPos;

View File

@@ -61,7 +61,7 @@ namespace Barotrauma.Items.Components
{
base.Draw(spriteBatch, editing);
textBlock.Rect = new Rectangle(item.WorldRect.X, -(item.WorldRect.Y - item.Rect.Height/2), item.Rect.Width, item.Rect.Height);
textBlock.Rect = new Rectangle((int)item.DrawPosition.X - item.Rect.Width/2, -(int)(item.DrawPosition.Y + item.Rect.Height/2), item.Rect.Width, item.Rect.Height);
textBlock.Draw(spriteBatch);
}
}

View File

@@ -118,7 +118,7 @@ namespace Barotrauma.Items.Components
fmj.WorldAnchorB = position;
}
item.SendSignal(ToolBox.Vector2ToString(character.CursorPosition), "position_out");
item.SendSignal(ToolBox.Vector2ToString(character.CursorWorldPosition), "position_out");
}
public override bool Use(float deltaTime, Character activator = null)
@@ -152,12 +152,12 @@ namespace Barotrauma.Items.Components
{
if (c2 == null || c2.Item==null || !c2.Item.Prefab.FocusOnSelected) continue;
Vector2 centerPos = c2.Item.Position;
Vector2 centerPos = c2.Item.WorldPosition;
if (character == Character.Controlled && cam != null)
{
Lights.LightManager.ViewPos = centerPos;
cam.TargetPos = c2.Item.Position;
cam.TargetPos = c2.Item.WorldPosition;
}
break;

View File

@@ -50,6 +50,8 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
currPowerConsumption = powerConsumption;
base.Update(deltaTime, cam);
for (int i = radarBlips.Count - 1; i >= 0; i-- )
@@ -71,6 +73,8 @@ namespace Barotrauma.Items.Components
{
pingState = 0.0f;
}
voltage = 0.0f;
}
public override bool Use(float deltaTime, Character character = null)
@@ -262,7 +266,6 @@ namespace Barotrauma.Items.Components
prevPos = pos;
}
voltage = 0.0f;
}
private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)

View File

@@ -153,7 +153,7 @@ namespace Barotrauma.Items.Components
projectile.body.ResetDynamics();
projectile.body.Enabled = true;
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y)), -rotation);
projectile.SetTransform(ConvertUnits.ToSimUnits(new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y)), -rotation);
projectiles[0].Use(deltaTime);
if (projectile.container != null) projectile.container.RemoveContained(projectile);
@@ -301,7 +301,7 @@ namespace Barotrauma.Items.Components
case "position_in":
Vector2 receivedPos = ToolBox.ParseToVector2(signal, false);
Vector2 centerPos = new Vector2(item.Rect.X + barrelPos.X, item.Rect.Y - barrelPos.Y);
Vector2 centerPos = new Vector2(item.WorldRect.X + barrelPos.X, item.WorldRect.Y - barrelPos.Y);
Vector2 offset = receivedPos - centerPos;
offset.Y = -offset.Y;

View File

@@ -110,6 +110,14 @@ namespace Barotrauma
private set;
}
public override Vector2 SimPosition
{
get
{
return ConvertUnits.ToSimUnits(Position);
}
}
public Vector2 Velocity
{
get { return subBody==null ? Vector2.Zero : subBody.Velocity; }

View File

@@ -402,7 +402,7 @@ namespace Barotrauma
}
var ragdoll = limb.character.AnimController;
ragdoll.FindHull();
ragdoll.FindHull();
return false;

View File

@@ -3,6 +3,7 @@ using Lidgren.Network;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Barotrauma.Networking.ReliableMessages;
using FarseerPhysics;
namespace Barotrauma.Networking
{
@@ -356,7 +357,7 @@ namespace Barotrauma.Networking
if (myCharacter.IsDead)
{
Character.Controlled = null;
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
//GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
}
else if (gameStarted)
{
@@ -742,7 +743,7 @@ namespace Barotrauma.Networking
float closestDist = 0.0f;
foreach (WayPoint wp in WayPoint.WayPointList)
{
float dist = Vector2.Distance(wp.SimPosition, position);
float dist = Vector2.Distance(wp.WorldPosition, position);
if (closestWaypoint != null && dist > closestDist) continue;
closestWaypoint = wp;
@@ -750,9 +751,7 @@ namespace Barotrauma.Networking
continue;
}
Character character = (closestWaypoint == null) ?
Character.Create(ch, position, !isMyCharacter) :
Character.Create(ch, closestWaypoint, !isMyCharacter);
Character character = Character.Create(ch, position, !isMyCharacter);
character.ID = ID;

View File

@@ -1223,8 +1223,8 @@ namespace Barotrauma.Networking
message.Write((byte)character.Info.HeadSpriteId);
message.Write(character.SimPosition.X);
message.Write(character.SimPosition.Y);
message.Write(character.WorldPosition.X);
message.Write(character.WorldPosition.Y);
message.Write(character.Info.Job.Name);
}

View File

@@ -18,14 +18,12 @@ namespace Barotrauma
public static float Range(float minimum, float maximum, bool local = true)
{
return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
return (float)(local ? localRandom : syncedRandom).NextDouble() * (maximum - minimum) + minimum;
}
public static int Range(int minimum, int maximum, bool local = true)
{
return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
return (local ? localRandom : syncedRandom).Next(maximum - minimum) + minimum;
}
public static int Int(int max = int.MaxValue, bool local = true)

Binary file not shown.