Пример #1
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        private void GameOver(int userId, FightRoom room)
        {
            //确定身份 是农民还是地主
            int        identity = room.GetPlayerIdentity(userId);
            List <int> winUids  = room.GetSameIdentityUids(identity);
            int        winBeen  = room.Mutiple * 1000;

            //给胜利的玩家  胜场   豆子  经验  等级..之后玩家数据模型刷新
            for (int i = 0; i < winUids.Count; i++)
            {
                UserModel model = user.GetModelByUserId(winUids[i]);
                model.winCount++;
                model.been += winBeen;
                model.exp  += 100;
                int maxExp = model.lv * 100;
                while (maxExp <= model.exp)
                {
                    model.lv++;
                    model.exp -= maxExp;
                    maxExp     = model.lv * 100;
                }
                user.Update(model);
            }

            //给失败的玩家  败场   豆子  经验  等级..之后玩家数据模型刷新
            List <int> loseUids = room.GetDifIdentityUids(identity);

            for (int i = 0; i < winUids.Count; i++)
            {
                UserModel model = user.GetModelByUserId(loseUids[i]);
                model.loseCount++;
                model.been -= winBeen;
                model.exp  += 10;
                int maxExp = model.lv * 100;;
                while (maxExp <= model.exp)
                {
                    model.lv++;
                    model.exp -= maxExp;
                    maxExp     = model.lv * 100;
                }
                user.Update(model);
            }
            //给逃跑的玩家  逃跑   豆子  经验  等级..之后玩家数据模型刷新
            for (int i = 0; i < room.LeaveUidList.Count; i++)
            {
                UserModel model = user.GetModelByUserId(room.LeaveUidList[i]);
                model.runCount++;
                model.been -= (winBeen) * 3;
                model.exp  += 0;
                user.Update(model);
            }
            //给客户端发消息  谁赢了。身份,豆子多少
            OverDto dto = new OverDto();

            dto.winIdentity = identity; dto.winUidList = winUids; dto.beenCount = winBeen;

            Brocast(room, OpCode.FIGHT, FightCode.OVER_BRO, dto);

            fight.Destroy(room);
        }