Separate interfaces for entities that the clients/server can send updates for (+ placeholder implementations)
May or may not be useful
This commit is contained in:
@@ -151,6 +151,7 @@
|
|||||||
<Compile Include="Source\Networking\ChatMessage.cs" />
|
<Compile Include="Source\Networking\ChatMessage.cs" />
|
||||||
<Compile Include="Source\Networking\Client.cs" />
|
<Compile Include="Source\Networking\Client.cs" />
|
||||||
<Compile Include="Source\Networking\GameServerLogin.cs" />
|
<Compile Include="Source\Networking\GameServerLogin.cs" />
|
||||||
|
<Compile Include="Source\Networking\INetSerializable.cs" />
|
||||||
<Compile Include="Source\Networking\NetBufferExtensions.cs" />
|
<Compile Include="Source\Networking\NetBufferExtensions.cs" />
|
||||||
<Compile Include="Source\Networking\NetConfig.cs" />
|
<Compile Include="Source\Networking\NetConfig.cs" />
|
||||||
<Compile Include="Source\Networking\NetStats.cs" />
|
<Compile Include="Source\Networking\NetStats.cs" />
|
||||||
|
|||||||
@@ -15,12 +15,18 @@ using System.Xml.Linq;
|
|||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
|
|
||||||
class Character : Entity, IDamageable, IPropertyObject
|
class Character : Entity, IDamageable, IPropertyObject, IClientSerializable, IServerSerializable
|
||||||
{
|
{
|
||||||
public static List<Character> CharacterList = new List<Character>();
|
public static List<Character> CharacterList = new List<Character>();
|
||||||
|
|
||||||
public static bool DisableControls;
|
public static bool DisableControls;
|
||||||
|
|
||||||
|
private ushort netStateID;
|
||||||
|
public ushort NetStateID
|
||||||
|
{
|
||||||
|
get { return netStateID; }
|
||||||
|
}
|
||||||
|
|
||||||
//the Character that the player is currently controlling
|
//the Character that the player is currently controlling
|
||||||
private static Character controlled;
|
private static Character controlled;
|
||||||
|
|
||||||
@@ -1567,5 +1573,25 @@ namespace Barotrauma
|
|||||||
if (AnimController!=null) AnimController.Remove();
|
if (AnimController!=null) AnimController.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ClientWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
//TODO: write inputs
|
||||||
|
}
|
||||||
|
public virtual void ServerRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
//TODO: read inputs
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ServerWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
//TODO: write position, health, etc
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void ClientRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
//TODO: read positions health, etc
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Barotrauma.Items.Components
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The base class for components holding the different functionalities of the item
|
/// The base class for components holding the different functionalities of the item
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class ItemComponent : IPropertyObject
|
class ItemComponent : IPropertyObject, IClientSerializable, IServerSerializable
|
||||||
{
|
{
|
||||||
protected Item item;
|
protected Item item;
|
||||||
|
|
||||||
@@ -74,6 +74,12 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
private string msg;
|
private string msg;
|
||||||
|
|
||||||
|
protected ushort netStateID;
|
||||||
|
public ushort NetStateID
|
||||||
|
{
|
||||||
|
get { return netStateID; }
|
||||||
|
}
|
||||||
|
|
||||||
[HasDefaultValue(0.0f, false)]
|
[HasDefaultValue(0.0f, false)]
|
||||||
public float PickingTime
|
public float PickingTime
|
||||||
{
|
{
|
||||||
@@ -577,22 +583,6 @@ namespace Barotrauma.Items.Components
|
|||||||
return (average+100.0f)/2.0f;
|
return (average+100.0f)/2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public bool CheckFailure(Character Character)
|
|
||||||
//{
|
|
||||||
// foreach (Skill skill in requiredSkills)
|
|
||||||
// {
|
|
||||||
// int characterLevel = Character.GetSkillLevel(skill.Name);
|
|
||||||
// if (characterLevel > skill.Level) continue;
|
|
||||||
|
|
||||||
// item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, Character);
|
|
||||||
// //Item.ApplyStatusEffects();
|
|
||||||
// return true;
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public bool HasRequiredContainedItems(bool addMessage)
|
public bool HasRequiredContainedItems(bool addMessage)
|
||||||
{
|
{
|
||||||
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
|
List<RelatedItem> requiredContained = requiredItems.FindAll(ri=> ri.Type == RelatedItem.RelationType.Contained);
|
||||||
@@ -668,6 +658,12 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ClientWrite(NetOutgoingMessage msg) { }
|
||||||
|
public virtual void ServerRead(NetIncomingMessage msg) { }
|
||||||
|
|
||||||
|
public virtual void ServerWrite(NetOutgoingMessage msg) { }
|
||||||
|
public virtual void ClientRead(NetIncomingMessage msg) { }
|
||||||
|
|
||||||
public virtual XElement Save(XElement parentElement)
|
public virtual XElement Save(XElement parentElement)
|
||||||
{
|
{
|
||||||
XElement componentElement = new XElement(name);
|
XElement componentElement = new XElement(name);
|
||||||
@@ -681,26 +677,6 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
ObjectProperty.SaveProperties(this, componentElement);
|
ObjectProperty.SaveProperties(this, componentElement);
|
||||||
|
|
||||||
//var saveProperties = ObjectProperty.GetProperties<Saveable>(this);
|
|
||||||
//foreach (var property in saveProperties)
|
|
||||||
//{
|
|
||||||
// object value = property.GetValue();
|
|
||||||
// if (value == null) continue;
|
|
||||||
|
|
||||||
// bool dontSave = false;
|
|
||||||
// foreach (var ini in property.Attributes.OfType<Initable>())
|
|
||||||
// {
|
|
||||||
// if (ini.defaultValue != value) continue;
|
|
||||||
|
|
||||||
// dontSave = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (dontSave) continue;
|
|
||||||
|
|
||||||
// componentElement.Add(new XAttribute(property.Name.ToLower(), value));
|
|
||||||
//}
|
|
||||||
|
|
||||||
parentElement.Add(componentElement);
|
parentElement.Add(componentElement);
|
||||||
return componentElement;
|
return componentElement;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Barotrauma
|
|||||||
OnImpact
|
OnImpact
|
||||||
}
|
}
|
||||||
|
|
||||||
class Item : MapEntity, IDamageable, IPropertyObject
|
class Item : MapEntity, IDamageable, IPropertyObject, IServerSerializable
|
||||||
{
|
{
|
||||||
public static List<Item> ItemList = new List<Item>();
|
public static List<Item> ItemList = new List<Item>();
|
||||||
private ItemPrefab prefab;
|
private ItemPrefab prefab;
|
||||||
@@ -55,6 +55,12 @@ namespace Barotrauma
|
|||||||
//a dictionary containing lists of the status effects in all the components of the item
|
//a dictionary containing lists of the status effects in all the components of the item
|
||||||
private Dictionary<ActionType, List<StatusEffect>> statusEffectLists;
|
private Dictionary<ActionType, List<StatusEffect>> statusEffectLists;
|
||||||
|
|
||||||
|
private ushort netStateID;
|
||||||
|
public ushort NetStateID
|
||||||
|
{
|
||||||
|
get { return netStateID; }
|
||||||
|
}
|
||||||
|
|
||||||
public readonly Dictionary<string, ObjectProperty> properties;
|
public readonly Dictionary<string, ObjectProperty> properties;
|
||||||
public Dictionary<string, ObjectProperty> ObjectProperties
|
public Dictionary<string, ObjectProperty> ObjectProperties
|
||||||
{
|
{
|
||||||
@@ -1383,12 +1389,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Drop(Character dropper = null)
|
public void Drop(Character dropper = null)
|
||||||
{
|
{
|
||||||
//if (dropper == Character.Controlled)
|
|
||||||
// new NetworkEvent(NetworkEventType.DropItem, ID, true);
|
|
||||||
|
|
||||||
|
|
||||||
//if (dropper != null) GameServer.Log(dropper.Name + " dropped " + Name, Color.Orange);
|
|
||||||
|
|
||||||
foreach (ItemComponent ic in components) ic.Drop(dropper);
|
foreach (ItemComponent ic in components) ic.Drop(dropper);
|
||||||
|
|
||||||
if (Container != null) Container.RemoveContained(this);
|
if (Container != null) Container.RemoveContained(this);
|
||||||
@@ -1515,6 +1515,9 @@ namespace Barotrauma
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ServerWrite(NetOutgoingMessage msg) { }
|
||||||
|
public void ClientRead(NetIncomingMessage msg) { }
|
||||||
|
|
||||||
public static void Load(XElement element, Submarine submarine)
|
public static void Load(XElement element, Submarine submarine)
|
||||||
{
|
{
|
||||||
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
|
string rectString = ToolBox.GetAttributeString(element, "rect", "0,0,0,0");
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public int GapIndex;
|
public int GapIndex;
|
||||||
|
|
||||||
public float lastSentDamage;
|
//public float lastSentDamage;
|
||||||
|
|
||||||
public bool isHighLighted;
|
public bool isHighLighted;
|
||||||
public ConvexHull hull;
|
public ConvexHull hull;
|
||||||
@@ -41,7 +41,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Structure : MapEntity, IDamageable
|
class Structure : MapEntity, IDamageable, IServerSerializable
|
||||||
{
|
{
|
||||||
public static int wallSectionSize = 100;
|
public static int wallSectionSize = 100;
|
||||||
public static List<Structure> WallList = new List<Structure>();
|
public static List<Structure> WallList = new List<Structure>();
|
||||||
@@ -58,7 +58,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
bool isHorizontal;
|
bool isHorizontal;
|
||||||
|
|
||||||
public float lastUpdate;
|
private ushort netStateID;
|
||||||
|
public ushort NetStateID
|
||||||
|
{
|
||||||
|
get { return netStateID; }
|
||||||
|
}
|
||||||
|
|
||||||
public override Sprite Sprite
|
public override Sprite Sprite
|
||||||
{
|
{
|
||||||
@@ -570,10 +574,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (!MathUtils.IsValid(damage)) return;
|
if (!MathUtils.IsValid(damage)) return;
|
||||||
|
|
||||||
if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage)>5.0f)
|
//if (damage != sections[sectionIndex].damage && Math.Abs(sections[sectionIndex].lastSentDamage - damage) > 5.0f)
|
||||||
{
|
//{
|
||||||
//sections[sectionIndex].lastSentDamage = damage;
|
// sections[sectionIndex].lastSentDamage = damage;
|
||||||
}
|
//}
|
||||||
|
|
||||||
if (damage < prefab.MaxHealth*0.5f)
|
if (damage < prefab.MaxHealth*0.5f)
|
||||||
{
|
{
|
||||||
@@ -685,6 +689,25 @@ namespace Barotrauma
|
|||||||
return newBody;
|
return newBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ServerWrite(NetOutgoingMessage msg)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sections.Length; i++)
|
||||||
|
{
|
||||||
|
msg.WriteRangedSingle(sections[i].damage / Health, 0.0f, 1.0f, 8);
|
||||||
|
|
||||||
|
//sections[i].lastSentDamage = sections[i].damage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClientRead(NetIncomingMessage msg)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sections.Count(); i++)
|
||||||
|
{
|
||||||
|
float damage = msg.ReadRangedSingle(0.0f, 1.0f, 8) * Health;
|
||||||
|
|
||||||
|
SetDamage(i, damage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override XElement Save(XElement parentElement)
|
public override XElement Save(XElement parentElement)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Lidgren.Network;
|
||||||
|
|
||||||
|
namespace Barotrauma.Networking
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for entities that the clients can send information of to the server
|
||||||
|
/// </summary>
|
||||||
|
interface IClientSerializable
|
||||||
|
{
|
||||||
|
ushort NetStateID { get; }
|
||||||
|
|
||||||
|
void ClientWrite(NetOutgoingMessage msg);
|
||||||
|
void ServerRead(NetIncomingMessage msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for entities that the server can send information of to the clients
|
||||||
|
/// </summary>
|
||||||
|
interface IServerSerializable
|
||||||
|
{
|
||||||
|
ushort NetStateID { get; }
|
||||||
|
|
||||||
|
void ServerWrite(NetOutgoingMessage msg);
|
||||||
|
void ClientRead(NetIncomingMessage msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user