跨服排行,初步修改
parent
d51a4715e0
commit
94bffe4947
|
@ -1288,8 +1288,16 @@ public class RedisUtil {
|
|||
return getKey(type,key,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取key
|
||||
* @param type
|
||||
* @param key
|
||||
* @param judge
|
||||
* 本服: true 跨服: false
|
||||
* @return
|
||||
*/
|
||||
public String getKey(String type,String key,boolean judge){
|
||||
if (judge){
|
||||
if (!judge){
|
||||
return type + RedisKey.Delimiter_colon + key;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,14 +151,22 @@ public class CrossServiceLogic {
|
|||
return arenaOfPlayerManager;
|
||||
}
|
||||
private ArenaOfHeroManager buildArenaOfHeroManager(User user){
|
||||
// 编队列表
|
||||
Map<Integer,List<TeamPosHeroInfo>> teams = new HashMap<>();
|
||||
List<TeamPosHeroInfo> infos =
|
||||
user.getTeamPosManager().getTeamPosForHero().getOrDefault(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,new ArrayList<>());
|
||||
teams.put(GlobalsDef.WORLD_TEAM_ARENA_DEFENSE,infos);
|
||||
// 需要存储的英雄列表
|
||||
HashSet<TeamPosHeroInfo> set = new HashSet<>();
|
||||
// 跨服世界阵编队
|
||||
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, Hero> heroMap = user.getHeroManager().getHeroMap();
|
||||
infos.forEach(v->{
|
||||
set.forEach(v->{
|
||||
Hero hero = heroMap.get(v.getHeroId());
|
||||
heroes.put(v.getHeroId(),buildArenaOfHero(user,hero));
|
||||
});
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TeamPosHeroInfo implements Comparable<TeamPosHeroInfo> {
|
||||
private String heroId;
|
||||
private int position;
|
||||
|
@ -30,6 +32,18 @@ public class TeamPosHeroInfo implements Comparable<TeamPosHeroInfo> {
|
|||
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
|
||||
public int compareTo(TeamPosHeroInfo o) {
|
||||
|
|
|
@ -68,7 +68,6 @@ public class RankLogic {
|
|||
}
|
||||
public void getRank(ISession session, int type, int activityId,int index,MessageTypeProto.MessageType messageType) throws Exception {
|
||||
LOGGER.info("获取排行榜信息type={},activityId={}",type,activityId);
|
||||
int page = 1;
|
||||
String rkey = "";
|
||||
if(activityId != 0){
|
||||
rkey = String.valueOf(activityId);
|
||||
|
|
|
@ -55,6 +55,34 @@ public abstract class AbstractRank implements IRank {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue