mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交
This commit is contained in:
3
JNFrame2/Assets/Scripts/Samples/Game/Data/State.meta
Normal file
3
JNFrame2/Assets/Scripts/Samples/Game/Data/State.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cecc61f462364f198db69cf70c6c557d
|
||||
timeCreated: 1726941153
|
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using JNGame.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
[Serializable]
|
||||
public class DValuePosition
|
||||
{
|
||||
public long x;
|
||||
public long y;
|
||||
public long z;
|
||||
|
||||
public Vector3 ToVector3()
|
||||
{
|
||||
return new Vector3()
|
||||
{
|
||||
x = new LFloat(true,x).ToFloat(),
|
||||
y = new LFloat(true,y).ToFloat(),
|
||||
z = new LFloat(true,z).ToFloat(),
|
||||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is not DValuePosition old) return false;
|
||||
return old.x == x && old.y == y && old.z == z;
|
||||
}
|
||||
|
||||
public LVector3 ToLVector3()
|
||||
{
|
||||
return new LVector3(new LFloat(true,x), new LFloat(true,y), new LFloat(true,z));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e710dfde494c4e8eb582ad2c45b3c12a
|
||||
timeCreated: 1722822666
|
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using Game.Logic.Entity.Nodes;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
public class EDBossData : GDataBase<EDBossData,EDNodeValue,EDBoss>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class EDBossDataSystem : GDataBaseSystem<EDBossData,EDNodeValue,EDBoss>
|
||||
{
|
||||
public EDBossDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDBossData;
|
||||
public override JNTileContext<EDBoss> NodeContext => Contexts.GetContext<EDBossContext>();
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 800b600f0af8416c9f450a329385cfcb
|
||||
timeCreated: 1724675405
|
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AppGame;
|
||||
using DotRecast.Core.Collections;
|
||||
using Entitas;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using Game.Logic.Entity.Nodes;
|
||||
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 EDNodeValue : GDataValue
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class EDNodeData : GDataBase<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
}
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override JNTileContext<EDNode> NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDNodeData;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f1c12a776364a24a4e8d1b1372bed25
|
||||
timeCreated: 1721101714
|
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using Game.Logic.Entity.Nodes;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public enum EDPlayerValueCode : int
|
||||
{
|
||||
Auth = 201
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EDPlayerValue : GDataValue
|
||||
{
|
||||
public int? Auth = null;
|
||||
}
|
||||
|
||||
public class EDPlayerData : GDataBase<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
base.BindEntity(entity);
|
||||
Value.Auth = Node.Controller.Auth;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
{
|
||||
var node = data as EDPlayerData;
|
||||
if (node is null) return false;
|
||||
return base.IsEquals(data) && Value.Auth.Equals(node.Value.Auth);
|
||||
}
|
||||
|
||||
public override void Difference(EDPlayerValue value, EDPlayerValue diff)
|
||||
{
|
||||
base.Difference(value, diff);
|
||||
if (diff.Auth is not null && !Equals(Value.Auth, diff.Auth)) value.Auth = diff.Auth;
|
||||
}
|
||||
|
||||
public override void UData(EDPlayerValue data)
|
||||
{
|
||||
base.UData(data);
|
||||
if (data.Auth is not null)
|
||||
{
|
||||
Value.Auth = data.Auth;
|
||||
WriteUpdate((int)EDPlayerValueCode.Auth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
|
||||
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDPlayerData;
|
||||
|
||||
public override JNTileContext<EDPlayer> NodeContext => Contexts.GetContext<EDPlayerContext>();
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7aabf53b2ce4c838b5a5812493a625c
|
||||
timeCreated: 1722256803
|
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AppGame;
|
||||
using AppGame.Systems.CServer;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Util;
|
||||
using TouchSocket.Core;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
public enum GDataValueCode : int
|
||||
{
|
||||
Position = 101
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class GDataValue
|
||||
{
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public abstract class IGDataBase : ISTileData
|
||||
{
|
||||
|
||||
//计入修改
|
||||
public readonly ConcurrentList<int> WriteCodes = new();
|
||||
|
||||
/// <summary>
|
||||
/// 计入修改
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
public void WriteUpdate(int code)
|
||||
{
|
||||
if (WriteCodes.Contains(code)) return;
|
||||
WriteCodes.Add(code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class GDataBase<Self,T,N> : IGDataBase 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 GDataBase()
|
||||
{
|
||||
}
|
||||
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
base.BindEntity(entity);
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = Node.Position.x.rawValue,
|
||||
y = Node.Position.y.rawValue,
|
||||
z = Node.Position.z.rawValue,
|
||||
};
|
||||
}
|
||||
|
||||
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));
|
||||
return ToUtil.ObjectToBytes(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));
|
||||
return ToUtil.ObjectToBytes(diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
public T GetDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as Self;
|
||||
if (diff is null || IsEquals(diffValue)) return null;
|
||||
|
||||
var value = new T();
|
||||
|
||||
Difference(value,diff.Value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public virtual void Difference(T value, T diff)
|
||||
{
|
||||
if (diff.Position is not null && !Equals(Value.Position, diff.Position)) value.Position = diff.Position;
|
||||
}
|
||||
|
||||
public sealed override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
// var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
var value = ToUtil.BytesToObject<T>(bytes);
|
||||
UData(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新数据
|
||||
/// </summary>
|
||||
public virtual void UData(T data)
|
||||
{
|
||||
if (data.Position is not null)
|
||||
{
|
||||
Value.Position = data.Position;
|
||||
WriteUpdate((int)GDataValueCode.Position);
|
||||
}
|
||||
}
|
||||
|
||||
public override LVector3 GetDataPosition()
|
||||
{
|
||||
return Value.Position.ToLVector3();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class GDataBaseSystem<T,V,E> : STileDataSystem<T,E> where T : GDataBase<T,V,E>,new() where E : JNTileEntity, new() where V : GDataValue,new()
|
||||
{
|
||||
protected GDataBaseSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnSendAllData(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
JNStateItemData player = new JNStateItemData(); //玩家状态数据
|
||||
player.NetID = NetID;
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
var data = new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
};
|
||||
player.Messages.Add(byteItem.Key,data);
|
||||
}
|
||||
//给玩家发送状态信息
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,player,client => App.Server.Roles.TryGetValue(client.Id,out var role) && role == JNGClientRole.Player);
|
||||
}
|
||||
|
||||
public override void OnSendSlaveData(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
JNStateItemData slave = new JNStateItemData(); //玩家状态数据
|
||||
slave.NetID = NetID;
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
var data = new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
};
|
||||
slave.Messages.Add(byteItem.Key,data);
|
||||
}
|
||||
//给从服务器发送状态信息
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,slave,client => App.Server.Roles.TryGetValue(client.Id,out var role) && role == JNGClientRole.SlaveServer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aadb74e9a104400fa1b865990faf8315
|
||||
timeCreated: 1721997279
|
@@ -0,0 +1,9 @@
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public enum NetDataEnum : int
|
||||
{
|
||||
EDNodeData = 0,
|
||||
EDPlayerData = 1,
|
||||
EDBossData = 2,
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e77dac300e7430c8ceebaf85db683c4
|
||||
timeCreated: 1721959245
|
Reference in New Issue
Block a user