mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
101 lines
2.7 KiB
C#
101 lines
2.7 KiB
C#
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using AppGame.Systems.CServer;
|
|
using Cysharp.Threading.Tasks;
|
|
using DotRecast.Core.Collections;
|
|
using JNGame.Network;
|
|
using Plugins.JNGame.Network;
|
|
using Plugins.JNGame.Network.Action;
|
|
|
|
namespace AppGame.Systems
|
|
{
|
|
public class JNGClient : JNTCPClient
|
|
{
|
|
|
|
private string _point;
|
|
private int _clientId;
|
|
public int ClientId => _clientId;
|
|
|
|
/// <summary>
|
|
/// 区块服务器标识
|
|
/// </summary>
|
|
private string _tileServer;
|
|
public string TileServer => _tileServer;
|
|
|
|
public void BindID(int clientId)
|
|
{
|
|
_clientId = clientId;
|
|
}
|
|
|
|
public void SetPoint(string point)
|
|
{
|
|
_point = point;
|
|
}
|
|
public void SetTileServer(string tileServer)
|
|
{
|
|
_tileServer = tileServer;
|
|
}
|
|
|
|
protected override async UniTask<string> GetEndPoint()
|
|
{
|
|
await UniTask.NextFrame();
|
|
return _point;
|
|
}
|
|
|
|
public override async Task OnInit()
|
|
{
|
|
|
|
//监听服务端事件
|
|
AddListener((int)NActionEnum.NSyncStateDataUpdate,OnNSyncStateDataUpdate);
|
|
AddListener((int)NActionEnum.LocalClientConnect,OnClientConnect);
|
|
AddListener((int)NActionEnum.NSyncTileAllUpdateBack,OnNSyncTileAllUpdateBack);
|
|
|
|
//连接
|
|
await base.OnInit();
|
|
|
|
}
|
|
|
|
private void OnClientConnect(byte[] obj)
|
|
{
|
|
//向服务器发送玩家Id
|
|
Send((int)GActionEnum.BindClientID,new GBindClientID()
|
|
{
|
|
ClientId = ClientId
|
|
});
|
|
//向服务器绑定角色
|
|
Send((int)GActionEnum.BindClientRole,new GBindClientRole()
|
|
{
|
|
Role = (int)JNGClientRole.Player
|
|
});
|
|
//向服务器索要全量信息
|
|
Send((int)NActionEnum.NSyncTileAllUpdate);
|
|
}
|
|
|
|
private void OnNSyncStateDataUpdate(byte[] data)
|
|
{
|
|
var info = JNStateItemData.Parser.ParseFrom(data);
|
|
App.Game.AddState(info);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 状态同步全量回调
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
private void OnNSyncTileAllUpdateBack(byte[] data)
|
|
{
|
|
|
|
var allData = JNStateTileAllData.Parser.ParseFrom(data);
|
|
|
|
App.Game.ClearTileState(allData.TId);
|
|
|
|
//生效全局回调
|
|
allData.Data.Data.ForEach(child =>
|
|
{
|
|
App.Game.AddState(child);
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
} |