diff --git a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll index 7b500ef132..851f70a125 100644 Binary files a/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll and b/Assets/NetworkLib/Debug/netstandard2.1/CSNetwork.dll differ diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs index 7383c50195..88362eef0f 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs @@ -2,8 +2,10 @@ using BrewMonster.Network; using CSNetwork; using CSNetwork.GPDataType; +using PerfectWorld.Scripts.Player; using System; using System.Collections; +using System.Collections.Generic; using System.Runtime.InteropServices; using TMPro; using UnityEngine; @@ -15,6 +17,9 @@ namespace PerfectWorld.Scripts.Managers { public class EC_ManPlayer : IMsgHandler { + Dictionary m_UkPlayerTab = new Dictionary(); + Dictionary m_PlayerTab = new Dictionary(); + private readonly object m_csPlayerTab = new object(); public int HandlerId => (int)MANAGER_INDEX.MAN_PLAYER; public bool ProcessMessage(ECMSG Msg) { @@ -56,7 +61,8 @@ namespace PerfectWorld.Scripts.Managers byteArray[i] = data[i]; } int cid = BitConverter.ToInt32(byteArray); - switch (Convert.ToInt32(Msg.dwParam2)) + int commandID = Convert.ToInt32(Msg.dwParam2); + switch (commandID) { case CommandID.PLAYER_INFO_1: case CommandID.PLAYER_ENTER_WORLD: @@ -64,6 +70,8 @@ namespace PerfectWorld.Scripts.Managers { if (cid != iHostID) { + info_player_1 info_Player_1 = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); + ElsePlayerEnter(info_Player_1, commandID); GameController.Instance.Log("ElsePlayer has join"); } break; @@ -118,58 +126,110 @@ namespace PerfectWorld.Scripts.Managers return true; } - public EC_ElsePlayer ElsePlayerEnter() + public EC_ElsePlayer ElsePlayerEnter(info_player_1 info, int iCmd) + { + + return null; + // If this player's id is in unknown table, remove it because this player + // won't be unknown anymore + if (m_UkPlayerTab.TryGetValue(info.cid, out int value)) + { + if (value != 0) // Pair.second != 0 + { + m_UkPlayerTab.Remove(info.cid); + } + } + + int iAppearFlag = (iCmd == (int)CommandID.PLAYER_ENTER_WORLD) ? + (int)PlayerAppearFlag.APPEAR_ENTERWORLD : (int)PlayerAppearFlag.APPEAR_RUNINTOVIEW; + + // Has player been in active player table ? + EC_ElsePlayer pPlayer = GetElsePlayer(info.cid); + if (pPlayer) + { + // This player has existed in player table, call special initial function + // TODO: fix after pPlayer init + //pPlayer.Init(Info, iAppearFlag, true); + return pPlayer; + } + + // Create a new player + if (!(pPlayer = CreateElsePlayer(info, iAppearFlag))) + { + return null; + } + return null; + } + + private EC_ElsePlayer CreateElsePlayer(info_player_1 info, int iAppearFlag) { return null; } + private EC_ElsePlayer GetElsePlayer(int cid, long dwBornStamp = 0) + { + lock (m_csPlayerTab) + { + if (!m_PlayerTab.TryGetValue(cid, out var player)) + return null; + if (dwBornStamp != 0) + { + //TO DO: fix after GetBornStamp() is create in code + //if (player.GetBornStamp() != dwBornStamp) + return null; + } + + return player; + } + } + private EC_ElsePlayer SeekOutElsePlayer(int cid) { return null; } - private cmd_object_move ConvertToStruct(byte[] bytes) - { - if (bytes.Length < Marshal.SizeOf()) - { - return default; - } + //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); + // 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_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_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.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.use_time = BitConverter.ToUInt16(arrByteData); - preLenghtData += lenghtDataType; - lenghtDataType = Marshal.SizeOf(); - arrByteData = GetBytes(bytes, lenghtDataType, preLenghtData); - result.sSpeed = BitConverter.ToInt16(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; - } + // preLenghtData += lenghtDataType; + // result.move_mode = bytes[preLenghtData + 1]; + // return result; + //} private byte[] GetBytes(byte[] bytes, int length, int index) { diff --git a/Assets/PerfectWorld/Scripts/Managers/NPCManager.cs b/Assets/PerfectWorld/Scripts/Managers/NPCManager.cs index 6b8aee75ea..3f80cd6492 100644 --- a/Assets/PerfectWorld/Scripts/Managers/NPCManager.cs +++ b/Assets/PerfectWorld/Scripts/Managers/NPCManager.cs @@ -1,27 +1,30 @@ using UnityEngine; -public class NPCManager : MonoBehaviour +namespace PerfectWorld.Scripts.Managers { - private static NPCManager instance; - - [SerializeField] private GameObject modelPlayerCharacter; - - public static NPCManager Instance + public class NPCManager : MonoBehaviour { - get + private static NPCManager instance; + + [SerializeField] private GameObject modelPlayerCharacter; + + public static NPCManager Instance { - if (instance == null) + get { - instance = FindAnyObjectByType(); - } - return instance; - } - } + if (instance == null) + { + instance = FindAnyObjectByType(); + } + return instance; + } + } - public GameObject GetModelPlayer() - { - var player = Instantiate(modelPlayerCharacter); - player.SetActive(true); - return player; + public GameObject GetModelPlayer() + { + var player = Instantiate(modelPlayerCharacter); + player.SetActive(true); + return player; + } } } diff --git a/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs b/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs index 9885ebb9d4..04c77f5739 100644 --- a/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs +++ b/Assets/PerfectWorld/Scripts/Players/EC_ElsePlayer.cs @@ -1,16 +1,28 @@ using UnityEngine; -public class EC_ElsePlayer : MonoBehaviour +namespace PerfectWorld.Scripts.Player { - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() + public class EC_ElsePlayer : MonoBehaviour { + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + } + + // Update is called once per frame + void Update() + { + + } } - // Update is called once per frame - void Update() + // Player appear flag + public enum PlayerAppearFlag { - - } + APPEAR_DISAPPEAR = -1, // Player disappear + APPEAR_ENTERWORLD = 0, // Player join world + APPEAR_RUNINTOVIEW, // Player run into view + APPEAR_GHOST, // Player is in ghost state, in player list but not active + }; } diff --git a/Assets/Scripts/CanvasController.cs b/Assets/Scripts/CanvasController.cs index 143c7ce08a..214f98307d 100644 --- a/Assets/Scripts/CanvasController.cs +++ b/Assets/Scripts/CanvasController.cs @@ -1,5 +1,6 @@ using BrewMonster.UI; using CSNetwork.Protocols.RPCData; +using PerfectWorld.Scripts.Managers; using System.Collections.Generic; using System.Threading; using UnityEngine; diff --git a/Assets/Scripts/CharacterCtrl.cs b/Assets/Scripts/CharacterCtrl.cs index bbcdf86f29..98070551e6 100644 --- a/Assets/Scripts/CharacterCtrl.cs +++ b/Assets/Scripts/CharacterCtrl.cs @@ -1,9 +1,9 @@ using CSNetwork.GPDataType; using CSNetwork.Protocols; using CSNetwork.Protocols.RPCData; +using PerfectWorld.Scripts.Managers; using System.Text; using TMPro; -using UnityEditor.SearchService; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index 15ce962f2c..9e2703bdee 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -4,60 +4,63 @@ using System.Data; using Unity.VisualScripting; using UnityEngine; -public class GameController : MonoBehaviour +namespace PerfectWorld.Scripts.Managers { - private static GameController instance; + public class GameController : MonoBehaviour + { + private static GameController instance; - [SerializeField] private CharacterCtrl characterPrefab; - //[SerializeField] private Transform ground; + [SerializeField] private CharacterCtrl characterPrefab; + //[SerializeField] private Transform ground; - Camera camera; + Camera camera; - public static GameController Instance - { - get - { - if (instance == null) + public static GameController Instance + { + get { - instance = FindAnyObjectByType(); + if (instance == null) + { + instance = FindAnyObjectByType(); + } + return instance; } - return instance; } - } - private void Awake() - { - if(instance == null) + private void Awake() { - instance = this; + if(instance == null) + { + instance = this; + } } - } - private void Start() - { - camera = Camera.main; - } - - public void Log(string s) - { - Debug.LogError(s); - } - - public void InitCharacter(cmd_self_info_1 info) - { - if(characterPrefab == null) + private void Start() { - Debug.LogError("null prefab"); - return; + camera = Camera.main; + } + + public void Log(string s) + { + Debug.LogError(s); + } + + public void InitCharacter(cmd_self_info_1 info) + { + if(characterPrefab == null) + { + Debug.LogError("null prefab"); + return; + } + CharacterCtrl character = Instantiate(characterPrefab, transform); + character.InitCharacter(info); + //Vector3 pos = new Vector3(info.pos.x, info.pos.y, info.pos.z); + //Vector3 posCam = pos; + //posCam.z -= 10f; + //camera.transform.position = posCam; + //Vector3 posGround = pos; + //posGround.y -= 2f; + //ground.transform.position = posGround; } - CharacterCtrl character = Instantiate(characterPrefab, transform); - character.InitCharacter(info); - //Vector3 pos = new Vector3(info.pos.x, info.pos.y, info.pos.z); - //Vector3 posCam = pos; - //posCam.z -= 10f; - //camera.transform.position = posCam; - //Vector3 posGround = pos; - //posGround.y -= 2f; - //ground.transform.position = posGround; } }