public static void onMySqlRespond(string respondData)
    {
        try
        {
            UserInfo_Game userInfo_Game = Newtonsoft.Json.JsonConvert.DeserializeObject <UserInfo_Game>(respondData);
            UserInfo_Game_Manager.addOneData(userInfo_Game);

            // 获取到玩家信息之后找到该玩家所在的房间,给同桌的玩家推送此人的信息
            {
                // 去升级找
                RoomData room = GameUtil.getRoomByUid(userInfo_Game.uid);
                if (room != null)
                {
                    string data = Newtonsoft.Json.JsonConvert.SerializeObject(userInfo_Game);

                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        if ((!room.getPlayerDataList()[i].isOffLine()) && (room.getPlayerDataList()[i].m_uid.CompareTo(userInfo_Game.uid) != 0))
                        {
                            // 发送给客户端
                            PlayService.m_serverUtil.sendMessage(room.getPlayerDataList()[i].m_connId, data);
                        }
                    }
                }
                else
                {
                    // 去斗地主找
                    DDZ_RoomData room_ddz = DDZ_GameUtil.getRoomByUid(userInfo_Game.uid);
                    if (room_ddz != null)
                    {
                        string data = Newtonsoft.Json.JsonConvert.SerializeObject(userInfo_Game);

                        for (int i = 0; i < room_ddz.getPlayerDataList().Count; i++)
                        {
                            if ((!room_ddz.getPlayerDataList()[i].isOffLine()) && (room_ddz.getPlayerDataList()[i].m_uid.CompareTo(userInfo_Game.uid) != 0))
                            {
                                // 发送给客户端
                                PlayService.m_serverUtil.sendMessage(room_ddz.getPlayerDataList()[i].m_connId, data);
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error("Request_UserInfo_Game.onMySqlRespond----" + ex.Message + "," + respondData);

            // 客户端参数错误
            //respondJO.Add("code", Convert.ToInt32(TLJCommon.Consts.Code.Code_ParamError));

            // 发送给客户端
            //LogicService.m_serverUtil.sendMessage(connId, respondJO.ToString());
        }
    }
Example #2
0
    public static bool checkRoomNonePlayer(DDZ_RoomData room)
    {
        // 清理机器人和离线的人
        clearRoomNonePlayer(room);

        bool isRemove = true;

        if (room.getPlayerDataList().Count > 0)
        {
            isRemove = false;
        }

        return(isRemove);
    }
Example #3
0
    public static int getGameRoomPlayerCount(string gameRoomType)
    {
        int count = 0;

        for (int i = 0; i < PlayLogic_PVP.getInstance().getRoomList().Count; i++)
        {
            DDZ_RoomData tempRoom = PlayLogic_DDZ.getInstance().getRoomList()[i];
            if (tempRoom.m_gameRoomType.CompareTo(gameRoomType) == 0)
            {
                for (int j = 0; j < tempRoom.getPlayerDataList().Count; j++)
                {
                    ++count;
                }
            }
        }

        return(count);
    }
Example #4
0
    public static void clearRoomNonePlayer(DDZ_RoomData room)
    {
        // 删除机器人
        for (int i = room.getPlayerDataList().Count - 1; i >= 0; i--)
        {
            if (room.getPlayerDataList()[i].m_isAI)
            {
                LogUtil.getInstance().addDebugLog("清理机器人:" + room.getPlayerDataList()[i].m_uid);

                AIDataScript.getInstance().backOneAI(room.getPlayerDataList()[i].m_uid);
                room.getPlayerDataList().RemoveAt(i);
            }
        }

        // 删除离线的人
        for (int i = room.getPlayerDataList().Count - 1; i >= 0; i--)
        {
            if (room.getPlayerDataList()[i].isOffLine())
            {
                LogUtil.getInstance().addDebugLog("清理离线的人:" + room.getPlayerDataList()[i].m_uid);
                room.getPlayerDataList().RemoveAt(i);
            }
        }
    }
Example #5
0
    public static void setPlayerScore(DDZ_RoomData room, bool canFuShu)
    {
        try
        {
            float jichufenshu  = 100;
            float changcixishu = 1;
            float beishu       = 1;

            for (int i = 0; i < room.getPlayerDataList().Count; i++)
            {
                float score = 0;

                // 叫分 * 春天倍数 * 炸弹倍数
                beishu = room.m_maxJiaoFenPlayerData.m_jiaofen * room.m_beishu_chuntian * room.m_beishu_bomb;
                if (room.getPlayerDataList()[i].m_isJiaBang == 1)
                {
                    beishu *= 2;
                }

                score = jichufenshu * changcixishu * beishu;
                room.getPlayerDataList()[i].m_score = (int)score;
            }

            // 地主赢
            if (room.m_winPlayerData.m_isDiZhu == 1)
            {
                int winerCanGetScote = 0;

                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    DDZ_PlayerData playerData = room.getPlayerDataList()[i];

                    if (playerData.m_isDiZhu != 1)
                    {
                        UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(playerData.m_uid);
                        if (userInfo_Game != null)
                        {
                            if (userInfo_Game.gold < playerData.m_score)
                            {
                                winerCanGetScote  += userInfo_Game.gold;
                                playerData.m_score = -userInfo_Game.gold;
                            }
                            else
                            {
                                winerCanGetScote  += playerData.m_score;
                                playerData.m_score = -playerData.m_score;
                            }
                        }
                    }
                }

                room.m_diZhuPlayer.m_score = winerCanGetScote;
            }
            // 农民赢
            else
            {
                int winerCanGetScote = 0;

                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    DDZ_PlayerData playerData = room.getPlayerDataList()[i];

                    if (playerData.m_isDiZhu != 1)
                    {
                        UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(playerData.m_uid);
                        if (userInfo_Game != null)
                        {
                            winerCanGetScote += playerData.m_score;
                        }
                    }
                }

                room.m_diZhuPlayer.m_score = -winerCanGetScote;
            }
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error("DDZ_GameUtil.setPlayerScore()----" + ex + "gameRoomType:" + room.m_gameRoomType);
        }
    }
Example #6
0
    // 记录房间日志
    public void writeRoomLog(DDZ_RoomData room, string data)
    {
        if (!m_canWriteDebugLog)
        {
            return;
        }

        if (room == null)
        {
            return;
        }

        // 把字符串中的换行符去掉
        data = data.Replace("\r\n", "");

        data = getCurTime() + "----" + data;

        m_canWriteDebugLog = false;

        StreamWriter sw = null;

        try
        {
            string path = m_rootFolderPath + "/" + getCurYearMonthDay() + "/";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path += room.getRoomId() + "  ";
            for (int i = 0; i < room.getPlayerDataList().Count; i++)
            {
                path += (room.getPlayerDataList()[i].m_uid + "、");
            }
            path += ".txt";

            if (!File.Exists(path))
            {
                File.Create(path).Close();
            }

            sw = new StreamWriter(path, true);

            sw.WriteLine(data);

            //清空缓冲区
            sw.Flush();

            //关闭流
            sw.Close();

            m_canWriteDebugLog = true;
        }
        catch (IOException e)
        {
            Console.Write(e);
        }
        finally
        {
            sw.Close();
        }
    }
Example #7
0
    // 游戏结束
    public override void gameOver(DDZ_RoomData room)
    {
        try
        {
            room.setRoomState(DDZ_RoomState.RoomState_end);

            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);
            }

            // 是否春天
            {
                if (room.m_winPlayerData.m_isDiZhu == 1)
                {
                    bool isChunTian = true;
                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        if (room.getPlayerDataList()[i].m_isDiZhu == 0)
                        {
                            if (room.getPlayerDataList()[i].m_outPokerCiShu > 0)
                            {
                                isChunTian = false;
                                break;
                            }
                        }
                    }

                    if (isChunTian)
                    {
                        room.m_beishu_chuntian = 2;
                    }
                }
                else
                {
                    bool isChunTian = true;
                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        if (room.getPlayerDataList()[i].m_isDiZhu == 1)
                        {
                            if (room.getPlayerDataList()[i].m_outPokerCiShu > 1)
                            {
                                isChunTian = false;
                                break;
                            }
                        }
                    }

                    if (isChunTian)
                    {
                        room.m_beishu_chuntian = 2;
                    }
                }
            }

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

            // 加减金币
            {
                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    // 加、减玩家金币值
                    Request_ChangeUserWealth.doRequest(room.getPlayerDataList()[i].m_uid, 1, room.getPlayerDataList()[i].m_score, "斗地主结算");
                }
            }

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

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

            {
                JObject respondJO = new JObject();
                {
                    respondJO.Add("tag", room.m_tag);
                    respondJO.Add("playAction", (int)TLJCommon.Consts.DDZ_PlayAction.PlayAction_GameOver);
                    respondJO.Add("isDiZhuWin", room.m_winPlayerData.m_isDiZhu);

                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        JObject jo = new JObject();
                        jo.Add("score", room.getPlayerDataList()[i].m_score);

                        float beishu = room.m_maxJiaoFenPlayerData.m_jiaofen * room.m_beishu_chuntian * room.m_beishu_bomb;
                        jo.Add("beishu", (int)beishu * (room.getPlayerDataList()[i].m_isJiaBang + 1));

                        respondJO.Add(room.getPlayerDataList()[i].m_uid, jo);
                    }

                    // 倍数
                    for (int i = 0; i < room.getPlayerDataList().Count; i++)
                    {
                        DDZ_PlayerData playerData = room.getPlayerDataList()[i];

                        JArray ja = new JArray();

                        {
                            ja.Add("初始倍数X" + room.m_maxJiaoFenPlayerData.m_jiaofen);

                            if (playerData.m_isJiaBang == 1)
                            {
                                ja.Add("加棒X2");
                            }

                            if (room.m_beishu_bomb > 1)
                            {
                                ja.Add("炸弹X" + room.m_beishu_bomb);
                            }

                            if (room.m_beishu_chuntian > 1)
                            {
                                ja.Add("春天X" + room.m_beishu_chuntian);
                            }
                        }

                        respondJO.Add("beishu_" + playerData.m_uid, ja);
                    }
                }

                for (int i = 0; i < room.getPlayerDataList().Count; i++)
                {
                    // 推送给客户端
                    if (!room.getPlayerDataList()[i].isOffLine())
                    {
                        PlayService.m_serverUtil.sendMessage(room.getPlayerDataList()[i].m_connId, respondJO.ToString());
                    }
                }
            }

            DDZ_GameLogic.removeRoom(this, room, true);
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error(m_logFlag + "gameOver异常: " + ex);
        }
    }
