mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
113 lines
3.3 KiB
C#
113 lines
3.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
using DotRecast.Core.Collections;
|
|||
|
using Entitas;
|
|||
|
using Game.JNGFrame.Logic.Entity;
|
|||
|
using Game.JNGFrame.Logic.Entity.Contexts;
|
|||
|
using JNGame.Math;
|
|||
|
using JNGame.Sync.State.Tile.Entity;
|
|||
|
using JNGame.Sync.System;
|
|||
|
using JNGame.Sync.System.Data;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Game.JNGState.Logic.Data
|
|||
|
{
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class EDPlayerValue
|
|||
|
{
|
|||
|
public int? Auth = null;
|
|||
|
public DValuePosition Position = null;
|
|||
|
}
|
|||
|
|
|||
|
public class EDPlayerData : ISTileData
|
|||
|
{
|
|||
|
|
|||
|
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;
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
public override byte[] GetByte()
|
|||
|
{
|
|||
|
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
|||
|
}
|
|||
|
|
|||
|
public override byte[] GetByteDifference(ISData diffValue = null)
|
|||
|
{
|
|||
|
var diff = diffValue as EDPlayerData;
|
|||
|
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
|||
|
|
|||
|
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));
|
|||
|
}
|
|||
|
|
|||
|
/// <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<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;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
public class EDPlayerDataSystem : DStateDataSystem<EDPlayerData,EDPlayer>
|
|||
|
{
|
|||
|
|
|||
|
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public override int NetID => (int)NetDataEnum.EDPlayerData;
|
|||
|
|
|||
|
public override JNTileContext<EDPlayer> NodeContext => Contexts.GetContext<EDPlayerContext>();
|
|||
|
|
|||
|
|
|||
|
public override Dictionary<long, EDPlayerData> GetLatest()
|
|||
|
{
|
|||
|
var nodes = new Dictionary<long, EDPlayerData>();
|
|||
|
NodeContext.GetEntities().ForEach(child =>
|
|||
|
{
|
|||
|
nodes.Add(child.Id,new EDPlayerData(child));
|
|||
|
});
|
|||
|
return nodes;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|