internal static void OnCreateSceneRole(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(CreateSceneRole))) { return; } CreateSceneRole createSceneRole = cmd as CreateSceneRole; // RoleDatabase roleDatabase = RoleTable.instance[createSceneRole.modelId]; if (roleDatabase == null) { Debug.LogError("未找到角色模型: " + createSceneRole.modelId); } //创建角色模型 var roleObj = ResourcesManager.instance.GetInstance(roleDatabase.modelPath); Role role; //判断是否时主角 if (RoleMgr.instance._mainRoleThisId == createSceneRole.thisId) { //主角 instance._mainRole = roleObj.AddComponent <MainRole>(); role = instance._mainRole; SceneMgr.instance.mainCameraControl.target = role.transform; } else { role = roleObj.AddComponent <Role>(); } role.Init(createSceneRole, roleDatabase); RoleMgr.instance.allRole[createSceneRole.thisId] = role; }
internal static void OnMainRoleThisid(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(MainRoleThisIdCmd))) { return; } MainRoleThisIdCmd thisIdCmd = cmd as MainRoleThisIdCmd; RoleMgr.instance._mainRoleThisId = thisIdCmd.thisId; }
internal static void OnJumpMap(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(JumpTo))) { return; } JumpTo jumpToCmd = cmd as JumpTo; //验证坐标信息 //跳地图 EnterMap(Server.instance.curPlayer.curRole, jumpToCmd.id); }
internal static void OnEnterMap(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(EnterMapCmd))) { return; } EnterMapCmd enterMapCmd = cmd as EnterMapCmd; // 跳转地图时,要重置RoleMgr、摇杆事件/摇杆状态、场景触摸事件、UI事件 Reset(); //enterMapCmd.mapId SceneMgr.instance.loadScene(enterMapCmd.mapId); }
internal static void OncreateSceneNpc(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(CreateSceneNpc))) { return; } CreateSceneNpc createNpc = cmd as CreateSceneNpc; // var npcDatabase = NpcTable.instance[createNpc.modelId]; var npcObj = ResourcesManager.instance.GetInstance(NpcTable.instance[createNpc.modelId].modelPath); var npc = npcObj.AddComponent <Npc>(); npc.Init(createNpc, npcDatabase); NpcMgr.instance.allNpc[npc.ThisId] = npc; }
public static void OnLogin(Cmd cmd) { Debug.Log("分发LoginCmd成功!"); //cmd的类型必须是LoginCmd if (!Net.CheckCmd(cmd, typeof(LoginCmd))) { return; } //验证账号密码 //找到玩家的存档 var playerData = Server.instance.DB.GetUserData(1); if (playerData == null) { playerData = new Player(); //分配thisid; playerData.thisId = 1; Server.instance.DB.SavePlayerData(playerData); } Server.instance.curPlayer = playerData; var player = Server.instance.curPlayer; //向客户端发送玩家的已创建的角色列表 RoleListCmd roleListCmd = new RoleListCmd(); //roleListCmd.allRole = player.allRole.GetRange(0, player.allRole.Count); //深拷贝 foreach (var role in player.allRole) { var roleInfo = new SelectRoleInfo() { name = role.name, modelId = role.modelId }; roleListCmd.allRole.Add(roleInfo); } Server.instance.SendCmd(roleListCmd); }
internal static void OnRoleList(Cmd cmd) { //cmd的类型必须是RoleListCmd if (!Net.CheckCmd(cmd, typeof(RoleListCmd))) { return; } RoleListCmd roleListCmd = cmd as RoleListCmd; UserData.instance.allRole = roleListCmd.allRole; if (roleListCmd.allRole.Count > 0) { //选人界面 //SceneManager.LoadScene("SelectRole"); UIManager.instance.Repalce("UIPrefabs/SelectRole/SelectRole", UILayer.Normal); } else { //创建角色界面 SceneManager.LoadScene("CreateRole"); } }
internal static void OnSelectRole(Cmd cmd) { if (!Net.CheckCmd(cmd, typeof(SelectRoleCmd))) { return; } SelectRoleCmd selectRoleCmd = cmd as SelectRoleCmd; var curPlayer = Server.instance.curPlayer; var curRole = Server.instance.curPlayer.allRole[selectRoleCmd.index]; curPlayer.curRole = curRole; var roleTableData = RoleTable.instance[curRole.modelId]; curRole.name = roleTableData.name; curRole.hp = roleTableData.hp; curRole.attack = roleTableData.attack; curRole.defence = roleTableData.defence; //告诉客户端,场景编号 //分配ThisId var thisId = RoleServer.getNewThisId(); curPlayer.curRole.thisID = thisId; //告诉客户端主角的Thisid MainRoleThisIdCmd thisIdCmd = new MainRoleThisIdCmd() { thisId = thisId }; Server.instance.SendCmd(thisIdCmd); //进入场景(原来的函数是没有MapId,或许这部分的代码应该另写) EnterMap(curRole, 1); }