伤害副本逻辑优化

back_recharge
duhui 2022-11-14 15:50:52 +08:00
parent d331fd5410
commit 8d7e3dd4ed
1 changed files with 105 additions and 141 deletions

View File

@ -26,6 +26,7 @@ import rpc.protocols.MessageTypeProto;
import rpc.protocols.PlayerInfoProto; import rpc.protocols.PlayerInfoProto;
import util.TimeUtils; import util.TimeUtils;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -44,89 +45,55 @@ public class ChallengeLogic {
return ChallengeLogic.Instance.instance; return ChallengeLogic.Instance.instance;
} }
public static boolean limit(int level, int id) { /**
if (level < id) { *
return false; * @param stage
} * @param type
return true; * @param win 1 2
} * @param bout
* @param builder
public static Map<Integer, Integer> dropMap(SChallengeStage sChallengeConfig, int model, int type, int win, long[] result,int bout,PlayerInfoProto.ChallengeResponse.Builder builder) { * model
/* * = + +
model //1为挑战 2为扫荡 * = +
win // 1赢 0输 * = +*
+ + * @return
= +
+*
*/ */
public static Map<Integer, Integer> dropMap(SChallengeStage stage,int type,int win,int bout,PlayerInfoProto.ChallengeResponse.Builder builder) {
Map<Integer, Integer> comDropMap = new HashMap<>(); Map<Integer, Integer> comDropMap = new HashMap<>();
//保底奖励 //保底奖励
for (int[] fix : sChallengeConfig.getFixedReward()) { for (int[] fix : stage.getFixedReward()) {
if (comDropMap.containsKey(fix[0])) { comDropMap.put(fix[0],comDropMap.getOrDefault(fix[1],0)+fix[1]);
comDropMap.put(fix[0], comDropMap.get(fix[0]) + fix[1]);
} else {
comDropMap.put(fix[0], fix[1]);
}
LOGGER.info("baodi reward");
} }
//总奖励 扫荡/挑战赢 // 普通赢
if (model == 2 || win == 1) { if (win >= 1){
//扫荡 int ratio = 0;
for (int[] fix : sChallengeConfig.getPassReward()) { int[][] value = stage.getReward1();
if (comDropMap.containsKey(fix[0])) { if (type == 1){
comDropMap.put(fix[0], comDropMap.get(fix[0]) + fix[1]); ratio = Arrays.stream(value).filter(v -> bout > v[0]).mapToInt(v -> v[1]).max().orElse(0);
} else {
comDropMap.put(fix[0], fix[1]);
} }
} if (type == 2){
LOGGER.info("zong reward"); ratio = Arrays.stream(value).filter(v -> bout < v[0]).mapToInt(v -> v[1]).min().orElse(0);
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]);
}
}
//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); builder.setLossBloodOrTimes(bout);
LOGGER.info("输了 回合数 times :=>{} id=>{}", bout,sChallengeConfig.getId());
} // 加成百分比
if (type == 2) { //血量 for (int[] fix : stage.getPassReward()) {
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()) {
Integer num = comDropMap.getOrDefault(fix[0], 0); 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); comDropMap.put(fix[0], num);
} }
LOGGER.info("no pass reward percent"); builder.setPercentReward(ratio);
builder.setPercentReward((int)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; return comDropMap;
} }
@ -177,98 +144,96 @@ public class ChallengeLogic {
//1 为挑战 2 为扫荡 //1 为挑战 2 为扫荡
int model = proto.getModel(); int model = proto.getModel();
int id = proto.getId(); int id = proto.getId();
SChallengeStage sChallengeConfig = STableManager.getConfig(SChallengeStage.class).get(id); SChallengeStage stage = STableManager.getConfig(SChallengeStage.class).get(id);
if (sChallengeConfig == null) { if (stage == null) {
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
} }
int endlessNewReplicaLexel = user.getPlayerInfoManager().getEndlessNewReplica(); int endlessNewReplicaLexel = user.getPlayerInfoManager().getEndlessNewReplica();
int treasureReplicaLexel = user.getPlayerInfoManager().getTreasureReplica(); 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) { if (!consume) {
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
} }
Map<Integer, Integer> comDropMap = new HashMap<>(); Map<Integer, Integer> comDropMap = new HashMap<>();
//扫荡 //扫荡
if (model == 2) { if (model == 2) {
switch (type) { int round = 0;
case 1: // 回合 if (type == 1){
if (!limit(endlessNewReplicaLexel, id)) { if (endlessNewReplicaLexel < id){
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true);
return; return;
} }
break; round = 20;
case 2:// 血量 }
if (!limit(treasureReplicaLexel, id)) { if (type == 2){
if (treasureReplicaLexel < id){
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true); MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true);
return; return;
} }
break; 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() 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); .map(n -> new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN);
builder.setDrop(drop); builder.setDrop(drop);
} }
// 挑战 // 挑战
if (model == 1){ if (model == 1){
GameFightType fightType = null; GameFightType fightType = GameFightType.EndlessNewTeam;
int teamId = 0; int teamId = 0;
if (type == 1) { if (type == 1) {
//回合 if (stage.getNextLevel() < endlessNewReplicaLexel) {
fightType = GameFightType.EndlessNewTeam; MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true);
return;
}
teamId = TeamEnum.CHALLENGE_ENDLESS_NEWTEAM.getTeamId(); 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) { if (type == 2) {
user.getPlayerInfoManager().setTreasureReplica(id); if (stage.getNextLevel() < treasureReplicaLexel) {
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.CHALLENGE_RESPONSE.getNumber(), builder.build(), true);
return;
} }
comDropMap = dropMap(sChallengeConfig, model, type, 1, fightResult.getCheckResult(),time,builder); fightType = GameFightType.TreasureTeam;
builder.setResult(1); teamId = TeamEnum.CHALLENGE_TREASURE_TEAM.getTeamId();
} else {// 输了 }
// 回合
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){ if (type == 1){
if(time >= 20){ int win = 1;
//无尽副本回合数超过20 赢 // 满足通关条件
if (round >= victoryValue){
user.getPlayerInfoManager().setEndlessNewReplica(id); user.getPlayerInfoManager().setEndlessNewReplica(id);
comDropMap = dropMap(sChallengeConfig, model, type, 1, fightResult.getCheckResult(),time,builder);
builder.setResult(1); builder.setResult(1);
builder.setLossBloodOrTimes(20); builder.setLossBloodOrTimes(20);
}else{ win = 2;
//没打过 //输了 保底+总奖励*奖励百分比
comDropMap = dropMap(sChallengeConfig, model, type, 0, fightResult.getCheckResult(),time,builder);
builder.setResult(0);
} }
comDropMap = dropMap(stage, type, win, round, builder);
} }
// 血量 // 伤害副本
if(type == 2){ if (type == 2){
//没打过-输了 保底+总奖励*奖励百分比 int win = 1;
comDropMap = dropMap(sChallengeConfig, model, type, 0, fightResult.getCheckResult(),time,builder); // 满足首通条件
builder.setResult(0); 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() CommonProto.FightData fightData = CommonProto.FightData.newBuilder()
.setFightMaxTime(20) .setFightMaxTime(20)
.setFightSeed(fightResult.getSeed()) .setFightSeed(fightResult.getSeed())
@ -278,11 +243,10 @@ public class ChallengeLogic {
.setFightId(FightUtil.getFightId(user.getId(), fightType)) .setFightId(FightUtil.getFightId(user.getId(), fightType))
.build(); .build();
builder.setFightData(fightData); builder.setFightData(fightData);
CommonProto.Drop.Builder drop = ItemUtil.drop(user, comDropMap.entrySet().stream().map(n -> CommonProto.Drop.Builder drop = ItemUtil.drop(user, comDropMap.entrySet().stream()
new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN); .map(n -> new int[]{n.getKey(), n.getValue()}).toArray(int[][]::new), BIReason.EXPLORE_MAP_COST_RETURN);
builder.setDrop(drop); builder.setDrop(drop);
builder.setType(type); builder.setType(type);
LOGGER.info("type :"+type);
} }
// 副本挑战任务 // 副本挑战任务