Networking bugfixes, underwater scooter, fixed limbs going through walls when flipping the ragdoll

This commit is contained in:
Regalis
2015-11-13 00:52:42 +02:00
parent 9c2aec4c8e
commit 24ed95cd68
26 changed files with 301 additions and 119 deletions
+4 -33
View File
@@ -357,17 +357,11 @@ namespace Barotrauma
public override bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
{
for (int i = 0; i < 5; i++ )
for (int i = 0; i < capacity; i++)
{
message.Write(items[i]==null ? (ushort)0 : (ushort)items[i].ID);
}
for (int i = 5; i < capacity; i++)
{
if (items[i] == null) continue;
message.Write((ushort)items[i].ID);
}
return true;
}
@@ -375,7 +369,7 @@ namespace Barotrauma
{
character.ClearInput(InputType.Use);
for (int i = 0; i<5; i++)
for (int i = 0; i<capacity; i++)
{
ushort itemId = message.ReadUInt16();
if (itemId==0)
@@ -387,34 +381,11 @@ namespace Barotrauma
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue;
if (items[i] != item) items[i].Drop(character, false);
TryPutItem(item, i, false);
}
}
List<ushort> newItemIDs = new List<ushort>();
for (int i = 5; i < capacity; i++)
{
newItemIDs.Add(message.ReadUInt16());
}
for (int i = 5; i < capacity; i++)
{
if (items[i] == null) continue;
if (!newItemIDs.Contains(items[i].ID))
{
items[i].Drop(null, false);
continue;
}
}
foreach (ushort itemId in newItemIDs)
{
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue;
TryPutItem(item, LimbSlot.Any, false);
}
}
}
@@ -19,7 +19,7 @@ namespace Barotrauma.Items.Components
protected Vector2 aimPos;
protected bool aimable;
//protected bool aimable;
private bool attachable, attached, attachedByDefault;
private PhysicsBody body;
@@ -35,10 +35,10 @@ namespace Barotrauma.Items.Components
}
[HasDefaultValue(false, false)]
public bool Aimable
public bool ControlPose
{
get { return aimable; }
set { aimable = value; }
get;
set;
}
[HasDefaultValue(false, false)]
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Particles;
namespace Barotrauma.Items.Components
{
class Propulsion : ItemComponent
{
private float force;
private string particles;
private ParticlePrefab.DrawTargetType usableIn;
[HasDefaultValue(0.0f, false)]
public float Force
{
get { return force; }
set { force = value; }
}
[HasDefaultValue("", false)]
public string Particles
{
get { return particles; }
set { particles = value; }
}
public Propulsion(Item item, XElement element)
: base(item,element)
{
switch (ToolBox.GetAttributeString(element, "usablein", "air").ToLower())
{
case "air":
usableIn = ParticlePrefab.DrawTargetType.Air;
break;
case "water":
usableIn = ParticlePrefab.DrawTargetType.Water;
break;
default:
usableIn = ParticlePrefab.DrawTargetType.Both;
break;
}
}
public override bool Use(float deltaTime, Character character = null)
{
if (character == null) return false;
if (!character.IsKeyDown(InputType.Aim)) return false;
if (item.InWater)
{
if (usableIn == ParticlePrefab.DrawTargetType.Air) return true;
}
else
{
if (usableIn == ParticlePrefab.DrawTargetType.Water) return true;
}
Vector2 dir = Vector2.Normalize(character.CursorPosition - character.Position);
Vector2 propulsion = dir * force;
if (character.AnimController.InWater) character.AnimController.TargetMovement = dir;
if (item.body.Enabled && false)
{
item.body.ApplyForce(propulsion);
}
else
{
foreach (Limb limb in character.AnimController.Limbs)
{
if (limb.WearingItem==null || limb.WearingItem.Item != item) continue;
limb.body.ApplyForce(propulsion);
}
if (character.SelectedItems[0] == item) character.AnimController.GetLimb(LimbType.RightHand).body.ApplyForce(propulsion);
if (character.SelectedItems[1] == item) character.AnimController.GetLimb(LimbType.LeftHand).body.ApplyForce(propulsion);
}
if (!string.IsNullOrWhiteSpace(particles))
{
GameMain.ParticleManager.CreateParticle(particles, item.Position,
item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi), 0.0f);
}
return true;
}
public override void Draw(SpriteBatch spriteBatch, bool editing)
{
if (!IsActive) return;
//Vector2 particleSpeed = new Vector2(
// (float)Math.Cos(item.body.Rotation),
// (float)Math.Sin(item.body.Rotation)) *item.body.Dir * 0.1f;
//Vector2 startPos = ConvertUnits.ToDisplayUnits(item.body.Position);
//Vector2 endPos = ConvertUnits.ToDisplayUnits(pickedPosition);
//endPos = new Vector2(endPos.X + Game1.localRandom.Next(-2, 2), endPos.Y + Game1.localRandom.Next(-2, 2));
//GUI.DrawLine(spriteBatch, startPos, endPos, Color.Orange, 0.0f);
IsActive = false;
}
}
}
@@ -4,35 +4,15 @@ namespace Barotrauma.Items.Components
{
class WaterDetector : ItemComponent
{
private Hull hull;
public WaterDetector(Item item, XElement element)
: base (item, element)
{
hull = Hull.FindHull(item.Position);
IsActive = true;
}
public override void OnMapLoaded()
{
hull = Hull.FindHull(item.Position);
}
public override void Move(Microsoft.Xna.Framework.Vector2 amount)
{
hull = Hull.FindHull(item.Position);
}
public override void Update(float deltaTime, Camera cam)
{
if (hull == null) return;
float waterDepth = hull.Volume / hull.Size.X;
bool underWater = (hull.Rect.Y-hull.Rect.Height + waterDepth)>item.Position.Y;
item.SendSignal(underWater ? "1" : "0", "signal_out");
item.SendSignal(item.InWater ? "1" : "0", "signal_out");
}
}
}
+24 -24
View File
@@ -58,6 +58,8 @@ namespace Barotrauma
private float condition;
private bool inWater;
//the inventory in which the item is contained in
public Inventory inventory;
@@ -153,6 +155,18 @@ namespace Barotrauma
get { return prefab.FireProof; }
}
public bool InWater
{
get
{
//if the item has an active physics body, inWater is updated in the Update method
if (body != null && body.Enabled) return inWater;
//if not, we'll just have to check
return IsInWater();
}
}
public bool Updated
{
set
@@ -501,6 +515,15 @@ namespace Barotrauma
return new AttackResult(damageAmount, 0.0f, false);
}
private bool IsInWater()
{
if (CurrentHull == null) return true;
float surfaceY = CurrentHull.Surface;
return Position.Y < surfaceY;
}
public override void Update(Camera cam, float deltaTime)
{
@@ -545,30 +568,7 @@ namespace Barotrauma
body.SetToTargetPosition();
bool inWater = true;
if (CurrentHull != null)
{
float surfaceY = ConvertUnits.ToSimUnits(CurrentHull.Surface);
if (body.SimPosition.Y < surfaceY )
{
inWater = true;
//the item has gone through the surface of the water -> apply an impulse which serves as surface tension
//if (body.SimPosition.Y - (body.LinearVelocity.Y / 60.0f) < surfaceY)
//{
// Vector2 impulse = -body.LinearVelocity * (body.Mass / body.Density);
// body.ApplyLinearImpulse(impulse);
// int n = (int)((ConvertUnits.ToDisplayUnits(body.SimPosition.X) - CurrentHull.Rect.X) / Hull.WaveWidth);
// CurrentHull.WaveVel[n] = impulse.Y * 10.0f;
//}
}
else
{
inWater = false;
}
}
inWater = IsInWater();
if (!inWater) return;