mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 16:48:30 +00:00
提交新概念 Tile从服务器
This commit is contained in:
28
JNFrame2/Assets/Scripts/Game/Data/EDBossDataSystem.cs
Normal file
28
JNFrame2/Assets/Scripts/Game/Data/EDBossDataSystem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
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
|
||||
@@ -25,16 +25,8 @@ namespace Game.JNGState.Logic.Data
|
||||
public class EDNodeData : GDataBase<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDNodeData(EDNode node) : base(node)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNode>
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
||||
@@ -44,21 +36,6 @@ namespace Game.JNGState.Logic.Data
|
||||
public override JNTileContext<EDNode> NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDNodeData;
|
||||
|
||||
public override Dictionary<ulong, EDNodeData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, EDNodeData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
if (nodes.ContainsKey(child.Id))
|
||||
{
|
||||
Debug.Log($"[EDNodeDataSystem] 出错 发现重复Key");
|
||||
return;
|
||||
}
|
||||
nodes.Add(child.Id,new EDNodeData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
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
|
||||
{
|
||||
@@ -23,13 +18,10 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public class EDPlayerData : GDataBase<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
public EDPlayerData()
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
}
|
||||
|
||||
public EDPlayerData(EDPlayer node) : base(node)
|
||||
{
|
||||
Value.Auth = node.Controller.Auth;
|
||||
base.BindEntity(entity);
|
||||
Value.Auth = Node.Controller.Auth;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
@@ -58,7 +50,7 @@ namespace Game.JNGState.Logic.Data
|
||||
}
|
||||
|
||||
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayer>
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
|
||||
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
||||
@@ -69,17 +61,6 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public override JNTileContext<EDPlayer> NodeContext => Contexts.GetContext<EDPlayerContext>();
|
||||
|
||||
|
||||
public override Dictionary<ulong, EDPlayerData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, EDPlayerData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
nodes.Add(child.Id,new EDPlayerData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using AppGame;
|
||||
using AppGame.Systems.CServer;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Entity;
|
||||
@@ -10,6 +14,7 @@ using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
@@ -27,22 +32,19 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public N Node => Entity as N;
|
||||
|
||||
public override bool IsHost => Node is not null && Node.IsHost;
|
||||
|
||||
public GDataBase()
|
||||
{
|
||||
}
|
||||
|
||||
public GDataBase(N node)
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
Id = node.Id;
|
||||
base.BindEntity(entity);
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
x = Node.Position.x.rawValue,
|
||||
y = Node.Position.y.rawValue,
|
||||
z = Node.Position.z.rawValue,
|
||||
};
|
||||
BindEntity(node);
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
@@ -54,7 +56,8 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public sealed override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
// return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
return ToUtil.ObjectToBytes(Value);
|
||||
}
|
||||
|
||||
public sealed override byte[] GetByteDifference(ISData diffValue = null)
|
||||
@@ -62,7 +65,8 @@ namespace Game.JNGState.Logic.Data
|
||||
var diff = GetDifference(diffValue);
|
||||
if (diff is not null)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(diff));
|
||||
// return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(diff));
|
||||
return ToUtil.ObjectToBytes(diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -85,7 +89,8 @@ namespace Game.JNGState.Logic.Data
|
||||
public sealed override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
// var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
var value = ToUtil.BytesToObject<T>(bytes);
|
||||
UData(value);
|
||||
}
|
||||
|
||||
@@ -104,28 +109,54 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
}
|
||||
|
||||
public abstract class GDataBaseSystem<T,E> : STileDataSystem<T,E> where T : ISTileData,new() where E : JNTileEntity, new()
|
||||
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 OnSendUBytes(Dictionary<ulong, byte[]> bytes)
|
||||
public override Dictionary<ulong, T> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, T>();
|
||||
NodeContext.GetHostEntities().ForEach(child =>
|
||||
{
|
||||
var entity = new T();
|
||||
entity.BindEntity(child);
|
||||
nodes.Add(child.Id,entity);
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
JNStateItemData data = new JNStateItemData();
|
||||
data.NetID = NetID;
|
||||
|
||||
public override void OnSendAllData(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
JNStateItemData player = new JNStateItemData(); //玩家状态数据
|
||||
player.NetID = NetID;
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
data.Messages.Add(byteItem.Key,new JNStateData()
|
||||
var data = new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
});
|
||||
};
|
||||
player.Messages.Add(byteItem.Key,data);
|
||||
}
|
||||
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
{
|
||||
EDNodeData = 0,
|
||||
EDPlayerData = 1,
|
||||
EDBossData = 2,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user