diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ChallengeLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ChallengeLogic.java index ab57a4e48..eeb7009a3 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ChallengeLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/arena/ChallengeLogic.java @@ -26,6 +26,7 @@ import rpc.protocols.MessageTypeProto; import rpc.protocols.PlayerInfoProto; import util.TimeUtils; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -44,89 +45,55 @@ public class ChallengeLogic { return ChallengeLogic.Instance.instance; } - public static boolean limit(int level, int id) { - if (level < id) { - return false; - } - return true; - } - - public static Map dropMap(SChallengeStage sChallengeConfig, int model, int type, int win, long[] result,int bout,PlayerInfoProto.ChallengeResponse.Builder builder) { - /* - model //1为挑战 2为扫荡 - win // 1赢 0输 - 首次通关 给 保底 +总奖励 +通关奖励 - 扫荡 = 保底 +总奖励 - 没打过 保底+总奖励*奖励百分比 - */ + /** + * + * @param stage + * @param type + * @param win 1赢 2首通 + * @param bout + * @param builder + * model + * 首次通关 = 保底 +总奖励 +通关奖励 + * 扫荡 = 保底 +总奖励 + * 没打过 = 保底+总奖励*奖励百分比 + * @return + */ + public static Map dropMap(SChallengeStage stage,int type,int win,int bout,PlayerInfoProto.ChallengeResponse.Builder builder) { Map comDropMap = new HashMap<>(); + //保底奖励 - for (int[] fix : sChallengeConfig.getFixedReward()) { - if (comDropMap.containsKey(fix[0])) { - comDropMap.put(fix[0], comDropMap.get(fix[0]) + fix[1]); - } else { - comDropMap.put(fix[0], fix[1]); - } - LOGGER.info("baodi reward"); + for (int[] fix : stage.getFixedReward()) { + comDropMap.put(fix[0],comDropMap.getOrDefault(fix[1],0)+fix[1]); } - //总奖励 扫荡/挑战赢 - if (model == 2 || win == 1) { - //扫荡 - for (int[] fix : sChallengeConfig.getPassReward()) { - if (comDropMap.containsKey(fix[0])) { - comDropMap.put(fix[0], comDropMap.get(fix[0]) + fix[1]); - } else { - comDropMap.put(fix[0], fix[1]); - } + // 普通赢 + if (win >= 1){ + int ratio = 0; + int[][] value = stage.getReward1(); + if (type == 1){ + ratio = Arrays.stream(value).filter(v -> bout > v[0]).mapToInt(v -> v[1]).max().orElse(0); } - LOGGER.info("zong reward"); - builder.setPercentReward(10000); - } - - //首通奖励,挑战赢了 - if (model == 1 && win == 1) { - for (int[] fix : sChallengeConfig.getVictoryReward()) { - if (comDropMap.containsKey(fix[0])) { - comDropMap.put(fix[0], comDropMap.get(fix[0]) + fix[1]); - } else { - comDropMap.put(fix[0], fix[1]); - } + if (type == 2){ + ratio = Arrays.stream(value).filter(v -> bout < v[0]).mapToInt(v -> v[1]).min().orElse(0); } - //todo 2022-11-11 策划需求全部返回回合书 回合副本 - builder.setPercentReward(10000); builder.setLossBloodOrTimes(bout); - LOGGER.info("tongguan reward win times 回合数:"+bout); - } - //没打过 - if (model == 1 && win == 0) { - int[][] reward1 = sChallengeConfig.getReward1(); - double ratio = 0; - if (type == 1) {//回合数 - for (int[] percent : reward1) { - if (percent[0] > bout) { - break; - } - ratio = percent[1]; - LOGGER.info("输了 回合数 percent[0]:"+percent[0]); - } - builder.setLossBloodOrTimes(bout); - LOGGER.info("输了 回合数 times :=>{} id=>{}", bout,sChallengeConfig.getId()); - } - if (type == 2) { //血量 - ratio = 0; - builder.setLossBloodOrTimes(20); - LOGGER.info("输了2 回合数 times :=>{} id=>{}",20,sChallengeConfig.getId()); - } - LOGGER.info("challengeHandler ====>id:{},ratio:{}", sChallengeConfig.getId(), ratio); - for (int[] fix : sChallengeConfig.getPassReward()) { + // 加成百分比 + for (int[] fix : stage.getPassReward()) { Integer num = comDropMap.getOrDefault(fix[0], 0); - num = num + fix[1] + (int) (fix[1] * (ratio / 10000)); + num = num + (int)(fix[1] * (ratio+10000d)); comDropMap.put(fix[0], num); } - LOGGER.info("no pass reward percent"); - builder.setPercentReward((int)ratio); + builder.setPercentReward(ratio); + } + + // 首通 + if (win >= 2){ + for (int[] fix : stage.getVictoryReward()) { + comDropMap.put(fix[0],comDropMap.getOrDefault(fix[1],0)+fix[1]); + } + builder.setPercentReward(10000); + builder.setLossBloodOrTimes(bout); } return comDropMap; } @@ -177,98 +144,96 @@ public class ChallengeLogic { //1 为挑战 2 为扫荡 int model = proto.getModel(); int id = proto.getId(); - SChallengeStage sChallengeConfig = STableManager.getConfig(SChallengeStage.class).get(id); - if (sChallengeConfig == null) { + SChallengeStage stage = STableManager.getConfig(SChallengeStage.class).get(id); + if (stage == null) { throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); } int endlessNewReplicaLexel = user.getPlayerInfoManager().getEndlessNewReplica(); int treasureReplicaLexel = user.getPlayerInfoManager().getTreasureReplica(); //限制 - boolean consume = PlayerLogic.getInstance().checkAndUpdate(user, sChallengeConfig.getPivilegeID()[1], 1); + boolean consume = PlayerLogic.getInstance().checkAndUpdate(user, stage.getPivilegeID()[1], 1); if (!consume) { throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); } Map comDropMap = new HashMap<>(); //扫荡 if (model == 2) { - switch (type) { - case 1: // 回合 - if (!limit(endlessNewReplicaLexel, id)) { - MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); - return; - } - break; - case 2:// 血量 - if (!limit(treasureReplicaLexel, id)) { - MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); - return; - } - break; + int round = 0; + if (type == 1){ + if (endlessNewReplicaLexel < id){ + MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); + return; + } + round = 20; + } + if (type == 2){ + if (treasureReplicaLexel < id){ + MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); + return; + } + round = 1; } //扫荡 = 保底 +总奖励 - comDropMap = dropMap(sChallengeConfig, model, type, 1, null,0,builder); + comDropMap = dropMap(stage, type, 1,round,builder); CommonProto.Drop.Builder drop = ItemUtil.drop(user, comDropMap.entrySet().stream() .map(n -> new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN); builder.setDrop(drop); } + // 挑战 if (model == 1){ - GameFightType fightType = null; + GameFightType fightType = GameFightType.EndlessNewTeam; int teamId = 0; + if (type == 1) { - //回合 - fightType = GameFightType.EndlessNewTeam; + if (stage.getNextLevel() < endlessNewReplicaLexel) { + MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); + return; + } teamId = TeamEnum.CHALLENGE_ENDLESS_NEWTEAM.getTeamId(); - if (sChallengeConfig.getNextLevel() < endlessNewReplicaLexel) { - MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); - return; - } - } else if (type == 2) { - //伤害 - fightType = GameFightType.TreasureTeam; - teamId = TeamEnum.CHALLENGE_TREASURE_TEAM.getTeamId(); - if (sChallengeConfig.getNextLevel() < treasureReplicaLexel) { - MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); - return; - } } - PVEFightEvent pveFightEvent = new PVEFightEvent(user.getId(), teamId, 20, "", fightType, sChallengeConfig.getMonsterGroup(), 3); - FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent); - int time = fightResult.getCurRound(); - //首次通关 给 保底 +总奖励 +通关奖励 - if (fightResult.getResult() == 1) { - //赢了 - if (type == 1) { - user.getPlayerInfoManager().setEndlessNewReplica(id); - } - if (type == 2) { - user.getPlayerInfoManager().setTreasureReplica(id); - } - comDropMap = dropMap(sChallengeConfig, model, type, 1, fightResult.getCheckResult(),time,builder); - builder.setResult(1); - } else {// 输了 - // 回合 - if (type == 1){ - if(time >= 20){ - //无尽副本回合数超过20 赢 - user.getPlayerInfoManager().setEndlessNewReplica(id); - comDropMap = dropMap(sChallengeConfig, model, type, 1, fightResult.getCheckResult(),time,builder); - builder.setResult(1); - builder.setLossBloodOrTimes(20); - }else{ - //没打过 //输了 保底+总奖励*奖励百分比 - comDropMap = dropMap(sChallengeConfig, model, type, 0, fightResult.getCheckResult(),time,builder); - builder.setResult(0); - } - } - // 血量 - if(type == 2){ - //没打过-输了 保底+总奖励*奖励百分比 - comDropMap = dropMap(sChallengeConfig, model, type, 0, fightResult.getCheckResult(),time,builder); - builder.setResult(0); + if (type == 2) { + if (stage.getNextLevel() < treasureReplicaLexel) { + MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); + return; } + fightType = GameFightType.TreasureTeam; + teamId = TeamEnum.CHALLENGE_TREASURE_TEAM.getTeamId(); } + + PVEFightEvent pveFightEvent = new PVEFightEvent(user.getId(), teamId, 20, "", fightType, stage.getMonsterGroup(), 3); + FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent); + builder.setResult(fightResult.getResult()); + + int round = fightResult.getCurRound(); + int victoryValue = stage.getReward1()[stage.getReward1().length - 1][0]; + // 回合副本 + if (type == 1){ + int win = 1; + // 满足通关条件 + if (round >= victoryValue){ + user.getPlayerInfoManager().setEndlessNewReplica(id); + builder.setResult(1); + builder.setLossBloodOrTimes(20); + win = 2; + } + comDropMap = dropMap(stage, type, win, round, builder); + } + // 伤害副本 + if (type == 2){ + int win = 1; + // 满足首通条件 + if (fightResult.getResult() == 1 && round <= victoryValue){ + user.getPlayerInfoManager().setTreasureReplica(id); + win = 2; + }else { + // 失败 + round = 20; + } + comDropMap = dropMap(stage, type, win, round, builder); + } + CommonProto.FightData fightData = CommonProto.FightData.newBuilder() .setFightMaxTime(20) .setFightSeed(fightResult.getSeed()) @@ -278,11 +243,10 @@ public class ChallengeLogic { .setFightId(FightUtil.getFightId(user.getId(), fightType)) .build(); builder.setFightData(fightData); - CommonProto.Drop.Builder drop = ItemUtil.drop(user, comDropMap.entrySet().stream().map(n -> - new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN); + CommonProto.Drop.Builder drop = ItemUtil.drop(user, comDropMap.entrySet().stream() + .map(n -> new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN); builder.setDrop(drop); builder.setType(type); - LOGGER.info("type :"+type); } // 副本挑战任务