public override void OnRecv(ref Conn conn) { CG_CreateRole createRole = GetData <CG_CreateRole>(structBytes); Console.WriteLine("userName:"******"接受创建name:" + createRole.name); Console.WriteLine("接受创建occ:" + createRole.occ); TablePlayer playerTable = DBPlayer.Inst.CreatePlayer(createRole.userName, createRole.name, createRole.occ); playerTable.X = 140; playerTable.Y = 170; if (playerTable != null) { eno = 0; playerData = MsgLogin.CreatePlayer(ref conn, createRole.userName, ref playerTable); Console.WriteLine("创建角色成功,返回角色信息"); // 进入默认场景 Lobby map = LobbyManager.Inst.GetLobby(playerData.mapId); map.AddPlayer(conn.player); } else { eno = -1; Console.WriteLine("创建角色失败"); } conn.Send(this); }
public TablePlayer CreatePlayer(string userName, string name, int occ) { try { TablePlayer player = new TablePlayer(); player.MapId = 3; // 默认场景先3吧 player.UserName = userName; player.Name = name; player.Occ = occ; context.Insert(player); return(player); } catch (Exception e) { return(null); } }