diff --git a/luafight/FightDataUtil.java b/luafight/FightDataUtil.java index 306782ee9..c5428ccef 100644 --- a/luafight/FightDataUtil.java +++ b/luafight/FightDataUtil.java @@ -150,8 +150,9 @@ public class FightDataUtil { for(int i=2;i newAreaCacChe = new HashSet<>();//进程排行 合区统一 public static Set rankCacChe = new HashSet<>(); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/gtw/GetWorldArenaInfoRequestHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/gtw/GetWorldArenaInfoRequestHandler.java index 739f8e9d7..6462a9de4 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/gtw/GetWorldArenaInfoRequestHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/gtw/GetWorldArenaInfoRequestHandler.java @@ -75,9 +75,9 @@ public class GetWorldArenaInfoRequestHandler extends BaseHandler> rankByKey = rank.getRankByKey(String.valueOf(crossGroup), 0, 20); //处理第一次在休战期开启 if(rankByKey.size()<1){ - builder.setStage(1); + builder.setStage(ArenaLogic.NORMAL_STATE); }else{ - builder.setStage(ArenaLogic.getInstance().getState()); + builder.setStage(ArenaLogic.getState()); } if (diff > setting.getRestTime()[0] && diff < setting.getRestTime()[1]) { diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapManager.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapManager.java index 0f253ba7f..ebb2b8314 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapManager.java @@ -5,8 +5,6 @@ import com.ljsd.common.mogodb.MongoBase; import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig; import com.ljsd.jieling.core.FunctionIdEnum; import com.ljsd.jieling.core.GlobalsDef; -import com.ljsd.jieling.db.mongo.MongoKey; -import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.globals.BIReason; import com.ljsd.jieling.globals.Global; import com.ljsd.jieling.handler.mission.Mission; @@ -18,8 +16,8 @@ import com.ljsd.jieling.logic.dao.PlayerManager; import com.ljsd.jieling.logic.dao.TimeControllerOfFunction; import com.ljsd.jieling.logic.dao.root.User; import com.ljsd.jieling.logic.player.PlayerLogic; -import util.MathUtils; import manager.STableManager; +import util.MathUtils; import util.TimeUtils; import java.util.*; @@ -315,7 +313,7 @@ public class MapManager extends MongoBase { int addValue = (updateTime - lastUpdateEnergyTime) / 60 / energyRecoverSpeed[1] * energyRecoverSpeed[0]; if (addValue != 0) { int curEnergy = MathUtils.setBetweenWithMax(itemNum + addValue, 0, playerInfoManager.getMaxStamina()); - item.setItemNum(curEnergy > playerInfoManager.getMaxStamina() ? playerInfoManager.getMaxStamina() : curEnergy); + item.setItemNum(Math.min(curEnergy, playerInfoManager.getMaxStamina())); KtEventUtils.onKtEvent(user, ParamEventBean.UserItemEvent, BIReason.TIME_REWARD,GlobalsDef.addReason,item.getItemId(),addValue,item.getItemNum()); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/GlobalDataManaager.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/GlobalDataManaager.java index 4ee222135..c6608eb5b 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/GlobalDataManaager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/GlobalDataManaager.java @@ -441,6 +441,8 @@ public class GlobalDataManaager implements IManager { RidingSwardLogic.getInstance().zeroClearRidingSwardByUser(user); // 公会援助 GuildLogic.getInstance().guildHelpDayHandler(user); + // 罗浮称号 + ArenaLogic.getInstance().takeTitleReward(user); WeekCardLogic.getInstance().weekCardInfoIndication(user,0,0); ChallengeLogic.getInstance().ChallengeInfoIndication(session); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ArenaLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ArenaLogic.java index 171e4440a..76d9198f0 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ArenaLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ArenaLogic.java @@ -53,8 +53,8 @@ import java.util.*; public class ArenaLogic { private static final Logger LOGGER = LoggerFactory.getLogger(ArenaLogic.class); - private ArenaLogic(){} - + private ArenaLogic() { + } public static class Instance { @@ -68,8 +68,11 @@ public class ArenaLogic { private int curSeason; private int viewSeason; + //未开启 public final static int NORMAL_STATE = 1; + //战斗 public final static int BATTLE_STATE = 2; + //发奖 public final static int RELAX_STATE = 3; public int getCurSeason() { @@ -82,20 +85,20 @@ public class ArenaLogic { public List getArenaEnemyList(List arenaEnemies) { List arenaEnemyList = new ArrayList<>(arenaEnemies.size()); - for(ArenaEnemy arenaEnemy : arenaEnemies){ + for (ArenaEnemy arenaEnemy : arenaEnemies) { int enemyId = arenaEnemy.getEnemyId(); int enemyType = arenaEnemy.getEnemyType(); try { - arenaEnemyList.add(getArenaEnemy(enemyId,enemyType)); - }catch (Exception e){ + arenaEnemyList.add(getArenaEnemy(enemyId, enemyType)); + } catch (Exception e) { e.printStackTrace(); } } return arenaEnemyList; } - public CommonProto.ArenaEnemy getArenaEnemy( int enemyId ,int enemyType) throws Exception { - if(enemyType == 0){ //机器人 + public CommonProto.ArenaEnemy getArenaEnemy(int enemyId, int enemyType) 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() @@ -109,19 +112,19 @@ public class ArenaLogic { .setPersonInfo(personInfoBuild) .setTeam(teamBuild) .build(); - }else{ + } else { User user = UserManager.getUser(enemyId); - int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, TeamEnum.TEAM_ARENA_DEFENSE.getTeamId(),false); + int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, TeamEnum.TEAM_ARENA_DEFENSE.getTeamId(), false); List teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(TeamEnum.TEAM_ARENA_DEFENSE.getTeamId()); Map heroMap = user.getHeroManager().getHeroMap(); List heroTids = new ArrayList<>(teamPosHeroInfoList.size()); - for(TeamPosHeroInfo teamPosHeroInfo:teamPosHeroInfoList){ + for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList) { heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId()); } CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build(); PlayerManager playerInfoManager = user.getPlayerInfoManager(); int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(enemyId)).intValue(); - if(score == -1){ + if (score == -1) { score = SArenaSetting.getSArenaSetting().getScore(); } CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() @@ -133,36 +136,36 @@ public class ArenaLogic { .setTotalForce(totalForce) .setPracticeLevel(user.getHeroManager().getPracticeLevel()) .build(); - return CommonProto.ArenaEnemy.newBuilder() + return CommonProto.ArenaEnemy.newBuilder() .setPersonInfo(personInfoBuild) .setTeam(teamBuild) .build(); } } - public CommonProto.ArenaEnemy getWorldArenaEnemy( int uid) throws Exception { - User user = UserManager.getUser(uid); - int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, TeamEnum.WORLD_TEAM_ARENA_DEFENSE.getTeamId(),false); - List teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(TeamEnum.WORLD_TEAM_ARENA_DEFENSE.getTeamId()); - Map heroMap = user.getHeroManager().getHeroMap(); - List heroTids = new ArrayList<>(teamPosHeroInfoList.size()); - for(TeamPosHeroInfo teamPosHeroInfo:teamPosHeroInfoList){ - heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId()); - } - CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build(); - PlayerManager playerInfoManager = user.getPlayerInfoManager(); - CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() - .setUid(uid) - .setLevel(playerInfoManager.getLevel()) - .setName(playerInfoManager.getNickName()) - .setHead(playerInfoManager.getHead()) - .setPracticeLevel(user.getHeroManager().getPracticeLevel()) - .setTotalForce(totalForce) - .build(); - return CommonProto.ArenaEnemy.newBuilder() - .setPersonInfo(personInfoBuild) - .setTeam(teamBuild) - .build(); + public CommonProto.ArenaEnemy getWorldArenaEnemy(int uid) throws Exception { + User user = UserManager.getUser(uid); + int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, TeamEnum.WORLD_TEAM_ARENA_DEFENSE.getTeamId(), false); + List teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(TeamEnum.WORLD_TEAM_ARENA_DEFENSE.getTeamId()); + Map heroMap = user.getHeroManager().getHeroMap(); + List heroTids = new ArrayList<>(teamPosHeroInfoList.size()); + for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList) { + heroTids.add(heroMap.get(teamPosHeroInfo.getHeroId()).getTemplateId()); + } + CommonProto.Team teamBuild = CommonProto.Team.newBuilder().addAllHeroTid(heroTids).build(); + PlayerManager playerInfoManager = user.getPlayerInfoManager(); + CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() + .setUid(uid) + .setLevel(playerInfoManager.getLevel()) + .setName(playerInfoManager.getNickName()) + .setHead(playerInfoManager.getHead()) + .setPracticeLevel(user.getHeroManager().getPracticeLevel()) + .setTotalForce(totalForce) + .build(); + return CommonProto.ArenaEnemy.newBuilder() + .setPersonInfo(personInfoBuild) + .setTeam(teamBuild) + .build(); } @@ -197,49 +200,47 @@ public class ArenaLogic { // } - public void setMyArenaEnemys(int uid,User user){ - int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(curSeason), Integer.toString(uid)).intValue(); - if(score == -1){ + public void setMyArenaEnemys(int uid, User user) { + int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(curSeason), Integer.toString(uid)).intValue(); + if (score == -1) { score = SArenaSetting.getSArenaSetting().getScore(); } ArenaManager arenaManager = user.getArenaManager(); - List arenaEnemies = new ArrayList<>(); - if(curSeason ==1 && arenaManager.getFlushNums() arenaEnemies = new ArrayList<>(); + if (curSeason == 1 && arenaManager.getFlushNums() < SArenaSetting.getSArenaSetting().getPveNum()) { Set robotIds = randomRobot(score, 5); - toArenaEnemy(uid,robotIds,arenaEnemies,GlobalsDef.ARENA_ROBOT_TYPE); - }else{ - Set robotIds = randomPerson(uid,score,true); + toArenaEnemy(uid, robotIds, arenaEnemies, GlobalsDef.ARENA_ROBOT_TYPE); + } else { + Set robotIds = randomPerson(uid, score, true); int type = GlobalsDef.ARENA_PLAYER_TYPE; - toArenaEnemy(uid,robotIds,arenaEnemies,type); - if(robotIds.isEmpty()){ - if(curSeason>1){ - robotIds = randomPerson(uid,score,false); + toArenaEnemy(uid, robotIds, arenaEnemies, type); + if (robotIds.isEmpty()) { + if (curSeason > 1) { + robotIds = randomPerson(uid, score, false); } - toArenaEnemy(uid,robotIds,arenaEnemies,type); + toArenaEnemy(uid, robotIds, arenaEnemies, type); } int size = robotIds.size(); - if(size<5){ - robotIds = randomRobot(score, 5-size); - type = GlobalsDef.ARENA_ROBOT_TYPE; - toArenaEnemy(uid,robotIds,arenaEnemies,type); + if (size < 5) { + robotIds = randomRobot(score, 5 - size); + type = GlobalsDef.ARENA_ROBOT_TYPE; + toArenaEnemy(uid, robotIds, arenaEnemies, type); } } arenaManager.setArenaEnemies(arenaEnemies); } - - - public static int getFightResultByPersonToPerson(User mine, int myteamId, User defUser, int defTeamId, ArenaRecord arenaRecord, ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception { - PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(),myteamId,SArenaSetting.getSArenaSetting().getMostTime(),"", GameFightType.ArenaPersonFight,defUser.getId(),defTeamId); + public static int getFightResultByPersonToPerson(User mine, int myteamId, User defUser, int defTeamId, ArenaRecord arenaRecord, ArenaInfoProto.ArenaChallengeResponse.Builder builder) throws Exception { + PVPFightEvent pvpFightEvent = new PVPFightEvent(mine.getId(), myteamId, SArenaSetting.getSArenaSetting().getMostTime(), "", GameFightType.ArenaPersonFight, defUser.getId(), defTeamId); int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, TeamEnum.TEAM_ARENA_DEFENSE.getTeamId(), false); int defForce = HeroLogic.getInstance().calTeamTotalForce(defUser, TeamEnum.TEAM_ARENA_DEFENSE.getTeamId(), false); arenaRecord.setAttackForce(myforce); - if(myforce randomRobot(int userSscore,int nums){ + public static Set randomRobot(int userSscore, int nums) { Set robotIds = new HashSet<>(5); Map config = STableManager.getConfig(SArenaRobotSetting.class); - for(SArenaRobotSetting sArenaRobotSetting : config.values()){ + for (SArenaRobotSetting sArenaRobotSetting : config.values()) { int playerLevelMin = sArenaRobotSetting.getPlayerScoreMin(); int playerLevelMax = sArenaRobotSetting.getPlayerScoreMax(); - if(userSscore>=playerLevelMin && userSscore<=playerLevelMax){ + if (userSscore >= playerLevelMin && userSscore <= playerLevelMax) { int poolId = sArenaRobotSetting.getPool(); List sArenaRobotConfigsByPool = SArenaRobotConfig.getSArenaRobotConfigsByPool(poolId); int size = sArenaRobotConfigsByPool.size(); - while (robotIds.size() < nums){ + while (robotIds.size() < nums) { robotIds.add(sArenaRobotConfigsByPool.get(MathUtils.randomInt(size)).getId()); } } @@ -364,22 +364,22 @@ public class ArenaLogic { return robotIds; } - public Set randomPerson(int uid,int myScore,boolean useCurSeason){ + public Set randomPerson(int uid, int myScore, boolean useCurSeason) { Set result = new HashSet<>(5); int[][] interval = SArenaSetting.getSArenaSetting().getInterval(); int matchSeason = curSeason; - if(!useCurSeason){ + if (!useCurSeason) { matchSeason = curSeason - 1; } - for(int[] item: interval){ + for (int[] item : interval) { int low = item[0]; int high = item[1]; - Set arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK,Integer.toString(matchSeason), myScore * low / 10000.0f-1, myScore * high / 10000.0f +1); - LOGGER.info("curSeason={},matchSeason={},the uid={},the myscore={},the low={},the high={},mylow={},myhigh={},",curSeason,matchSeason,uid,myScore,low,high,myScore * low / 10000.0f-1,myScore * high / 10000.0f +1); - if(arenaRank!=null && !arenaRank.isEmpty()){ + Set arenaRank = RedisUtil.getInstence().getZsetRange(RedisKey.ARENA_RANK, Integer.toString(matchSeason), myScore * low / 10000.0f - 1, myScore * high / 10000.0f + 1); + LOGGER.info("curSeason={},matchSeason={},the uid={},the myscore={},the low={},the high={},mylow={},myhigh={},", curSeason, matchSeason, uid, myScore, low, high, myScore * low / 10000.0f - 1, myScore * high / 10000.0f + 1); + if (arenaRank != null && !arenaRank.isEmpty()) { arenaRank.remove(Integer.toString(uid)); String s = randomSet(arenaRank); - if(!StringUtil.isEmpty(s)){ + if (!StringUtil.isEmpty(s)) { result.add(Integer.parseInt(s)); } } @@ -387,31 +387,31 @@ public class ArenaLogic { return result; } - private String randomSet(Set infos){ - if(infos == null || infos.isEmpty()){ + private String randomSet(Set infos) { + if (infos == null || infos.isEmpty()) { return null; } int num = MathUtils.randomInt(infos.size()); - for(String id : infos){ - if(num-- == 0){ - return id; + for (String id : infos) { + if (num-- == 0) { + return id; } } return null; } - public void toArenaEnemy(int uid,Set enemyList,List arenaEnemies,int type){ - for(Integer enemyId: enemyList){ - if(1 == type && enemyId == uid){ + public void toArenaEnemy(int uid, Set enemyList, List arenaEnemies, int type) { + for (Integer enemyId : enemyList) { + if (1 == type && enemyId == uid) { continue; } - arenaEnemies.add(new ArenaEnemy(enemyId,type,type)); + arenaEnemies.add(new ArenaEnemy(enemyId, type, type)); } } - public void getWorldRankByPage(ISession session,int page) throws Exception { + public void getWorldRankByPage(ISession session, int page) throws Exception { if (page == 0) { page = 1; } @@ -419,18 +419,18 @@ public class ArenaLogic { List arenaRankMemberInfo = new ArrayList<>(20); int rankEndLine = SSpecialConfig.getIntegerValue(SSpecialConfig.ARENA_RANKINGSHOWNUM); - if(end> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK, Integer.toString(viewSeason), start, end); for (ZSetOperations.TypedTuple item : arenaRankInfo) { String value = item.getValue(); int score = item.getScore().intValue(); int uid = Integer.parseInt(value); - User user = UserManager.getUser(uid,true); + User user = UserManager.getUser(uid, true); if (null == user) { continue; } int totalForce = HeroLogic.getInstance().calTeamTotalForce(user, TeamEnum.TEAM_ARENA_DEFENSE.getTeamId(), false); - LOGGER.info("获取世界排行榜信息===========玩家id:{}",uid); + LOGGER.info("获取世界排行榜信息===========玩家id:{}", uid); List teamPosHeroInfoList = user.getTeamPosManager().getTeamPosForHero().get(TeamEnum.TEAM_ARENA_DEFENSE.getTeamId()); Map heroMap = user.getHeroManager().getHeroMap(); List heroTids = new ArrayList<>(teamPosHeroInfoList.size()); @@ -461,12 +461,12 @@ public class ArenaLogic { } } int uid = session.getUid(); - int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK,Integer.toString(viewSeason), Integer.toString(uid)).intValue(); - int myRank =-1; - if(score == -1){ + int score = RedisUtil.getInstence().getZSetScore(RedisKey.ARENA_RANK, Integer.toString(viewSeason), Integer.toString(uid)).intValue(); + int myRank = -1; + if (score == -1) { score = SArenaSetting.getSArenaSetting().getScore(); - }else{ - myRank= RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK,Integer.toString(viewSeason),Integer.toString(uid)).intValue(); + } else { + myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.ARENA_RANK, Integer.toString(viewSeason), Integer.toString(uid)).intValue(); } ArenaInfoProto.GetArenaRankInfoResponse buildResponse = ArenaInfoProto.GetArenaRankInfoResponse.newBuilder() @@ -474,29 +474,27 @@ public class ArenaLogic { .setMyRank(myRank) .setMyscore(score) .build(); - MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.ARENA_RANK_RESPONSE_VALUE,buildResponse,true); + MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.ARENA_RANK_RESPONSE_VALUE, buildResponse, true); } /** - * - Sa: 实际胜负值, 胜 = 1 负=0 - - Ra: A选手比赛前的分 Rb: B选手比赛前的分数 - R'a: A选手比赛完的分数 R'b: B选手比赛完的分数 - - Ea:EA = 1/(1+10^[(Rb-Ra)/400]) - Eb: EB = 1/(1+10^[(Ra-Rb)/400]) - R'a = Ra + K(Sa-Ea) - R'b = Rb + K(Sb-Eb) - * + * Sa: 实际胜负值, 胜 = 1 负=0 + *

+ * Ra: A选手比赛前的分 Rb: B选手比赛前的分数 + * R'a: A选手比赛完的分数 R'b: B选手比赛完的分数 + *

+ * Ea:EA = 1/(1+10^[(Rb-Ra)/400]) + * Eb: EB = 1/(1+10^[(Ra-Rb)/400]) + * R'a = Ra + K(Sa-Ea) + * R'b = Rb + K(Sb-Eb) */ - public int calScore(int myScore,int defScore,int result){ + public int calScore(int myScore, int defScore, int result) { SArenaSetting sArenaSetting = SArenaSetting.getSArenaSetting(); int k = sArenaSetting.getK(); - double ea = 1.0/(1 + Math.pow(10,(defScore - myScore)/400.0f)); - int parm = result == 1?1:-1; - return (int)(k*(result-ea) + 0.5*parm); + double ea = 1.0 / (1 + Math.pow(10, (defScore - myScore) / 400.0f)); + int parm = result == 1 ? 1 : -1; + return (int) (k * (result - ea) + 0.5 * parm); } /** @@ -505,43 +503,43 @@ public class ArenaLogic { * 2:竞技场冠军纪录 * 3:boss记录 * 4:四灵试炼战斗记录,【fightId格式为:类型#层数#类别(0:首次,1:最低)】 - * 例子:人塔1层首通:1#1#0,佛塔1层最低:2#1#1 + * 例子:人塔1层首通:1#1#0,佛塔1层最低:2#1#1 */ - public void getFightReplayData(ISession iSession,int type,String fightId) throws Exception { + public void getFightReplayData(ISession iSession, int type, String fightId) throws Exception { int uid = iSession.getUid(); ArenaRecord arenaRecord = null; - if(type == 2){ - arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_ARENA_RECORD,"", fightId, ArenaRecord.class); - }else if(type == 1){ + if (type == 2) { + arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.CHAMPION_ARENA_RECORD, "", fightId, ArenaRecord.class); + } else if (type == 1) { // 竞技场 arenaRecord = RedisUtil.getInstence().getMapEntry(RedisKey.ARENA_RRECORD, Integer.toString(uid), fightId, ArenaRecord.class); - }else if(type == 3){ + } else if (type == 3) { arenaRecord = RedisUtil.getInstence().get(RedisKey.GUILDBOSS_ARENA_RECORD, fightId, ArenaRecord.class); - }else if (type == 4){ + } else if (type == 4) { // 四灵试炼 String[] split = fightId.split("#"); String key = null; // 首通 - if ("0".equals(split[2])){ + if ("0".equals(split[2])) { key = FourChallengeLogic.getKey(FourChallengeLogic.FIRST, Integer.parseInt(split[0]), Integer.parseInt(split[1])); } // 最低战力 - if ("1".equals(split[2])){ + if ("1".equals(split[2])) { key = FourChallengeLogic.getKey(FourChallengeLogic.MINI, Integer.parseInt(split[0]), Integer.parseInt(split[1])); } com.ljsd.jieling.logic.dao.root.ArenaRecord record = FourChallengeLogic.getInstance().getRecord(key); - if (record != null){ + if (record != null) { arenaRecord = new ArenaRecord(); arenaRecord.setFightData(record.getFightData()); } } - if(arenaRecord == null){ + if (arenaRecord == null) { throw new ErrorCodeException(ErrorCode.newDefineCode("arena_rrecord null")); } byte[] fightData = arenaRecord.getFightData(); CommonProto.FightData fightDataProto = CommonProto.FightData.parseFrom(fightData); FightInfoProto.FightRePlayResponse build = FightInfoProto.FightRePlayResponse.newBuilder().setFightData(fightDataProto).build(); - MessageUtil.sendMessage(iSession,1, MessageTypeProto.MessageType.VIEW_FIGHTREPLAY_RESPONSE_VALUE,build,true); + MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.VIEW_FIGHTREPLAY_RESPONSE_VALUE, build, true); } @@ -549,84 +547,84 @@ public class ArenaLogic { * 发送结算奖励 */ public void sendReward(int type) throws Exception { - if(curSeason == 0){ + if (curSeason == 0) { return; } long start = System.currentTimeMillis(); String title; String content; - if(type == GlobalsDef.ARENA_DAILY_REWARD){ + if (type == GlobalsDef.ARENA_DAILY_REWARD) { title = SErrorCodeEerverConfig.getI18NMessage("arena_daily_reward_title"); - }else{ + } else { title = SErrorCodeEerverConfig.getI18NMessage("arena_season_reward_title"); } - Set> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK,Integer.toString(curSeason), 0, -1); - if(type == GlobalsDef.ARENA_SEASON_REWARD){ - curSeason=0; + Set> arenaRankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.ARENA_RANK, Integer.toString(curSeason), 0, -1); + if (type == GlobalsDef.ARENA_SEASON_REWARD) { + curSeason = 0; } int rank = 1; int maxRank = getMaxRank(); - for(ZSetOperations.TypedTuple item : arenaRankInfo){ - if (rank > maxRank){ + for (ZSetOperations.TypedTuple item : arenaRankInfo) { + if (rank > maxRank) { break; } String value = item.getValue(); int uid = Integer.parseInt(value); CSPlayer csPlayer = CrossServiceLogic.getPlayerByRedis(uid); - if (csPlayer == null){ + if (csPlayer == null) { continue; } // 超7天未登录玩家,不再发奖励 long offLineTime = csPlayer.getOffLineTime(); - if (TimeUtils.now() > (offLineTime + TimeUtils.WEEK)){ + if (TimeUtils.now() > (offLineTime + TimeUtils.WEEK)) { String recordKey = RedisUtil.getInstence().getKey(RedisKey.ARENA_RRECORD, Integer.toString(uid)); RedisUtil.getInstence().del(recordKey); - LOGGER.error("竞技场发奖,玩家:{} ,排名:{},离线时间超过七天,剔除排行榜并且不再发奖,上次离线时间:{}",uid,rank,offLineTime); + LOGGER.error("竞技场发奖,玩家:{} ,排名:{},离线时间超过七天,剔除排行榜并且不再发奖,上次离线时间:{}", uid, rank, offLineTime); continue; } User user = UserManager.getUserNotCache(uid); - if (user == null){ + if (user == null) { continue; } - if(type == GlobalsDef.ARENA_DAILY_REWARD){ + if (type == GlobalsDef.ARENA_DAILY_REWARD) { MissionEventDistributor.requestStart(); - user.getUserMissionManager().onGameEvent(user,GameEvent.ARENA_UPDATE_RANK,rank); + user.getUserMissionManager().onGameEvent(user, GameEvent.ARENA_UPDATE_RANK, rank); ISession sessionByUid = OnlineUserManager.getSessionByUid(uid); - if(sessionByUid!=null){ - MissionEventDistributor.requestEnd(sessionByUid,true); + if (sessionByUid != null) { + MissionEventDistributor.requestEnd(sessionByUid, true); } } - if(type == GlobalsDef.ARENA_DAILY_REWARD){ - content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("arena_daily_reward_txt",new Object[]{rank},new int[0],"#"); - }else{ - content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("arena_season_reward_txt",new Object[]{rank},new int[0],"#"); + if (type == GlobalsDef.ARENA_DAILY_REWARD) { + content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("arena_daily_reward_txt", new Object[]{rank}, new int[0], "#"); + } else { + content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("arena_season_reward_txt", new Object[]{rank}, new int[0], "#"); user.getPlayerInfoManager().removeRed(GlobalsDef.ARENA_CHALLENGE_TYPE); String key = RedisUtil.getInstence().getKey(RedisKey.ARENA_RRECORD, Integer.toString(uid)); RedisUtil.getInstence().del(key); } - if(rank == 1 && type == GlobalsDef.ARENA_SEASON_REWARD){ - Poster.getPoster().dispatchEvent(new WelfareRedPackEvent(user.getId(), WelfareRedPacketType.arena_rank.getType(),1)); + if (rank == 1 && type == GlobalsDef.ARENA_SEASON_REWARD) { + Poster.getPoster().dispatchEvent(new WelfareRedPackEvent(user.getId(), WelfareRedPacketType.arena_rank.getType(), 1)); } String rewardByRank = getRewardByRank(rank++, type); - if(!"".equals(rewardByRank)){ - MailLogic.getInstance().sendMail(user.getId(),title,content,rewardByRank,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME); + if (!"".equals(rewardByRank)) { + MailLogic.getInstance().sendMail(user.getId(), title, content, rewardByRank, TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME); } } MongoUtil.getInstence().lastUpdate(); - LOGGER.info("发送竞技场每日发奖共耗时:{} ms, 当前时间:{}",System.currentTimeMillis()-start,TimeUtils.getTimeStamp2(TimeUtils.now())); + LOGGER.info("发送竞技场每日发奖共耗时:{} ms, 当前时间:{}", System.currentTimeMillis() - start, TimeUtils.getTimeStamp2(TimeUtils.now())); } - public String getRewardByRank(int rank,int type){ + public String getRewardByRank(int rank, int type) { Map config = STableManager.getConfig(SArenaReward.class); - for(SArenaReward sArenaReward : config.values()){ + for (SArenaReward sArenaReward : config.values()) { int minRank = sArenaReward.getMinRank(); int maxRank = sArenaReward.getMaxRank(); - if(rank>=minRank && rank<=maxRank){ - if(type == GlobalsDef.ARENA_DAILY_REWARD){ + if (rank >= minRank && rank <= maxRank) { + if (type == GlobalsDef.ARENA_DAILY_REWARD) { int[][] dailyReward = sArenaReward.getDailyReward(); return StringUtil.parseArrayToString(dailyReward); - }else{ + } else { int[][] seasonReward = sArenaReward.getSeasonReward(); return StringUtil.parseArrayToString(seasonReward); } @@ -635,76 +633,77 @@ public class ArenaLogic { return ""; } - public int getMaxRank(){ + public int getMaxRank() { Map config = STableManager.getConfig(SArenaReward.class); OptionalInt optionalInt = config.values().stream().mapToInt(SArenaReward::getMaxRank).max(); - if (optionalInt.isPresent()){ + if (optionalInt.isPresent()) { return optionalInt.getAsInt(); } return 0; } - public void updateArenaSeason(int curSeason){ + public void updateArenaSeason(int curSeason) { this.curSeason = curSeason; //初始化竞技场新周期数据 - if(curSeason>viewSeason){ - String oldRedisKey = RedisUtil.getInstence().getKey(RedisKey.ARENA_RANK,String.valueOf(viewSeason)); - String newRedisKey = RedisUtil.getInstence().getKey(RedisKey.ARENA_RANK,String.valueOf(curSeason)); - Set> set= RedisUtil.getInstence().getAllZsetRange(oldRedisKey); - for(ZSetOperations.TypedTuple item : set){ + if (curSeason > viewSeason) { + String oldRedisKey = RedisUtil.getInstence().getKey(RedisKey.ARENA_RANK, String.valueOf(viewSeason)); + String newRedisKey = RedisUtil.getInstence().getKey(RedisKey.ARENA_RANK, String.valueOf(curSeason)); + Set> set = RedisUtil.getInstence().getAllZsetRange(oldRedisKey); + for (ZSetOperations.TypedTuple item : set) { String id = item.getValue(); Double score = item.getScore(); double time = score - score.intValue(); - double newScore =(int)(score.intValue()*0.8)+ time; - RedisUtil.getInstence().zsetAddOne(newRedisKey,id,newScore); + double newScore = (int) (score.intValue() * 0.8) + time; + RedisUtil.getInstence().zsetAddOne(newRedisKey, id, newScore); } - } - if(this.curSeason!=0){ + } + if (this.curSeason != 0) { viewSeason = this.curSeason; } } //0为本服 1为跨服 - public void playWithSb(ISession session,int challengeUid,int myteamId,int cross) throws Exception { + public void playWithSb(ISession session, int challengeUid, int myteamId, int cross) throws Exception { User mine = UserManager.getUser(session.getUid()); int myforce = HeroLogic.getInstance().calTeamTotalForce(mine, myteamId, false); - CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(mine, myteamId,true); + CommonProto.FightTeamInfo fightTeamInfo = BehaviorUtil.getFightTeamInfo(mine, myteamId, true); User defUser = PlayerLogic.getInstance().getUserByRpc(challengeUid); - if (defUser == null){ + if (defUser == null) { throw new ErrorCodeException(ErrorCode.USE_NOT_EXIT); } - if(!defUser.getTeamPosManager().getTeamPosForHero().containsKey(1)){ + if (!defUser.getTeamPosManager().getTeamPosForHero().containsKey(1)) { throw new ErrorCodeException(ErrorCode.newDefineCode("对方未设置阵容")); } int deforce = HeroLogic.getInstance().calTeamTotalForce(defUser, myteamId, false); - CommonProto.FightTeamInfo deffightTeamInfo= BehaviorUtil.getFightTeamInfo(defUser,1,false); + CommonProto.FightTeamInfo deffightTeamInfo = BehaviorUtil.getFightTeamInfo(defUser, 1, false); - if(myforceInteger.valueOf(v.toString())) - .orElse(0); - } - - public void setState(int state) { - String key = RedisUtil.getInstence().getKey(RedisKey.CROSS_SERVICE_ARENA_STATE, ""); - RedisUtil.getInstence().set(key,String.valueOf(state)); - } - - private void b2r(){ - if(getState() != RELAX_STATE){ - if(getState() == BATTLE_STATE){ - Map sessionMap = OnlineUserManager.sessionMap; - for(Map.Entry entry:sessionMap.entrySet()){ - MessageUtil.sendIndicationMessage(entry.getValue(),1,MessageTypeProto.MessageType.GetWorldArenaInfoIndication_VALUE,null,true); - } - LOGGER.info("罗浮争锋,发奖"); - int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup(); - if(crossGroup==-1){ - return; - } - AbstractRank rank = RankContext.getRankEnum(RankEnum.CROSS_SERVICE_ARENA.getType()); - String title = SErrorCodeEerverConfig.getI18NMessage("mserverarena_reward_title"); - TreeMap rewardMapByRank = SMServerArenaReward.rewardMapByRank; - - Set> rankInfo= rank.getRankByKey(String.valueOf(crossGroup), 0, -1); - int index = 0; - for (ZSetOperations.TypedTuple stringTypedTuple : rankInfo) { - int uid = Integer.parseInt(stringTypedTuple.getValue()); - CSPlayer player = CrossServiceLogic.getPlayerByRedis(uid); - index++; - if (player == null || TimeUtils.now() > (player.getOffLineTime()+TimeUtils.WEEK)){ - LOGGER.error("罗浮争锋发奖,玩家未登陆时间超过七天,不予发奖,uid:{},rank:{}",uid,index); - continue; - } - if (uid < 1000) { - continue; - } - try { - User user = UserManager.getUserNotCache(uid); - if (user == null) { - continue; - } - Map.Entry entry = rewardMapByRank.floorEntry(index); - SMServerArenaReward value = entry.getValue(); - int[][] titleReward = value.getTitleReward(); - if (titleReward != null) { - for (int[] reward : titleReward) { - long time = TimeUtils.getBeginOfDay(TimeUtils.now() + reward[1] * 1000L) + TimeUtils.DAY; - user.getPlayerInfoManager().putUserTitleValidTime(reward[0], time); - PlayerInfoProto.UserTitleAddIndication.Builder builder = PlayerInfoProto.UserTitleAddIndication.newBuilder().setDecorationId(reward[0]).setTime((int) (time / 1000)); - MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(user.getId()), 1, MessageTypeProto.MessageType.USER_TITLE_ADD_INDICATION_VALUE, builder.build(), true); - } - } - - String content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("mserverarena_reward_content", new Object[]{index}, new int[]{0}, "#"); - MailLogic.getInstance().sendMail(uid, title, content, StringUtil.parseArrayToString(value.getSeasonReward()), TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME); - } catch (Exception e) { - e.printStackTrace(); - } - } - try { - MongoUtil.getLjsdMongoTemplate().lastUpdate(); - } catch (Exception e) { - e.printStackTrace(); - } - } - LOGGER.info("罗浮争霸:转到休息状态,nowstate:{} to RELAX_STATE",getState()); - getInstance().setState(RELAX_STATE); - } - } - - public void r2e(){ - if(getState() != NORMAL_STATE){ - LOGGER.info("罗浮争霸:转到未开始状态,nowstate:{} to NORMAL_STATE",getState()); - getInstance().setState(NORMAL_STATE); - } - } - - public void e2b(){ - if(getState() != BATTLE_STATE){ - LOGGER.info("罗浮争霸:转到战斗状态,nowstate:{} to BATTLE_STATE",getState()); - getInstance().setState(BATTLE_STATE); - initRank(); - Map sessionMap = OnlineUserManager.sessionMap; - for(Map.Entry entry:sessionMap.entrySet()){ - MessageUtil.sendIndicationMessage(entry.getValue(),1,MessageTypeProto.MessageType.GetWorldArenaInfoIndication_VALUE,null,true); - } - } - } - - private void checkState(){ + public void checkState() { TimeControllerOfFunction timeControllerOfFunction = GlobalDataManaager.getInstance().getTimeControllerOfFunctionByFunctinoType(FunctionIdEnum.World_Arena); - if(null == timeControllerOfFunction){ + if (null == timeControllerOfFunction) { return; } - long diff = (System.currentTimeMillis() - timeControllerOfFunction.getStartTime())/1000; + int now = TimeUtils.nowInt(); + int startTime = (int) (timeControllerOfFunction.getStartTime() / 1000); SMServerArenaSetting setting = STableManager.getConfig(SMServerArenaSetting.class).get(1); + int diff = now - startTime; if (diff >= setting.getBattleTime()[0] && diff <= setting.getBattleTime()[1]) { e2b(); - }else if (diff > setting.getBattleTime()[1] && diff <= setting.getRestTime()[1]) { + } else if (diff > setting.getBattleTime()[1] && diff <= setting.getRestTime()[1]) { b2r(); } else if (diff > setting.getRestTime()[1]) { r2e(); } } + public static int getState() { + String key = RedisUtil.getInstence().getKey2(RedisKey.CROSS_SERVICE_ARENA_STATE, String.valueOf(GlobleSystemLogic.crossGroup)); + Object value = RedisUtil.getInstence().get(key); + int state = 1; + if (value == null){ + // 兼容老状态 + key = RedisUtil.getInstence().getKey(RedisKey.CROSS_SERVICE_ARENA_STATE, ""); + value = RedisUtil.getInstence().get(key); + if (value != null){ + setState(state); + state = (int) value; + } + }else { + state = (int) value; + } + return state; + } + + public static void setState(int state) { + String key = RedisUtil.getInstence().getKey2(RedisKey.CROSS_SERVICE_ARENA_STATE, String.valueOf(GlobleSystemLogic.crossGroup)); + RedisUtil.getInstence().set(key, String.valueOf(state)); + } + + public void LuoFuSendReward() { + LOGGER.info("罗浮争霸,开始发奖"); + Map sessionMap = OnlineUserManager.sessionMap; + for (Map.Entry entry : sessionMap.entrySet()) { + MessageUtil.sendIndicationMessage(entry.getValue(), 1, MessageTypeProto.MessageType.GetWorldArenaInfoIndication_VALUE, null, true); + } + int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup(); + if (crossGroup == -1) { + return; + } + boolean lock = RedisUtil.getInstence().lock("WORLD_ARENA_SEND_REWARD_RANK:" + crossGroup, TimeUtils.ONE_MINUTE * 5); + if (!lock) { + return; + } + AbstractRank rank = RankContext.getRankEnum(RankEnum.CROSS_SERVICE_ARENA.getType()); + String title = SErrorCodeEerverConfig.getI18NMessage("mserverarena_reward_title"); + TreeMap rewardMapByRank = SMServerArenaReward.rewardMapByRank; + + Set> rankInfo = rank.getRankByKey(String.valueOf(crossGroup), 0, -1); + int index = 0; + for (ZSetOperations.TypedTuple stringTypedTuple : rankInfo) { + index++; + int uid = Integer.parseInt(stringTypedTuple.getValue()); + if (uid < 1000) { + continue; + } + CSPlayer player = CrossServiceLogic.getPlayerByRedis(uid); + if (player == null || TimeUtils.now() > (player.getOffLineTime() + TimeUtils.WEEK)) { + LOGGER.error("罗浮争锋发奖,玩家未登陆时间超过七天,不予发奖,uid:{},rank:{}", uid, index); + continue; + } + Map.Entry entry = rewardMapByRank.floorEntry(index); + SMServerArenaReward value = entry.getValue(); + // 称号奖励 + int[][] titleReward = value.getTitleReward(); + if (titleReward != null) { + sendTitleReward(uid,titleReward); + } + // 基础奖励邮件 + String content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("mserverarena_reward_content", new Object[]{index}, new int[]{0}, "#"); + MailLogic.getInstance().sendMail(uid, title, content, StringUtil.parseArrayToString(value.getSeasonReward()), TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME); + } + try { + MongoUtil.getLjsdMongoTemplate().lastUpdate(); + } catch (Exception e) { + e.printStackTrace(); + } + LOGGER.info("罗浮争霸:转到休息状态,nowstate:{} to RELAX_STATE", getState()); + } + + /** + * 发送标题奖励 + * @param uid + * @param titleReward + */ + public void sendTitleReward(int uid, int[][] titleReward){ + RedisUtil redisUtil = RedisUtil.getInstence(); + String key = redisUtil.getKey2(RedisKey.LUOFU_TITLE_REWARD_MARK, String.valueOf(uid)); + for (int[] reward : titleReward) { + long time = TimeUtils.getBeginOfDay(TimeUtils.now() + reward[1] * 1000L) + TimeUtils.DAY; + redisUtil.putMapEntry2(key,String.valueOf(reward[0]),time); + } + redisUtil.expire(key,TimeUtils.WEEK/1000); + } + + /** + * 领取标题奖励 + * @param user + */ + public void takeTitleReward(User user){ + RedisUtil redisUtil = RedisUtil.getInstence(); + String key = redisUtil.getKey2(RedisKey.LUOFU_TITLE_REWARD_MARK, String.valueOf(user.getId())); + Map titleMap = redisUtil.getMapValues(key, String.class, Long.class); + for (Map.Entry entry : titleMap.entrySet()) { + int titleId = Integer.parseInt(entry.getKey()); + Long time = entry.getValue(); + user.getPlayerInfoManager().putUserTitleValidTime(titleId, time); + PlayerInfoProto.UserTitleAddIndication.Builder builder = PlayerInfoProto.UserTitleAddIndication.newBuilder().setDecorationId(titleId).setTime((int) (time / 1000)); + MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(user.getId()), 1, MessageTypeProto.MessageType.USER_TITLE_ADD_INDICATION_VALUE, builder.build(), true); + } + redisUtil.del(key); + } + + private void b2r() { + if (getState() == BATTLE_STATE) { + if (getState() != RELAX_STATE) { + LuoFuSendReward(); + } + LOGGER.info("罗浮争霸:转到休息状态,now state:{} to RELAX_STATE", getState()); + setState(RELAX_STATE); + } + } + + public void r2e() { + if (getState() != NORMAL_STATE) { + LOGGER.info("罗浮争霸:转到未开始状态,now state:{} to NORMAL_STATE", getState()); + setState(NORMAL_STATE); + } + } + + public void e2b() { + if (getState() != BATTLE_STATE) { + LOGGER.info("罗浮争霸:转到战斗状态,now state:{} to BATTLE_STATE", getState()); + setState(BATTLE_STATE); + initRank(); + Map sessionMap = OnlineUserManager.sessionMap; + for (Map.Entry entry : sessionMap.entrySet()) { + MessageUtil.sendIndicationMessage(entry.getValue(), 1, MessageTypeProto.MessageType.GetWorldArenaInfoIndication_VALUE, null, true); + } + } + } + static List randomCrossRobot(int start, int end, int nums) { List robotIds = new LinkedList<>(); int index = 0; @@ -852,32 +892,34 @@ public class ArenaLogic { } //初始化机器人信息 - private void initRank(){ + private void initRank() { int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup(); - if(crossGroup==-1){ + if (crossGroup == -1) { return; } //分布式锁,保证一个组只有一个服进行初始化 boolean lock = RedisUtil.getInstence().lock("WORLD_ARENA_INIT_RANK:" + crossGroup, TimeUtils.ONE_MINUTE * 5); - if(!lock){ + if (!lock) { return; } LOGGER.info("跨服信息初始化..."); - RedisUtil.getInstence().expire("WORLD_ARENA_INIT_RANK:" + crossGroup,TimeUtils.ONE_MINUTE * 5); + RedisUtil.getInstence().expire("WORLD_ARENA_INIT_RANK:" + crossGroup, TimeUtils.ONE_MINUTE * 5); String key1 = RedisUtil.getInstence().getKey(RedisKey.CROSS_ARENA_ROBOT_INFO, String.valueOf(crossGroup)); String key2 = RedisUtil.getInstence().getKey(RedisKey.CROSS_SERVICE_ARENA, String.valueOf(crossGroup)); - RedisUtil.getInstence().del(key1,key2); + RedisUtil.getInstence().del(key1, key2); AbstractRank rank = RankContext.getRankEnum(RankEnum.CROSS_SERVICE_ARENA.getType()); int robotIndex = 1000; Random random = new Random(); - Map robotInfo = new HashMap<>(1000); + Map robotInfo = new HashMap<>(1000); Map groupValues = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO, "", Integer.class, Integer.class); List groupList = new ArrayList<>(8); - groupValues.forEach((k,v)->{ - if(v==crossGroup){ groupList.add(k);} + groupValues.forEach((k, v) -> { + if (v == crossGroup) { + groupList.add(k); + } }); int[] fightArea = STableManager.getConfig(SMServerArenaSetting.class).get(1).getFightArea(); @@ -885,57 +927,57 @@ public class ArenaLogic { int robotNum = setting.getRobotNum(); List robotIds = randomCrossRobot(fightArea[0], fightArea[1], robotNum); - while(--robotIndex>0){ + while (--robotIndex > 0) { int server = random.nextInt(groupList.size()); - rank.addRank(robotIndex,String.valueOf(crossGroup),robotNum-robotIndex); + rank.addRank(robotIndex, String.valueOf(crossGroup), robotNum - robotIndex); SArenaRobotConfig config = SArenaRobotConfig.getsArenaRobotConfigById(robotIds.get(robotIndex)); - robotInfo.put(String.valueOf(robotIndex),new CrossArenaEnemy(robotIds.get(robotIndex),robotIndex,groupList.get(server),0,0,random.nextBoolean(),PlayerLogic.getInstance().getRandomName2WithOutVerify(),config.getTotalForce(),config.getRobotLevel())); + robotInfo.put(String.valueOf(robotIndex), new CrossArenaEnemy(robotIds.get(robotIndex), robotIndex, groupList.get(server), 0, 0, random.nextBoolean(), PlayerLogic.getInstance().getRandomName2WithOutVerify(), config.getTotalForce(), config.getRobotLevel())); } LOGGER.info("跨服信息初始化结束"); - RedisUtil.getInstence().putMapEntrys(RedisKey.CROSS_ARENA_ROBOT_INFO,String.valueOf(crossGroup),robotInfo); + RedisUtil.getInstence().putMapEntrys(RedisKey.CROSS_ARENA_ROBOT_INFO, String.valueOf(crossGroup), robotInfo); } //获取跨服信息 - public List getCrossArenaEnemyList(int uid,Set rankInfo,int groupId){ + public List getCrossArenaEnemyList(int uid, Set rankInfo, int groupId) { List arenaEnemyList = new ArrayList<>(); List list = RedisUtil.getInstence().lGet(RedisKey.WORLD_ARENA_MY_PRON, String.valueOf(uid), 0, -1); AbstractRank rank = RankContext.getRankEnum(RankEnum.CROSS_SERVICE_ARENA.getType()); - rankInfo.forEach(rankIndex->{ - Set> rankByKey = rank.getRankByKey(String.valueOf(groupId),rankIndex-1,rankIndex-1); - if(!rankByKey.iterator().hasNext()){ + rankInfo.forEach(rankIndex -> { + Set> rankByKey = rank.getRankByKey(String.valueOf(groupId), rankIndex - 1, rankIndex - 1); + if (!rankByKey.iterator().hasNext()) { return; } ZSetOperations.TypedTuple next = rankByKey.iterator().next(); - if(Integer.parseInt(next.getValue())<1000){ - CommonProto.ArenaEnemy.Builder robotCrossArenaEnemy = getRobotCrossArenaEnemy(groupId,rankIndex,Integer.parseInt(next.getValue())); - if(list!=null&&list.size()>0){ + if (Integer.parseInt(next.getValue()) < 1000) { + CommonProto.ArenaEnemy.Builder robotCrossArenaEnemy = getRobotCrossArenaEnemy(groupId, rankIndex, Integer.parseInt(next.getValue())); + if (list != null && list.size() > 0) { robotCrossArenaEnemy.setHadProud(list.contains(String.valueOf(rankIndex))); } arenaEnemyList.add(robotCrossArenaEnemy.build()); - }else{ - arenaEnemyList.add(getUserCrossArenaEnemy(rankIndex,Integer.parseInt(next.getValue()),list.contains(next.getValue()))); + } else { + arenaEnemyList.add(getUserCrossArenaEnemy(rankIndex, Integer.parseInt(next.getValue()), list.contains(next.getValue()))); } }); return arenaEnemyList; } //获取单个玩家信息(玩家) - public CommonProto.ArenaEnemy getUserCrossArenaEnemy(int rank,int id,boolean hadProud) { + public CommonProto.ArenaEnemy getUserCrossArenaEnemy(int rank, int id, boolean hadProud) { CSPlayer csPlayer = CrossServiceLogic.getPlayerByRedis(id); - if (csPlayer == null){ + if (csPlayer == null) { return CommonProto.ArenaEnemy.newBuilder().build(); } - return getUserCrossArenaEnemy(csPlayer,rank,hadProud).build(); + return getUserCrossArenaEnemy(csPlayer, rank, hadProud).build(); } //获取单个信息(机器人) - public CommonProto.ArenaEnemy.Builder getRobotCrossArenaEnemy(int groupId,int rank,int id){ + public CommonProto.ArenaEnemy.Builder getRobotCrossArenaEnemy(int groupId, int rank, int id) { CrossArenaEnemy info = RedisUtil.getInstence().getMapEntry(RedisKey.CROSS_ARENA_ROBOT_INFO, String.valueOf(groupId), String.valueOf(id), CrossArenaEnemy.class); - if(info==null){ + if (info == null) { return null; } - return getRobotCrossArenaEnemy(rank,info); + return getRobotCrossArenaEnemy(rank, info); } /** @@ -948,10 +990,10 @@ public class ArenaLogic { TreeSet 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]) ; + 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); @@ -962,9 +1004,9 @@ public class ArenaLogic { /** * 随机匹配 */ - public static List randomRank(int uid, int myRank,int crossGroup) { + public static List randomRank(int uid, int myRank, int crossGroup) { //缓存每次匹配结果 - TreeSet matchRank = getMatchID(myRank==9999?1000:myRank); + TreeSet matchRank = getMatchID(myRank == 9999 ? 1000 : myRank); // AbstractRank rankEnum = RankContext.getRankEnum(RankEnum.CROSS_SERVICE_ARENA.getType()); // List ids = new ArrayList<>(4); // RedisUtil.getInstence().set(RedisKey.WORLD_ARENA_RANK_MY_MATH, String.valueOf(uid), matchRank); @@ -976,12 +1018,12 @@ public class ArenaLogic { // ids.add(Integer.parseInt(next.getValue())); // } // }); - return ArenaLogic.getInstance().getCrossArenaEnemyList(uid,matchRank,crossGroup); + return ArenaLogic.getInstance().getCrossArenaEnemyList(uid, matchRank, crossGroup); } - public CommonProto.ArenaEnemy.Builder getUserCrossArenaEnemy(CSPlayer csPlayer,int rank,boolean hadProud){ + public CommonProto.ArenaEnemy.Builder getUserCrossArenaEnemy(CSPlayer csPlayer, int rank, boolean hadProud) { Object get = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT, String.valueOf(csPlayer.getUserId())); - int proudTime = get==null?1:Integer.parseInt((String)get); + int proudTime = get == null ? 1 : Integer.parseInt((String) get); String serverName = CrossServiceLogic.simplifyServerName(csPlayer.getServerId()); CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() .setUid(csPlayer.getUserId()) @@ -998,11 +1040,11 @@ public class ArenaLogic { .build(); return CommonProto.ArenaEnemy.newBuilder() .setPersonInfo(personInfoBuild).setHadProud(hadProud).setWorshipTime(proudTime); - } + } - public CommonProto.ArenaEnemy.Builder getRobotCrossArenaEnemy(int rank,CrossArenaEnemy enemy){ + public CommonProto.ArenaEnemy.Builder getRobotCrossArenaEnemy(int rank, CrossArenaEnemy enemy) { Object get = RedisUtil.getInstence().hget(RedisKey.ARENA_PROUD_COUNT_ROBOT, String.valueOf(rank)); - int proudTime = get==null?1:Integer.parseInt((String)get); + int proudTime = get == null ? 1 : Integer.parseInt((String) get); int enemyId = enemy.getEnemyId(); SArenaRobotConfig sArenaRobotConfig = SArenaRobotConfig.getsArenaRobotConfigById(enemyId); @@ -1011,12 +1053,12 @@ public class ArenaLogic { CommonProto.ArenaPersonInfo personInfoBuild = CommonProto.ArenaPersonInfo.newBuilder() .setUid(enemy.getEnemyId_UUid()) .setLevel(sArenaRobotConfig.getRobotLevel()) - .setName(enemy.getRandomName()==null?"":enemy.getRandomName()) + .setName(enemy.getRandomName() == null ? "" : enemy.getRandomName()) .setScore(sArenaRobotConfig.getRobotScore()) .setTotalForce(sArenaRobotConfig.getTotalForce()) .setServername(serverName) .setUserSkin(80012) - .setGender(enemy.isGender()?1:0) + .setGender(enemy.isGender() ? 1 : 0) .setRank(rank) .build(); return CommonProto.ArenaEnemy.newBuilder() diff --git a/serverlogic/src/main/java/com/ljsd/jieling/thread/task/MinuteTask.java b/serverlogic/src/main/java/com/ljsd/jieling/thread/task/MinuteTask.java index 7ce782b62..98a786383 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/thread/task/MinuteTask.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/thread/task/MinuteTask.java @@ -172,7 +172,7 @@ public class MinuteTask extends Thread { } try { - ArenaLogic.getInstance().worldSendReward(); + ArenaLogic.getInstance().checkState(); }catch (Exception e){ e.printStackTrace(); LOGGER.error("Exception::=>{}",e.toString()); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java index b1d005b47..b60f9c5ed 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java @@ -84,14 +84,13 @@ public class CBean2Proto { if(itemNum == -1){ itemNum = item.getItemNum(); } - CommonProto.Item itemProto = CommonProto.Item + return CommonProto.Item .newBuilder() .setItemId(item.getItemId()) .setItemNum(itemNum) .setEndingTime(item.getEndingTime()) .setNextFlushTime(item.getEndingTime() + getRecoverSpeedByItem(item.getItemId())) .build(); - return itemProto; } /**