mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交
This commit is contained in:
@@ -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(), };
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfdb770e32914215b20ea0b4722157cf
|
||||
timeCreated: 1712736751
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0f4f8b42fdc465b9ad60b8e574aa996
|
||||
timeCreated: 1725096772
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3cfa4711bbd4f9792fbc3070838c8f5
|
||||
timeCreated: 1720855417
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce99e4925cfe4cf6a4551f4bc4e07fdc
|
||||
timeCreated: 1720749441
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bc49819e5242139ad5104c369b8c82
|
||||
timeCreated: 1720864794
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0346ed1171e4add9c2dd1f43d7d13d7
|
||||
timeCreated: 1720864691
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a0c80afea4d4209bb59b4725c030013
|
||||
timeCreated: 1723013031
|
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3e21eba1a90402cbcf1c142b7c6b103
|
||||
timeCreated: 1724723406
|
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d63a18dd1f04046ac493221c82130e8
|
||||
timeCreated: 1723013044
|
@@ -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;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c880d909098c44d59b5ec8d009dc1fe4
|
||||
timeCreated: 1725097481
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 835547007d6f4d88a441f5c4e782b103
|
||||
timeCreated: 1725097492
|
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3000f079bc5f4d72aa5d6b4145ac5e0e
|
||||
timeCreated: 1724723017
|
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aeea4b9b15934aba9d557d99f16c4d3f
|
||||
timeCreated: 1720749462
|
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df072d4041fb497cb8122a7449c04455
|
||||
timeCreated: 1722225086
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab58dfb4e61e45d587eb9695240e9cbc
|
||||
timeCreated: 1712737231
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dae9cf4b44914450b1624b40d7646190
|
||||
timeCreated: 1724723007
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71e757d251804ce4b37ba605cbf54016
|
||||
timeCreated: 1712737245
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2358fccfc7ee4ab6b0ccdabc5e75060b
|
||||
timeCreated: 1722225016
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 473e297b1bcf4ff1ad73d3fd1de8c597
|
||||
timeCreated: 1724675433
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c4bcab5b4174eda9afc6b994666a72f
|
||||
timeCreated: 1712736545
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 020606cd1a564efeb88ce4df7c6fce56
|
||||
timeCreated: 1722225061
|
Reference in New Issue
Block a user