大闹天宫,获取排行榜速度优化
parent
25aa13bfd5
commit
9cc1fd8fc9
|
@ -322,6 +322,9 @@ public class ExpeditionLogic {
|
||||||
double minFoce = sExpeditionSetting.getMatchForce()[leve-1][0]/base;
|
double minFoce = sExpeditionSetting.getMatchForce()[leve-1][0]/base;
|
||||||
double maxFoce = sExpeditionSetting.getMatchForce()[leve-1][1]/base;
|
double maxFoce = sExpeditionSetting.getMatchForce()[leve-1][1]/base;
|
||||||
|
|
||||||
|
List<List<Integer>> rankTeam = RankLogic.getInstance().getRandomUserByRank(user, nodeSets.size());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
//存储并设置英雄快照
|
//存储并设置英雄快照
|
||||||
for (ExpeditionNodeInfo nodeInfo : nodeSets) {
|
for (ExpeditionNodeInfo nodeInfo : nodeSets) {
|
||||||
try {
|
try {
|
||||||
|
@ -340,7 +343,7 @@ public class ExpeditionLogic {
|
||||||
robotLevel += (Math.ceil(sExpeditionSetting.getPowerfulForce()[2][1]/base*robotLevel));
|
robotLevel += (Math.ceil(sExpeditionSetting.getPowerfulForce()[2][1]/base*robotLevel));
|
||||||
}
|
}
|
||||||
// 随机出来的队伍信息
|
// 随机出来的队伍信息
|
||||||
List<Integer> randomFaceRankTeam = getRandomFaceRankTeam(user);
|
List<Integer> randomFaceRankTeam = rankTeam.get(count);
|
||||||
|
|
||||||
int robotLevel2 = getRobotLevelByUser(user, robotLevel);
|
int robotLevel2 = getRobotLevelByUser(user, robotLevel);
|
||||||
// 节点英雄快照
|
// 节点英雄快照
|
||||||
|
@ -354,6 +357,7 @@ public class ExpeditionLogic {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
user.getExpeditionManager().putExpeditionNodeInfos(nodeInfo.getSortId(), nodeInfo);
|
user.getExpeditionManager().putExpeditionNodeInfos(nodeInfo.getSortId(), nodeInfo);
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,68 +405,6 @@ public class ExpeditionLogic {
|
||||||
return level>1?level:1;
|
return level>1?level:1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取随机排名的队伍信息
|
|
||||||
* @param user
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private List<Integer> getRandomFaceRankTeam(User user) throws Exception {
|
|
||||||
// 战力排行榜
|
|
||||||
AbstractRank rank = RankContext.getRankEnum(RankEnum.FORCE_CURR_RANK.getType());
|
|
||||||
// 获取排行信息
|
|
||||||
PlayerInfoProto.RankResponse rankResponse = null;
|
|
||||||
try {
|
|
||||||
rankResponse = rank.getRank(user.getId(), "", 1, 50);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"获取战力排行榜数据错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TeamPosHeroInfo> heroInfos = new ArrayList<>();
|
|
||||||
ArrayList<Integer> integers = new ArrayList<>();
|
|
||||||
// -1方便后面取值操作,防止下标越界异常
|
|
||||||
int rankSize = rankResponse.getRanksCount()-1;
|
|
||||||
if (rankSize < 0){
|
|
||||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"战力排行榜找不到人");
|
|
||||||
}
|
|
||||||
// 计数器
|
|
||||||
int count = 0;
|
|
||||||
do {
|
|
||||||
// 从0开始的随机
|
|
||||||
int random = MathUtils.randomInt(50);
|
|
||||||
// 随机排名
|
|
||||||
int anInt = random > rankSize?rankSize:random;
|
|
||||||
|
|
||||||
CommonProto.UserRank ranks = rankResponse.getRanks(anInt);
|
|
||||||
User other = UserManager.getUser(ranks.getUid());
|
|
||||||
// 获取随机玩家的主线队伍阵容
|
|
||||||
heroInfos = other.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.FORMATION_NORMAL);
|
|
||||||
if (heroInfos.size() < 6){
|
|
||||||
count++;
|
|
||||||
}else {
|
|
||||||
heroInfos.forEach(v->{
|
|
||||||
// 获取英雄模板id
|
|
||||||
Hero hero = other.getHeroManager().getHero(v.getHeroId());
|
|
||||||
integers.add(hero.getTemplateId());
|
|
||||||
});
|
|
||||||
return integers;
|
|
||||||
}
|
|
||||||
}while (count < 5);
|
|
||||||
|
|
||||||
// 走到这里说明五次循环全部不足6个英雄,直接取第一名的队伍
|
|
||||||
CommonProto.UserRank ranks = rankResponse.getRanks(0);
|
|
||||||
User other = UserManager.getUser(ranks.getUid());
|
|
||||||
// 获取随机玩家的主线队伍阵容
|
|
||||||
heroInfos = other.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.FORMATION_NORMAL);
|
|
||||||
heroInfos.forEach(v->{
|
|
||||||
// 获取英雄模板id
|
|
||||||
Hero hero = other.getHeroManager().getHero(v.getHeroId());
|
|
||||||
integers.add(hero.getTemplateId());
|
|
||||||
});
|
|
||||||
|
|
||||||
return integers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取节点结构 确定type id state
|
* 获取节点结构 确定type id state
|
||||||
*/
|
*/
|
||||||
|
@ -1247,7 +1189,7 @@ public class ExpeditionLogic {
|
||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Map<Integer, Integer> getType2holy2weightRemoveHas(User user, int type) {
|
private Map<Integer, Integer> getType2holy2weightRemoveHas(User user, int type) {
|
||||||
// 策划表的圣物,因为会有删除操作,所以需要重新赋值,而不是直接引用
|
// 策划表的圣物,因为会有删除操作,所以需要重新赋值,而不是直接引用
|
||||||
Map<Integer, Integer> weight = STableManager.getFigureConfig(CommonStaticConfig.class).getType2holy2weight(type);
|
Map<Integer, Integer> weight = STableManager.getFigureConfig(CommonStaticConfig.class).getType2holy2weight(type);
|
||||||
Map<Integer, Integer> valueMap = new HashMap<>(weight);
|
Map<Integer, Integer> valueMap = new HashMap<>(weight);
|
||||||
|
|
|
@ -4334,10 +4334,8 @@ public class HeroLogic{
|
||||||
Collection<Hero> values = heroManager.getHeroMap().values();
|
Collection<Hero> values = heroManager.getHeroMap().values();
|
||||||
List<Hero> heroes = new ArrayList<>(values);
|
List<Hero> heroes = new ArrayList<>(values);
|
||||||
|
|
||||||
// 玩家英雄背包按等级排序
|
// 玩家英雄背包按等级排
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
Collections.sort(heroes);
|
Collections.sort(heroes);
|
||||||
LOGGER.info("英雄背包排序耗时:{}ms",System.currentTimeMillis()-start);
|
|
||||||
// 等级相加
|
// 等级相加
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.ljsd.jieling.exception.ErrorCodeException;
|
||||||
import com.ljsd.jieling.globals.BIReason;
|
import com.ljsd.jieling.globals.BIReason;
|
||||||
import com.ljsd.jieling.ktbeans.ReportEventEnum;
|
import com.ljsd.jieling.ktbeans.ReportEventEnum;
|
||||||
import com.ljsd.jieling.ktbeans.ReportUtil;
|
import com.ljsd.jieling.ktbeans.ReportUtil;
|
||||||
|
import com.ljsd.jieling.logic.dao.Hero;
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
|
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
@ -24,9 +25,11 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import rpc.world.WorldProto;
|
import rpc.world.WorldProto;
|
||||||
import util.MathUtils;
|
import util.MathUtils;
|
||||||
|
import util.TimeUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lvxinran
|
* @author lvxinran
|
||||||
|
@ -39,6 +42,13 @@ public class RankLogic {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 长度为2
|
||||||
|
* 0:时间
|
||||||
|
* 1:排行榜信息
|
||||||
|
*/
|
||||||
|
private static List<Object> force_curr_rank = new ArrayList<>(2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单例
|
* 获取单例
|
||||||
*
|
*
|
||||||
|
@ -83,6 +93,117 @@ public class RankLogic {
|
||||||
MessageUtil.sendMessage(session,1,messageType.getNumber(),rankResponse,true);
|
MessageUtil.sendMessage(session,1,messageType.getNumber(),rankResponse,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取排行榜信息
|
||||||
|
* @param user
|
||||||
|
* @param start
|
||||||
|
* @param end
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private PlayerInfoProto.RankResponse getRankInfo(User user,int start,int end) throws Exception{
|
||||||
|
// 上次存储时间+一小时
|
||||||
|
if (force_curr_rank.size() <= 0){
|
||||||
|
force_curr_rank.add(0L);
|
||||||
|
force_curr_rank.add(1L);
|
||||||
|
}
|
||||||
|
long old = (long)force_curr_rank.get(0) + TimeUtils.HOUR;
|
||||||
|
// 当前时间
|
||||||
|
long now = TimeUtils.now();
|
||||||
|
if (now > old){
|
||||||
|
// 距离上次存储超过一小时,重新获取
|
||||||
|
AbstractRank rank = RankContext.getRankEnum(RankEnum.FORCE_CURR_RANK.getType());
|
||||||
|
PlayerInfoProto.RankResponse rankResponse = null;
|
||||||
|
try {
|
||||||
|
rankResponse = rank.getRank(user.getId(), "", start, end);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"获取战力排行榜数据错误");
|
||||||
|
}
|
||||||
|
force_curr_rank.set(0,now);
|
||||||
|
force_curr_rank.set(1,rankResponse);
|
||||||
|
}
|
||||||
|
return (PlayerInfoProto.RankResponse)force_curr_rank.get(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取随机排名的用户id
|
||||||
|
* @param user
|
||||||
|
* @return
|
||||||
|
* @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);
|
||||||
|
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 count = 0;
|
||||||
|
do {
|
||||||
|
// 从0开始的随机
|
||||||
|
int random = MathUtils.randomInt(rankEndLine);
|
||||||
|
// 随机排名
|
||||||
|
int anInt = random > rankSize?rankSize:random;
|
||||||
|
|
||||||
|
// 获取随机玩家的主线队伍阵容
|
||||||
|
User other1 = getRankUid(rankResponse, anInt);
|
||||||
|
List<Integer> heroInfos = getTeamByUid(other1);
|
||||||
|
|
||||||
|
if (heroInfos.size() < 6){
|
||||||
|
// 队伍长度不足六人
|
||||||
|
if (count == 5){
|
||||||
|
// 最多循环五次,五次之后直接取第一名得id
|
||||||
|
User other2 = getRankUid(rankResponse, 0);
|
||||||
|
result.add(getTeamByUid(other2));
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}else {
|
||||||
|
result.add(heroInfos);
|
||||||
|
}
|
||||||
|
}while (result.size() < counts);
|
||||||
|
|
||||||
|
LOGGER.info("获取随机排名的队伍耗时:{}",System.currentTimeMillis()-start);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id获取队伍
|
||||||
|
* @param user
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private List<Integer> getTeamByUid(User user){
|
||||||
|
ArrayList<Integer> integers = new ArrayList<>();
|
||||||
|
List<TeamPosHeroInfo> heroInfos = user.getTeamPosManager().getTeamPosForHero().get(GlobalsDef.FORMATION_NORMAL);
|
||||||
|
heroInfos.forEach(v->{
|
||||||
|
// 获取英雄模板id
|
||||||
|
Hero hero = user.getHeroManager().getHero(v.getHeroId());
|
||||||
|
integers.add(hero.getTemplateId());
|
||||||
|
});
|
||||||
|
return integers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据排行获取排行榜玩家id
|
||||||
|
* @param rankResponse
|
||||||
|
* @param ranking
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private User getRankUid(PlayerInfoProto.RankResponse rankResponse, int ranking) throws Exception {
|
||||||
|
CommonProto.UserRank ranks = rankResponse.getRanks(ranking);
|
||||||
|
return UserManager.getUser(ranks.getUid());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取每个排行第一名信息
|
* 获取每个排行第一名信息
|
||||||
* @param session
|
* @param session
|
||||||
|
|
Loading…
Reference in New Issue