Example #8
0
    public override bool doTaskPlayerCloseConn(string uid)
    {
        try
        {
            DDZ_RoomData room = getRoomByUid(uid);
            if (room == null)
            {
                return(false);
            }

            DDZ_PlayerData playerData = DDZ_GameUtil.getPlayerDataByUid(uid);
            if (playerData == null)
            {
                return(false);
            }

            //// 记录逃跑数据
            //if ((m_roomList[i].m_roomState != RoomState.RoomState_waiting) &&
            //    (m_roomList[i].m_roomState != RoomState.RoomState_end))
            //{
            //    Request_RecordUserGameData.doRequest(room.getPlayerDataList()[i].m_uid, room.m_gameRoomType, (int)TLJCommon.Consts.GameAction.GameAction_Run);
            //}

            switch (room.getRoomState())
            {
            case DDZ_RoomState.RoomState_waiting:
            {
                if (!playerData.isOffLine())
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":玩家在本桌满人之前退出:" + playerData.m_uid);

                    room.getPlayerDataList().Remove(playerData);

                    if (DDZ_GameUtil.checkRoomNonePlayer(room))
                    {
                        LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此房间人数为0,解散房间:" + room.getRoomId());

                        DDZ_GameLogic.removeRoom(this, room, true);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此玩家连续退出/掉线:" + playerData.m_uid);
                }
            }
            break;

            case DDZ_RoomState.RoomState_fapai:
            case DDZ_RoomState.RoomState_qiangdizhu:
            case DDZ_RoomState.RoomState_jiabang:
            case DDZ_RoomState.RoomState_gaming:
            {
                if (!playerData.isOffLine())
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":玩家在游戏中退出:" + playerData.m_uid);
                    playerData.setIsOffLine(true);
                }
                else
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此玩家连续退出/掉线:" + playerData.m_uid);
                }
            }
            break;

            case DDZ_RoomState.RoomState_end:
            {
                if (!playerData.isOffLine())
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":玩家在本桌打完后退出:" + playerData.m_uid);

                    room.getPlayerDataList().Remove(playerData);
                    if (room.getPlayerDataList().Count == 0)
                    {
                        LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此房间人数为0,解散房间:" + room.getRoomId());

                        DDZ_GameLogic.removeRoom(this, room, true);
                    }
                    else
                    {
                        // 如果房间人数为空,则删除此房间
                        {
                            if (DDZ_GameUtil.checkRoomNonePlayer(room))
                            {
                                LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此房间人数为0,解散房间:" + room.getRoomId());

                                DDZ_GameLogic.removeRoom(this, room, true);
                            }
                        }
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此玩家连续退出/掉线:" + playerData.m_uid);
                }
            }
            break;

            default:
            {
                if (!playerData.isOffLine())
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":玩家在未知阶段退出:" + playerData.m_uid);

                    room.getPlayerDataList().Remove(playerData);

                    if (DDZ_GameUtil.checkRoomNonePlayer(room))
                    {
                        LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此房间人数为0,解散房间:" + room.getRoomId());

                        DDZ_GameLogic.removeRoom(this, room, true);
                    }
                }
                else
                {
                    LogUtil.getInstance().addDebugLog(m_logFlag + "----" + ":此玩家连续退出/掉线:" + playerData.m_uid);
                }
            }
            break;
            }

            return(true);
        }
        catch (Exception ex)
        {
            TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":doTaskPlayerCloseConn异常:" + ex);
        }

        return(false);
    }