From 51ea71333eb796a5b3245bd6d5570b57b29c2cae Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 24 Jan 2018 15:53:32 +0200 Subject: [PATCH] Fixed ChangeProperty network events --- .../Serialization/SerializableEntityEditor.cs | 6 +++ .../BarotraumaShared/Source/Items/Item.cs | 53 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs index 42c56e245..ec2473f1e 100644 --- a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs +++ b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework.Graphics; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -461,6 +462,11 @@ namespace Barotrauma private void TrySendNetworkUpdate(ISerializableEntity entity, SerializableProperty property) { + if (entity is ItemComponent) + { + entity = ((ItemComponent)entity).Item; + } + if (GameMain.Server != null) { IServerSerializable serverSerializable = entity as IServerSerializable; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index e10e7b72b..82836b977 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1409,6 +1409,39 @@ namespace Barotrauma { msg.Write((bool)value); } + else if (value is Color) + { + Color color = (Color)value; + msg.Write(color.R); + msg.Write(color.G); + msg.Write(color.B); + msg.Write(color.A); + } + else if (value is Vector2) + { + msg.Write(((Vector2)value).X); + msg.Write(((Vector2)value).Y); + } + else if (value is Vector3) + { + msg.Write(((Vector3)value).X); + msg.Write(((Vector3)value).Y); + msg.Write(((Vector3)value).Z); + } + else if (value is Vector4) + { + msg.Write(((Vector4)value).X); + msg.Write(((Vector4)value).Y); + msg.Write(((Vector4)value).Z); + msg.Write(((Vector4)value).W); + } + else if (value is Rectangle) + { + msg.Write(((Rectangle)value).X); + msg.Write(((Rectangle)value).Y); + msg.Write(((Rectangle)value).Width); + msg.Write(((Rectangle)value).Height); + } else { throw new System.NotImplementedException("Serializing item properties of the type \"" + value.GetType() + "\" not supported"); @@ -1446,6 +1479,26 @@ namespace Barotrauma { property.TrySetValue(msg.ReadBoolean()); } + else if (type == typeof(Color)) + { + property.TrySetValue(new Color(msg.ReadByte(), msg.ReadByte(),msg.ReadByte(),msg.ReadByte())); + } + else if (type == typeof(Vector2)) + { + property.TrySetValue(new Vector2(msg.ReadFloat(), msg.ReadFloat())); + } + else if (type == typeof(Vector3)) + { + property.TrySetValue(new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat())); + } + else if (type == typeof(Vector4)) + { + property.TrySetValue(new Vector4(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat())); + } + else if (type == typeof(Rectangle)) + { + property.TrySetValue(new Vector4(msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32())); + } else { return;