169 lines
6.1 KiB
C#
169 lines
6.1 KiB
C#
using BrewMonster;
|
|
using CSNetwork;
|
|
using CSNetwork.GPDataType;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using TMPro;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace PerfectWorld.Scripts.Managers
|
|
{
|
|
namespace BrewMonster.Managers
|
|
{
|
|
public class EC_ManPlayer : IMsgHandler, IAutoInitialize
|
|
{
|
|
public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER;
|
|
public bool ProcessMessage(ECMSG Msg)
|
|
{
|
|
if (Msg.iSubID == 0)
|
|
{
|
|
|
|
}
|
|
else if (Msg.iSubID < 0)
|
|
{
|
|
switch ((int)Msg.dwMsg)
|
|
{
|
|
case int value when value == EC_MsgDef.MSG_PM_PLAYERINFO:
|
|
{
|
|
OnMsgPlayerInfo(Msg);
|
|
break;
|
|
}
|
|
case int value when value == EC_MsgDef.MSG_PM_PLAYERMOVE:
|
|
{
|
|
OnMsgPlayerMove(Msg);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void OnMsgPlayerInfo(ECMSG Msg)
|
|
{
|
|
int iHostID = Convert.ToInt32(Msg.dwParam3);
|
|
int lenghtByte = Marshal.SizeOf<int>();
|
|
byte[] byteArray = new byte[lenghtByte];
|
|
byte[] data = (byte[])Msg.dwParam1;
|
|
for (int i = 0; i < lenghtByte; i++)
|
|
{
|
|
byteArray[i] = data[i];
|
|
}
|
|
int cid = BitConverter.ToInt32(byteArray);
|
|
switch (Convert.ToInt32(Msg.dwParam2))
|
|
{
|
|
case CommandID.PLAYER_INFO_1:
|
|
case CommandID.PLAYER_ENTER_WORLD:
|
|
case CommandID.PLAYER_ENTER_SLICE:
|
|
{
|
|
if (cid != iHostID)
|
|
{
|
|
GameController.Instance.Log("ElsePlayer has join");
|
|
}
|
|
break;
|
|
}
|
|
case CommandID.SELF_INFO_1:
|
|
cmd_self_info_1 info = GPDataTypeHelper.FromBytes<cmd_self_info_1>((byte[])Msg.dwParam1);
|
|
HostPlayerInfo1(info);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void OnMsgPlayerMove(ECMSG Msg)
|
|
{
|
|
int iHostID = Convert.ToInt32(Msg.dwParam3);
|
|
cmd_object_move pCmd = GPDataTypeHelper.FromBytes<cmd_object_move>((byte[])Msg.dwParam1);
|
|
if (pCmd.use_time == 0)
|
|
return;
|
|
if (pCmd.id != iHostID)
|
|
{
|
|
EC_ElsePlayer pPlayer = SeekOutElsePlayer(pCmd.id);
|
|
if (pPlayer)
|
|
{
|
|
//pPlayer->MoveTo(*pCmd);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool HostPlayerInfo1(cmd_self_info_1 info)
|
|
{
|
|
string nameScene = "NPCRender";
|
|
SceneManager.LoadScene(nameScene, LoadSceneMode.Single);
|
|
nameScene = "WorldRender";
|
|
SceneManager.LoadScene(nameScene, LoadSceneMode.Additive);
|
|
return true;
|
|
}
|
|
|
|
public EC_ElsePlayer ElsePlayerEnter()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
private EC_ElsePlayer SeekOutElsePlayer(int cid)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
private cmd_object_move ConvertToStruct(byte[] bytes)
|
|
{
|
|
if (bytes.Length < Marshal.SizeOf<cmd_object_move>())
|
|
{
|
|
return default;
|
|
}
|
|
|
|
cmd_object_move result = new cmd_object_move();
|
|
int preLenghtData = 0;
|
|
int lenghtDataType = Marshal.SizeOf<int>();
|
|
byte[] arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.id = BitConverter.ToInt32(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
lenghtDataType = Marshal.SizeOf<float>();
|
|
arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.dest_X = BitConverter.ToSingle(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
lenghtDataType = Marshal.SizeOf<float>();
|
|
arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.dest_Y = BitConverter.ToSingle(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
lenghtDataType = Marshal.SizeOf<float>();
|
|
arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.dest_Z = BitConverter.ToSingle(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
lenghtDataType = Marshal.SizeOf<ushort>();
|
|
arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.use_time = BitConverter.ToUInt16(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
lenghtDataType = Marshal.SizeOf<short>();
|
|
arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData);
|
|
result.sSpeed = BitConverter.ToInt16(arrByteData);
|
|
|
|
preLenghtData += lenghtDataType;
|
|
result.move_mode = bytes[preLenghtData + 1];
|
|
return result;
|
|
}
|
|
|
|
private byte[] GetBytes(byte[] bytes, int length, int index)
|
|
{
|
|
byte[] arrByteData = new byte[length];
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
arrByteData[i] = bytes[i + index];
|
|
}
|
|
return arrByteData;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
} |