Ejemplo n.º 1
0
    // 游戏结束
    public override void gameOver(RoomData now_room)
    {
        try
        {
            now_room.setRoomState(RoomState.RoomState_end);

            LogUtil.getInstance().writeRoomLog(now_room, m_logFlag + "----" + ":比赛结束,roomid = :" + now_room.getRoomId());

            // 游戏在线统计
            for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
            {
                Request_OnlineStatistics.doRequest(now_room.getPlayerDataList()[i].m_uid, now_room.getRoomId(), now_room.m_gameRoomType, now_room.getPlayerDataList()[i].m_isAI, (int)Request_OnlineStatistics.OnlineStatisticsType.OnlineStatisticsType_exit);
            }

            // 计算每个玩家的金币(积分)
            GameUtil.setPlayerScore(now_room, true);

            List <PlayerData> winPlayerList = new List <PlayerData>();

            string gameRoomType = now_room.m_gameRoomType;
            int    rounds_pvp   = now_room.m_rounds_pvp;


            bool isContiune   = true;       // 是否打到最后一轮
            bool isJueShengJu = false;      // 下一局是否是决胜局

            {
                PVPGameRoomData pvpGameRoomData = PVPGameRoomDataScript.getInstance().getDataByRoomType(gameRoomType);
                if (pvpGameRoomData == null)
                {
                    LogUtil.getInstance().writeRoomLog(now_room, "获取比赛场信息失败:" + gameRoomType);
                    return;
                }

                int kaisairenshu = pvpGameRoomData.kaisairenshu;
                switch (kaisairenshu)
                {
                case 8:
                {
                    if (rounds_pvp == 3)
                    {
                        isContiune = false;
                    }
                    // 决胜局
                    else if (rounds_pvp == 2)
                    {
                        isJueShengJu = true;
                    }
                }
                break;

                case 16:
                {
                    if (rounds_pvp == 4)
                    {
                        isContiune = false;
                    }
                    // 决胜局
                    else if (rounds_pvp == 3)
                    {
                        isJueShengJu = true;
                    }
                }
                break;

                case 32:
                {
                    if (rounds_pvp == 5)
                    {
                        isContiune = false;
                    }
                    // 决胜局
                    else if (rounds_pvp == 4)
                    {
                        isJueShengJu = true;
                    }
                }
                break;
                }
            }

            List <string> winnerList = new List <string>();

            // 逻辑处理
            {
                // 闲家赢
                if (now_room.m_getAllScore >= 80)
                {
                    for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
                    {
                        if (now_room.getPlayerDataList()[i].m_isBanker == 0)
                        {
                            winnerList.Add(now_room.getPlayerDataList()[i].m_uid);

                            ++now_room.getPlayerDataList()[i].m_myLevelPoker;
                            if (now_room.getPlayerDataList()[i].m_myLevelPoker == 15)
                            {
                                now_room.getPlayerDataList()[i].m_myLevelPoker = 2;
                            }

                            now_room.m_levelPokerNum = now_room.getPlayerDataList()[i].m_myLevelPoker;

                            winPlayerList.Add(now_room.getPlayerDataList()[i]);

                            // 提交任务
                            if (!now_room.getPlayerDataList()[i].m_isAI)
                            {
                                Request_ProgressTask.doRequest(now_room.getPlayerDataList()[i].m_uid, 203);
                                Request_ProgressTask.doRequest(now_room.getPlayerDataList()[i].m_uid, 212);
                            }

                            // 记录胜利次数数据
                            {
                                Request_RecordUserGameData.doRequest(now_room.getPlayerDataList()[i].m_uid, now_room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Win);
                            }

                            // 分数在原来的基础上减半,防止玩家之间分数差距太大
                            {
                                now_room.getPlayerDataList()[i].m_score /= 2;
                            }
                        }
                        // 加入淘汰人员列表里
                        else
                        {
                            //PVPChangCiUtil.getInstance().addPlayerToThere(now_room.m_gameRoomType, now_room.getPlayerDataList()[i]);

                            //// 分数在原来的基础上减10000,防止比晋级的人分数高,影响排名
                            //if (!isJueShengJu && isContiune)
                            //{
                            //    now_room.getPlayerDataList()[i].m_score -= 10000;
                            //}
                        }
                    }
                }
                // 庄家赢
                else
                {
                    for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
                    {
                        if (now_room.getPlayerDataList()[i].m_isBanker == 1)
                        {
                            winnerList.Add(now_room.getPlayerDataList()[i].m_uid);

                            ++now_room.getPlayerDataList()[i].m_myLevelPoker;
                            if (now_room.getPlayerDataList()[i].m_myLevelPoker == 15)
                            {
                                now_room.getPlayerDataList()[i].m_myLevelPoker = 2;
                            }

                            now_room.m_levelPokerNum = now_room.getPlayerDataList()[i].m_myLevelPoker;

                            winPlayerList.Add(now_room.getPlayerDataList()[i]);

                            // 提交任务
                            if (!now_room.getPlayerDataList()[i].m_isAI)
                            {
                                Request_ProgressTask.doRequest(now_room.getPlayerDataList()[i].m_uid, 212);
                            }

                            // 记录胜利次数数据
                            {
                                Request_RecordUserGameData.doRequest(now_room.getPlayerDataList()[i].m_uid, now_room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Win);
                            }

                            // 分数在原来的基础上减半,防止玩家之间分数差距太大
                            {
                                now_room.getPlayerDataList()[i].m_score /= 2;
                            }
                        }
                        // 加入淘汰人员列表里
                        else
                        {
                            //PVPChangCiUtil.getInstance().addPlayerToThere(now_room.m_gameRoomType, now_room.getPlayerDataList()[i]);

                            //// 分数在原来的基础上减10000,防止比晋级的人分数高,影响排名
                            //if (!isJueShengJu && isContiune)
                            //{
                            //    now_room.getPlayerDataList()[i].m_score -= 10000;
                            //}
                        }
                    }
                }
            }

            for (int i = 0; i < winPlayerList.Count; i++)
            {
                LogUtil.getInstance().writeRoomLog(now_room, m_logFlag + "----" + ":胜利的人:" + winPlayerList[i].m_uid + "  isBanker:" + winPlayerList[i].m_isBanker);
            }

            // 通知
            {
                JObject respondJO;
                {
                    respondJO = new JObject();

                    respondJO.Add("tag", m_tag);
                    respondJO.Add("playAction", (int)TLJCommon.Consts.PlayAction.PlayAction_GameOver);
                    respondJO.Add("getAllScore", now_room.m_getAllScore);
                    respondJO.Add("isBankerWin", now_room.m_getAllScore >= 80 ? 0 : 1);
                    respondJO.Add("isContiune", isContiune);
                }

                // 给在线的人推送
                for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
                {
                    // 推送给客户端
                    if (!now_room.getPlayerDataList()[i].isOffLine())
                    {
                        if (!(now_room.getPlayerDataList()[i].m_isAI))
                        {
                            if (respondJO.GetValue("score") != null)
                            {
                                respondJO.Remove("score");
                            }

                            respondJO.Add("score", now_room.getPlayerDataList()[i].m_score);

                            PlayService.m_serverUtil.sendMessage(now_room.getPlayerDataList()[i].m_connId, respondJO.ToString());
                        }
                    }
                    else
                    {
                        if (!(now_room.getPlayerDataList()[i].m_isAI))
                        {
                            // 记录逃跑数据
                            Request_RecordUserGameData.doRequest(now_room.getPlayerDataList()[i].m_uid, now_room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Run);
                        }
                    }

                    // 告诉数据库服务器该玩家打完一局
                    {
                        Request_GameOver.doRequest(now_room.getPlayerDataList()[i].m_uid, now_room.m_gameRoomType);
                    }
                }
            }

            if (isJueShengJu)
            {
                // 游戏数据统计
                Request_GameStatistics.doRequest(now_room, winnerList);

                jueshengju(now_room);

                return;
            }

            // 进入新房间,准备开始下一局
            if (isContiune)
            {
                // 游戏数据统计
                Request_GameStatistics.doRequest(now_room, winnerList);

                // 删除该房间
                {
                    LogUtil.getInstance().writeRoomLog(now_room, m_logFlag + ":本局打完,强制解散该房间:" + now_room.getRoomId());

                    GameLogic.removeRoom(this, now_room, true);
                }

                for (int i = 0; i < winPlayerList.Count; i++)
                {
                    if (!winPlayerList[i].isOffLine())
                    {
                        {
                            RoomData room = null;

                            // 玩家数据清理
                            {
                                winPlayerList[i].m_isBanker = 0;
                            }

                            lock (m_roomList)
                            {
                                // 在已有的房间寻找可以加入的房间
                                for (int j = 0; j < m_roomList.Count; j++)
                                {
                                    if ((gameRoomType.CompareTo(m_roomList[j].m_gameRoomType) == 0) && ((rounds_pvp + 1) == m_roomList[j].m_rounds_pvp) && (m_roomList[j].getRoomState() == RoomState.RoomState_waiting))
                                    {
                                        if (m_roomList[j].joinPlayer(winPlayerList[i]))
                                        {
                                            winPlayerList[i].clearData();
                                            room = m_roomList[j];
                                            LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":找到新房间:" + room.getRoomId());

                                            break;
                                        }
                                    }
                                }

                                // 当前没有房间可加入的话则创建一个新的房间
                                if (room == null)
                                {
                                    winPlayerList[i].clearData();

                                    //room = new RoomData(this, m_roomList.Count + 1, gameRoomType);
                                    room = new RoomData(this, gameRoomType);
                                    room.joinPlayer(winPlayerList[i]);
                                    room.m_rounds_pvp = rounds_pvp + 1;

                                    m_roomList.Add(room);

                                    LogUtil.getInstance().writeRoomLog(room, "新建比赛场房间:" + room.getRoomId());
                                }
                            }

                            LogUtil.getInstance().writeRoomLog(room, ":该新房间人数:" + room.getPlayerDataList().Count);
                            if (room.getPlayerDataList().Count == 4)
                            {
                                // 延迟3秒开赛
                                room.m_timerUtil.startTimer(3000, TimerType.TimerType_pvpNextStartGame);
                            }
                        }
                    }
                }
            }
            // 所有局数已经打完
            else
            {
                {
                    //for (int i = 0; i < winPlayerList.Count; i++)
                    //{
                    //    // 加入淘汰人员列表里
                    //    PVPChangCiUtil.getInstance().addPlayerToThere(gameRoomType, winPlayerList[i]);
                    //}

                    // 加入到8、16人列表里
                    {
                        for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
                        {
                            PVPChangCiUtil.getInstance().addPlayerToThere(now_room);
                        }
                    }
                }

                PVPRoomPlayerList curPVPRoomPlayerList = PVPChangCiUtil.getInstance().getPVPRoomPlayerListByUid(winPlayerList[0].m_uid);
                if (curPVPRoomPlayerList != null)
                {
                    PVPChangCiUtil.getInstance().sortPVPRoomPlayerList(curPVPRoomPlayerList);
                    PVPChangCiUtil.getInstance().deletePVPRoomPlayerList(curPVPRoomPlayerList);

                    GameUtil.setPVPReward(curPVPRoomPlayerList);

                    // 游戏数据统计
                    Request_GameStatistics.doRequest(now_room, winnerList);

                    string gameroomname = PVPGameRoomDataScript.getInstance().getDataByRoomType(curPVPRoomPlayerList.m_gameRoomType).gameroomname;

                    // 用邮件给他们发奖励
                    for (int i = 0; i < curPVPRoomPlayerList.m_playerList.Count; i++)
                    {
                        LogUtil.getInstance().addDebugLog(m_tag + "----名次" + (i + 1) + "  id = " + curPVPRoomPlayerList.m_playerList[i].m_uid + " 分数为" + curPVPRoomPlayerList.m_playerList[i].m_score + "  奖励为:" + curPVPRoomPlayerList.m_playerList[i].m_pvpReward);

                        if (curPVPRoomPlayerList.m_playerList[i].m_pvpReward.CompareTo("") != 0)
                        {
                            string title   = gameroomname + "奖励";
                            string content = "恭喜您在" + gameroomname + "获得第" + curPVPRoomPlayerList.m_playerList[i].m_rank + "名,为您送上专属奖励";
                            Request_SendMailToUser.doRequest(curPVPRoomPlayerList.m_playerList[i].m_uid, title, content, curPVPRoomPlayerList.m_playerList[i].m_pvpReward);
                        }

                        // 提交任务
                        if (i == 0)
                        {
                            Request_ProgressTask.doRequest(curPVPRoomPlayerList.m_playerList[i].m_uid, 214);
                        }
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog(m_tag + "----curPVPRoomPlayerList == null");
                }

                {
                    JObject respondJO;
                    {
                        respondJO = new JObject();

                        respondJO.Add("tag", m_tag);
                        respondJO.Add("playAction", (int)TLJCommon.Consts.PlayAction.PlayAction_PVPGameOver);
                    }

                    // 给在线的人推送
                    for (int i = 0; i < now_room.getPlayerDataList().Count; i++)
                    {
                        if (!now_room.getPlayerDataList()[i].isOffLine())
                        {
                            if (respondJO.GetValue("mingci") != null)
                            {
                                respondJO.Remove("mingci");
                            }

                            if (respondJO.GetValue("pvpreward") != null)
                            {
                                respondJO.Remove("pvpreward");
                            }

                            respondJO.Add("mingci", now_room.getPlayerDataList()[i].m_rank);
                            respondJO.Add("pvpreward", now_room.getPlayerDataList()[i].m_pvpReward);

                            PlayService.m_serverUtil.sendMessage(now_room.getPlayerDataList()[i].m_connId, respondJO.ToString());
                        }
                    }
                }

                // 删除该房间
                {
                    LogUtil.getInstance().writeRoomLog(now_room, m_logFlag + "----" + ":PVP所有局数已打完,强制解散该房间:" + now_room.getRoomId());

                    GameLogic.removeRoom(this, now_room, true);
                }
            }
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":gameOver异常:" + ex);
        }
    }
    // 游戏结束
    public override void gameOver(RoomData room)
    {
        try
        {
            room.setRoomState(RoomState.RoomState_end);
            room.m_masterPokerType = -1;

            LogUtil.getInstance().writeRoomLog(room, m_logFlag + "----" + ":比赛结束,roomid = :" + room.getRoomId());

            // 游戏在线统计
            for (int i = 0; i < room.getPlayerDataList().Count; i++)
            {
                Request_OnlineStatistics.doRequest(room.getPlayerDataList()[i].m_uid, room.getRoomId(), room.m_gameRoomType, room.getPlayerDataList()[i].m_isAI, (int)Request_OnlineStatistics.OnlineStatisticsType.OnlineStatisticsType_exit);
            }

            // 计算每个玩家的金币(积分)
            GameUtil.setPlayerScore(room, false);

            // 加减金币
            {
                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    // 如果玩家这一局赢了,则检测是否有金币加倍buff?
                    if (room.getPlayerDataList()[i].m_score > 0)
                    {
                        bool          canUse        = false;
                        UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(room.getPlayerDataList()[i].m_uid);
                        if (userInfo_Game != null)
                        {
                            for (int j = 0; j < userInfo_Game.BuffData.Count; j++)
                            {
                                if ((userInfo_Game.BuffData[j].prop_id == (int)TLJCommon.Consts.Prop.Prop_jiabeika) && (userInfo_Game.BuffData[j].buff_num > 0))
                                {
                                    userInfo_Game.BuffData[j].buff_num -= 1;
                                    canUse = true;

                                    LogUtil.getInstance().writeRoomLog(room, m_logFlag + "----" + ":此玩家有双倍金币buff,金币奖励加倍 :" + room.getPlayerDataList()[i].m_uid);

                                    break;
                                }
                            }
                        }

                        if (canUse)
                        {
                            room.getPlayerDataList()[i].m_score *= 2;

                            // 扣除玩家buff:加倍卡
                            Request_UseBuff.doRequest(room.getPlayerDataList()[i].m_uid, (int)TLJCommon.Consts.Prop.Prop_jiabeika);
                        }
                    }

                    // 加、减玩家金币值
                    Request_ChangeUserWealth.doRequest(room.getPlayerDataList()[i].m_uid, 1, room.getPlayerDataList()[i].m_score, "休闲场结算");
                }
            }

            // 逻辑处理
            {
                List <string> winnerList = new List <string>();

                // 闲家赢
                if (room.m_getAllScore >= 80)
                {
                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        if (room.getPlayerDataList()[i].m_isBanker == 0)
                        {
                            winnerList.Add(room.getPlayerDataList()[i].m_uid);

                            ++room.getPlayerDataList()[i].m_myLevelPoker;
                            if (room.getPlayerDataList()[i].m_myLevelPoker == 15)
                            {
                                room.getPlayerDataList()[i].m_myLevelPoker = 2;
                            }

                            room.m_levelPokerNum = room.getPlayerDataList()[i].m_myLevelPoker;

                            // 提交任务
                            if (!room.getPlayerDataList()[i].m_isAI)
                            {
                                Request_ProgressTask.doRequest(room.getPlayerDataList()[i].m_uid, 203);
                                Request_ProgressTask.doRequest(room.getPlayerDataList()[i].m_uid, 212);
                            }

                            // 记录胜利次数数据
                            {
                                Request_RecordUserGameData.doRequest(room.getPlayerDataList()[i].m_uid, room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Win);
                            }
                        }
                    }
                }
                // 庄家赢
                else
                {
                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        if (room.getPlayerDataList()[i].m_isBanker == 1)
                        {
                            winnerList.Add(room.getPlayerDataList()[i].m_uid);

                            ++room.getPlayerDataList()[i].m_myLevelPoker;
                            if (room.getPlayerDataList()[i].m_myLevelPoker == 15)
                            {
                                room.getPlayerDataList()[i].m_myLevelPoker = 2;
                            }

                            room.m_levelPokerNum = room.getPlayerDataList()[i].m_myLevelPoker;

                            // 提交任务
                            if (!room.getPlayerDataList()[i].m_isAI)
                            {
                                Request_ProgressTask.doRequest(room.getPlayerDataList()[i].m_uid, 203);
                                Request_ProgressTask.doRequest(room.getPlayerDataList()[i].m_uid, 212);
                            }

                            // 记录胜利次数数据
                            {
                                Request_RecordUserGameData.doRequest(room.getPlayerDataList()[i].m_uid, room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Win);
                            }
                        }
                    }
                }

                // 游戏数据统计
                Request_GameStatistics.doRequest(room, winnerList);
            }

            // 通知
            {
                JObject respondJO;
                {
                    respondJO = new JObject();

                    respondJO.Add("tag", m_tag);
                    respondJO.Add("playAction", (int)TLJCommon.Consts.PlayAction.PlayAction_GameOver);
                    respondJO.Add("getAllScore", room.m_getAllScore);
                    respondJO.Add("isBankerWin", room.m_getAllScore >= 80 ? 0 : 1);
                    respondJO.Add("isContiune", false);
                }

                // 给在线的人推送
                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    // 推送给客户端
                    if (!room.getPlayerDataList()[i].isOffLine())
                    {
                        if (!(room.getPlayerDataList()[i].m_isAI))
                        {
                            if (respondJO.GetValue("score") != null)
                            {
                                respondJO.Remove("score");
                            }

                            respondJO.Add("score", room.getPlayerDataList()[i].m_score);

                            PlayService.m_serverUtil.sendMessage(room.getPlayerDataList()[i].m_connId, respondJO.ToString());
                        }
                    }
                    else
                    {
                        if (!(room.getPlayerDataList()[i].m_isAI))
                        {
                            // 记录逃跑数据
                            Request_RecordUserGameData.doRequest(room.getPlayerDataList()[i].m_uid, room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Run);
                        }
                    }

                    // 告诉数据库服务器该玩家打完一局
                    {
                        Request_GameOver.doRequest(room.getPlayerDataList()[i].m_uid, room.m_gameRoomType);
                    }
                }
            }

            // 检查是否删除该房间
            {
                if (GameUtil.checkRoomNonePlayer(room))
                {
                    LogUtil.getInstance().writeRoomLog(room, m_logFlag + "----" + ":所有人都离线,解散该房间:" + room.getRoomId());
                    GameLogic.removeRoom(this, room, true);
                }
            }
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":gameOver异常:" + ex);
        }
    }