代码恢复
parent
806d107bf4
commit
cc588bd1c1
|
|
@ -0,0 +1,46 @@
|
|||
package com.world.db.mongo;
|
||||
|
||||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.db.mongo.core.CServerInfo;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MongoUtil {
|
||||
|
||||
|
||||
private MongoUtil() {
|
||||
}
|
||||
|
||||
public static MongoUtil getInstence() {
|
||||
return MongoUtil.InnerClass.instance;
|
||||
}
|
||||
|
||||
private static class InnerClass {
|
||||
private static final MongoUtil instance = new MongoUtil();
|
||||
}
|
||||
|
||||
private volatile MongoTemplate coreMongoTemplate;
|
||||
|
||||
private volatile Map<Integer,CServerInfo> cServerInfoMap;
|
||||
|
||||
public void init() {
|
||||
if(coreMongoTemplate==null){
|
||||
coreMongoTemplate = (MongoTemplate) ConfigurableApplicationContextManager.getBean("coreMongoTemplate");
|
||||
}
|
||||
List<CServerInfo> cServerInfos = coreMongoTemplate.findAll(CServerInfo.class);
|
||||
Map<Integer,CServerInfo> serverInfoMap = new HashMap<>(cServerInfos.size());
|
||||
cServerInfos.forEach(n->serverInfoMap.put(n.getServerId(),n));
|
||||
cServerInfoMap = serverInfoMap;
|
||||
}
|
||||
public String getServerNameById(int serverId){
|
||||
CServerInfo cServerInfo = cServerInfoMap.get(serverId);
|
||||
if(cServerInfo==null){
|
||||
return "";
|
||||
}
|
||||
return cServerInfo.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.world.db.mongo.core;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
@Document(collection = "server_info")
|
||||
public class CServerInfo {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Field(value = "server_id")
|
||||
private int serverId;
|
||||
@Field(value = "name")
|
||||
private String name;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getServerId() {
|
||||
return serverId;
|
||||
}
|
||||
|
||||
public void setServerId(int serverId) {
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.world.db.mongo.core;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/9
|
||||
* @discribe
|
||||
*/
|
||||
public class CrossGuild {
|
||||
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.logic.rank.AbstractCrossRank;
|
||||
import com.world.logic.rank.DeathPathCrossEveryPersonRank;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import org.luaj.vm2.ast.Str;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/3
|
||||
* @discribe
|
||||
*/
|
||||
public class AddDeathPathRankRequestHandler extends gtGBaseHandler<WorldProto.AddDeathPathRankRequest>{
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.AddDeathPathRankRequest proto) throws Exception {
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
//操作每个关的公会、个人数据
|
||||
BigDecimal decimal = new BigDecimal(String.valueOf(proto.getDamage())).divide(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
long everyGuildChangeScore = (long)proto.getDamage()*1000;
|
||||
if(redisUtil.getZSetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_EVERY_PERSON_RANK,String.valueOf(proto.getPathId()), String.valueOf(proto.getUid()))==-1){
|
||||
// decimal = decimal.add(new BigDecimal(0));
|
||||
//记录人数操作
|
||||
everyGuildChangeScore = everyGuildChangeScore+1;
|
||||
}
|
||||
|
||||
String before= firstGuild(redisUtil, proto.getGroupId(), proto.getPathId());
|
||||
redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_EVERY_GUILD_RANK,String.valueOf(proto.getPathId()),String.valueOf(proto.getGuildId()), everyGuildChangeScore);
|
||||
String after = firstGuild(redisUtil, proto.getGroupId(), proto.getPathId());
|
||||
if(!before.equals(after)){
|
||||
decimal = decimal.add(new BigDecimal(1));
|
||||
if(!"".equals(before)){
|
||||
redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_TOTAL_GUILD_RANK,"",before, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_EVERY_PERSON_RANK,String.valueOf(proto.getPathId()),String.valueOf(proto.getUid()), proto.getDamage());
|
||||
|
||||
// redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_EVERY_PERSON_RANK,String.valueOf(proto.getPathId()),String.valueOf(proto.getUid()), proto.getDamage());
|
||||
|
||||
//操作总的个人伤害
|
||||
redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_TOTAL_PERSON_RANK,"",String.valueOf(proto.getUid()), proto.getDamage());
|
||||
|
||||
//操作总的工会伤害
|
||||
|
||||
redisUtil.incrementZsetScore(proto.getGroupId()+":"+RedisKey.DEATH_PATH_TOTAL_GUILD_RANK,"",String.valueOf(proto.getGuildId()), decimal.doubleValue());
|
||||
|
||||
redisUtil.hset(RedisKey.DEATH_PATH_EVERY_OVER_HASH,String.valueOf(rpcMessage.getServerId()),1);
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
private String firstGuild(RedisUtil redisUtil,int groupId,int pathId){
|
||||
Set<ZSetOperations.TypedTuple<String>> scores = redisUtil.getZsetreverseRangeWithScores(groupId + ":" + RedisKey.DEATH_PATH_EVERY_GUILD_RANK, String.valueOf(pathId), 0, 0);
|
||||
return scores.iterator().hasNext()?scores.iterator().next().getValue():"";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
import com.ljsd.jieling.logic.dao.PlayerInfoCache;
|
||||
import com.world.logic.rank.AbstractCrossRank;
|
||||
import com.world.logic.rank.DeathPathCrossEveryGuildRank;
|
||||
import com.world.logic.rank.DeathPathCrossTotalGuildRank;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/15
|
||||
* @discribe
|
||||
*/
|
||||
public class DeathPathWorldRewardRequestHandler extends gtGBaseHandler<WorldProto.DeathPathWorldRewardRequest> {
|
||||
private static Set<Integer> groupIds = new HashSet<>();
|
||||
@Override
|
||||
public WorldProto.DeathPathWorldRewardResponse processWithProto(RpcMessage rpcMessage, WorldProto.DeathPathWorldRewardRequest proto) throws Exception {
|
||||
|
||||
WorldProto.DeathPathWorldRewardResponse.Builder builder = WorldProto.DeathPathWorldRewardResponse.newBuilder();
|
||||
if(TimeUtils.getHourOfDay()!=0){
|
||||
return builder.build();
|
||||
}
|
||||
groupIds.add(proto.getGroupId());
|
||||
int serverId = rpcMessage.getServerId();
|
||||
Set<ZSetOperations.TypedTuple<String>> values = RedisUtil.getInstence().getZsetreverseRangeWithScores(proto.getGroupId()+":" + RedisKey.DEATH_PATH_TOTAL_GUILD_RANK, "", 0, -1);
|
||||
|
||||
int rank =0;
|
||||
for(ZSetOperations.TypedTuple<String> value:values){
|
||||
rank++;
|
||||
GuildInfoCache guild = new DeathPathCrossTotalGuildRank(RedisKey.DEATH_PATH_TOTAL_PERSON_RANK).getCrossGuild(Integer.valueOf(value.getValue()));
|
||||
if(guild==null||guild.getServerId()!=serverId){
|
||||
continue;
|
||||
}
|
||||
builder.addRanks(WorldProto.GuildRank.newBuilder().setGuildId(Integer.parseInt(value.getValue())).setRank(rank).build());
|
||||
}
|
||||
RedisUtil.getInstence().hdel(RedisKey.DEATH_PATH_EVERY_OVER_HASH,String.valueOf(rpcMessage.getServerId()));
|
||||
|
||||
Map<Object, Object> hmget = RedisUtil.getInstence().hmget(RedisKey.DEATH_PATH_EVERY_OVER_HASH);
|
||||
if(proto.getGroupId()!=0)
|
||||
groupIds.add(proto.getGroupId());
|
||||
|
||||
if(hmget==null||hmget.size()<1){
|
||||
groupIds.forEach(n->{
|
||||
Cursor<String> cursor = RedisUtil.getInstence().scan(n+":DEATH_PATH*", -1);
|
||||
while (cursor.hasNext()) {
|
||||
//找到一次就添加一次
|
||||
String next = cursor.next();
|
||||
LOGGER.info("删除排行{}",next);
|
||||
RedisUtil.getInstence().del(next);
|
||||
}
|
||||
});
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: lxr
|
||||
* CreateDate: 2020/12/22 4:27
|
||||
*/
|
||||
public class GetArenaRankRewardRequestHandler extends gtGBaseHandler<WorldProto.GetArenaRankRewardRequest> {
|
||||
@Override
|
||||
public WorldProto.GetArenaRankRewardResponse processWithProto(RpcMessage rpcMessage, WorldProto.GetArenaRankRewardRequest proto) throws Exception {
|
||||
int serverId = rpcMessage.getServerId();
|
||||
WorldProto.GetArenaRankRewardResponse.Builder response = WorldProto.GetArenaRankRewardResponse.newBuilder();
|
||||
if(proto.getGroupId()==0){
|
||||
return response.build();
|
||||
}
|
||||
Map<Integer, ArenaEnemy> rankMap = ArenaLogic.ranInfo.get(proto.getGroupId());
|
||||
for(Map.Entry<Integer, ArenaEnemy> entry:rankMap.entrySet()){
|
||||
if(entry.getValue().getServerID()!=serverId){
|
||||
continue;
|
||||
}
|
||||
response.addRankInfo(WorldProto.ArenaRank.newBuilder().setRank(entry.getKey()).setUid(entry.getValue().getEnemyId()).build());
|
||||
}
|
||||
return response.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/14
|
||||
* @discribe
|
||||
*/
|
||||
public class GetDeathPathRewardRequestHandler extends gtGBaseHandler<WorldProto.GetDeathPathRewardRequest> {
|
||||
@Override
|
||||
public WorldProto.GetDeathPathRewardResponse processWithProto(RpcMessage rpcMessage, WorldProto.GetDeathPathRewardRequest proto) throws Exception {
|
||||
|
||||
int rank = RedisUtil.getInstence().getZSetreverseRank(proto.getGroupId() + ":" + RedisKey.DEATH_PATH_TOTAL_GUILD_RANK, "", String.valueOf(proto.getGuildId())).intValue();
|
||||
|
||||
|
||||
return WorldProto.GetDeathPathRewardResponse.newBuilder().setRankTotal(rank).build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.network.server.gsHelper;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2021/1/9 1:30
|
||||
*/
|
||||
public class GetPlayerOneTeamInfoRequestHandler extends gtGBaseHandler<WorldProto.GetPlayerOneTeamInfoRequest>{
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetPlayerOneTeamInfoRequest proto) throws Exception {
|
||||
PlayerInfoProto.GetPlayerOneTeamInfoResponse getPlayerOneTeamInfoResponse = gsHelper.sendMessageToGs(rpcMessage.getServerId(), rpcMessage.getUid(), proto, PlayerInfoProto.GetPlayerOneTeamInfoResponse.class);
|
||||
if (getPlayerOneTeamInfoResponse == null) {
|
||||
return null;
|
||||
}
|
||||
return getPlayerOneTeamInfoResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.logic.rank.DeathPathCrossEveryGuildRank;
|
||||
import com.world.logic.rank.DeathPathCrossEveryPersonRank;
|
||||
import com.world.logic.rank.DeathPathCrossTotalGuildRank;
|
||||
import com.world.redis.RedisKey;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/3
|
||||
* @discribe
|
||||
*/
|
||||
public class GetRankRequestHandler extends gtGBaseHandler<WorldProto.GetRankRequest> {
|
||||
|
||||
@Override
|
||||
public PlayerInfoProto.RankResponse processWithProto(RpcMessage rpcMessage, WorldProto.GetRankRequest proto) throws Exception {
|
||||
switch (proto.getType()){
|
||||
// RankEnum.DEATH_PATH_TOTAL_PERSON_RANK.getType();
|
||||
case 15:
|
||||
return new DeathPathCrossEveryPersonRank(proto.getCrossId()+":"+RedisKey.DEATH_PATH_EVERY_PERSON_RANK).getRank(proto.getUid(),String.valueOf(proto.getAcitvityId()),1,-1);
|
||||
case 16:
|
||||
return new DeathPathCrossEveryGuildRank(proto.getCrossId()+":"+RedisKey.DEATH_PATH_EVERY_GUILD_RANK).getRank(proto.getUid(),String.valueOf(proto.getAcitvityId()),1,-1);
|
||||
case 17:
|
||||
return new DeathPathCrossEveryPersonRank(proto.getCrossId()+":"+RedisKey.DEATH_PATH_TOTAL_PERSON_RANK).getRank(proto.getUid(),"",1,-1);
|
||||
case 18:
|
||||
return new DeathPathCrossTotalGuildRank(proto.getCrossId()+":"+RedisKey.DEATH_PATH_TOTAL_GUILD_RANK).getRank(proto.getUid(),"",1,-1);
|
||||
case 28:
|
||||
return ArenaLogic.getInstance().getRank(rpcMessage.getUid(),rpcMessage.getServerId());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.logic.fight.result.FightResult;
|
||||
import com.ljsd.jieling.util.KeyGenUtils;
|
||||
import com.ljsd.jieling.util.UUIDEnum;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.logic.arean.fight.FightUtil;
|
||||
import com.world.network.server.gsHelper;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import config.SArenaRobotConfig;
|
||||
import config.SArenaSetting;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.world.WorldProto;
|
||||
import util.Lockeys;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Description: 跨服天梯挑战
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/19 10:51
|
||||
*/
|
||||
public class GetWorldArenaChallengeRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaChallengeRequest> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaChallengeRequest proto) throws Exception {
|
||||
|
||||
WorldProto.GetWorldArenaChallengeResponse.Builder builder1 = WorldProto.GetWorldArenaChallengeResponse.newBuilder();
|
||||
if (proto.getSkipFight() == 1) {
|
||||
//扫荡直接发 奖励
|
||||
//TODO DROP 放在gs做了
|
||||
// SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1);
|
||||
// setting.getBattleWinReward();
|
||||
builder1.setFightResult(1);
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
|
||||
// Lockeys.getInstance().lock("arena", rpcMessage.getServerId());
|
||||
|
||||
try {
|
||||
//TODO 校验需要对手是否在匹配范围内
|
||||
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(rpcMessage.getServerId()));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
//判断信息是否改变
|
||||
//我的信息
|
||||
Set<Integer> hisRank = RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(rpcMessage.getUid())), new TypeToken<Set<Integer>>() {
|
||||
}.getType());
|
||||
if (hisRank.size() == 0) {
|
||||
//被替了
|
||||
//重新拿数据
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
//对方信息
|
||||
ArenaEnemy arenaEnemy = integerIntegerHashMap.get(proto.getChallengeRank());
|
||||
if (arenaEnemy == null || arenaEnemy.getEnemyId() != proto.getChallengeUid()) {
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
|
||||
int force;
|
||||
CommonProto.FightTeamInfo teamInfo;
|
||||
CommonProto.ArenaEnemy arenaEnemys;
|
||||
if (arenaEnemy.getEnemyType() == 1) {
|
||||
WorldProto.GetGSUserArenaInfoResponse getGSUserArenaInfoResponse = gsHelper.sendMessageToGs(arenaEnemy.getServerID(), arenaEnemy.getEnemyId(), WorldProto.GetGSUserArenaInfoRequest.newBuilder().setUid(arenaEnemy.getEnemyId()).build(), WorldProto.GetGSUserArenaInfoResponse.class);
|
||||
if (getGSUserArenaInfoResponse == null) {
|
||||
builder1.setErr(-2);
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
//更新缓存数据
|
||||
ArenaLogic.getUserCacheMap().put(arenaEnemy.getEnemyId(),getGSUserArenaInfoResponse.getArenaEnemys());
|
||||
|
||||
force = getGSUserArenaInfoResponse.getTotalForce();
|
||||
teamInfo = getGSUserArenaInfoResponse.getFightTeamInfo();
|
||||
arenaEnemys = getGSUserArenaInfoResponse.getArenaEnemys();
|
||||
} else {
|
||||
teamInfo = FightUtil.makeRobotFightData(arenaEnemy.getEnemyId());
|
||||
force = SArenaRobotConfig.getsArenaRobotConfigById(arenaEnemy.getEnemyId()).getTotalForce();
|
||||
arenaEnemys =ArenaLogic.getInstance().getRobotArenaEnemy(arenaEnemy.getEnemyId());
|
||||
}
|
||||
|
||||
|
||||
boolean isRevert = proto.getTotalForce() < force;
|
||||
FightResult fightResult = FightUtil.getFightForPVP(rpcMessage.getUid(), proto.getChallengeUid(), proto.getFightTeamInfo(), teamInfo, FightUtil.getFightSeed(), isRevert);
|
||||
builder1.setFightResult(fightResult.getCheckResult()[0]);
|
||||
int seed = fightResult.getSeed();
|
||||
CommonProto.FightData build = CommonProto.FightData.newBuilder()
|
||||
.setFightMaxTime(SArenaSetting.getSArenaSetting().getMostTime())
|
||||
.setFightSeed(seed)
|
||||
.setHeroFightInfos(fightResult.getFightTeamInfo())
|
||||
.addMonsterList(fightResult.getDefFightTeamInfo())
|
||||
.build();
|
||||
builder1.setFightData(build);
|
||||
CommonProto.ArenaInfo.Builder arenaInfoBuild = CommonProto.ArenaInfo.newBuilder();
|
||||
WorldProto.WroldBattleRecord.Builder builder = WorldProto.WroldBattleRecord.newBuilder();
|
||||
builder.setFightData(fightResult.getFightData());
|
||||
builder.setResult(fightResult.getCheckResult()[0]);
|
||||
String s = KeyGenUtils.produceIdByModule(UUIDEnum.ARENARECORD, rpcMessage.getUid());
|
||||
builder.setRecordId(s);
|
||||
builder.setAttackTime((int)(System.currentTimeMillis()/1000));
|
||||
//record
|
||||
builder.setRedEnemy(proto.getArenaEnemys());
|
||||
builder.setBlueEnemy(arenaEnemys);
|
||||
if (fightResult.getCheckResult()[0] > 0) {
|
||||
|
||||
//交换队伍
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
if (myRank != null) {
|
||||
builder.setOldrank(myRank.getKey());
|
||||
if(myRank.getKey()>proto.getChallengeRank()){
|
||||
arenaInfoBuild.setScore(proto.getChallengeRank());
|
||||
ArenaEnemy temp = new ArenaEnemy();
|
||||
temp = myRank.getValue();
|
||||
integerIntegerHashMap.put(myRank.getKey(), arenaEnemy);
|
||||
integerIntegerHashMap.put(proto.getChallengeRank(), temp);
|
||||
arenaInfoBuild.setScore(proto.getChallengeRank());
|
||||
}else{
|
||||
arenaInfoBuild.setScore(myRank.getKey());
|
||||
}
|
||||
if (arenaEnemy.getEnemyType() == 0) {
|
||||
//清空匹配
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(arenaEnemy.getEnemyId()), new HashSet<>());
|
||||
}
|
||||
} else {
|
||||
arenaInfoBuild.setScore(proto.getChallengeRank());
|
||||
builder.setOldrank(9999);
|
||||
integerIntegerHashMap.put(proto.getChallengeRank(), new ArenaEnemy(rpcMessage.getUid(), rpcMessage.getServerId(), 1, 0));
|
||||
}
|
||||
myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
//处理匹配信息
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(rpcMessage.getUid()), new HashSet<>());
|
||||
List<ArenaEnemy> arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myRank == null ? 9999 : myRank.getKey());
|
||||
|
||||
//notify client
|
||||
List<String> strings = RedisUtil.getInstence().lGet(RedisKey.WORLD_ARENA_MY_PRON,String.valueOf(rpcMessage.getUid()), 0, -1);
|
||||
List<CommonProto.ArenaEnemy> arenaEnemyList = ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies),new LinkedList<>(strings));
|
||||
arenaInfoBuild.addAllArenaEnemys(arenaEnemyList);
|
||||
builder.setRank(myRank == null ? 9999 : myRank.getKey());
|
||||
}
|
||||
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(proto.getChallengeUid()), s, builder.build().toByteArray());
|
||||
RedisUtil.getInstence().putMapEntry(RedisKey.WORLD_ARENA_RRECORD,Integer.toString(rpcMessage.getUid()), s, builder.build().toByteArray());
|
||||
|
||||
builder1.setArenaInfo(arenaInfoBuild);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
Lockeys.getInstance().reset();
|
||||
}
|
||||
//TODO 掉落
|
||||
|
||||
return builder1.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.world.WorldProto;
|
||||
import util.Lockeys;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Description: 获取跨服竞技场信息
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/11/19 10:51
|
||||
*/
|
||||
public class GetWorldArenaInfoRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaInfoRequest> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaInfoRequest proto) throws Exception {
|
||||
WorldProto.GetWorldArenaInfoResponse.Builder builder = WorldProto.GetWorldArenaInfoResponse.newBuilder();
|
||||
CommonProto.ArenaInfo.Builder builder1 = CommonProto.ArenaInfo.newBuilder();
|
||||
try {
|
||||
// Lockeys.getInstance().lock("arena", rpcMessage.getServerId());
|
||||
int serverId = rpcMessage.getServerId();
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(serverId));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
if (integerIntegerHashMap == null) {
|
||||
builder.setStage(1);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
//获取我的排名
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
//根据我的排名获取
|
||||
int myIndex = 9999;
|
||||
if (myRank != null) {
|
||||
myIndex = myRank.getKey();
|
||||
}
|
||||
List<ArenaEnemy> arenaEnemies;
|
||||
if(proto.getIsPro()){
|
||||
//获取前4名
|
||||
arenaEnemies = new LinkedList<>();
|
||||
for (int i = 1; i <=4 ; i++) {
|
||||
ArenaEnemy arenaEnemy = integerIntegerHashMap.get(i);
|
||||
if(arenaEnemy.getRank()==0){
|
||||
arenaEnemy.setRank(i);
|
||||
}
|
||||
arenaEnemies.add(arenaEnemy);
|
||||
}
|
||||
}else {
|
||||
arenaEnemies = ArenaLogic.randomRank(integerIntegerHashMap, rpcMessage.getUid(), myIndex);
|
||||
}
|
||||
|
||||
builder.setStage(2);
|
||||
List<String> strings = RedisUtil.getInstence().lGet(RedisKey.WORLD_ARENA_MY_PRON,String.valueOf(rpcMessage.getUid()), 0, -1);
|
||||
List<CommonProto.ArenaEnemy> arenaEnemyList = ArenaLogic.getInstance().getArenaEnemyList(new LinkedList<>(arenaEnemies),strings);
|
||||
builder1.setScore(myIndex)
|
||||
.addAllArenaEnemys(arenaEnemyList)
|
||||
.build();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.toString());
|
||||
} finally {
|
||||
// Lockeys.getInstance().reset();
|
||||
}
|
||||
return builder.setArenaInfo(builder1).build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.world.WorldProto;
|
||||
import rpc.world.WorldProto;
|
||||
import util.Lockeys;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/12/2 21:19
|
||||
*/
|
||||
public class GetWorldArenaProudRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaProudRequest> {
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaProudRequest proto) throws Exception {
|
||||
WorldProto.GetWorldArenaProudResponse.Builder builder = WorldProto.GetWorldArenaProudResponse.newBuilder();
|
||||
|
||||
try {
|
||||
//check 膜拜 在逻辑服做
|
||||
// Lockeys.getInstance().lock("arena", rpcMessage.getServerId());
|
||||
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(rpcMessage.getServerId()));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
ArenaEnemy arenaEnemy = integerIntegerHashMap.get(proto.getChallengeRank());
|
||||
if(arenaEnemy==null||arenaEnemy.getEnemyId()!=proto.getChallengeUid()){
|
||||
builder.setErr(-1);
|
||||
return builder.build();
|
||||
}
|
||||
RedisUtil.getInstence().lSet(RedisKey.WORLD_ARENA_MY_PRON+":"+rpcMessage.getUid(),String.valueOf(arenaEnemy.getEnemyId_UUid()));
|
||||
|
||||
if(arenaEnemy.getEnemyType()==0){
|
||||
Object get = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT_ROBOT, arenaEnemy.getEnemyId_UUid());
|
||||
|
||||
int proudTime = get==null?1:Integer.parseInt((String)get)+1;
|
||||
RedisUtil.getInstence().hset(RedisKey.ARENA_PROUD_COUNT_ROBOT,arenaEnemy.getEnemyId_UUid(),proudTime);
|
||||
builder.setWorshipTime(proudTime);
|
||||
}else{
|
||||
Object get = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT, String.valueOf(arenaEnemy.getEnemyId()));
|
||||
|
||||
int proudTime = get==null?1:Integer.parseInt((String)get)+1;
|
||||
RedisUtil.getInstence().hset(RedisKey.ARENA_PROUD_COUNT,String.valueOf(arenaEnemy.getEnemyId()),proudTime);
|
||||
builder.setWorshipTime(proudTime);
|
||||
}
|
||||
// builder.setDrop()
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
// Lockeys.getInstance().reset();
|
||||
}
|
||||
|
||||
//todo 添加掉落
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.fight.ArenaRecordWrap;
|
||||
import com.world.logic.arean.ArenaEnemy;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/12/4 16:27
|
||||
*/
|
||||
public class GetWorldArenaRecordInfoRequestHandler extends gtGBaseHandler<WorldProto.GetWorldArenaRecordInfoRequest> {
|
||||
|
||||
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.GetWorldArenaRecordInfoRequest proto) throws Exception {
|
||||
|
||||
WorldProto.GetWorldArenaRecordInfoResponse.Builder builder = WorldProto.GetWorldArenaRecordInfoResponse.newBuilder();
|
||||
int serverId = rpcMessage.getServerId();
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(serverId));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
//个人信息
|
||||
// Map.Entry<Integer, ArenaEnemy> challRank = ArenaLogic.getKey(integerIntegerHashMap, rpcMessage.getUid());
|
||||
// if (challRank == null) {
|
||||
// return builder.build();
|
||||
// }
|
||||
Map<String, byte[]> result = RedisUtil.getInstence().getMapValues(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(rpcMessage.getUid()), String.class, byte[].class);
|
||||
|
||||
if (result != null && !result.isEmpty()) {
|
||||
List< byte[]> arenaRecordList = new ArrayList<>(result.values());
|
||||
List<WorldProto.WroldBattleRecord> collect = arenaRecordList.stream().map(bytes -> {try {
|
||||
return WorldProto.WroldBattleRecord.parseFrom(bytes);
|
||||
}catch (Exception e){}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
collect.sort(Comparator.comparingInt(WorldProto.WroldBattleRecord::getAttackTime));
|
||||
Collections.reverse(collect);
|
||||
int size = arenaRecordList.size();
|
||||
if (size > 15) {
|
||||
String[] removeMapKeys = new String[size - 15];
|
||||
for (int i = 0; i < size - 15; i++) {
|
||||
WorldProto.WroldBattleRecord remove = collect.remove(size-i-1);
|
||||
String removeId = remove.getRecordId();
|
||||
removeMapKeys[i] = (removeId);
|
||||
}
|
||||
RedisUtil.getInstence().removeMapEntrys(RedisKey.WORLD_ARENA_RRECORD, Integer.toString(rpcMessage.getUid()), removeMapKeys);
|
||||
}
|
||||
|
||||
builder.addAllWroldBattleRecord(collect);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.world.handler;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import com.world.network.server.gsHelper;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
import rpc.world.WorldProto;
|
||||
|
||||
|
||||
/**
|
||||
* Description: des
|
||||
* Author: zsx
|
||||
* CreateDate: 2021/1/3 1:13
|
||||
*/
|
||||
public class ViewHeroInfoRequestHandler extends gtGBaseHandler<WorldProto.ViewHeroInfoRequest> {
|
||||
@Override
|
||||
public GeneratedMessage processWithProto(RpcMessage rpcMessage, WorldProto.ViewHeroInfoRequest proto) throws Exception {
|
||||
PlayerInfoProto.ViewHeroInfoResponse viewHeroInfoResponse = gsHelper.sendMessageToGs(rpcMessage.getServerId(), rpcMessage.getUid(), proto, PlayerInfoProto.ViewHeroInfoResponse.class);
|
||||
if (viewHeroInfoResponse == null) {
|
||||
return null;
|
||||
}
|
||||
return viewHeroInfoResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.world.logic;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/3
|
||||
* @discribe
|
||||
*/
|
||||
public class WorldDeathPathLogic {
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.world.logic.arean;
|
||||
|
||||
|
||||
import com.ljsd.jieling.util.KeyGenUtils;
|
||||
import com.ljsd.jieling.util.UUIDEnum;
|
||||
|
||||
public class ArenaEnemy {
|
||||
private int enemyId;
|
||||
private String enemyId_UUid;//机器人唯一ID
|
||||
private int serverID;
|
||||
// 0:机器人
|
||||
private int enemyType;
|
||||
// 0:未挑战,1:挑战成功,2:挑战失败
|
||||
private int enemyStatus;
|
||||
private int rank;//排名
|
||||
private boolean gender;
|
||||
|
||||
public ArenaEnemy(int enemyId, String enemyId_UUid, int serverID, int enemyType, int enemyStatus, int rank) {
|
||||
this.enemyId = enemyId;
|
||||
this.enemyId_UUid = enemyId_UUid;
|
||||
this.serverID = serverID;
|
||||
this.enemyType = enemyType;
|
||||
this.enemyStatus = enemyStatus;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public ArenaEnemy(int enemyId, int serverID, int enemyType, int enemyStatus,boolean gender) {
|
||||
this.enemyId = enemyId;
|
||||
this.enemyId_UUid=enemyType==0? KeyGenUtils.produceIdByModule(UUIDEnum.EXPEDITION, 0):String.valueOf(enemyId);
|
||||
this.serverID = serverID;
|
||||
this.enemyType = enemyType;
|
||||
this.enemyStatus = enemyStatus;
|
||||
this.gender=gender;
|
||||
}
|
||||
public ArenaEnemy(int enemyId, int serverID, int enemyType, int enemyStatus) {
|
||||
this.enemyId = enemyId;
|
||||
this.enemyId_UUid=enemyType==0? KeyGenUtils.produceIdByModule(UUIDEnum.EXPEDITION, 0):String.valueOf(enemyId);
|
||||
this.serverID = serverID;
|
||||
this.enemyType = enemyType;
|
||||
this.enemyStatus = enemyStatus;
|
||||
}
|
||||
|
||||
public ArenaEnemy(){
|
||||
|
||||
}
|
||||
|
||||
public String getEnemyId_UUid() {
|
||||
return enemyId_UUid;
|
||||
}
|
||||
|
||||
public void setEnemyId_UUid(String enemyId_UUid) {
|
||||
this.enemyId_UUid = enemyId_UUid;
|
||||
}
|
||||
|
||||
public int getRank() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
public void setRank(int rank) {
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public int getServerID() {
|
||||
return serverID;
|
||||
}
|
||||
|
||||
public int getEnemyId() {
|
||||
return enemyId;
|
||||
}
|
||||
|
||||
public int getEnemyType() {
|
||||
return enemyType>0?1:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getEnemyStatus() {
|
||||
return enemyStatus;
|
||||
}
|
||||
|
||||
public boolean isGender() {
|
||||
return gender;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,433 @@
|
|||
package com.world.logic.arean;
|
||||
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ljsd.fight.ArenaRecord;
|
||||
import com.ljsd.jieling.config.clazzStaticCfg.SArenaRobotStaticConfig;
|
||||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.core.Lockey;
|
||||
import com.ljsd.jieling.core.SimpleTransaction;
|
||||
import com.ljsd.jieling.logic.dao.PlayerInfoCache;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.family.DeathChallengeCount;
|
||||
import com.ljsd.jieling.logic.fight.GameFightType;
|
||||
import com.ljsd.jieling.logic.fight.PVPFightEvent;
|
||||
import com.ljsd.jieling.logic.fight.result.FightResult;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.util.KeyGenUtils;
|
||||
import com.ljsd.jieling.util.UUIDEnum;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.logic.arean.fight.FightUtil;
|
||||
import com.world.logic.rank.AbstractCrossRank;
|
||||
import com.world.network.server.gsHelper;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import config.*;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.protocols.ArenaInfoProto;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
import rpc.world.WorldProto;
|
||||
import util.MathUtils;
|
||||
import util.StringUtil;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class ArenaLogic {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ArenaLogic.class);
|
||||
|
||||
private ArenaLogic() {
|
||||
}
|
||||
|
||||
|
||||
public static class Instance {
|
||||
public final static ArenaLogic instance = new ArenaLogic();
|
||||
}
|
||||
|
||||
public static ArenaLogic getInstance() {
|
||||
return ArenaLogic.Instance.instance;
|
||||
}
|
||||
|
||||
public static ConcurrentHashMap<Integer, HashSet<String>> map = new ConcurrentHashMap<>();//服务器分组信息
|
||||
public static volatile Map<String, Integer> serverSplit = new HashMap<>();
|
||||
public static ConcurrentHashMap<Integer, HashMap<Integer, ArenaEnemy>> ranInfo = new ConcurrentHashMap<>();//每个分组内排行榜信息
|
||||
private static Map<Integer, CommonProto.ArenaEnemy> userCacheMap = new ConcurrentHashMap<>();
|
||||
// public static ConcurrentHashMap<Integer, ArenaEnemy> userInfoCache = new ConcurrentHashMap<>();//成员信息缓存
|
||||
|
||||
// private static ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock();
|
||||
// public static ReentrantReadWriteLock.ReadLock rlock =rwlock.readLock(); 使用不规范 容易死锁 等有时间了封装
|
||||
// public static ReentrantReadWriteLock.WriteLock wlock=rwlock.writeLock();
|
||||
|
||||
|
||||
public static void initRank() throws Exception {
|
||||
|
||||
Map<String, Integer> serverSplit = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO, String.class, Integer.class);
|
||||
serverSplit.forEach((s, integer) -> {
|
||||
HashSet<String> strings = map.getOrDefault(integer, new HashSet<>());
|
||||
strings.add(s);
|
||||
map.put(integer, strings);
|
||||
});
|
||||
ArenaLogic.serverSplit = serverSplit;
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
Cursor<String> cursor = RedisUtil.getInstence().scan("WORLD_ARENA_RANK:*", 200);
|
||||
while (cursor.hasNext()) {
|
||||
//找到一次就添加一次
|
||||
keys.add(cursor.next());
|
||||
}
|
||||
cursor.close();
|
||||
keys.forEach(k -> {
|
||||
HashMap<Integer, ArenaEnemy> object = RedisUtil.getInstence().getObject(k, new TypeToken<HashMap<Integer, ArenaEnemy>>() {
|
||||
}.getType());
|
||||
|
||||
ranInfo.put(Integer.valueOf(k.split(":")[1]), object);
|
||||
});
|
||||
}
|
||||
|
||||
public void minCheck() {
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
// String matched = redisUtil.getObject(RedisKey.MATCHED_VERSION, String.class);//global 分组日期
|
||||
// String myVersion = redisUtil.getObject(RedisKey.MATCHED_MY_VERSION, String.class);
|
||||
// if (null == matched || Integer.valueOf(matched) == 0) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
long time = TimeUtils.now() + TimeUtils.ONE_MINUTE * 2;
|
||||
//刷新
|
||||
if(TimeUtils.getDayOfWeek(time)==6&&TimeUtils.getHourOfDay(time)==0&&TimeUtils.getMiunte(time)==0){
|
||||
{
|
||||
onfinish();
|
||||
//TODO start
|
||||
//重新获取分组信息
|
||||
// redisUtil.set(RedisKey.MATCHED_MY_VERSION, matched);
|
||||
Map<String, Integer> serverSplit = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO, String.class, Integer.class);
|
||||
serverSplit.forEach((s, integer) -> {
|
||||
HashSet<String> strings = map.getOrDefault(integer, new HashSet<>());
|
||||
strings.add(s);
|
||||
map.put(integer, strings);
|
||||
});
|
||||
//为每组生成排行榜
|
||||
ArenaLogic.serverSplit = serverSplit;
|
||||
int[] fightArea = STableManager.getConfig(SMServerArenaSetting.class).get(1).getFightArea();
|
||||
SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1);
|
||||
int robotNum = setting.getRobotNum();
|
||||
Random random = new Random();
|
||||
map.forEach((integer, strings) -> {
|
||||
List<Integer> robotIds = randomRobot(fightArea[0], fightArea[1], robotNum);
|
||||
HashMap<Integer, ArenaEnemy> orDefault = ranInfo.getOrDefault(integer, new HashMap<>());
|
||||
for (int i = 1; i <= robotIds.size(); i++) {
|
||||
orDefault.put(i, new ArenaEnemy(robotIds.get(i - 1), 0, 0, 0,random.nextBoolean()));
|
||||
}
|
||||
ranInfo.put(integer, orDefault);
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK, String.valueOf(integer), orDefault, new TypeToken<HashMap<Integer, ArenaEnemy>>() {
|
||||
}.getType());
|
||||
});
|
||||
}
|
||||
}
|
||||
// if (null != myVersion && !myVersion.equals("")) {
|
||||
// if (!myVersion.equals(matched) )
|
||||
// }
|
||||
//定时入库
|
||||
lastSaved();
|
||||
}
|
||||
|
||||
private void onfinish(){
|
||||
map.clear();
|
||||
|
||||
List<String> delKeys = new ArrayList<>();
|
||||
|
||||
delKeys.add(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, ""));
|
||||
delKeys.add(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RRECORD, ""));
|
||||
delKeys.add(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_MY_PRON, ""));
|
||||
|
||||
Cursor<String> cursor = RedisUtil.getInstence().scan("WORLD_ARENA_RANK_MY_MATH:*", -1);
|
||||
while (cursor.hasNext()) {
|
||||
String next = cursor.next();
|
||||
System.out.println("清除:"+next);
|
||||
delKeys.add(next);
|
||||
}
|
||||
Cursor<String> curso1 = RedisUtil.getInstence().scan("WORLD_ARENA_RRECORD:*", -1);
|
||||
while (curso1.hasNext()) {
|
||||
String next = curso1.next();
|
||||
System.out.println("清除:"+next);
|
||||
delKeys.add(next);
|
||||
}
|
||||
RedisUtil.getInstence().del(delKeys.toArray(new String[0]));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<CommonProto.ArenaEnemy> getArenaEnemyList(List<ArenaEnemy> arenaEnemies,List<String> myPro) throws Exception {
|
||||
List<CommonProto.ArenaEnemy> arenaEnemyList = new ArrayList<>(arenaEnemies.size());
|
||||
for (ArenaEnemy arenaEnemy : arenaEnemies) {
|
||||
int enemyId = arenaEnemy.getEnemyId();
|
||||
int enemyType = arenaEnemy.getEnemyType();
|
||||
int rank = arenaEnemy.getRank();//only robot
|
||||
boolean gender = arenaEnemy.isGender();
|
||||
if(enemyType==0){
|
||||
Object hget = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT_ROBOT, String.valueOf(arenaEnemy.getEnemyId_UUid()));
|
||||
arenaEnemyList.add(getArenaEnemy(enemyId, arenaEnemy.getServerID(), enemyType, rank,hget==null?0:Integer.parseInt((String)hget),myPro.contains(arenaEnemy.getEnemyId_UUid())));
|
||||
}else{
|
||||
Object hget = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT, String.valueOf(enemyId));
|
||||
|
||||
arenaEnemyList.add(getArenaEnemy(enemyId, arenaEnemy.getServerID(), enemyType, rank,hget==null?0:Integer.parseInt((String)hget),myPro.contains(arenaEnemy.getEnemyId_UUid()),gender));
|
||||
}
|
||||
}
|
||||
return arenaEnemyList;
|
||||
}
|
||||
|
||||
public CommonProto.ArenaEnemy getRobotArenaEnemy(int enemyId) throws Exception {
|
||||
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId);
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(enemyId)
|
||||
.setLevel(sArenaRobotConfig.getRobotLevel())
|
||||
.setName(sArenaRobotConfig.getRobotName())
|
||||
.setScore(sArenaRobotConfig.getRobotScore())
|
||||
.setTotalForce(sArenaRobotConfig.getTotalForce())
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.build();
|
||||
|
||||
|
||||
}
|
||||
public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int serverId, int enemyType, int rank,int proTime,boolean isContain) throws Exception {
|
||||
return getArenaEnemy(enemyId,serverId,enemyType,rank,proTime,isContain,false);
|
||||
}
|
||||
|
||||
public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int serverId, int enemyType, int rank,int proTime,boolean isContain,boolean gender) throws Exception {
|
||||
|
||||
if (enemyType == 0) { //机器人
|
||||
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId);
|
||||
CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(sArenaRobotConfig.getHeroList()).build();
|
||||
CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder()
|
||||
.setUid(enemyId)
|
||||
.setLevel(sArenaRobotConfig.getRobotLevel())
|
||||
.setName(sArenaRobotConfig.getRobotName())
|
||||
.setScore(sArenaRobotConfig.getRobotScore())
|
||||
.setTotalForce(sArenaRobotConfig.getTotalForce())
|
||||
.setRank(rank)
|
||||
.setGender(gender?0:1)
|
||||
.setServername(MongoUtil.getInstence().getServerNameById(serverId))
|
||||
.build();
|
||||
return CommonProto.ArenaEnemy.newBuilder()
|
||||
.setPersonInfo(personInfoBuild)
|
||||
.setTeam(teamBuild)
|
||||
.setWorshipTime(proTime)
|
||||
.setHadProud(isContain)
|
||||
.build();
|
||||
} else {
|
||||
boolean b = userCacheMap.containsKey(enemyId);
|
||||
CommonProto.ArenaPersonInfo.Builder builder;
|
||||
CommonProto.Team.Builder teamBuilder;
|
||||
if(b){
|
||||
builder= CommonProto.ArenaPersonInfo.newBuilder().mergeFrom(userCacheMap.get(enemyId).getPersonInfo());
|
||||
teamBuilder= CommonProto.Team.newBuilder().mergeFrom(userCacheMap.get(enemyId).getTeam());
|
||||
}else {
|
||||
WorldProto.GetGSUserArenaInfoResponse getGSUserArenaInfoResponse = gsHelper.sendMessageToGs(serverId, enemyId, WorldProto.GetGSUserArenaInfoRequest.newBuilder().setUid(enemyId).build(), WorldProto.GetGSUserArenaInfoResponse.class);
|
||||
if (getGSUserArenaInfoResponse == null) {
|
||||
return null;
|
||||
}
|
||||
builder = CommonProto.ArenaPersonInfo.newBuilder().mergeFrom(getGSUserArenaInfoResponse.getArenaEnemys().getPersonInfo());
|
||||
teamBuilder = CommonProto.Team.newBuilder().mergeFrom(getGSUserArenaInfoResponse.getArenaEnemys().getTeam());
|
||||
}
|
||||
builder.setRank(rank).setServername(MongoUtil.getInstence().getServerNameById(serverId));
|
||||
CommonProto.ArenaEnemy build = CommonProto.ArenaEnemy.newBuilder().setTeam(teamBuilder.build()).setPersonInfo(builder.build()).setWorshipTime(proTime).setHadProud(isContain).build();
|
||||
//缓存数据
|
||||
userCacheMap.put(enemyId,build);
|
||||
return build;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, CommonProto.ArenaEnemy> getUserCacheMap() {
|
||||
return userCacheMap;
|
||||
}
|
||||
|
||||
public static void setUserCacheMap(Map<Integer, CommonProto.ArenaEnemy> userCacheMap) {
|
||||
ArenaLogic.userCacheMap = userCacheMap;
|
||||
}
|
||||
|
||||
public ArenaEnemy getEnemyInList(int challengeUid, List<ArenaEnemy> enemys) {
|
||||
for (ArenaEnemy data : enemys) {
|
||||
if (data.getEnemyId() == challengeUid) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static List<Integer> randomRobot(int start, int end, int nums) {
|
||||
List<Integer> robotIds = new LinkedList<>();
|
||||
int index = 0;
|
||||
while (robotIds.size() < nums) {
|
||||
index++;
|
||||
if (index == 10000) {
|
||||
break;
|
||||
}
|
||||
double v = Math.random() * (end - start) + start;
|
||||
int robotId = SArenaRobotStaticConfig.getFloorForce2robotId((int) v);
|
||||
robotIds.add(robotId);
|
||||
}
|
||||
return robotIds;
|
||||
}
|
||||
|
||||
|
||||
public void lastSaved() {
|
||||
map.forEach((integer, strings) -> {
|
||||
HashMap<Integer, ArenaEnemy> orDefault = ranInfo.getOrDefault(integer, new HashMap<>());
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK, String.valueOf(integer), orDefault);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static Map.Entry<Integer, ArenaEnemy> getKey(HashMap<Integer, ArenaEnemy> map, int value) {
|
||||
for (Map.Entry<Integer, ArenaEnemy> entry : map.entrySet()) {
|
||||
ArenaEnemy value1 = entry.getValue();
|
||||
if (value1.getEnemyId() == value) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上层加锁
|
||||
*/
|
||||
public static List<ArenaEnemy> randomRank(HashMap<Integer, ArenaEnemy> integerIntegerHashMap, int uid, int myRank) {
|
||||
//缓存每次匹配结果
|
||||
Set<Integer> hisRank = RedisUtil.getInstence().getObject(RedisUtil.getInstence().getKey(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid)), new TypeToken<Set<Integer>>() {
|
||||
}.getType());
|
||||
List<ArenaEnemy> arenaEnemies = new ArrayList<>();
|
||||
|
||||
TreeSet<Integer> matchRank;
|
||||
if (hisRank == null || hisRank.size() == 0) {
|
||||
//获取匹配对手
|
||||
matchRank = getMatchID(myRank==9999?1000:myRank);
|
||||
} else {
|
||||
matchRank = new TreeSet<>(hisRank);
|
||||
}
|
||||
|
||||
matchRank.forEach(rank -> {
|
||||
if (!integerIntegerHashMap.containsKey(rank)) {
|
||||
return;
|
||||
}
|
||||
ArenaEnemy matchInfo = integerIntegerHashMap.get(rank);
|
||||
matchInfo.setRank(rank);
|
||||
arenaEnemies.add(matchInfo);
|
||||
// matchRank.add(rank);
|
||||
});
|
||||
RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid), matchRank);
|
||||
return arenaEnemies;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时随机 暂时不缓存
|
||||
*/
|
||||
private static TreeSet<Integer> getMatchID(int index) {
|
||||
//玩家排名 获取配置
|
||||
Integer integer = SMServerArenaMatchConfig.rank2miss.floorKey(index);
|
||||
Integer integer1 = SMServerArenaMatchConfig.rank2miss.get(integer);
|
||||
TreeSet<Integer> objects = new TreeSet<>();
|
||||
//分配对手
|
||||
SMServerArenaMatchConfig serverArenaMatchConfig = STableManager.getConfig(SMServerArenaMatchConfig.class).get(integer1);
|
||||
int blockID1 = index-(int) (Math.random() * (serverArenaMatchConfig.getBlock1()[1] - serverArenaMatchConfig.getBlock1()[0]) + serverArenaMatchConfig.getBlock1()[0]) ;
|
||||
int blockID2 = index-(int) (Math.random() * (serverArenaMatchConfig.getBlock2()[1] - serverArenaMatchConfig.getBlock2()[0]) + serverArenaMatchConfig.getBlock2()[0]) ;
|
||||
int blockID3 = index-(int) (Math.random() * (serverArenaMatchConfig.getBlock3()[1] - serverArenaMatchConfig.getBlock3()[0]) + serverArenaMatchConfig.getBlock3()[0]) ;
|
||||
int blockID4 = index-(int) (Math.random() * (serverArenaMatchConfig.getBlock4()[1] - serverArenaMatchConfig.getBlock4()[0]) + serverArenaMatchConfig.getBlock4()[0]) ;
|
||||
objects.add(blockID1);
|
||||
objects.add(blockID2);
|
||||
objects.add(blockID3);
|
||||
objects.add(blockID4);
|
||||
return objects;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 零点重置
|
||||
*/
|
||||
public static void clearReidsInTime() {
|
||||
List<String> delKeys = new ArrayList<>();
|
||||
Cursor<String> cursor = RedisUtil.getInstence().scan("WORLD_ARENA_MY_PRON:*", -1);
|
||||
while (cursor.hasNext()) {
|
||||
delKeys.add(cursor.next());
|
||||
}
|
||||
RedisUtil.getInstence().del(delKeys.toArray(new String[0]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public PlayerInfoProto.RankResponse getRank(int uid,int serverID) throws Exception {
|
||||
|
||||
Integer integer = ArenaLogic.serverSplit.get(String.valueOf(serverID));
|
||||
HashMap<Integer, ArenaEnemy> integerIntegerHashMap = ArenaLogic.ranInfo.get(integer);
|
||||
//获取我的排名
|
||||
Map.Entry<Integer, ArenaEnemy> myRank = ArenaLogic.getKey(integerIntegerHashMap,uid);
|
||||
//根据我的排名获取
|
||||
int myIndex = 9999;
|
||||
if (myRank != null) {
|
||||
myIndex = myRank.getKey();
|
||||
}
|
||||
PlayerInfoProto.RankResponse.Builder builder = PlayerInfoProto.RankResponse.newBuilder();
|
||||
for (int i = 1; i < (uid==0?integerIntegerHashMap.size():100); i++) {
|
||||
ArenaEnemy arenaEnemy = integerIntegerHashMap.get(i);
|
||||
if (arenaEnemy.getEnemyType() == 1) {
|
||||
int enemyId = arenaEnemy.getEnemyId();
|
||||
int enemyType = arenaEnemy.getEnemyType();
|
||||
int rank = arenaEnemy.getRank();//only robot
|
||||
List<String> strings = RedisUtil.getInstence().lGet(RedisKey.WORLD_ARENA_MY_PRON,String.valueOf(uid), 0, -1);
|
||||
Object proudGet = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT, String.valueOf(enemyId));
|
||||
CommonProto.ArenaEnemy arenaEnemy1 = getArenaEnemy(enemyId, arenaEnemy.getServerID(), enemyType, rank, proudGet==null?0:Integer.parseInt((String)proudGet), strings.contains(arenaEnemy.getEnemyId_UUid()));
|
||||
CommonProto.RankInfo everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(i).setParam1(arenaEnemy1.getPersonInfo().getTotalForce()).build();
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(arenaEnemy1.getPersonInfo().getUid())
|
||||
.setUserName(arenaEnemy1.getPersonInfo().getName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setServerName(arenaEnemy1.getPersonInfo().getServername());
|
||||
builder.addRanks(everyRank);
|
||||
|
||||
} else {
|
||||
SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(arenaEnemy.getEnemyId());
|
||||
CommonProto.RankInfo everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(i).setParam1(sArenaRobotConfig.getTotalForce()).build();
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(arenaEnemy.getEnemyId())
|
||||
.setUserName(sArenaRobotConfig.getRobotName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setForce(sArenaRobotConfig.getTotalForce())
|
||||
.setLevel(sArenaRobotConfig.getRobotLevel())
|
||||
.setServerName(MongoUtil.getInstence().getServerNameById(arenaEnemy.getServerID()));
|
||||
builder.addRanks(everyRank);
|
||||
}
|
||||
}
|
||||
|
||||
CommonProto.ArenaEnemy arenaEnemy1 = getArenaEnemy(uid, serverID, 1, myIndex,0, true);
|
||||
if(arenaEnemy1!=null&&uid!=0){
|
||||
CommonProto.RankInfo everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(myIndex)
|
||||
.setParam1(arenaEnemy1.getPersonInfo().getTotalForce())
|
||||
.build();
|
||||
builder.setMyRankInfo(everyRankInfo);
|
||||
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
package com.world.logic.rank;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
import com.ljsd.jieling.logic.dao.PlayerInfoCache;
|
||||
import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.db.mongo.core.CrossGuild;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/8
|
||||
* @discribe
|
||||
*/
|
||||
public abstract class AbstractCrossRank extends AbstractRank {
|
||||
|
||||
private static Map<Integer, PlayerInfoCache> crossUserMap = new ConcurrentHashMap<>();
|
||||
|
||||
private static Map<Integer, GuildInfoCache> crossGuildMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<Integer, PlayerInfoCache> getCrossUserMap() {
|
||||
return crossUserMap;
|
||||
}
|
||||
|
||||
public AbstractCrossRank(int type, String redisKey) {
|
||||
super(type, redisKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨服获取排行榜数据,包括个人的排名和所有人的信息,获取调用此方法
|
||||
* @param rkey 自定义小key 可以是 活动id(活动有多期,排行榜保留) 、 工会boss里工会id+“:”+期数 组合的key
|
||||
* @param uid 改用户id
|
||||
* @param rankEndLine 所有人条目上线
|
||||
* @return 当前排行榜数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public PlayerInfoProto.RankResponse getRank(int uid,String rkey,int page,int rankEndLine) throws Exception {
|
||||
if(rankEndLine==-1){
|
||||
rankEndLine = 100;
|
||||
}
|
||||
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==0){
|
||||
start=1;
|
||||
}
|
||||
PlayerInfoProto.RankResponse.Builder allUserResponse = getAllUserResponse(zsetreverseRangeWithScores,start);
|
||||
//当前用户信息
|
||||
getMyInfo(uid,rkey,allUserResponse);
|
||||
return allUserResponse.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 向排行榜添加或修改某条数据
|
||||
* @param uid 修改用户id
|
||||
* @param rkey redis 小key 自定义
|
||||
* @param data 注意:此处为传入修改的分数需要的所有参数即可,里面调用getScore方法,注意参数顺序
|
||||
*/
|
||||
public void addRank(int uid,String rkey,double... data){
|
||||
String key = redisKey+":"+rkey;
|
||||
RedisUtil.getInstence().zsetAddOne(key,String.valueOf(uid), getScore(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向排行榜增减分数
|
||||
* @param uid
|
||||
* @param rkey
|
||||
* @param data
|
||||
*/
|
||||
public void incrementRankScore(int uid,String rkey,double... data){
|
||||
RedisUtil.getInstence().incrementZsetScore(redisKey,rkey,String.valueOf(uid), getScore(data));
|
||||
}
|
||||
public void incrementRankScoreOnly(int uid,String rkey,double... data){
|
||||
RedisUtil.getInstence().incrementZsetScore(redisKey,rkey,String.valueOf(uid), data[0]);
|
||||
}
|
||||
|
||||
public String getRedisKey() {
|
||||
return redisKey;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Set<ZSetOperations.TypedTuple<String>> getRankByKey(String rkey,int start,int end){
|
||||
return RedisUtil.getInstence().getZsetreverseRangeWithScores(redisKey, rkey, start, end);
|
||||
}
|
||||
|
||||
|
||||
protected PlayerInfoProto.RankResponse.Builder getAllUserResponse(Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores, int start) throws Exception{
|
||||
PlayerInfoProto.RankResponse.Builder builder = PlayerInfoProto.RankResponse.newBuilder();
|
||||
forEach(start,zsetreverseRangeWithScores,(index,data)->{
|
||||
try {
|
||||
getOptional(index,data,builder);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
protected void getOptional(int index,ZSetOperations.TypedTuple<String> data,PlayerInfoProto.RankResponse.Builder builder) throws Exception {
|
||||
|
||||
PlayerInfoCache everyUser =getCrossUser(Integer.parseInt(data.getValue()));
|
||||
CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(index)
|
||||
.setParam1(getParam1(data.getScore()))
|
||||
.setParam2(getParam2(data.getScore()))
|
||||
.setParam3(getParam3(data.getScore()));
|
||||
CommonProto.UserRank.Builder oneUserRank = getOneUserRank(everyUser, everyRankInfo);
|
||||
builder.addRanks(oneUserRank);
|
||||
}
|
||||
public CommonProto.UserRank.Builder getOneUserRank(PlayerInfoCache everyUser,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(everyUser.getId())
|
||||
.setUserName(everyUser.getName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setServerName(MongoUtil.getInstence().getServerNameById(everyUser.getServerId()));
|
||||
|
||||
return everyRank;
|
||||
}
|
||||
|
||||
protected void getMyInfo(int uid,String rkey,PlayerInfoProto.RankResponse.Builder allUserResponse){
|
||||
int myRank= RedisUtil.getInstence().getZSetreverseRank(redisKey,rkey,Integer.toString(uid)).intValue();
|
||||
Double zSetScore = RedisUtil.getInstence().getZSetScore(redisKey, rkey, Integer.toString(uid));
|
||||
CommonProto.RankInfo towerRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(myRank)
|
||||
.setParam1(getParam1(zSetScore))
|
||||
.setParam2(getParam2(zSetScore)).build();
|
||||
allUserResponse.setMyRankInfo(towerRankInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子类需重写此方法来获得Redis解析后所需要的数据数组
|
||||
* @param score
|
||||
* @return
|
||||
*/
|
||||
public abstract long[] getDataByScore(Double score);
|
||||
|
||||
/**
|
||||
* 子类需重写此方法来获得向Redis里添加的数据,根据需要的参数进行组合
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public abstract double getScore(double... data);
|
||||
|
||||
protected static <T> void forEach(int startIndex,Iterable<? extends T> elements, BiConsumer<Integer, ? super T> action) {
|
||||
Objects.requireNonNull(elements);
|
||||
Objects.requireNonNull(action);
|
||||
if(startIndex < 0) {
|
||||
startIndex = 0;
|
||||
}
|
||||
int index = startIndex;
|
||||
for (T element : elements) {
|
||||
index++;
|
||||
// if(index <= startIndex) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
action.accept(index-1, element);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public long getParam1(Double data) {
|
||||
|
||||
return getDataByScore(data).length>0?getDataByScore(data)[0]:0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParam2(Double data) {
|
||||
return getDataByScore(data).length>1?(int)(getDataByScore(data)[1]):0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParam3(Double data) {
|
||||
return getDataByScore(data).length>2?(int)(getDataByScore(data)[2]):0;
|
||||
}
|
||||
|
||||
public double getScoreById(int uid,String rkey){
|
||||
return RedisUtil.getInstence().getZSetScore(redisKey,rkey, String.valueOf(uid));
|
||||
}
|
||||
|
||||
public PlayerInfoCache getCrossUser(int id){
|
||||
PlayerInfoCache crossUser = crossUserMap.get(id);
|
||||
if(crossUser==null){
|
||||
crossUser = RedisUtil.getInstence().getMapEntry(RedisKey.PLAYER_INFO_CACHE, "", String.valueOf(id), PlayerInfoCache.class);
|
||||
crossUserMap.put(id,crossUser);
|
||||
}
|
||||
return crossUser;
|
||||
}
|
||||
|
||||
public GuildInfoCache getCrossGuild(int id){
|
||||
GuildInfoCache crossGuild = crossGuildMap.get(id);
|
||||
if(crossGuild==null){
|
||||
crossGuild = RedisUtil.getInstence().getMapEntry(RedisKey.GUILD_INFO_CACHE, "", String.valueOf(id), GuildInfoCache.class);
|
||||
crossGuildMap.put(id,crossGuild);
|
||||
}
|
||||
return crossGuild;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.world.logic.rank;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/8
|
||||
* @discribe
|
||||
*/
|
||||
public class DeathPathCrossEveryPersonRank extends AbstractCrossRank {
|
||||
|
||||
|
||||
public DeathPathCrossEveryPersonRank(String redisKey) {
|
||||
super(1, redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] getDataByScore(Double score) {
|
||||
return new long[]{score.longValue()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getScore(double... data) {
|
||||
return data[0];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue