大闹天宫,随机阵容问题处理
parent
0567561cee
commit
bf0ab56a93
|
@ -132,34 +132,27 @@ public class RankLogic {
|
|||
* @throws Exception
|
||||
*/
|
||||
public List<List<Integer>> getRandomUserByRank(User user,int counts) throws Exception {
|
||||
// 获取排行榜得数量
|
||||
int rankEndLine = 50;
|
||||
if (counts > rankEndLine){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"逻辑错误,传值有问题");
|
||||
}
|
||||
// 获取排行信息
|
||||
PlayerInfoProto.RankResponse rankResponse = getRankInfo(user,1,rankEndLine);
|
||||
PlayerInfoProto.RankResponse rankResponse = getRankInfo(user,1,50);
|
||||
// 计时器
|
||||
long start = System.currentTimeMillis();
|
||||
List<List<Integer>> result = new ArrayList<>();
|
||||
// -1方便后面取值操作,防止下标越界异常
|
||||
int rankSize = rankResponse.getRanksCount()-1;
|
||||
if (rankSize < 0){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"战力排行榜找不到人");
|
||||
|
||||
int rankSize = rankResponse.getRanksCount();
|
||||
if (rankSize <= 0){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"战力排行榜暂无数据,没有人上榜");
|
||||
}
|
||||
|
||||
List<List<Integer>> result = new ArrayList<>();
|
||||
// 计数器
|
||||
int count = 0;
|
||||
do {
|
||||
// 从0开始的随机
|
||||
int random = MathUtils.randomInt(rankEndLine);
|
||||
// 随机排名
|
||||
int anInt = random > rankSize?rankSize:random;
|
||||
|
||||
int random = MathUtils.randomInt(rankSize);
|
||||
// 获取随机玩家的主线队伍阵容
|
||||
User other1 = getRankUid(rankResponse, anInt);
|
||||
User other1 = getRankUid(rankResponse, random);
|
||||
List<Integer> heroInfos = getTeamByUid(other1);
|
||||
|
||||
// 队伍长度不足六人
|
||||
if (heroInfos.size() < 6){
|
||||
// 队伍长度不足六人
|
||||
if (count == 5){
|
||||
// 最多循环五次,五次之后直接取第一名得id
|
||||
User other2 = getRankUid(rankResponse, 0);
|
||||
|
|
Loading…
Reference in New Issue