private void Handle(MsgLeaveGame pckt)
 {
     if (this.State == KnownClientState.InGame)
     {
         OnLeaveGame();
     }
 }
Exemple #2
0
    //删除玩家
    public bool RemovePlayer(string id)
    {
        //获取玩家
        Player player = PlayerManager.GetPlayer(id);

        if (player == null)
        {
            Console.WriteLine("room.RemovePlayer fail, player is null");
            return(false);
        }
        //没有在房间里
        if (!playerIds.ContainsKey(id))
        {
            Console.WriteLine("room.RemovePlayer fail, not in this room");
            return(false);
        }
        //删除列表
        playerIds.Remove(id);
        player.roomId = -1;
        //设置房主
        if (ownerId == player.id)
        {
            ownerId = SwitchOwner();
        }
        //战斗状态退出
        if (status == Status.FIGHT)
        {
            MsgLeaveGame msg = new MsgLeaveGame();
            msg.id = player.id;
            Broadcast(msg);
        }
        //房间为空
        if (playerIds.Count == 0)
        {
            RoomManager.RemoveRoom(this.id);
        }
        //广播
        Broadcast(ToMsg());
        return(true);
    }