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()); } }
public static UserInfo_Game getDataByUid(string uid) { UserInfo_Game userInfo_Game = null; for (int i = 0; i < s_dataList.Count; i++) { if (s_dataList[i].uid.CompareTo(uid) == 0) { userInfo_Game = s_dataList[i]; break; } } return(userInfo_Game); }
public static void addOneData(UserInfo_Game userInfo_Game) { lock (s_dataList) { for (int i = 0; i < s_dataList.Count; i++) { if (s_dataList[i].uid.CompareTo(userInfo_Game.uid) == 0) { s_dataList[i] = userInfo_Game; return; } } s_dataList.Add(userInfo_Game); } }
public override string OnResponse(string data) { OtherUserInfoReq defaultReq = null; try { defaultReq = JsonConvert.DeserializeObject <OtherUserInfoReq>(data); } catch (Exception e) { MySqlService.log.Warn("传入的参数有误:" + e); return(null); } string Tag = defaultReq.tag; int connId = defaultReq.connId; string uid = defaultReq.uid; int isClientReq = defaultReq.isClientReq; if (string.IsNullOrWhiteSpace(Tag) || string.IsNullOrWhiteSpace(uid)) { MySqlService.log.Warn("字段有空"); return(null); } //传给客户端的数据 // JObject responseData = new JObject(); // responseData.Add(MyCommon.TAG, Tag); // responseData.Add(MyCommon.CONNID, connId); // responseData.Add(MyCommon.UID, uid); // responseData.Add("isClientReq", isClientReq); UserInfo_Game userInfoGame = new UserInfo_Game() { connId = connId, tag = Tag, uid = uid, isClientReq = isClientReq, }; GetOtherUserInfoSql(uid, userInfoGame); return(JsonConvert.SerializeObject(userInfoGame)); }
private void GetOtherUserInfoSql(string uid, UserInfo_Game userInfo_Game) { User user = NHibernateHelper.userManager.GetByUid(uid); if (user == null) { OperatorFail(userInfo_Game); MySqlService.log.Warn("传入的uid未注册"); } else { UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid); UserGame userGame = NHibernateHelper.userGameManager.GetByUid(uid); //用户信息表中没有用户信息 if (userInfo == null) { //注册用户数据 userInfo = GetUserInfoHandler.AddUserInfo(user.Uid, user.Username); userGame = GetUserInfoHandler.AddUserGame(user.Uid); if (NHibernateHelper.userInfoManager.Add(userInfo) && NHibernateHelper.userGameManager.Add(userGame)) { OperatorSuccess(userInfo, userGame, userInfo_Game); } else { OperatorFail(userInfo_Game); MySqlService.log.Warn("添加用户信息失败"); } } else { OperatorSuccess(userInfo, userGame, userInfo_Game); } } }
//数据库操作成功 private void OperatorSuccess(UserInfo userInfo, UserGame userGame, UserInfo_Game userInfo_Game) { userInfo_Game.code = (int)Consts.Code.Code_OK; userInfo_Game.name = userInfo.NickName; var vipLevel = VipUtil.GetVipLevel(userInfo.RechargeVip); userInfo_Game.vipLevel = vipLevel; userInfo_Game.gold = userInfo.Gold; userInfo_Game.head = userInfo.Head; userInfo_Game.gameData = new UserInfo_Game.Gamedata(); userInfo_Game.gameData.allGameCount = userGame.AllGameCount; userInfo_Game.gameData.winCount = userGame.WinCount; userInfo_Game.gameData.runCount = userGame.RunCount; userInfo_Game.gameData.meiliZhi = userGame.MeiliZhi; //用户buff List <UserInfo_Game.UserBuff> userBuffJsonObjects = new List <UserInfo_Game.UserBuff>(); List <UserProp> userProps = NHibernateHelper.userPropManager.GetListByUid(userInfo.Uid); if (userProps != null) { for (int i = 0; i < userProps.Count; i++) { if (userProps[i].BuffNum > 0) { UserInfo_Game.UserBuff userBuffJsonObject = new UserInfo_Game.UserBuff() { prop_id = userProps[i].PropId, buff_num = userProps[i].BuffNum }; userBuffJsonObjects.Add(userBuffJsonObject); } } } userInfo_Game.BuffData = userBuffJsonObjects; }
public static void setPVPReward(PVPRoomPlayerList curPVPRoomPlayerList) { string gameRoomType = curPVPRoomPlayerList.m_gameRoomType; List <string> list = new List <string>(); CommonUtil.splitStr(gameRoomType, list, '_'); if (list.Count == 3) { if (list[0].CompareTo("PVP") == 0) { PVPGameRoomData pvpGameRoomData = PVPGameRoomDataScript.getInstance().getDataByRoomType(gameRoomType); // PVP-金币场 if (list[1].CompareTo("JinBi") == 0) { // 2000金币场 if (pvpGameRoomData.reward_num == 2000) { // 第一名 { int getHuiZhangNum = 1; UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(curPVPRoomPlayerList.m_playerList[0].m_uid); if (userInfo_Game != null) { int vipLevel = userInfo_Game.vipLevel; if ((vipLevel >= 2) && (vipLevel <= 4)) { getHuiZhangNum += 1; } else if ((vipLevel >= 5) && (vipLevel <= 7)) { getHuiZhangNum += 2; } else if ((vipLevel >= 8) && (vipLevel <= 10)) { getHuiZhangNum += 3; } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPVPReward出错:UserInfo_Game_Manager.getDataByUid()为空"); } curPVPRoomPlayerList.m_playerList[0].m_pvpReward = "1:2000;110:" + getHuiZhangNum; } // 第二名 { curPVPRoomPlayerList.m_playerList[1].m_pvpReward = "1:1000"; } } // 10000金币场 else if (pvpGameRoomData.reward_num == 10000) { // 第一名 { int getHuiZhangNum = 1; UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(curPVPRoomPlayerList.m_playerList[0].m_uid); if (userInfo_Game != null) { int vipLevel = userInfo_Game.vipLevel; if ((vipLevel >= 2) && (vipLevel <= 4)) { getHuiZhangNum += 1; } else if ((vipLevel >= 5) && (vipLevel <= 7)) { getHuiZhangNum += 2; } else if ((vipLevel >= 8) && (vipLevel <= 10)) { getHuiZhangNum += 3; } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPVPReward出错:UserInfo_Game_Manager.getDataByUid()为空"); } curPVPRoomPlayerList.m_playerList[0].m_pvpReward = "1:10000;110:" + getHuiZhangNum; } // 第二名 { curPVPRoomPlayerList.m_playerList[1].m_pvpReward = "1:1000"; } } // 5000金币场(用于ios审核) else if (pvpGameRoomData.reward_num == 5000) { // 第一名 { int getHuiZhangNum = 1; UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(curPVPRoomPlayerList.m_playerList[0].m_uid); if (userInfo_Game != null) { int vipLevel = userInfo_Game.vipLevel; if ((vipLevel >= 2) && (vipLevel <= 4)) { getHuiZhangNum += 1; } else if ((vipLevel >= 5) && (vipLevel <= 7)) { getHuiZhangNum += 2; } else if ((vipLevel >= 8) && (vipLevel <= 10)) { getHuiZhangNum += 3; } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPVPReward出错:UserInfo_Game_Manager.getDataByUid()为空"); } curPVPRoomPlayerList.m_playerList[0].m_pvpReward = "1:5000;110:" + getHuiZhangNum; } // 第二名 { curPVPRoomPlayerList.m_playerList[1].m_pvpReward = "1:1000"; } } } // PVP-话费场 else if (list[1].CompareTo("HuaFei") == 0) { // 1元话费场 if (list[2].CompareTo("1") == 0) { // 第一名 { int getHuiZhangNum = 1; UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(curPVPRoomPlayerList.m_playerList[0].m_uid); if (userInfo_Game != null) { int vipLevel = userInfo_Game.vipLevel; if ((vipLevel >= 2) && (vipLevel <= 4)) { getHuiZhangNum += 1; } else if ((vipLevel >= 5) && (vipLevel <= 7)) { getHuiZhangNum += 2; } else if ((vipLevel >= 8) && (vipLevel <= 10)) { getHuiZhangNum += 3; } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPVPReward出错:UserInfo_Game_Manager.getDataByUid()为空"); } curPVPRoomPlayerList.m_playerList[0].m_pvpReward = "111:1;110:" + getHuiZhangNum; } // 第二名 { curPVPRoomPlayerList.m_playerList[1].m_pvpReward = "1:500"; } } // 5元话费场 else if (list[2].CompareTo("5") == 0) { // 第一名 { int getHuiZhangNum = 2; UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(curPVPRoomPlayerList.m_playerList[0].m_uid); if (userInfo_Game != null) { int vipLevel = userInfo_Game.vipLevel; if ((vipLevel >= 2) && (vipLevel <= 4)) { getHuiZhangNum += 1; } else if ((vipLevel >= 5) && (vipLevel <= 7)) { getHuiZhangNum += 2; } else if ((vipLevel >= 8) && (vipLevel <= 10)) { getHuiZhangNum += 3; } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPVPReward出错:UserInfo_Game_Manager.getDataByUid()为空"); } curPVPRoomPlayerList.m_playerList[0].m_pvpReward = "112:1;110:" + getHuiZhangNum; } // 第二名 { curPVPRoomPlayerList.m_playerList[1].m_pvpReward = "1:5000;110:1"; } } } } } }
/* * canFuShu:是否可以为负数? * 休闲场score代表金币,是要扣除的,所以可以为负数 * PVP场score代表积分,扣到0就不扣了,不能为负数 */ public static void setPlayerScore(RoomData room, bool canFuShu) { try { float jichufenshu = 985; float changcixishu = 1; float defenxishu = 1; float xianjiadefen; // 计算场次系数 { List <string> tempList = new List <string>(); CommonUtil.splitStr(room.m_gameRoomType, tempList, '_'); switch (tempList[0]) { case "XiuXian": { if (tempList[2].CompareTo("Common") == 0) { changcixishu = 2; } else if (tempList[2].CompareTo("ChuJi") == 0) { changcixishu = 1; } else if (tempList[2].CompareTo("ZhongJi") == 0) { changcixishu = 2; } else if (tempList[2].CompareTo("GaoJi") == 0) { changcixishu = 3; } } break; case "PVP": { changcixishu = 1; } break; } } // 计算得分系数 { if (room.m_getAllScore == 0) { defenxishu = -3.6f; } else if ((room.m_getAllScore >= 5) && (room.m_getAllScore <= 40)) { defenxishu = -2.6f; } else if ((room.m_getAllScore >= 45) && (room.m_getAllScore <= 75)) { defenxishu = -1.6f; } else if (room.m_getAllScore == 80) { defenxishu = 1.0f; } else if ((room.m_getAllScore >= 85) && (room.m_getAllScore <= 120)) { defenxishu = 1.6f; } else if ((room.m_getAllScore >= 125) && (room.m_getAllScore <= 195)) { defenxishu = 2.6f; } else if (room.m_getAllScore >= 200) { defenxishu = 3.6f; } } xianjiadefen = jichufenshu * changcixishu * defenxishu; if (!canFuShu) { // 闲家赢 if (xianjiadefen > 0) { float winerCanGetScote = 0; for (int i = 0; i < room.getPlayerDataList().Count; i++) { if (room.getPlayerDataList()[i].m_isBanker == 1) { UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(room.getPlayerDataList()[i].m_uid); if (userInfo_Game != null) { if (userInfo_Game.gold >= xianjiadefen) { winerCanGetScote += xianjiadefen; room.getPlayerDataList()[i].m_score = (int)(-xianjiadefen); } else { winerCanGetScote += userInfo_Game.gold; room.getPlayerDataList()[i].m_score = (-userInfo_Game.gold); } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPlayerScore出错:UserInfo_Game_Manager.getDataByUid()为空"); } } } for (int i = 0; i < room.getPlayerDataList().Count; i++) { if (room.getPlayerDataList()[i].m_isBanker != 1) { room.getPlayerDataList()[i].m_score = (int)winerCanGetScote / 2; } } } // 庄家赢 else { float winerCanGetScote = 0; for (int i = 0; i < room.getPlayerDataList().Count; i++) { UserInfo_Game userInfo_Game = UserInfo_Game_Manager.getDataByUid(room.getPlayerDataList()[i].m_uid); if (userInfo_Game != null) { if (room.getPlayerDataList()[i].m_isBanker != 1) { if (userInfo_Game.gold >= (-xianjiadefen)) { winerCanGetScote += (-xianjiadefen); room.getPlayerDataList()[i].m_score = (int)xianjiadefen; } else { winerCanGetScote += userInfo_Game.gold; room.getPlayerDataList()[i].m_score = (-userInfo_Game.gold); } } } else { TLJ_PlayService.PlayService.log.Error(m_logFlag + "----" + ":setPlayerScore出错:UserInfo_Game_Manager.getDataByUid()为空"); } } for (int i = 0; i < room.getPlayerDataList().Count; i++) { if (room.getPlayerDataList()[i].m_isBanker == 1) { room.getPlayerDataList()[i].m_score = (int)winerCanGetScote / 2; } } } } else { for (int i = 0; i < room.getPlayerDataList().Count; i++) { if (room.getPlayerDataList()[i].m_isBanker == 1) { room.getPlayerDataList()[i].m_score += (-(int)xianjiadefen); } else { room.getPlayerDataList()[i].m_score += (int)xianjiadefen; } } } } catch (Exception ex) { TLJ_PlayService.PlayService.log.Error("GameUtil.setPlayerScore()----" + ex.Message + "gameRoomType:" + room.m_gameRoomType); } }
// 游戏结束 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); } }
//数据库操作失败 private void OperatorFail(UserInfo_Game userInfo_Game) { userInfo_Game.code = (int)Consts.Code.Code_CommonFail; }
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); } }