mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交bug 艰难先这样
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using AppGame;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public abstract class DStateDataSystem<T,E> : STileDataSystem<T,E> where T : ISTileData,new() where E : JNTileEntity, new()
|
||||
{
|
||||
protected DStateDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnSendUBytes(Dictionary<long, byte[]> bytes)
|
||||
{
|
||||
|
||||
JNStateItemData data = new JNStateItemData();
|
||||
data.NetID = NetID;
|
||||
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
data.Messages.Add(byteItem.Key,new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
});
|
||||
}
|
||||
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AppGame;
|
||||
using DotRecast.Core.Collections;
|
||||
using Entitas;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
@@ -14,73 +15,26 @@ using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class EDNodeValue
|
||||
public class EDNodeValue : GDataValue
|
||||
{
|
||||
public DValuePosition Position = null;
|
||||
|
||||
}
|
||||
|
||||
public class EDNodeData : ISTileData
|
||||
public class EDNodeData : GDataBase<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public readonly EDNodeValue Value = new ();
|
||||
|
||||
private readonly EDNode _data;
|
||||
public override bool IsHost => _data is not null && _data.IsHost;
|
||||
|
||||
|
||||
public EDNodeData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDNodeData(EDNode node){
|
||||
Id = node.Id;
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
};
|
||||
_data = node;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
public EDNodeData(EDNode node) : base(node)
|
||||
{
|
||||
var node = data as EDNodeData;
|
||||
if (node is null) return false;
|
||||
return Value.Position.Equals(node.Value.Position);
|
||||
}
|
||||
|
||||
public override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
}
|
||||
|
||||
public override byte[] GetByteDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as EDNodeData;
|
||||
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
||||
|
||||
var value = new EDNodeValue();
|
||||
|
||||
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
||||
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生效字节
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<EDNodeValue>(Encoding.UTF8.GetString(bytes));
|
||||
if (value.Position is not null) Value.Position = value.Position;
|
||||
}
|
||||
|
||||
}
|
||||
public class EDNodeDataSystem : DStateDataSystem<EDNodeData,EDNode>
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
||||
|
@@ -16,77 +16,49 @@ namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class EDPlayerValue
|
||||
public class EDPlayerValue : GDataValue
|
||||
{
|
||||
public int? Auth = null;
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public class EDPlayerData : ISTileData
|
||||
public class EDPlayerData : GDataBase<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
|
||||
public readonly EDPlayerValue Value = new ();
|
||||
private readonly EDPlayer _data;
|
||||
public override bool IsHost => _data is not null && _data.IsHost;
|
||||
|
||||
public EDPlayerData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDPlayerData(EDPlayer node){
|
||||
Id = node.Id;
|
||||
public EDPlayerData(EDPlayer node) : base(node)
|
||||
{
|
||||
Value.Auth = node.Controller.Auth;
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
};
|
||||
_data = node;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
{
|
||||
var node = data as EDPlayerData;
|
||||
if (node is null) return false;
|
||||
return Value.Position.Equals(node.Value.Position)
|
||||
&& Value.Auth.Equals(node.Value.Auth);
|
||||
return base.IsEquals(data) && Value.Auth.Equals(node.Value.Auth);
|
||||
}
|
||||
|
||||
public override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
}
|
||||
|
||||
public override byte[] GetByteDifference(ISData diffValue = null)
|
||||
public override EDPlayerValue GetDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as EDPlayerData;
|
||||
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
||||
var value = base.GetDifference(diffValue);
|
||||
if (value is null || diff is null) return null;
|
||||
|
||||
var value = new EDPlayerValue();
|
||||
|
||||
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
||||
if (diff.Value.Auth is not null) value.Auth = diff.Value.Auth;
|
||||
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生效字节
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override void UByte(byte[] bytes)
|
||||
public override void UData(EDPlayerValue data)
|
||||
{
|
||||
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<EDPlayerValue>(Encoding.UTF8.GetString(bytes));
|
||||
if (value.Position is not null) Value.Position = value.Position;
|
||||
if (value.Auth is not null) Value.Auth = value.Auth;
|
||||
|
||||
base.UData(data);
|
||||
if (data.Auth is not null) Value.Auth = data.Auth;
|
||||
}
|
||||
}
|
||||
public class EDPlayerDataSystem : DStateDataSystem<EDPlayerData,EDPlayer>
|
||||
|
||||
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayer>
|
||||
{
|
||||
|
||||
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
||||
|
132
JNFrame2/Assets/Scripts/Game/Data/GDataBaseSystem.cs
Normal file
132
JNFrame2/Assets/Scripts/Game/Data/GDataBaseSystem.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AppGame;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class GDataValue
|
||||
{
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public class GDataBase<Self,T,N> : ISTileData where Self : GDataBase<Self,T,N> where T : GDataValue,new() where N : JNTileEntity
|
||||
{
|
||||
|
||||
public readonly T Value = new ();
|
||||
|
||||
public N Node => Entity as N;
|
||||
|
||||
public override bool IsHost => Node is not null && Node.IsHost;
|
||||
|
||||
public GDataBase()
|
||||
{
|
||||
}
|
||||
|
||||
public GDataBase(N node)
|
||||
{
|
||||
Id = node.Id;
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
};
|
||||
BindEntity(node);
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
{
|
||||
var node = data as Self;
|
||||
if (node is null) return false;
|
||||
return Value.Position.Equals(node.Value.Position);
|
||||
}
|
||||
|
||||
public sealed override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
}
|
||||
|
||||
public sealed override byte[] GetByteDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = GetDifference(diffValue);
|
||||
if (diff is not null)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(diff));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual T GetDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as Self;
|
||||
if (diff is null || IsEquals(diffValue)) return null;
|
||||
|
||||
var value = new T();
|
||||
|
||||
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public sealed override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
UData(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新数据
|
||||
/// </summary>
|
||||
public virtual void UData(T data)
|
||||
{
|
||||
if (data.Position is not null) Value.Position = data.Position;
|
||||
}
|
||||
|
||||
public override LVector3 GetDataPosition()
|
||||
{
|
||||
return Value.Position.ToLVector3();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class GDataBaseSystem<T,E> : STileDataSystem<T,E> where T : ISTileData,new() where E : JNTileEntity, new()
|
||||
{
|
||||
protected GDataBaseSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnSendUBytes(Dictionary<long, byte[]> bytes)
|
||||
{
|
||||
|
||||
JNStateItemData data = new JNStateItemData();
|
||||
data.NetID = NetID;
|
||||
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
data.Messages.Add(byteItem.Key,new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
});
|
||||
}
|
||||
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user