using BrewMonster; using BrewMonster.Network; using CSNetwork; using CSNetwork.GPDataType; using System; using System.Collections; using System.Runtime.InteropServices; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; namespace PerfectWorld.Scripts.Managers { namespace BrewMonster.Managers { public class EC_ManPlayer : IMsgHandler { public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER; //public EC_HostPlayer EC_HostPlayer; public bool ProcessMessage(ECMSG Msg) { if (Msg.iSubID == 0) { //EC_HostPlayer.ProcessMessage(Msg); } 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(); 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((byte[])Msg.dwParam1); HostPlayerInfo1(info); break; } } public void OnMsgPlayerMove(ECMSG Msg) { int iHostID = Convert.ToInt32(Msg.dwParam3); cmd_object_move pCmd = GPDataTypeHelper.FromBytes((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) { bool isDoneWorldRender = false; bool isDoneNPCRender = false; Action actLoadChar = () => { if(!isDoneNPCRender || !isDoneWorldRender) { return; } GameController.Instance.InitCharacter(info); }; string nameScene = "NPCRender"; UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Single, (value) => { isDoneNPCRender = value; actLoadChar?.Invoke(); }); nameScene = "WorldRender"; UnityGameSession.Instance.LoadScene(nameScene, LoadSceneMode.Additive, (value) => { isDoneWorldRender = value; actLoadChar?.Invoke(); }); 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()) { return default; } cmd_object_move result = new cmd_object_move(); int preLenghtData = 0; int lenghtDataType = Marshal.SizeOf(); byte[] arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); result.id = BitConverter.ToInt32(arrByteData); preLenghtData += lenghtDataType; lenghtDataType = Marshal.SizeOf(); arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); result.dest_X = BitConverter.ToSingle(arrByteData); preLenghtData += lenghtDataType; lenghtDataType = Marshal.SizeOf(); arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); result.dest_Y = BitConverter.ToSingle(arrByteData); preLenghtData += lenghtDataType; lenghtDataType = Marshal.SizeOf(); arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); result.dest_Z = BitConverter.ToSingle(arrByteData); preLenghtData += lenghtDataType; lenghtDataType = Marshal.SizeOf(); arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); result.use_time = BitConverter.ToUInt16(arrByteData); preLenghtData += lenghtDataType; lenghtDataType = Marshal.SizeOf(); 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() { } } } }