Exemple #1
0
        /// <summary>
        /// 结束游戏
        /// </summary>
        /// <param name="room">房间模型</param>
        /// <param name="uid">获胜角色id</param>
        private void GameOver(FightRoomModel room, int uid)
        {
            //获取获胜者身份
            int identity = room.GetPlayerIdentity(uid);

            if (identity == Identity.LANDLORD)
            {
                //地主获胜
                #region 更新地主玩家的信息,增加豆子,增加经验
                UserModel userModel = userModelCache.GetModelByUid(uid);
                userModel.Been += room.Multiple * 100 * 2;
                userModel.AddExp(20);
                userModel.Win++;
                userModelCache.Update(userModel);
                #endregion

                #region 更新农民玩家的信息,减少豆子,增加经验
                room.GetSameIdentityUids(Identity.FARMER).ForEach(u =>
                {
                    UserModel user = userModelCache.GetModelByUid(u.Uid);
                    user.Been     -= room.Multiple * 100;
                    user.Fail++;
                    user.AddExp(10);
                    userModelCache.Update(user);
                });
                #endregion
            }
            else
            {
                //农民获胜
                #region 更新农民玩家的信息,增加豆子,增加经验
                room.GetSameIdentityUids(Identity.FARMER).ForEach(u =>
                {
                    UserModel user = userModelCache.GetModelByUid(u.Uid);
                    user.Been     += room.Multiple * 100;
                    user.Win++;
                    user.AddExp(20);
                    userModelCache.Update(user);
                });
                #endregion

                #region 更新地主玩家的信息,减少豆子,增加经验
                room.GetSameIdentityUids(Identity.LANDLORD).ForEach(u =>
                {
                    UserModel user = userModelCache.GetModelByUid(u.Uid);
                    user.Been     -= room.Multiple * 100 * 2;
                    user.Fail++;
                    user.AddExp(10);
                    userModelCache.Update(user);
                });
                #endregion
            }

            //惩罚逃跑者
            userModelCache.GetModelsByUids(room.EscapePlayerId).ForEach(u =>
            {
                u.Been -= room.Multiple * 100;
                u.Escape++;
                userModelCache.Update(u);
            });


            OverDto overDto = new OverDto();
            overDto.WinIdentity = identity;
            List <PlayerDto> playerDtos = room.GetSameIdentityUids(identity);
            List <int>       uids       = new List <int>();
            foreach (var item in playerDtos)
            {
                uids.Add(item.Uid);
            }
            overDto.WinUidList = uids;
            overDto.BeenCount  = room.Multiple * 100;
            //广播游戏结束消息
            Brocast(room, OpCode.FIGHT, FightCode.OVER, overDto);

            //摧毁匹配房间
            RoomCache roomCache = Caches.RoomCache;
            roomCache.DestoryRoom(roomCache.GetRoomModelByUid(uid));

            //摧毁战斗房间
            fightRoomCache.DestoryRoom(room);
        }