Beispiel #1
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="room"></param>
        private void gameOver(int userId, FightRoom room)
        {
            int        winIdentity = room.GetPlayerIdeentity(userId);
            int        winBeen     = room.Multiple * 1000;
            List <int> winUIds     = room.GetSameIdentityUIds(winIdentity);

            //给胜利的玩家添加胜场
            for (int i = 0; i < winUIds.Count; i++)
            {
                UserModel um = userCache.GetModelById(winUIds[i]);
                um.WinCount++;
                um.Been = winBeen;
                um.Exp += 100;
                int maxExp = um.Lv * 100;
                while (maxExp <= um.Exp)
                {
                    um.Lv++;
                    um.Exp -= maxExp;
                }
                userCache.Update(um);
            }
            //给失败的玩家添加负场
            List <int> loseUIds = room.GetDifferentIdentityUIds(winIdentity);

            for (int i = 0; i < loseUIds.Count; i++)
            {
                UserModel um = userCache.GetModelById(loseUIds[i]);
                um.LoseCount++;
                um.Been -= winBeen;
                um.Exp  += 10;
                int maxExp = um.Lv * 100;
                while (maxExp <= um.Exp)
                {
                    um.Lv++;
                    um.Exp -= maxExp;
                }
                userCache.Update(um);
            }
            //给逃跑玩家添加逃跑场次
            for (int i = 0; i < room.LeaveUIdList.Count; i++)
            {
                UserModel um = userCache.GetModelById(room.LeaveUIdList[i]);
                um.RunCount++;
                um.Been -= winBeen * 3;
                um.Exp  += 0;
                userCache.Update(um);
            }
            //给客户端发消息 谁赢了以及赢的豆子,身份?
            OverDto dto = new OverDto();

            dto.WinIdentity = winIdentity;
            dto.WinUIdList  = winUIds;
            dto.BeenCount   = winBeen;
            Brocast(room, OpCode.FIGHT, FightCode.OVER_BRO, dto);

            //在缓存层销毁房间数据
            fightCache.Destroy(room);
        }