Item condition syncing
This commit is contained in:
@@ -47,6 +47,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public PhysicsBody body;
|
public PhysicsBody body;
|
||||||
|
|
||||||
|
private float lastSentCondition;
|
||||||
private float condition;
|
private float condition;
|
||||||
|
|
||||||
private bool inWater;
|
private bool inWater;
|
||||||
@@ -181,6 +182,15 @@ namespace Barotrauma
|
|||||||
req.Fixed = false;
|
req.Fixed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameMain.Server != null && lastSentCondition != condition)
|
||||||
|
{
|
||||||
|
if (Math.Abs(lastSentCondition - condition) > 1.0f || condition == 0.0f || condition == 100.0f)
|
||||||
|
{
|
||||||
|
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
|
||||||
|
lastSentCondition = condition;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1659,35 +1669,42 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.ComponentState)
|
|
||||||
|
msg.WriteRangedInteger(0, 2, (int)((NetEntityEvent.Type)extraData[0]));
|
||||||
|
|
||||||
|
switch ((NetEntityEvent.Type)extraData[0])
|
||||||
{
|
{
|
||||||
msg.Write(true);
|
case NetEntityEvent.Type.ComponentState:
|
||||||
|
int componentIndex = (int)extraData[1];
|
||||||
|
msg.WriteRangedInteger(0, components.Count-1, componentIndex);
|
||||||
|
|
||||||
int componentIndex = (int)extraData[1];
|
(components[componentIndex] as IServerSerializable).ServerWrite(msg, c, extraData);
|
||||||
msg.Write((byte)componentIndex);
|
break;
|
||||||
|
case NetEntityEvent.Type.InventoryState:
|
||||||
(components[componentIndex] as IServerSerializable).ServerWrite(msg, c, extraData);
|
ownInventory.ServerWrite(msg, c, extraData);
|
||||||
}
|
break;
|
||||||
else if ((NetEntityEvent.Type)extraData[0] == NetEntityEvent.Type.InventoryState)
|
case NetEntityEvent.Type.Status:
|
||||||
{
|
msg.WriteRangedSingle(condition, 0.0f, 100.0f, 8);
|
||||||
msg.Write(false);
|
break;
|
||||||
|
|
||||||
ownInventory.ServerWrite(msg, c, extraData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
|
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
|
||||||
{
|
{
|
||||||
bool isComponentUpdate = msg.ReadBoolean();
|
NetEntityEvent.Type eventType = (NetEntityEvent.Type)msg.ReadRangedInteger(0, 2);
|
||||||
|
|
||||||
if (isComponentUpdate)
|
switch (eventType)
|
||||||
{
|
{
|
||||||
int componentIndex = msg.ReadByte();
|
case NetEntityEvent.Type.ComponentState:
|
||||||
(components[componentIndex] as IServerSerializable).ClientRead(type, msg, sendingTime);
|
int componentIndex = msg.ReadRangedInteger(0, components.Count - 1);
|
||||||
}
|
(components[componentIndex] as IServerSerializable).ClientRead(type, msg, sendingTime);
|
||||||
else
|
break;
|
||||||
{
|
case NetEntityEvent.Type.InventoryState:
|
||||||
ownInventory.ClientRead(type, msg, sendingTime);
|
ownInventory.ClientRead(type, msg, sendingTime);
|
||||||
|
break;
|
||||||
|
case NetEntityEvent.Type.Status:
|
||||||
|
Condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1702,7 +1719,7 @@ namespace Barotrauma
|
|||||||
msg.Write(true);
|
msg.Write(true);
|
||||||
|
|
||||||
int componentIndex = (int)extraData[1];
|
int componentIndex = (int)extraData[1];
|
||||||
msg.Write((byte)componentIndex);
|
msg.WriteRangedInteger(0, components.Count - 1, componentIndex);
|
||||||
|
|
||||||
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
|
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
|
||||||
}
|
}
|
||||||
@@ -1720,7 +1737,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (isComponentUpdate)
|
if (isComponentUpdate)
|
||||||
{
|
{
|
||||||
int componentIndex = msg.ReadByte();
|
int componentIndex = msg.ReadRangedInteger(0, components.Count - 1);
|
||||||
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
|
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
public enum Type
|
public enum Type
|
||||||
{
|
{
|
||||||
Default,
|
|
||||||
ComponentState,
|
ComponentState,
|
||||||
InventoryState,
|
InventoryState,
|
||||||
Status
|
Status
|
||||||
|
|||||||
Reference in New Issue
Block a user