Ejemplo n.º 1
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        /// <param name="room"></param>
        /// <param name="userId"></param>
        private void GameOver(FightRoom room, int userId)
        {
            var winIdentity = room.GetPlayerIdentity(userId);
            var winUserIds  = room.GetSameIdentityUserIds(winIdentity);
            var beens       = room.multiple * 1000;

            //给胜利的玩家结算
            for (int i = 0; i < winUserIds.Count; i++)
            {
                var userModel = user.GetModelById(winUserIds[i]);
                userModel.winCount++;
                userModel.beens += winIdentity == Identity.Landlord ? beens : beens / 2;
                userModel.exp   += 100;
                user.Update(userModel);
            }
            var loseUserIds = room.GetDifferentIdentityUserIds(winIdentity);

            //给失败的玩家结算
            for (int i = 0; i < loseUserIds.Count; i++)
            {
                var userModel = user.GetModelById(loseUserIds[i]);
                userModel.loseCount++;
                userModel.beens -= winIdentity == Identity.Landlord ? beens / 2 : beens;
                userModel.exp   += 50;
                user.Update(userModel);
            }
            //给逃跑玩家结算  离开的时候已经结算了
            //for (int i = 0; i < room.leavePlayerIdList.Count; i++)
            //{
            //    var userModel = user.GetModelById(room.leavePlayerIdList[i]);
            //    userModel.runCount++;
            //    userModel.loseCount++;
            //    userModel.beens -= beens * 3;//逃跑的人减3倍
            //    user.Update(userModel);
            //}
            //给客户端发消息  游戏结束了
            var dto = new OverDto(winIdentity, winUserIds, beens);

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

            //游戏结束
            fight.Destroy(room);
        }