老跨服代码注释
parent
2fd6b82d04
commit
884e3b1276
|
@ -4,8 +4,6 @@ import com.ljsd.jieling.util.KeyGenUtils;
|
|||
import com.world.config.ConfigurableApplicationContextManager;
|
||||
import com.world.config.WorldCoreSettings;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import com.world.redis.RedisUtil;
|
||||
import com.world.thread.ThreadManager;
|
||||
import com.world.thrift.idl.pool.RPCServerTask;
|
||||
import com.world.thrift.idl.pool.ThriftPoolUtils;
|
||||
|
@ -46,7 +44,7 @@ public class WorldServerApplication {
|
|||
|
||||
|
||||
try {
|
||||
RedisUtil.getInstence().init();
|
||||
// RedisUtil.getInstence().init();
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("MongoUtil err ->{}", e);
|
||||
}
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
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
|
||||
*/
|
||||
@Deprecated
|
||||
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();
|
||||
}
|
||||
}
|
||||
//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
|
||||
// */
|
||||
//@Deprecated
|
||||
//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();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,35 +1,33 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
//package com.world.handler;
|
||||
//
|
||||
//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.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();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
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
|
||||
*/
|
||||
@Deprecated
|
||||
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();
|
||||
}
|
||||
}
|
||||
//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
|
||||
// */
|
||||
//@Deprecated
|
||||
//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();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,26 +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;
|
||||
}
|
||||
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,168 +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((int)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((int)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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//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((int)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((int)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();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,64 +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();
|
||||
}
|
||||
}
|
||||
//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();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,63 +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();
|
||||
//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);
|
||||
// }
|
||||
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();
|
||||
}
|
||||
}
|
||||
// return builder.build();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,26 +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;
|
||||
}
|
||||
}
|
||||
//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;
|
||||
// }
|
||||
//}
|
|
@ -1,433 +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);
|
||||
//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);
|
||||
// });
|
||||
// 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());
|
||||
//
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// cursor.close();
|
||||
// keys.forEach(k -> {
|
||||
// HashMap<Integer, ArenaEnemy> object = RedisUtil.getInstence().getObject(k, new TypeToken<HashMap<Integer, ArenaEnemy>>() {
|
||||
// }.getType());
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// ranInfo.put(Integer.valueOf(k.split(":")[1]), object);
|
||||
//
|
||||
// /**
|
||||
// * 上层加锁
|
||||
// */
|
||||
// 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);
|
||||
// });
|
||||
}
|
||||
|
||||
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();
|
||||
// RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid), matchRank);
|
||||
// return arenaEnemies;
|
||||
// }
|
||||
//
|
||||
// List<String> delKeys = new ArrayList<>();
|
||||
// /**
|
||||
// * 实时随机 暂时不缓存
|
||||
// */
|
||||
// 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;
|
||||
// }
|
||||
//
|
||||
// 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();
|
||||
// /**
|
||||
// * 零点重置
|
||||
// */
|
||||
// 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();
|
||||
////
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,215 +1,214 @@
|
|||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ZSetOperations.TypedTuple<String>> getRankByKey(String rkey, int start, int end){
|
||||
return RedisUtil.getInstence().getZsetreverseRangeWithScores(redisKey, rkey, start, end);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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)
|
||||
.setPracticeLevel(everyUser.getPracticeLevel())
|
||||
.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;
|
||||
//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.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;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Set<ZSetOperations.TypedTuple<String>> getRankByKey(String rkey, int start, int end){
|
||||
// return RedisUtil.getInstence().getZsetreverseRangeWithScores(redisKey, rkey, start, end);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// 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();
|
||||
// }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
// });
|
||||
// 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)
|
||||
// .setPracticeLevel(everyUser.getPracticeLevel())
|
||||
// .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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
package com.world.logic.rank;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
import com.ljsd.jieling.logic.dao.PlayerInfoCache;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.redis.RedisUtil;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/11
|
||||
* @discribe
|
||||
*/
|
||||
public class DeathPathCrossEveryGuildRank extends AbstractCrossRank {
|
||||
|
||||
|
||||
public DeathPathCrossEveryGuildRank(String redisKey) {
|
||||
super(1,redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] getDataByScore(Double score) {
|
||||
return new long[]{(long)(score/1000),(int)(score%1000)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getScore(double... data) {
|
||||
long result = (long) (data[0]*1000);
|
||||
if(data.length>1){
|
||||
result+=data[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
|
||||
|
||||
GuildInfoCache everyGuild =getCrossGuild(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(everyGuild, everyRankInfo);
|
||||
builder.addRanks(oneUserRank);
|
||||
}
|
||||
|
||||
public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(everyGuild.getGuildId())
|
||||
.setGuildName(everyGuild.getGuildName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
;
|
||||
|
||||
return everyRank;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.world.logic.rank;
|
||||
//
|
||||
//import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
//import com.ljsd.jieling.logic.dao.PlayerInfoCache;
|
||||
//import com.world.db.mongo.MongoUtil;
|
||||
//import com.world.redis.RedisUtil;
|
||||
//import org.springframework.data.redis.core.ZSetOperations;
|
||||
//import rpc.protocols.CommonProto;
|
||||
//import rpc.protocols.PlayerInfoProto;
|
||||
//
|
||||
///**
|
||||
// * @author lvxinran
|
||||
// * @date 2020/12/11
|
||||
// * @discribe
|
||||
// */
|
||||
//public class DeathPathCrossEveryGuildRank extends AbstractCrossRank {
|
||||
//
|
||||
//
|
||||
// public DeathPathCrossEveryGuildRank(String redisKey) {
|
||||
// super(1,redisKey);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public long[] getDataByScore(Double score) {
|
||||
// return new long[]{(long)(score/1000),(int)(score%1000)};
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getScore(double... data) {
|
||||
// long result = (long) (data[0]*1000);
|
||||
// if(data.length>1){
|
||||
// result+=data[1];
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
|
||||
//
|
||||
// GuildInfoCache everyGuild =getCrossGuild(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(everyGuild, everyRankInfo);
|
||||
// builder.addRanks(oneUserRank);
|
||||
// }
|
||||
//
|
||||
// public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
// CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
// .setUid(everyGuild.getGuildId())
|
||||
// .setGuildName(everyGuild.getGuildName())
|
||||
// .setRankInfo(everyRankInfo)
|
||||
// .setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
// ;
|
||||
//
|
||||
// return everyRank;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,24 +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];
|
||||
}
|
||||
}
|
||||
//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];
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,64 +1,64 @@
|
|||
package com.world.logic.rank;
|
||||
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
import com.ljsd.jieling.logic.family.DeathChallengeCount;
|
||||
import com.ljsd.jieling.logic.family.DeathPathLogic;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.redis.RedisUtil;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import rpc.protocols.CommonProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/11
|
||||
* @discribe
|
||||
*/
|
||||
public class DeathPathCrossTotalGuildRank extends AbstractCrossRank {
|
||||
public DeathPathCrossTotalGuildRank(String redisKey) {
|
||||
super(1, redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] getDataByScore(Double score) {
|
||||
BigDecimal bigDecimal = new BigDecimal(score.toString()).subtract(new BigDecimal(score.intValue())).multiply(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
return new long[]{bigDecimal.longValue(),score.intValue()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getScore(double... data) {
|
||||
BigDecimal decimal = null;
|
||||
decimal = new BigDecimal(String.valueOf(data[0])).divide(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
if(data.length>1){
|
||||
decimal = decimal.add(new BigDecimal(data[1]));
|
||||
}
|
||||
return decimal.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
|
||||
GuildInfoCache crossGuild = getCrossGuild(Integer.parseInt(data.getValue()));
|
||||
DeathChallengeCount countInfo = DeathPathLogic.getInstance().getDeathChallengeCount(crossGuild.getGuildId());
|
||||
GuildInfoCache everyGuild =getCrossGuild(Integer.parseInt(data.getValue()));
|
||||
CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
.setRank(index)
|
||||
.setParam1(getParam1(data.getScore()))
|
||||
.setParam2(getParam2(data.getScore()))
|
||||
.setParam3(countInfo==null?0:countInfo.getUserReward().size());
|
||||
CommonProto.UserRank.Builder oneUserRank = getOneUserRank(everyGuild, everyRankInfo);
|
||||
builder.addRanks(oneUserRank);
|
||||
}
|
||||
|
||||
public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(everyGuild.getGuildId())
|
||||
.setGuildName(everyGuild.getGuildName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
|
||||
return everyRank;
|
||||
}
|
||||
}
|
||||
//package com.world.logic.rank;
|
||||
//
|
||||
//import com.ljsd.jieling.db.redis.RedisKey;
|
||||
//import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
//import com.ljsd.jieling.logic.family.DeathChallengeCount;
|
||||
//import com.ljsd.jieling.logic.family.DeathPathLogic;
|
||||
//import com.world.db.mongo.MongoUtil;
|
||||
//import com.world.redis.RedisUtil;
|
||||
//import org.springframework.data.redis.core.ZSetOperations;
|
||||
//import rpc.protocols.CommonProto;
|
||||
//import rpc.protocols.PlayerInfoProto;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//
|
||||
///**
|
||||
// * @author lvxinran
|
||||
// * @date 2020/12/11
|
||||
// * @discribe
|
||||
// */
|
||||
//public class DeathPathCrossTotalGuildRank extends AbstractCrossRank {
|
||||
// public DeathPathCrossTotalGuildRank(String redisKey) {
|
||||
// super(1, redisKey);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public long[] getDataByScore(Double score) {
|
||||
// BigDecimal bigDecimal = new BigDecimal(score.toString()).subtract(new BigDecimal(score.intValue())).multiply(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
// return new long[]{bigDecimal.longValue(),score.intValue()};
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getScore(double... data) {
|
||||
// BigDecimal decimal = null;
|
||||
// decimal = new BigDecimal(String.valueOf(data[0])).divide(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
// if(data.length>1){
|
||||
// decimal = decimal.add(new BigDecimal(data[1]));
|
||||
// }
|
||||
// return decimal.doubleValue();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void getOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) throws Exception {
|
||||
// GuildInfoCache crossGuild = getCrossGuild(Integer.parseInt(data.getValue()));
|
||||
// DeathChallengeCount countInfo = DeathPathLogic.getInstance().getDeathChallengeCount(crossGuild.getGuildId());
|
||||
// GuildInfoCache everyGuild =getCrossGuild(Integer.parseInt(data.getValue()));
|
||||
// CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
|
||||
// .setRank(index)
|
||||
// .setParam1(getParam1(data.getScore()))
|
||||
// .setParam2(getParam2(data.getScore()))
|
||||
// .setParam3(countInfo==null?0:countInfo.getUserReward().size());
|
||||
// CommonProto.UserRank.Builder oneUserRank = getOneUserRank(everyGuild, everyRankInfo);
|
||||
// builder.addRanks(oneUserRank);
|
||||
// }
|
||||
//
|
||||
// public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
// CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
// .setUid(everyGuild.getGuildId())
|
||||
// .setGuildName(everyGuild.getGuildName())
|
||||
// .setRankInfo(everyRankInfo)
|
||||
// .setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
//
|
||||
// return everyRank;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
package com.world.logic.rank;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import rpc.protocols.CommonProto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/11
|
||||
* @discribe
|
||||
*/
|
||||
public class WorldArenaRank extends AbstractCrossRank {
|
||||
public WorldArenaRank(String redisKey) {
|
||||
super(1, redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] getDataByScore(Double score) {
|
||||
BigDecimal bigDecimal = new BigDecimal(score.toString()).subtract(new BigDecimal(score.intValue())).multiply(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
return new long[]{bigDecimal.longValue(),score.intValue()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getScore(double... data) {
|
||||
BigDecimal decimal = null;
|
||||
decimal = new BigDecimal(String.valueOf(data[0])).divide(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
if(data.length>1){
|
||||
decimal = decimal.add(new BigDecimal(data[1]));
|
||||
}
|
||||
return decimal.doubleValue();
|
||||
}
|
||||
|
||||
public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
.setUid(everyGuild.getGuildId())
|
||||
.setGuildName(everyGuild.getGuildName())
|
||||
.setRankInfo(everyRankInfo)
|
||||
.setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
|
||||
return everyRank;
|
||||
}
|
||||
}
|
||||
//package com.world.logic.rank;
|
||||
//
|
||||
//import com.ljsd.jieling.logic.dao.GuildInfoCache;
|
||||
//import com.world.db.mongo.MongoUtil;
|
||||
//import rpc.protocols.CommonProto;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//
|
||||
///**
|
||||
// * @author lvxinran
|
||||
// * @date 2020/12/11
|
||||
// * @discribe
|
||||
// */
|
||||
//public class WorldArenaRank extends AbstractCrossRank {
|
||||
// public WorldArenaRank(String redisKey) {
|
||||
// super(1, redisKey);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public long[] getDataByScore(Double score) {
|
||||
// BigDecimal bigDecimal = new BigDecimal(score.toString()).subtract(new BigDecimal(score.intValue())).multiply(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
// return new long[]{bigDecimal.longValue(),score.intValue()};
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getScore(double... data) {
|
||||
// BigDecimal decimal = null;
|
||||
// decimal = new BigDecimal(String.valueOf(data[0])).divide(new BigDecimal(String.valueOf(Math.pow(10,15))));
|
||||
// if(data.length>1){
|
||||
// decimal = decimal.add(new BigDecimal(data[1]));
|
||||
// }
|
||||
// return decimal.doubleValue();
|
||||
// }
|
||||
//
|
||||
// public CommonProto.UserRank.Builder getOneUserRank(GuildInfoCache everyGuild,CommonProto.RankInfo.Builder everyRankInfo) throws Exception {
|
||||
// CommonProto.UserRank.Builder everyRank = CommonProto.UserRank.newBuilder()
|
||||
// .setUid(everyGuild.getGuildId())
|
||||
// .setGuildName(everyGuild.getGuildName())
|
||||
// .setRankInfo(everyRankInfo)
|
||||
// .setServerName(MongoUtil.getInstence().getServerNameById(everyGuild.getServerId()));
|
||||
//
|
||||
// return everyRank;
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,110 +1,109 @@
|
|||
package com.world.network.server;
|
||||
|
||||
import com.google.protobuf.GeneratedMessage;
|
||||
import com.world.redis.RedisKey;
|
||||
import com.world.redis.RedisUtil;
|
||||
import com.world.thrift.idl.InnerResult;
|
||||
import com.world.thrift.idl.RPCwTgRequestIFace;
|
||||
import com.world.thrift.idl.pool.ClientAdapterPo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import rpc.net.GlobalProtocolsManager;
|
||||
import rpc.net.RpcMessage;
|
||||
import rpc.net.gtGBaseHandler;
|
||||
import rpc.thrift.ServiceKey;
|
||||
import util.StringUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Description: 链接逻辑服 获取逻辑服信息
|
||||
* Author: ZSX
|
||||
* CreateDate: 2020/11/17 19:52
|
||||
*/
|
||||
public class gsHelper extends GlobalProtocolsManager {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(gsHelper.class);
|
||||
public static gsHelper instance = new gsHelper();
|
||||
|
||||
private gsHelper() {
|
||||
}
|
||||
|
||||
public static boolean sendMessageToWord(int serverId,int uid, GeneratedMessage message)throws Exception{
|
||||
|
||||
ClientAdapterPo<RPCwTgRequestIFace.Client> rPCClient = null;
|
||||
String rpcString = RedisUtil.getInstence().getObject(RedisKey.LOGIC_SERVER_INFO, String.valueOf(serverId), String.class, -1);
|
||||
if (null == rpcString) {
|
||||
LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", serverId, uid);
|
||||
return false;
|
||||
}
|
||||
String thriftIp = rpcString.split(":")[0];
|
||||
String thriftPort = rpcString.split(":")[2];
|
||||
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String serviceKey = StringUtil.getServiceKey(ServiceKey.RPC_WORLD, thriftIp,thriftPort);
|
||||
try {
|
||||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||
InnerResult innerResult = rPCClient.getClient().messageRequest(uid,getProtoIdBySimpleName(message.getClass().getSimpleName()) , ByteBuffer.wrap(message.toByteArray()));
|
||||
processMessage( new RpcMessage(0,uid, innerResult.getProtpId(),ByteBuffer.wrap(innerResult.getMessage())));
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("callback=>",e);
|
||||
return false;
|
||||
}finally {
|
||||
if (rPCClient != null){
|
||||
rPCClient.returnObject(serviceKey);
|
||||
}else{
|
||||
LOGGER.info("callback=> rPCClient is null ");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static <T extends GeneratedMessage> T sendMessageToGs(int serverId,int uid, GeneratedMessage message,Class<T> protoClazz)throws Exception{
|
||||
|
||||
|
||||
String rpcString = RedisUtil.getInstence().getObject(RedisKey.LOGIC_SERVER_INFO, String.valueOf(serverId), String.class, -1);
|
||||
if (null == rpcString) {
|
||||
LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", serverId, uid);
|
||||
return null;
|
||||
}
|
||||
String thriftIp = rpcString.split(":")[0];
|
||||
String thriftPort = rpcString.split(":")[2];
|
||||
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
ClientAdapterPo<RPCwTgRequestIFace.Client> rPCClient = null;
|
||||
String serviceKey = StringUtil.getServiceKey(ServiceKey.RPC_WORLD, thriftIp,thriftPort);
|
||||
try {
|
||||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||
InnerResult innerResult = rPCClient.getClient().messageRequest(uid,getProtoIdBySimpleName(message.getClass().getSimpleName()) , ByteBuffer.wrap(message.toByteArray()));
|
||||
return gtGBaseHandler.getProto(protoClazz,innerResult.getMessage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("callback=>",e);
|
||||
return null;
|
||||
}finally {
|
||||
if (rPCClient != null){
|
||||
rPCClient.returnObject(serviceKey);
|
||||
}else{
|
||||
LOGGER.info("callback=> rPCClient is null ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static InnerResult processMessage(RpcMessage message) throws Exception {
|
||||
gtGBaseHandler baseHandler = getHandlers().get(message.getProtpId());
|
||||
if (baseHandler == null) {
|
||||
//检查一下 没有定义handler
|
||||
LOGGER.info("request unknow commond : " + message.getProtpId());
|
||||
throw new Exception("request unknow commond");
|
||||
} else {
|
||||
baseHandler.execute(message);//client not return
|
||||
return new InnerResult();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//package com.world.network.server;
|
||||
//
|
||||
//import com.google.protobuf.GeneratedMessage;
|
||||
//import com.world.redis.RedisUtil;
|
||||
//import com.world.thrift.idl.InnerResult;
|
||||
//import com.world.thrift.idl.RPCwTgRequestIFace;
|
||||
//import com.world.thrift.idl.pool.ClientAdapterPo;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import rpc.net.GlobalProtocolsManager;
|
||||
//import rpc.net.RpcMessage;
|
||||
//import rpc.net.gtGBaseHandler;
|
||||
//import rpc.thrift.ServiceKey;
|
||||
//import util.StringUtil;
|
||||
//
|
||||
//import java.nio.ByteBuffer;
|
||||
//
|
||||
///**
|
||||
// * Description: 链接逻辑服 获取逻辑服信息
|
||||
// * Author: ZSX
|
||||
// * CreateDate: 2020/11/17 19:52
|
||||
// */
|
||||
//public class gsHelper extends GlobalProtocolsManager {
|
||||
// private static final Logger LOGGER = LoggerFactory.getLogger(gsHelper.class);
|
||||
// public static gsHelper instance = new gsHelper();
|
||||
//
|
||||
// private gsHelper() {
|
||||
// }
|
||||
//
|
||||
// public static boolean sendMessageToWord(int serverId,int uid, GeneratedMessage message)throws Exception{
|
||||
//
|
||||
// ClientAdapterPo<RPCwTgRequestIFace.Client> rPCClient = null;
|
||||
// String rpcString = RedisUtil.getInstence().getObject(RedisKey.LOGIC_SERVER_INFO, String.valueOf(serverId), String.class, -1);
|
||||
// if (null == rpcString) {
|
||||
// LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", serverId, uid);
|
||||
// return false;
|
||||
// }
|
||||
// String thriftIp = rpcString.split(":")[0];
|
||||
// String thriftPort = rpcString.split(":")[2];
|
||||
// if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
// return false;
|
||||
// }
|
||||
// String serviceKey = StringUtil.getServiceKey(ServiceKey.RPC_WORLD, thriftIp,thriftPort);
|
||||
// try {
|
||||
// rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||
// InnerResult innerResult = rPCClient.getClient().messageRequest(uid,getProtoIdBySimpleName(message.getClass().getSimpleName()) , ByteBuffer.wrap(message.toByteArray()));
|
||||
// processMessage( new RpcMessage(0,uid, innerResult.getProtpId(),ByteBuffer.wrap(innerResult.getMessage())));
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.info("callback=>",e);
|
||||
// return false;
|
||||
// }finally {
|
||||
// if (rPCClient != null){
|
||||
// rPCClient.returnObject(serviceKey);
|
||||
// }else{
|
||||
// LOGGER.info("callback=> rPCClient is null ");
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static <T extends GeneratedMessage> T sendMessageToGs(int serverId,int uid, GeneratedMessage message,Class<T> protoClazz)throws Exception{
|
||||
//
|
||||
//
|
||||
// String rpcString = RedisUtil.getInstence().getObject(RedisKey.LOGIC_SERVER_INFO, String.valueOf(serverId), String.class, -1);
|
||||
// if (null == rpcString) {
|
||||
// LOGGER.error("Exception send err rpcString dsid=>{},uid=>{},cmd=>{}", serverId, uid);
|
||||
// return null;
|
||||
// }
|
||||
// String thriftIp = rpcString.split(":")[0];
|
||||
// String thriftPort = rpcString.split(":")[2];
|
||||
// if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
// return null;
|
||||
// }
|
||||
// ClientAdapterPo<RPCwTgRequestIFace.Client> rPCClient = null;
|
||||
// String serviceKey = StringUtil.getServiceKey(ServiceKey.RPC_WORLD, thriftIp,thriftPort);
|
||||
// try {
|
||||
// rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||
// InnerResult innerResult = rPCClient.getClient().messageRequest(uid,getProtoIdBySimpleName(message.getClass().getSimpleName()) , ByteBuffer.wrap(message.toByteArray()));
|
||||
// return gtGBaseHandler.getProto(protoClazz,innerResult.getMessage());
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.info("callback=>",e);
|
||||
// return null;
|
||||
// }finally {
|
||||
// if (rPCClient != null){
|
||||
// rPCClient.returnObject(serviceKey);
|
||||
// }else{
|
||||
// LOGGER.info("callback=> rPCClient is null ");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static InnerResult processMessage(RpcMessage message) throws Exception {
|
||||
// gtGBaseHandler baseHandler = getHandlers().get(message.getProtpId());
|
||||
// if (baseHandler == null) {
|
||||
// //检查一下 没有定义handler
|
||||
// LOGGER.info("request unknow commond : " + message.getProtpId());
|
||||
// throw new Exception("request unknow commond");
|
||||
// } else {
|
||||
// baseHandler.execute(message);//client not return
|
||||
// return new InnerResult();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
package com.world.redis;
|
||||
|
||||
public class RedisKey {
|
||||
|
||||
public final static String Delimiter_colon = ":";
|
||||
|
||||
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
|
||||
/**
|
||||
* 服务器世界等级
|
||||
*/
|
||||
public static final String SERVER_WORLDLEVE_INFO = "SERVER_WORLDLEVE_INFO";
|
||||
|
||||
|
||||
/**
|
||||
* 服务器世界等级
|
||||
*/
|
||||
public static final String WORLD_RANK = "WORLD_RANK";
|
||||
|
||||
public static final String MATCHED_VERSION = "MATCHED_VERSION";
|
||||
|
||||
public static final String MATCHED_MY_VERSION = "MATCHED_MY_VERSION";
|
||||
public static final String SERVER_SPLIT_INFO = "SERVER_SPLIT_INFO";//分组信息
|
||||
|
||||
public static final String WORLD_ARENA_RANK = "WORLD_ARENA_RANK";//以map存
|
||||
|
||||
public static final String WORLD_ARENA_RANK_MY_MATH = "WORLD_ARENA_RANK_MY_MATH";//我匹配到的数据
|
||||
|
||||
public static final String WORLD_ARENA_RRECORD = "WORLD_ARENA_RRECORD";//竞技场记录
|
||||
|
||||
// public static final String DEATH_PATH_EVERY_PERSON_RANK = "DEATH_PATH_EVERY_PERSON_RANK";
|
||||
//package com.world.redis;
|
||||
//
|
||||
// public static final String DEATH_PATH_TOTAL_PERSON_RANK = "DEATH_PATH_TOTAL_PERSON_RANK";
|
||||
//public class RedisKey {
|
||||
//
|
||||
// public static final String DEATH_PATH_TOTAL_GUILD_RANK = "DEATH_PATH_TOTAL_GUILD_RANK";
|
||||
// public final static String Delimiter_colon = ":";
|
||||
//
|
||||
// public static final String DEATH_PATH_EVERY_GUILD_RANK = "DEATH_PATH_EVERY_GUILD_RANK";
|
||||
|
||||
public static final String PLAYER_INFO_CACHE = "PLAYER_INFO_CACHE";
|
||||
|
||||
public static final String GUILD_INFO_CACHE = "GUILD_INFO_CACHE";
|
||||
|
||||
public static final String WORLD_ARENA_MY_PRON = "WORLD_ARENA_MY_PRON";//我的膜拜记录
|
||||
|
||||
// public static final String DEATH_PATH_EVERY_OVER_HASH = "DEATH_PATH_EVERY_OVER_HASH";//结算标识
|
||||
|
||||
public static final String ARENA_PROUD_COUNT = "ARENA_PROUD_COUNT";
|
||||
public static final String ARENA_PROUD_COUNT_ROBOT = "ARENA_PROUD_COUNT_ROBOT";
|
||||
|
||||
}
|
||||
// public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
|
||||
// /**
|
||||
// * 服务器世界等级
|
||||
// */
|
||||
// public static final String SERVER_WORLDLEVE_INFO = "SERVER_WORLDLEVE_INFO";
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 服务器世界等级
|
||||
// */
|
||||
// public static final String WORLD_RANK = "WORLD_RANK";
|
||||
//
|
||||
// public static final String MATCHED_VERSION = "MATCHED_VERSION";
|
||||
//
|
||||
// public static final String MATCHED_MY_VERSION = "MATCHED_MY_VERSION";
|
||||
// public static final String SERVER_SPLIT_INFO = "SERVER_SPLIT_INFO";//分组信息
|
||||
//
|
||||
// public static final String WORLD_ARENA_RANK = "WORLD_ARENA_RANK";//以map存
|
||||
//
|
||||
// public static final String WORLD_ARENA_RANK_MY_MATH = "WORLD_ARENA_RANK_MY_MATH";//我匹配到的数据
|
||||
//
|
||||
// public static final String WORLD_ARENA_RRECORD = "WORLD_ARENA_RRECORD";//竞技场记录
|
||||
//
|
||||
//// public static final String DEATH_PATH_EVERY_PERSON_RANK = "DEATH_PATH_EVERY_PERSON_RANK";
|
||||
////
|
||||
//// public static final String DEATH_PATH_TOTAL_PERSON_RANK = "DEATH_PATH_TOTAL_PERSON_RANK";
|
||||
////
|
||||
//// public static final String DEATH_PATH_TOTAL_GUILD_RANK = "DEATH_PATH_TOTAL_GUILD_RANK";
|
||||
////
|
||||
//// public static final String DEATH_PATH_EVERY_GUILD_RANK = "DEATH_PATH_EVERY_GUILD_RANK";
|
||||
//
|
||||
// public static final String PLAYER_INFO_CACHE = "PLAYER_INFO_CACHE";
|
||||
//
|
||||
// public static final String GUILD_INFO_CACHE = "GUILD_INFO_CACHE";
|
||||
//
|
||||
// public static final String WORLD_ARENA_MY_PRON = "WORLD_ARENA_MY_PRON";//我的膜拜记录
|
||||
//
|
||||
//// public static final String DEATH_PATH_EVERY_OVER_HASH = "DEATH_PATH_EVERY_OVER_HASH";//结算标识
|
||||
//
|
||||
// public static final String ARENA_PROUD_COUNT = "ARENA_PROUD_COUNT";
|
||||
// public static final String ARENA_PROUD_COUNT_ROBOT = "ARENA_PROUD_COUNT_ROBOT";
|
||||
//
|
||||
//}
|
||||
|
|
|
@ -395,17 +395,17 @@
|
|||
// return false;
|
||||
// }
|
||||
// }
|
||||
//// public <K,T> Map<K,T> getMapValues(String type,String key,Class<K> keyClazz,Class<T> valueClazz){
|
||||
//// Map<K,T> result = new HashMap<>();
|
||||
//// String rkey = getKey(type, key);
|
||||
//// Map<Object, Object> entries = redisTemplate.opsForHash().entries(rkey);
|
||||
//// for(Map.Entry<Object,Object> item : entries.entrySet()){
|
||||
//// Object key1 = item.getKey();
|
||||
//// Object value = item.getValue();
|
||||
//// result.put(gson.fromJson(gson.toJson(key1),keyClazz),gson.fromJson(value.toString(),valueClazz));
|
||||
//// }
|
||||
//// return result;
|
||||
//// }
|
||||
// public <K,T> Map<K,T> getMapValues(String type,String key,Class<K> keyClazz,Class<T> valueClazz){
|
||||
// Map<K,T> result = new HashMap<>();
|
||||
// String rkey = getKey(type, key);
|
||||
// Map<Object, Object> entries = redisTemplate.opsForHash().entries(rkey);
|
||||
// for(Map.Entry<Object,Object> item : entries.entrySet()){
|
||||
// Object key1 = item.getKey();
|
||||
// Object value = item.getValue();
|
||||
// result.put(gson.fromJson(gson.toJson(key1),keyClazz),gson.fromJson(value.toString(),valueClazz));
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
// public <K,T> Map<K,T> getMapValues(String type,Class<K> keyClazz,Class<T> valueClazz){
|
||||
// Map<K,T> result = new HashMap<>();
|
||||
// Map<Object, Object> entries = redisTemplate.opsForHash().entries(type);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.world.thread;
|
||||
|
||||
import com.world.db.mongo.MongoUtil;
|
||||
import com.world.logic.arean.ArenaLogic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
Loading…
Reference in New Issue