Ejemplo n.º 1
0
        /// <summary>
        /// 处理玩家离开
        /// </summary>
        /// <param name="clientPeer"></param>
        private void processLeave(ClientPeer clientPeer)
        {
            SingleExecute.Instance.processSingle(
                () =>
            {
                if (!UserCache.Instance.IsOnline(clientPeer))
                {
                    return;
                }
                int uid = UserCache.Instance.GetId(clientPeer);

                if (!FightRoomCache.Instance.IsJoinFight(uid))
                {
                    //如果没有进入战斗房间
                    return;
                }

                FightRoom fightRoom = FightRoomCache.Instance.GetRoomByUid(uid);
                PlayerDto playerDto = fightRoom.GetPlayerDto(uid);

                fightRoom.LeavePlayerDtos.Add(playerDto);
                fightRoom.Leave(clientPeer);
                fightRoom.UidRaceidDic.Remove(uid);

                if (fightRoom.LeavePlayerDtos.Count >= 2)
                {
                    //所有玩家都离开了
                    FightRoomCache.Instance.Destroy(fightRoom.ID);
                }
            }
                );
        }