This commit is contained in:
PC-20230316NUNE\Administrator
2024-09-29 20:30:29 +08:00
parent c5700ce655
commit a16d51d033
151 changed files with 69 additions and 63 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 659ee015a1d7417d820cb34271c8c8ba
timeCreated: 1721188292

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cecc61f462364f198db69cf70c6c557d
timeCreated: 1726941153

View File

@@ -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));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e710dfde494c4e8eb582ad2c45b3c12a
timeCreated: 1722822666

View File

@@ -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>();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 800b600f0af8416c9f450a329385cfcb
timeCreated: 1724675405

View File

@@ -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;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f1c12a776364a24a4e8d1b1372bed25
timeCreated: 1721101714

View File

@@ -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>();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f7aabf53b2ce4c838b5a5812493a625c
timeCreated: 1722256803

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aadb74e9a104400fa1b865990faf8315
timeCreated: 1721997279

View File

@@ -0,0 +1,9 @@
namespace Game.JNGState.Logic.Data
{
public enum NetDataEnum : int
{
EDNodeData = 0,
EDPlayerData = 1,
EDBossData = 2,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2e77dac300e7430c8ceebaf85db683c4
timeCreated: 1721959245

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e904e6b6d5f5480f8a1bd0c31efb43c7
timeCreated: 1721635877

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using JNGame.Sync.System.View;
using JNGame.Util.Types;
namespace Game.Input
{
public class DInputSystem : JNInputSystem
{
private KeyValue<Type, int> _tClass = new KeyValue<Type, int>();
protected override KeyValue<Type, int> TClass => _tClass;
protected override void OnInit()
{
base.OnInit();
_tClass.Add(typeof(IDWorld),0);
_tClass.Add(typeof(IDPlayer),1);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ff9df2dda66b4661b9c1459e93f9c56c
timeCreated: 1721638606

View File

@@ -0,0 +1,34 @@
using System;
using JNGame.Math;
using JNGame.Sync.System.View;
namespace Game.Input
{
public class IDPlayerMoveVector
{
public LFloat X;
public LFloat Y;
public LVector2 ToLVector2()
{
return new LVector2(X, Y);
}
}
/// <summary>
/// DPlayerSystem 的输入类
/// </summary>
[Serializable]
public class IDPlayer : JNInputJson
{
/// <summary>
/// 移动的向量
/// </summary>
public IDPlayerMoveVector? MoveVector;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 342bf3e39b8641a3a60be01d52293a32
timeCreated: 1722225398

View File

@@ -0,0 +1,12 @@
using JNGame.Math;
using JNGame.Sync.System.View;
namespace Game.Input
{
/// <summary>
/// DPlayerSystem 的输入类
/// </summary>
public class IDPlayer2 : JNInputJson
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: adc56bc7451447ddb670bb1e8edafb9c
timeCreated: 1722248435

View File

@@ -0,0 +1,29 @@
using System;
using JNGame.Sync.System.View;
namespace Game.Input
{
/// <summary>
/// DWorldSystem 的输入类
/// </summary>
[Serializable]
public class IDWorld : JNInputJson
{
/// <summary>
/// 创建球
/// </summary>
public bool IsAdd;
/// <summary>
/// 主角创建
/// </summary>
public bool IsPlayerCreate;
/// <summary>
/// Boss创建
/// </summary>
public bool IsBossCreate;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f2f47660de0d4e36b6b6a58f674fbc24
timeCreated: 1721635974

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b63cf61a85a24222952513854b17d4ec
timeCreated: 1712748558

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4f606ce125c442629b63f210beeabaa2
timeCreated: 1712734968

View File

@@ -0,0 +1,15 @@
using Entitas;
using Game.JNGFrame.Logic.Entity.Contexts;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity
{
public class EDContexts : JNTileContexts
{
public override IContext[] allContexts { get; } = { new EDNodeContext(),new EDPlayerContext(),new EDBossContext(), };
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dfdb770e32914215b20ea0b4722157cf
timeCreated: 1712736751

View File

@@ -0,0 +1,42 @@
using JNGame.Math;
using JNGame.Sync.Frame.Service;
using JNGame.Sync.State.Tile;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
using NotImplementedException = System.NotImplementedException;
namespace Game.Logic.Entity
{
public abstract class EDEntityBasis : JNTileEntity
{
public JNRandomSystem Random => Context.GetSync().GetSystem<JNRandomSystem>();
//获取当前权限瓦块随机点
public LVector3 GetTileRandom()
{
if (Context.GetSync() is JNSSTileServerService tileServer)
{
return new LVector3(
Random.Float(tileServer.MinContains.x,tileServer.MaxContains.x),
LFloat.Zero,
Random.Float(tileServer.MinContains.y,tileServer.MaxContains.y)
);
}
return LVector3.Down;
}
public override void TileSyncData(ISTileData data)
{
Transform.Position = data.GetDataPosition();
}
public override void OnTileSlaveExit()
{
base.OnTileSlaveExit();
//从服务器 - 实体移出后立即删除
Destroy();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b0f4f8b42fdc465b9ad60b8e574aa996
timeCreated: 1725096772

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f3cfa4711bbd4f9792fbc3070838c8f5
timeCreated: 1720855417

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ce99e4925cfe4cf6a4551f4bc4e07fdc
timeCreated: 1720749441

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0bc49819e5242139ad5104c369b8c82
timeCreated: 1720864794

View File

@@ -0,0 +1,131 @@
using System;
using DotRecast.Detour.Crowd;
using Game.Logic.System.Usual;
using JNGame.Math;
namespace Game.Logic.Entity.Nodes.Component.Components
{
/// <summary>
/// 移动组件
/// </summary>
public class EDMoveComponent : EDEntityComponent
{
public DMapSystem Map => GetSystem<DMapSystem>();
/// <summary>
/// 避障配置
/// </summary>
private DtCrowdAgentParams _info;
/// <summary>
/// 移动速度
/// </summary>
private LFloat _speed = LFloat.One;
public LFloat Speed
{
get => _speed;
set
{
_speed = value;
_info.maxSpeed = _speed;
_info.maxAcceleration = _info.maxSpeed * 4;
}
}
public LVector3 MoveTarget
{
get
{
DtCrowdAgent agent = Map.GetAgent(Entity.Id);
if (agent is null) return LVector3.Zero;
return new LVector3(agent.targetPos.X,agent.targetPos.Y,agent.targetPos.Z);
}
}
public override void OnSyncStart()
{
base.OnSyncStart();
_info = Map.GetAgentParams();
Speed = Speed;
AddAgent();
}
public override void OnTileEnter()
{
base.OnTileEnter();
AddAgent();
}
public override void OnTileExit()
{
base.OnTileExit();
DelAgent();
}
/// <summary>
/// 添加避障
/// </summary>
public void AddAgent()
{
if(IsHost) Map.AddAgent(Entity.Id,Entity.Position,_info);
}
/// <summary>
/// 删除避障
/// </summary>
public void DelAgent()
{
Map.DelAgent(Entity.Id);
}
/// <summary>
/// 设置位置
/// </summary>
/// <param name="spawn"></param>
public void SetPosition(LVector3 spawn)
{
Entity.Transform.Position = Map.GetNearbyPoints(spawn);
DelAgent();
AddAgent();
}
/// <summary>
/// 设置移动目标
/// </summary>
public void Go(LVector3 spawn)
{
Map.MoveAgent(Entity.Id, Map.GetNearbyPoints(spawn));
}
/// <summary>
/// 向量移动
/// </summary>
public void Vector(LVector2 vector)
{
Map.VectorMoveAgent(Entity.Id, vector * Speed);
}
public bool IsNearTarget()
{
if (MoveTarget == LVector3.Zero) return true;
DtCrowdAgent agent = Map.GetAgent(Entity.Id);
return EntityBasis.Transform.IsRange(MoveTarget, LFloat.L1 + agent.option.radius);
}
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
var npos = Map.GetAgent(Entity.Id).npos;
Entity.Transform.Position = new LVector3((LFloat)npos.X, (LFloat)npos.Y, (LFloat)npos.Z);
}
public override void OnSyncDestroy()
{
base.OnSyncDestroy();
DelAgent();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d0346ed1171e4add9c2dd1f43d7d13d7
timeCreated: 1720864691

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a0c80afea4d4209bb59b4725c030013
timeCreated: 1723013031

View File

@@ -0,0 +1,43 @@
using Game.Logic.Entity;
using Game.Logic.Entity.Nodes.Component;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Math;
using JNGame.Sync.State.Tile.Entity.Component;
namespace Game.JNGFrame.Logic.Entity.Controller
{
/// <summary>
/// Boss控制器
/// </summary>
public class EDBossController : EDEntityComponent
{
public EDMoveComponent Move => Entity.GetComponent<EDMoveComponent>();
public override void OnSyncStart()
{
base.OnSyncStart();
//Boss 同步到从服务器
TileEntity.IsSyncSlave = true;
Move.Speed = LFloat.L10;
}
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
// 到达目标则移动
if (Move.IsNearTarget())
{
Move.Go(EntityBasis.GetTileRandom());
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b3e21eba1a90402cbcf1c142b7c6b103
timeCreated: 1724723406

View File

@@ -0,0 +1,63 @@
using Game.Input;
using Game.Logic.Entity.Nodes.Component;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Math;
using UnityEngine;
namespace Game.JNGFrame.Logic.Entity.Controller
{
/// <summary>
/// 角色控制器
/// </summary>
public class EDPlayerController : EDEntityComponent
{
/// <summary>
/// 权限Id
/// </summary>
private int _auth;
public int Auth => _auth;
public DInputSystem Input => GetSystem<DInputSystem>();
public EDMoveComponent Move => Entity.GetComponent<EDMoveComponent>();
/// <summary>
/// 绑定权限
/// </summary>
/// <param name="id"></param>
public void AuthBind(int id)
{
_auth = id;
}
public override void OnSyncStart()
{
//Player 同步到从服务器
TileEntity.IsSyncSlave = true;
base.OnSyncStart();
Move.Speed = LFloat.L10;
}
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
OnMoveUpdate();
}
/// <summary>
/// 移动更新
/// </summary>
private void OnMoveUpdate()
{
if (Input.SInput<IDPlayer>(Auth) is not IDPlayer input || input.MoveVector is null) return;
Move.Vector(input.MoveVector.ToLVector2());
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d63a18dd1f04046ac493221c82130e8
timeCreated: 1723013044

View File

@@ -0,0 +1,11 @@
using JNGame.Sync.State.Tile.Entity.Component;
namespace Game.Logic.Entity.Nodes.Component
{
public class EDEntityComponent : JNTileComponent
{
public EDEntityBasis EntityBasis => Entity as EDEntityBasis;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c880d909098c44d59b5ec8d009dc1fe4
timeCreated: 1725097481

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 835547007d6f4d88a441f5c4e782b103
timeCreated: 1725097492

View File

@@ -0,0 +1,31 @@
using System;
using Game.JNGFrame.Logic.Entity.Controller;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Util.Types;
namespace Game.Logic.Entity.Nodes.Component.Lookup
{
public class EDBoosLookup : JNEntityLookup
{
//移动组件
public int Movement { get; set; }
public int Controller { get; set; }
protected override void BindIndex()
{
base.BindIndex();
Movement = Next();
Controller = Next();
}
protected override void BindType(KeyValue<int, Type> types)
{
base.BindType(types);
types.Add(Movement,typeof(EDMoveComponent));
types.Add(Controller,typeof(EDBossController));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3000f079bc5f4d72aa5d6b4145ac5e0e
timeCreated: 1724723017

View File

@@ -0,0 +1,27 @@
using System;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Util.Types;
namespace Game.Logic.Entity.Nodes.Component.Lookup
{
public class EDNodeLookup : JNEntityLookup
{
//移动组件
public int Movement { get; set; }
protected override void BindIndex()
{
base.BindIndex();
Movement = Next();
}
protected override void BindType(KeyValue<int, Type> types)
{
base.BindType(types);
types.Add(Movement,typeof(EDMoveComponent));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aeea4b9b15934aba9d557d99f16c4d3f
timeCreated: 1720749462

View File

@@ -0,0 +1,31 @@
using System;
using Game.JNGFrame.Logic.Entity.Controller;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Util.Types;
namespace Game.Logic.Entity.Nodes.Component.Lookup
{
public class EDPlayerLookup : JNEntityLookup
{
//移动组件
public int Movement { get; set; }
public int Controller { get; set; }
protected override void BindIndex()
{
base.BindIndex();
Movement = Next();
Controller = Next();
}
protected override void BindType(KeyValue<int, Type> types)
{
base.BindType(types);
types.Add(Movement,typeof(EDMoveComponent));
types.Add(Controller,typeof(EDPlayerController));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df072d4041fb497cb8122a7449c04455
timeCreated: 1722225086

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab58dfb4e61e45d587eb9695240e9cbc
timeCreated: 1712737231

View File

@@ -0,0 +1,19 @@
using Game.JNGFrame.Logic.Entity.Controller;
using Game.Logic.Entity.Nodes;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.Frame.Entity;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDBossContext : JNTileContext<EDBoss>
{
protected override EDBoss BindComponent(EDBoss entity)
{
base.BindComponent(entity);
entity.AddComponent<EDMoveComponent>();
entity.AddComponent<EDBossController>();
return entity;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dae9cf4b44914450b1624b40d7646190
timeCreated: 1724723007

View File

@@ -0,0 +1,17 @@
using Game.Logic.Entity.Nodes;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.Frame.Entity;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDNodeContext : JNTileContext<EDNode>
{
protected override EDNode BindComponent(EDNode entity)
{
base.BindComponent(entity);
entity.AddComponent<EDMoveComponent>();
return entity;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71e757d251804ce4b37ba605cbf54016
timeCreated: 1712737245

View File

@@ -0,0 +1,21 @@
using Entitas;
using Game.JNGFrame.Logic.Entity.Controller;
using Game.Logic.Entity.Nodes;
using Game.Logic.Entity.Nodes.Component.Components;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDPlayerContext : JNTileContext<EDPlayer>
{
protected override EDPlayer BindComponent(EDPlayer entity)
{
base.BindComponent(entity);
entity.AddComponent<EDMoveComponent>();
entity.AddComponent<EDPlayerController>();
return entity;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2358fccfc7ee4ab6b0ccdabc5e75060b
timeCreated: 1722225016

View File

@@ -0,0 +1,22 @@
using Game.JNGFrame.Logic.Entity.Controller;
using Game.JNGState.Logic.Data;
using Game.Logic.Entity.Nodes.Component.Components;
using Game.Logic.Entity.Nodes.Component.Lookup;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Sync.System.Data;
namespace Game.Logic.Entity.Nodes
{
public class EDBoss : EDEntityBasis
{
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public EDBossController Controller => CLookup.Query<EDBossController>(this);
public override JNEntityLookup NewCLookup()
{
return new EDBoosLookup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 473e297b1bcf4ff1ad73d3fd1de8c597
timeCreated: 1724675433

View File

@@ -0,0 +1,21 @@
using Game.JNGState.Logic.Data;
using Game.Logic.Entity.Nodes.Component.Components;
using Game.Logic.Entity.Nodes.Component.Lookup;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
namespace Game.Logic.Entity.Nodes
{
public class EDNode : EDEntityBasis
{
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public override JNEntityLookup NewCLookup()
{
return new EDNodeLookup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4c4bcab5b4174eda9afc6b994666a72f
timeCreated: 1712736545

View File

@@ -0,0 +1,30 @@
using Game.JNGFrame.Logic.Entity.Controller;
using Game.JNGState.Logic.Data;
using Game.Logic.Entity.Nodes.Component.Components;
using Game.Logic.Entity.Nodes.Component.Lookup;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
namespace Game.Logic.Entity.Nodes
{
public class EDPlayer : EDEntityBasis
{
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public EDPlayerController Controller => CLookup.Query<EDPlayerController>(this);
public override void TileSyncData(ISTileData data)
{
base.TileSyncData(data);
var nodeData = data as EDPlayerData;
Controller.AuthBind(nodeData.Value.Auth.Value);
}
public override JNEntityLookup NewCLookup()
{
return new EDPlayerLookup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 020606cd1a564efeb88ce4df7c6fce56
timeCreated: 1722225061

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66f9154d1a7c41e88a3c95d0408dc2cf
timeCreated: 1720863460

View File

@@ -0,0 +1,40 @@
using JNGame.Math;
using JNGame.Sync.Frame.Service;
using JNGame.Sync.State.Tile;
using JNGame.Sync.System;
namespace Game.Logic.System
{
public class DGBasisSystem : SLogicSystem
{
public JNRandomSystem Random => GetSystem<JNRandomSystem>();
//判断是否是Tile模式
public bool IsTile()
{
return Sync is JNSSTileServerService;
}
//获取当前权限瓦块随机点
public LVector3 GetTileRandom()
{
if (Sync is JNSSTileServerService tileServer)
{
return new LVector3(
Random.Float(tileServer.MinContains.x,tileServer.MaxContains.x),
LFloat.Zero,
Random.Float(tileServer.MinContains.y,tileServer.MaxContains.y)
);
}
return LVector3.Down;
}
/// <summary>
/// [状态同步生命周期] 玩家离开服务器 不在游戏线程中执行
/// </summary>
public virtual void OnPlayerExitServer(int auth){}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c42fd1121fb849b38dc7f94db9c3f3df
timeCreated: 1722861514

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: babf7d8ac075441b803a0078da31ce8a
timeCreated: 1724724193

View File

@@ -0,0 +1,41 @@
using DotRecast.Core.Collections;
using Game.Input;
using Game.JNGFrame.Logic.Entity;
using Game.JNGFrame.Logic.Entity.Contexts;
using Game.Logic.Entity.Nodes;
using JNGame.Math;
namespace Game.Logic.System.Logic
{
/// <summary>
/// Boss逻辑
/// </summary>
public class DBossSystem : DGBasisSystem
{
//Node 节点
public EDBoss[] Nodes => NodeContext.GetHostEntities();
public EDBossContext NodeContext => Contexts.GetContext<EDBossContext>();
public DInputSystem Input => GetSystem<DInputSystem>();
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
//创建Boss
GetSystem<DInputSystem>().SInput<IDWorld>().ForEach(child =>
{
var idWorld = (IDWorld)child.Value;
if (idWorld is { IsBossCreate: true })
{
var entity = NodeContext.CreateEntity();
entity.Move.SetPosition(GetTileRandom());
}
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b48944cb153b4e67809d2cddde1acc6b
timeCreated: 1724724224

View File

@@ -0,0 +1,58 @@
using DotRecast.Core.Collections;
using Game.Input;
using Game.JNGFrame.Logic.Entity.Contexts;
using Game.Logic.Entity.Nodes;
using JNGame.Math;
namespace Game.Logic.System.Logic
{
/// <summary>
/// 玩家逻辑
/// </summary>
public class DPlayerSystem : DGBasisSystem
{
//Node 节点
public EDPlayer[] Nodes => NodeContext.GetHostEntities();
public EDPlayerContext NodeContext => Contexts.GetContext<EDPlayerContext>();
public DInputSystem Input => GetSystem<DInputSystem>();
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
//创建角色
GetSystem<DInputSystem>().SInput<IDWorld>().ForEach(child =>
{
var key = child.Key;
var idWorld = (IDWorld)child.Value;
if (idWorld is { IsPlayerCreate: true })
{
var entity = NodeContext.CreateEntity();
entity.Controller.AuthBind(key);
var spawn = new LVector3(Random.Float(0, 0),Random.Float(0, 0),Random.Float(0, 0));
entity.Move.SetPosition(spawn);
}
});
}
public override void OnPlayerExitServer(int auth)
{
base.OnPlayerExitServer(auth);
NodeContext.GetHostEntities().ForEach(child =>
{
if (child.Controller.Auth == auth)
{
child.DelayDestroy();
}
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b59673517e1408295737003f44b2690
timeCreated: 1722224946

View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
using Game.Input;
using Game.JNGFrame.Logic.Entity;
using Game.JNGFrame.Logic.Entity.Contexts;
using Game.Logic.Entity.Nodes;
using JNGame.Math;
namespace Game.Logic.System.Logic
{
public class DWorldSystem : DGBasisSystem
{
//Node 节点
public EDNode[] Nodes => NodeContext.GetHostEntities();
public EDNodeContext NodeContext => Contexts.GetContext<EDNodeContext>();
//Node 第一个节点
public Queue<EDNode> NodeQueue = new();
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
if (GetSystem<DInputSystem>().SInputOne<IDWorld>() is not IDWorld { IsAdd: true }) return;
//超过500 则 销毁第一个实体
if (Nodes.Length >= 100)
{
NodeQueue.Dequeue().Destroy();
return;
}
var max = 100;
EDNode entity;
if (IsTile())
{
entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
entity.Move.SetPosition(GetTileRandom());
entity.Move.Go(GetTileRandom());
}
else
{
entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
var spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
entity.Move.SetPosition(spawn);
spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
entity.Move.Go(spawn);
}
NodeQueue.Enqueue(entity);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00e91648e3cd42a8ae1399000b88fdd6
timeCreated: 1712720318

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9c7f6594b809471b929e958068a70d32
timeCreated: 1724724127

View File

@@ -0,0 +1,23 @@
using AppGame;
using JNGame.Map;
using JNGame.Map.DotRecast.Util;
namespace Game.Logic.System.Usual
{
/// <summary>
/// 游戏数据
/// </summary>
public class DDataSystem : DGBasisSystem
{
public StaticMapData MapData;
public MeshData MapData2;
public override void OnSyncStart()
{
base.OnSyncStart();
MapData = App.Resource.MapData;
MapData2 = App.Resource.MapData2;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5c9d6660f75144ce84276d8536a9ffc2
timeCreated: 1715158899

View File

@@ -0,0 +1,105 @@
using System.Collections.Generic;
using DotRecast.Core.Numerics;
using DotRecast.Detour;
using DotRecast.Detour.Crowd;
using JNGame.Map.DotRecast;
using JNGame.Math;
using UnityEngine;
namespace Game.Logic.System.Usual
{
/// <summary>
/// 地图
/// </summary>
public class DMapSystem : DGBasisSystem
{
public DotRecastRoot Root;
public override void OnSyncStart()
{
base.OnSyncStart();
Root = new DotRecastRoot(GetSystem<DDataSystem>().MapData2);
Debug.Log($"DemoMapService - 加载完成地图");
}
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
Root.Update(new LFloat(null,Sync.DeltaTime));
}
public DtCrowdAgentParams GetAgentParams()
{
int updateFlags = DtCrowdAgentUpdateFlags.DT_CROWD_ANTICIPATE_TURNS |
DtCrowdAgentUpdateFlags.DT_CROWD_OPTIMIZE_VIS |
DtCrowdAgentUpdateFlags.DT_CROWD_OPTIMIZE_TOPO |
DtCrowdAgentUpdateFlags.DT_CROWD_OBSTACLE_AVOIDANCE;
DtCrowdAgentParams ap = new DtCrowdAgentParams();
ap.radius = (LFloat)0.6f;
ap.height = (LFloat)2f;
ap.maxAcceleration = (LFloat)8.0f;
ap.maxSpeed = (LFloat)6f;
ap.collisionQueryRange = ap.radius * (LFloat)12f;
ap.pathOptimizationRange = ap.radius * (LFloat)30f;
ap.updateFlags = updateFlags;
ap.obstacleAvoidanceType = 0;
ap.separationWeight = (LFloat)2f;
return ap;
}
/// <summary>
/// 返回最近点
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public LVector3 GetNearbyPoints(LVector3 pos)
{
return Root.GetNearbyPoints(pos);
}
/// <summary>
/// 查询导航
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public List<DtStraightPath> FindPath(LVector3 start,LVector3 end)
{
return Root.FindPath(start,end);
}
//添加避障
public void AddAgent(ulong id,LVector3 start)
{
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z));
}
public void AddAgent(ulong id,LVector3 start,DtCrowdAgentParams agentParams)
{
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z),agentParams);
}
//删除避障
public void DelAgent(ulong id)
{
Root.DelAgent(id);
}
//移动避障
public void MoveAgent(ulong id,LVector3 move)
{
Root.MoveAgent(id,new RcVec3f(move.x,move.y,move.z));
}
//向量移动避障
public void VectorMoveAgent(ulong id,LVector2 vector)
{
Root.VectorMoveAgent(id,new RcVec3f(vector.x,0,vector.y));
}
//获取避障
public DtCrowdAgent GetAgent(ulong id)
{
return Root.GetAgent(id);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f6e62838e334b6e983b238063cc2479
timeCreated: 1715157690

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 70895d8be1b84f40ac7ee3c61c8bdbaa
timeCreated: 1712748571

View File

@@ -0,0 +1,41 @@
using Game.JNGFrame.View.Entity;
using JNGame.Sync.System;
using JNGame.Sync.View;
using JNGame.Util;
namespace Game.JNGFrame.View
{
public class DViewSystem : SViewSystem
{
private readonly IViewData[] views;
public DViewSystem()
{
views = new IViewData[] {
new VDNodes(this), //显示Demo实体
new VDPlayers(this), //显示玩家实体
new VDBoss(this), //显示Boss实体
};
}
public override void OnSyncUpdate(int dt)
{
base.OnSyncUpdate(dt);
foreach (var view in views)
{
//视图逻辑交给主线程运行
UnityMainThreadDispatcher.Instance.Enqueue(view.Execute);
}
}
// public override void Execute()
// {
// foreach (var view in views)
// {
// view.Execute();
// }
// }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b957e5e22fd84759a0ece337922e616d
timeCreated: 1712750046

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7723835c77a04a6f98cf04c58f01b9c1
timeCreated: 1712750018

View File

@@ -0,0 +1,52 @@
using AppGame;
using AppGame.Sync;
using Cinemachine;
using DG.Tweening;
using Game.JNGFrame.Logic.Entity;
using Game.JNGState.Logic.Data;
using JNGame.Math;
using JNGame.Sync.System;
using JNGame.Sync.View;
using Service;
using UnityEngine;
namespace Game.JNGFrame.View.Entity
{
public class VDBoss : VDEntityBasis<EDBossData>
{
public GameObject VWorld => App.Resource.VWorld;
public GameObject Boss => App.Resource.Boss;
public VDBoss(SViewSystem root) : base(root)
{
Register((int)GDataValueCode.Position, OnUpdatePosition);
}
private void OnUpdatePosition((GameObject View, EDBossData Data) tuple)
{
var (view, data) = tuple;
if (data.Value.Position != null)
{
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
}
}
public override GameObject NewView(EDBossData data)
{
var view = Object.Instantiate(Boss, VWorld.transform);
view.name = $"Boss_{data.Id}";
return view;
}
public override EDBossData[] GetData()
{
return GetService<EDBossDataSystem>().Datas;
}
public override void ViewRemove(GameObject view)
{
view.transform.DOKill();
Object.Destroy(view);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 211b4062ef0644d583693f4b36358c40
timeCreated: 1724724729

View File

@@ -0,0 +1,52 @@
using AppGame;
using DG.Tweening;
using Game.JNGFrame.Logic.Entity;
using Game.JNGState.Logic.Data;
using JNGame.Math;
using JNGame.Sync.System;
using JNGame.Sync.View;
using Service;
using UnityEngine;
namespace Game.JNGFrame.View.Entity
{
public class VDNodes : VDEntityBasis<EDNodeData>
{
public GameObject VWorld => App.Resource.VWorld;
public GameObject Player => App.Resource.Player;
public VDNodes(SViewSystem root) : base(root)
{
Register((int)GDataValueCode.Position, OnUpdatePosition);
}
/// <summary>
/// 更新位置
/// </summary>
private void OnUpdatePosition((GameObject View, EDNodeData Data) tuple)
{
var (view, data) = tuple;
if (data.Value.Position != null)
{
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
}
}
public override GameObject NewView(EDNodeData data)
{
var view = Object.Instantiate(Player, VWorld.transform);
view.name = $"Node_{data.Id}";
return view;
}
public override EDNodeData[] GetData()
{
return GetService<EDNodeDataSystem>().Datas;
}
public override void ViewRemove(GameObject view)
{
view.transform.DOKill();
Object.Destroy(view);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 658e1c8925f546749725181702b989e9
timeCreated: 1715169861

View File

@@ -0,0 +1,103 @@
using AppGame;
using AppGame.Sync;
using Cinemachine;
using DG.Tweening;
using Game.JNGState.Logic.Data;
using JNGame.Sync.System;
using JNGame.Sync.View;
using UnityEngine;
namespace Game.JNGFrame.View.Entity
{
public class VDPlayers : VDEntityBasis<EDPlayerData>
{
public GameObject VWorld => App.Resource.VWorld;
public GameObject Player => App.Resource.Player;
public CinemachineFreeLook FreeLook => App.Resource.FreeLook;
//本地玩家 视图
private GameObject LocalView;
public VDPlayers(SViewSystem root) : base(root)
{
Register((int)GDataValueCode.Position, OnUpdatePosition);
Register((int)EDPlayerValueCode.Auth, OnUpdateAuth);
}
/// <summary>
/// 更新坐标
/// </summary>
/// <param name="tuple"></param>
private void OnUpdatePosition((GameObject View, EDPlayerData Data) tuple)
{
var (view, data) = tuple;
//更新位置
if (data.Value.Position != null)
{
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
}
if (data.Value.Auth == App.ClientID)
{
//更新本地玩家位置
if (data.Value.Position != null) App.Game.GetClient<JNGTileClientSystem>()?.SetPlayerPosition(data.Value.Position.ToLVector3());
}
}
/// <summary>
/// 更新权限
/// </summary>
private void OnUpdateAuth((GameObject View, EDPlayerData Data) tuple)
{
var (view, data) = tuple;
//权限操作
if (App.IsClient() && data.Value.Auth == App.ClientID)
{
//绑定相机
FreeLook.LookAt = view.transform;
FreeLook.Follow = view.transform;
}
}
public override GameObject NewView(EDPlayerData data)
{
GameObject view;
//如果这个角色是自己 则 直接拿自己的 View
if (App.IsClient() && data.Value.Auth == App.ClientID)
{
if (LocalView is null) LocalView = Object.Instantiate(Player, VWorld.transform);
view = LocalView;
}
else
{
view = Object.Instantiate(Player, VWorld.transform);
}
view.name = $"Player_{data.Id}";
return view;
}
public override EDPlayerData[] GetData()
{
return GetService<EDPlayerDataSystem>().Datas;
}
public override void ViewRemove(GameObject view)
{
view.transform.DOKill();
if (LocalView != view)
{
Object.Destroy(view);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c45ed812046443709890cdd79dfdcb19
timeCreated: 1722252921

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using DotRecast.Core.Collections;
using Game.JNGState.Logic.Data;
using JNGame.Sync.System;
using JNGame.Sync.View;
using Plugins.JNGame.Util;
using UnityEngine;
namespace Game.JNGFrame.View
{
public abstract class VDEntityBasis<T> : ViewData<T> where T : IGDataBase
{
private readonly Dictionary<int, Action<(GameObject View, T Data)>> Event = new();
protected VDEntityBasis(SViewSystem root) : base(root)
{
}
public override void Execute()
{
base.Execute();
//调用改动
var dataList = GetData();
foreach (var data in dataList){
if (views.TryGetValue(data.Id,out var view))
{
data.WriteCodes.ForEach(code =>
{
Event[code]?.Invoke((view.Data,data));
});
}
}
}
public override void ViewUpdate(T data, GameObject view)
{
}
public void Register(int code,Action<(GameObject View, T Data)> action)
{
Event[code] = action;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d099ea459fc642698d0c5dcdbb1fa64a
timeCreated: 1726944240