跨服排行,初步修改

back_recharge
duhui 2021-07-28 16:05:50 +08:00
parent d51a4715e0
commit 94bffe4947
5 changed files with 63 additions and 6 deletions

View File

@ -1288,8 +1288,16 @@ public class RedisUtil {
return getKey(type,key,true); return getKey(type,key,true);
} }
/**
* key
* @param type
* @param key
* @param judge
* true false
* @return
*/
public String getKey(String type,String key,boolean judge){ public String getKey(String type,String key,boolean judge){
if (judge){ if (!judge){
return type + RedisKey.Delimiter_colon + key; return type + RedisKey.Delimiter_colon + key;
} }

View File

@ -151,14 +151,22 @@ public class CrossServiceLogic {
return arenaOfPlayerManager; return arenaOfPlayerManager;
} }
private ArenaOfHeroManager buildArenaOfHeroManager(User user){ private ArenaOfHeroManager buildArenaOfHeroManager(User user){
// 编队列表
Map<Integer,List<TeamPosHeroInfo>> teams = new HashMap<>(); Map<Integer,List<TeamPosHeroInfo>> teams = new HashMap<>();
List<TeamPosHeroInfo> infos = // 需要存储的英雄列表
user.getTeamPosManager().getTeamPosForHero().getOrDefault(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,new ArrayList<>()); HashSet<TeamPosHeroInfo> set = new HashSet<>();
teams.put(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,infos); // 跨服世界阵编队
List<TeamPosHeroInfo> worldTeam = user.getTeamPosManager().getTeamPosForHero().getOrDefault(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,new ArrayList<>());
teams.put(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,worldTeam);
set.addAll(worldTeam);
// 主线阵容编队
List<TeamPosHeroInfo> firstTeam = user.getTeamPosManager().getTeamPosForHero().getOrDefault(GlobalsDef.FORMATION_NORMAL,new ArrayList<>());
teams.put(GlobalsDef.FORMATION_NORMAL,firstTeam);
set.addAll(firstTeam);
// 英雄 // 英雄
Map<String,ArenaOfHero> heroes = new HashMap<>(); Map<String,ArenaOfHero> heroes = new HashMap<>();
Map<String, Hero> heroMap = user.getHeroManager().getHeroMap(); Map<String, Hero> heroMap = user.getHeroManager().getHeroMap();
infos.forEach(v->{ set.forEach(v->{
Hero hero = heroMap.get(v.getHeroId()); Hero hero = heroMap.get(v.getHeroId());
heroes.put(v.getHeroId(),buildArenaOfHero(user,hero)); heroes.put(v.getHeroId(),buildArenaOfHero(user,hero));
}); });

View File

@ -1,6 +1,8 @@
package com.ljsd.jieling.logic.dao; package com.ljsd.jieling.logic.dao;
import java.util.Objects;
public class TeamPosHeroInfo implements Comparable<TeamPosHeroInfo> { public class TeamPosHeroInfo implements Comparable<TeamPosHeroInfo> {
private String heroId; private String heroId;
private int position; private int position;
@ -30,6 +32,18 @@ public class TeamPosHeroInfo implements Comparable<TeamPosHeroInfo> {
this.position = position; this.position = position;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TeamPosHeroInfo that = (TeamPosHeroInfo) o;
return Objects.equals(heroId, that.heroId);
}
@Override
public int hashCode() {
return Objects.hash(heroId, position);
}
@Override @Override
public int compareTo(TeamPosHeroInfo o) { public int compareTo(TeamPosHeroInfo o) {

View File

@ -68,7 +68,6 @@ public class RankLogic {
} }
public void getRank(ISession session, int type, int activityId,int index,MessageTypeProto.MessageType messageType) throws Exception { public void getRank(ISession session, int type, int activityId,int index,MessageTypeProto.MessageType messageType) throws Exception {
LOGGER.info("获取排行榜信息type={},activityId={}",type,activityId); LOGGER.info("获取排行榜信息type={},activityId={}",type,activityId);
int page = 1;
String rkey = ""; String rkey = "";
if(activityId != 0){ if(activityId != 0){
rkey = String.valueOf(activityId); rkey = String.valueOf(activityId);

View File

@ -55,6 +55,34 @@ public abstract class AbstractRank implements IRank {
return allUserResponse.build(); return allUserResponse.build();
} }
/**
*
* @param uid
* @param rkey
* @param page
* @param rankEndLine
* @return
* @throws Exception
*/
public PlayerInfoProto.RankResponse getCrossRank(int uid, String rkey, int page, int rankEndLine) throws Exception {
if(rankEndLine==-1){
rankEndLine = 100;
}
User user = UserManager.getUser(uid);
if (page == 0) {
page = 1;
}
int start = (page - 1) * rankEndLine, end = page * rankEndLine - 1;
Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores = getRankByKey(rkey,start,end);
if(start%rankEndLine == 0){
start++;
}
PlayerInfoProto.RankResponse.Builder allUserResponse = getAllUserResponse(zsetreverseRangeWithScores,start);
//当前用户信息
getMyInfo(user,rkey,allUserResponse);
return allUserResponse.build();
}
/** /**
* *
* @param uid id * @param uid id