public List <PlayerJingJiMiniData> getChallengeData(int[] challengeRankings) { List <PlayerJingJiMiniData> miniDataList = new List <PlayerJingJiMiniData>(); lock (this.changeRankingLock) { if (challengeRankings.Length > 1 && challengeRankings[0] < 0) { int delta = Math.Min(this.rankingDatas.Count / 6, -challengeRankings[0]); if (delta <= 2) { return(miniDataList); } challengeRankings[0] = this.rankingDatas.Count - 1 - delta; challengeRankings[1] = this.rankingDatas.Count - 1 - delta * 2; challengeRankings[2] = this.rankingDatas.Count - 1 - delta * 3; } int nCheckCount = 0; while (nCheckCount++ < 6) { bool bErrorRank = false; foreach (int challengeRanking in challengeRankings) { PlayerJingJiData robotData = null; if (challengeRanking <= this.rankingDatas.Count) { PlayerJingJiRankingData rankingData = this.rankingDatas[challengeRanking - 1]; if (rankingData.ranking < 0) { bErrorRank = true; this.rankingDatas.Remove(rankingData); break; } } } if (!bErrorRank) { break; } this.rankingDatas.Sort(); } foreach (int challengeRanking in challengeRankings) { PlayerJingJiData robotData = null; if (challengeRanking <= this.rankingDatas.Count) { PlayerJingJiRankingData rankingData = this.rankingDatas[challengeRanking - 1]; if (this.playerJingJiDatas.TryGetValue(rankingData.roleId, out robotData)) { miniDataList.Add(robotData.getPlayerJingJiMiniData()); } } } } return(miniDataList); }
public JingJiBeChallengeData requestChallenge(int challengerId, int beChallengerId, int beChallengerRanking) { JingJiBeChallengeData data = new JingJiBeChallengeData(); PlayerJingJiData challengerData = null; JingJiBeChallengeData result; lock (this.changeRankingLock) { if (!this.playerJingJiDatas.TryGetValue(challengerId, out challengerData)) { data.state = 0; result = data; } else if (TimeUtil.NOW() < challengerData.nextChallengeTime) { data.state = -1; result = data; } else if ((challengerData.ranking > 100 || challengerData.ranking < 0) && beChallengerRanking <= 3) { data.state = -5; result = data; } else if (beChallengerRanking > this.rankingDatas.Count || beChallengerRanking < 1) { data.state = -2; result = data; } else { PlayerJingJiRankingData rankingData = this.rankingDatas[beChallengerRanking - 1]; PlayerJingJiData beChallengerData = null; if (!this.playerJingJiDatas.TryGetValue(rankingData.roleId, out beChallengerData)) { data.state = 0; result = data; } else if (challengerId == rankingData.roleId) { data.state = -3; result = data; } else { BeChallengerCount beChallengerCount = null; this.lockPlayerJingJiDatas.TryGetValue(beChallengerData.roleId, out beChallengerCount); if (null == beChallengerCount) { beChallengerCount = new BeChallengerCount(); beChallengerCount.nBeChallengerCount = 1; this.lockPlayerJingJiDatas.Add(beChallengerData.roleId, beChallengerCount); } else { beChallengerCount.nBeChallengerCount++; } data.state = 1; data.beChallengerData = beChallengerData; result = data; } } } return(result); }
/// <summary> /// 请求挑战 /// </summary> /// <param name="beChallengeId">被挑战者ID</param> /// <param name="beChallengeRanking">被挑战者排名</param> /// <returns>1:请求成功,0:非法参数,-1:冷却时间未到,-2:被挑战机器人不存在,-3:被挑战机器人排名已更改,-4:正在被其他玩家挑战</returns> public JingJiBeChallengeData requestChallenge(int challengerId, int beChallengerId, int beChallengerRanking) { JingJiBeChallengeData data = new JingJiBeChallengeData(); PlayerJingJiData challengerData = null; lock (changeRankingLock) { if (!playerJingJiDatas.TryGetValue(challengerId, out challengerData)) { data.state = 0; return(data); } //冷却时间未到 if (TimeUtil.NOW() < challengerData.nextChallengeTime) { data.state = -1; return(data); } PlayerJingJiRankingData rankingData = null; int bakBeChallengerRanking = beChallengerRanking; // int bakBeChallengerRanking = beChallengerData.ranking; if (bakBeChallengerRanking > rankingDatas.Count || bakBeChallengerRanking < 1) { //被挑战机器人不存在 data.state = -2; return(data); } //lock (rankingDatas) { rankingData = rankingDatas[bakBeChallengerRanking - 1]; } PlayerJingJiData beChallengerData = null; if (!playerJingJiDatas.TryGetValue(rankingData.roleId, out beChallengerData)) { data.state = 0; return(data); } if (challengerId == rankingData.roleId) { //不能挑战自己 data.state = -3; return(data); } //if (beChallengerId != rankingData.roleId) //{ // //被挑战机器人排名已更改 // data.state = -3; // return data; //} //lock (lockPlayerJingJiDatas) //{ // if (lockPlayerJingJiDatas.TryGetValue(beChallengerId, out beChallengerData)) // { // //正在被其他玩家挑战 // data.state = -4; // return data; // } // //获取被挑战者数据 // playerJingJiDatas.TryGetValue(beChallengerId, out beChallengerData); // //锁定 // lockPlayerJingJiDatas.Add(beChallengerData.roleId, beChallengerData); //} BeChallengerCount beChallengerCount = null; lockPlayerJingJiDatas.TryGetValue(beChallengerData.roleId, out beChallengerCount); if (null == beChallengerCount) { beChallengerCount = new BeChallengerCount(); beChallengerCount.nBeChallengerCount = 1; lockPlayerJingJiDatas.Add(beChallengerData.roleId, beChallengerCount); } else { beChallengerCount.nBeChallengerCount += 1; } data.state = 1; data.beChallengerData = beChallengerData; return(data); } }