自动战斗

master_ob2
PC-202302260912\Administrator 2023-07-06 16:02:15 +08:00
parent 8bc2e97047
commit c381a9cf58
10 changed files with 143 additions and 59 deletions

View File

@ -34,6 +34,7 @@ public enum FightType {
ENDLESS_NEW_TEAM(28),//新无尽战斗
TREASURE_TEAM(29),//宝物战斗
DUODUI_FIGHT(30),//多队挑战
AUTO_FIGHT(31),//自动挑战
;
private final int type;

View File

@ -0,0 +1,21 @@
package com.ljsd.jieling.handler.fight;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.network.session.ISession;
import org.springframework.stereotype.Component;
import rpc.protocols.FightInfoProto;
import rpc.protocols.MessageTypeProto;
@Component
public class AutoFightHandler extends BaseHandler<FightInfoProto.AutoFightRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.AutoFightRequest;
}
@Override
public void processWithProto(ISession iSession, FightInfoProto.AutoFightRequest proto) throws Exception {
MapLogic.getInstance().autoFight(iSession,proto.getFightId(),proto.getTeamId());
}
}

View File

@ -1,4 +1,4 @@
package com.ljsd.jieling.handler.map.mapHandler;
package com.ljsd.jieling.handler.fight;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;

View File

@ -1,4 +1,4 @@
package com.ljsd.jieling.handler.map.mapHandler;
package com.ljsd.jieling.handler.fight;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;

View File

@ -1603,6 +1603,72 @@ public class MapLogic {
MessageUtil.sendMessage(iSession, 1, msgId, builder.build(), true);
}
public boolean checkMainFight(User user, int fightId, int teamId) throws Exception {
MainLevelManager mainLevelManager = user.getMainLevelManager();
SMainLevelConfig sMainLevelConfig = SMainLevelConfig.config.get(fightId);
LOGGER.info("校验主线战斗 the uid={},play fightId={}", user.getId(), fightId);
int mineFightId = mainLevelManager.getFightId();
if (mineFightId != fightId) {
LOGGER.info("校验主线战斗 ==> uid={},fightId={}, levelDifficulty is not allow ", user.getId(), fightId);
return false;
}
if (mainLevelManager.getState() != 1) {
// 动态匹配最新的表数据
if (sMainLevelConfig != null && sMainLevelConfig.getNextLevel() != -1 && user.getPlayerInfoManager().getLevel() >= sMainLevelConfig.getLevelLimit()) {
mainLevelManager.setState(1);
} else {
LOGGER.info("校验主线战斗 ==> uid={},fightId={}, 级别难度不允许", user.getId(), fightId);
return false;
}
}
boolean isOpenRule = checkFigthLevelOpen(user, sMainLevelConfig.getOpenRule());
if (!isOpenRule) {
LOGGER.info("校验主线战斗 ==> uid={},fightId={}, 挑战条件不足", user.getId(), fightId);
return false;
}
List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId);
if (teamPosHeroInfos == null || teamPosHeroInfos.size() == 0) {
LOGGER.info("校验主线战斗 ==> uid={},fightId={},teamId={} 队伍信息为空", user.getId(), fightId, teamId);
return false;
}
return true;
}
/**
*
* @param session
* @param fightId
* @param teamId
* @throws Exception
*/
public void autoFight(ISession session, int fightId, int teamId) throws Exception {
User user = UserManager.getUser(session.getUid());
boolean checked = checkMainFight(user, fightId, teamId);
if (!checked){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
FightInfoProto.AutoFightResponse.Builder builder = FightInfoProto.AutoFightResponse.newBuilder();
SMainLevelConfig mainConfig = SMainLevelConfig.config.get(fightId);
int result = 1;
// 小关卡直接胜利,大关卡需要走战斗
if (mainConfig.getDifferentiation() == 1){
PVEFightEvent pveFightEvent = new PVEFightEvent(user.getId(), teamId, mainConfig.getRankTime(), "", GameFightType.AutoFight, mainConfig.getMonsterGroup(), 3);
FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent);
result = fightResult.getResult();
}
builder.setResult(result);
if (result == 1){
// 关卡胜利掉落道具
CommonProto.Drop.Builder drop = mainFightWinHandler(session, fightId);
builder.setDrop(drop);
}
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.AutoFightResponse_VALUE, builder.build(), true);
}
/**
*
@ -1610,47 +1676,29 @@ public class MapLogic {
public void startMainLevelFight(ISession session, int fightId, int teamId, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
MainLevelManager mainLevelManager = user.getMainLevelManager();
SMainLevelConfig sMainLevelConfig = SMainLevelConfig.config.get(fightId);
LOGGER.info("the uid={},play fightId={}", uid, fightId);
int mineFightId = mainLevelManager.getFightId();
if (mineFightId != fightId) {
LOGGER.info("startMainLevelFight==> uid={},fightId={}, levelDifficulty is not allow ", uid, fightId);
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
} else if (mainLevelManager.getState() != 1) {
// 动态匹配最新的表数据
if (sMainLevelConfig != null && sMainLevelConfig.getNextLevel() != -1 && user.getPlayerInfoManager().getLevel() >= sMainLevelConfig.getLevelLimit()) {
mainLevelManager.setState(1);
} else {
LOGGER.info("startMainLevelFight==> uid={},fightId={}, levelDifficulty is not allow ", uid, fightId);
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
}
boolean isOpenRule = CheckFigthLevelOpen(user, sMainLevelConfig.getOpenRule());
if (!isOpenRule) {
LOGGER.info("startMainLevelFight==> uid={},fightId={}, levelDifficulty is not allow ", uid, fightId);
throw new ErrorCodeException(ErrorCode.HANDLE_FAILED);
}
List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId);
if (teamPosHeroInfos == null || teamPosHeroInfos.size() == 0) {
LOGGER.info("startLevelDifficultyFight==> uid={},fightId={},teamId={}", uid, fightId, teamId);
throw new ErrorCodeException(ErrorCode.newDefineCode("阵容有误!!"));
boolean checked = checkMainFight(user, fightId, teamId);
if (!checked){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
KtEventUtils.onKtEvent(user,ParamEventBean.UserGameType,KTGameType.STORY.getIndex(),fightId);
// ReportUtil.onReportEvent(user, ReportEventEnum.ENTER_STAGE.getType(), String.valueOf(fightId));
user.getTeamPosManager().setCurTeamPosId(teamId);
String fightInfo = fightId + "#" + teamId;
String key = RedisKey.getKey(RedisKey.LEVE_DIFFICULTY_INFO, String.valueOf(uid), false);
LOGGER.info("关卡战斗start{}{}", uid, fightInfo);
RedisUtil.getInstence().set(key, fightInfo, 600);
//扣除预先道具
mainFightOfRedis(uid,fightId,teamId);
SMainLevelConfig sMainLevelConfig = SMainLevelConfig.config.get(fightId);
FightInfoProto.FightStartResponse.Builder fightStartResponse = FightInfoProto.FightStartResponse.newBuilder();
BehaviorUtil.getLevelDifficultyifficuFightInfo(user, FightType.StoryFight, sMainLevelConfig.getMonsterGroup(), teamId, sMainLevelConfig.getRankTime(), fightStartResponse, RedisKey.LEVE_DIFFICULTY_FIGHT);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true);
}
public void mainFightOfRedis(int uid, int fightId, int teamId){
String fightInfo = fightId + "#" + teamId;
String key = RedisKey.getKey(RedisKey.LEVE_DIFFICULTY_INFO, String.valueOf(uid), false);
RedisUtil.getInstence().set(key, fightInfo, 600);
LOGGER.info("关卡战斗start{}{}", uid, fightInfo);
}
/**
*
* 0
@ -1667,7 +1715,7 @@ public class MapLogic {
* @return
* @throws Exception
*/
private boolean CheckFigthLevelOpen(User user, int[][] openRule) throws Exception {
private boolean checkFigthLevelOpen(User user, int[][] openRule) throws Exception {
boolean isOpen = true;
for (int[] ints : openRule) {
int type = ints[0];
@ -1749,9 +1797,32 @@ public class MapLogic {
return isOpen;
}
/**
* 线
* @param session
* @param fightId
* @return
* @throws Exception
*/
public CommonProto.Drop.Builder mainFightWinHandler(ISession session, int fightId) throws Exception {
User user = UserManager.getUser(session.getUid());
// 关卡信息
openNextMainLevel(session, user, fightId);
// 排行榜
SMainLevelConfig sMainLevelConfig = SMainLevelConfig.config.get(fightId);
RankContext.getRankEnum(RankEnum.MAIN_LEVEL_RANK.getType()).addRank(user.getId(), "", sMainLevelConfig.getVirtureId(), user.getPlayerInfoManager().getMaxForce());
// 推送
MainLevelManager mainLevelManager = user.getMainLevelManager();
FightInfoProto.MainLevelFightUpdateIndication build = FightInfoProto.MainLevelFightUpdateIndication.newBuilder().setState(mainLevelManager.getState()).setFightId(mainLevelManager.getFightId()).build();
MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.MAIN_LEVEL_FIGHT_UPDATE_INDICATION_VALUE, build, true);
// 打点,现在不用
ReportUtil.onReportEvent(user, ReportEventEnum.PASS_STAGE.getType(), String.valueOf(fightId), "", sMainLevelConfig.getReward(), new Date());
// 奖励道具
return ItemUtil.dropToPrivilege(user, sMainLevelConfig.getReward(), BIReason.LEVELDIFFICULTY_FIGHT_REWARD);
}
public void endMainLevelFight(ISession session, String frames, int fightId, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
String fightKey = RedisKey.getKey(RedisKey.LEVE_DIFFICULTY_INFO, String.valueOf(uid), false);
String fightInfos = (String) RedisUtil.getInstence().get(fightKey);
if (StringUtil.isEmpty(fightInfos)) {
@ -1780,22 +1851,14 @@ public class MapLogic {
return;
}
}
CommonProto.Drop.Builder drop = ItemUtil.dropToPrivilege(user, sMainLevelConfig.getReward(), BIReason.LEVELDIFFICULTY_FIGHT_REWARD);
openNextMainLevel(session, user, fightId);
FightInfoProto.FightEndResponse.Builder fightEndResponse = FightInfoProto.FightEndResponse.newBuilder();
CommonProto.Drop.Builder drop = mainFightWinHandler(session, fightId);
fightEndResponse.setEnventDrop(drop);
fightEndResponse.setResult(fightResult == null ? 1 : fightResult.getResult());
fightEndResponse.build();
MainLevelManager mainLevelManager = user.getMainLevelManager();
FightInfoProto.MainLevelFightUpdateIndication build = FightInfoProto.MainLevelFightUpdateIndication.newBuilder().setState(mainLevelManager.getState()).setFightId(mainLevelManager.getFightId()).build();
RankContext.getRankEnum(RankEnum.MAIN_LEVEL_RANK.getType()).addRank(uid, "", sMainLevelConfig.getVirtureId(), user.getPlayerInfoManager().getMaxForce());
MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.MAIN_LEVEL_FIGHT_UPDATE_INDICATION_VALUE, build, true);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse.build(), true);
ReportUtil.onReportEvent(user, ReportEventEnum.PASS_STAGE.getType(), String.valueOf(fightId), "", sMainLevelConfig.getReward(), new Date());
}
public void openNextMainLevel(ISession session, User user, int fightId) throws Exception {
int level = user.getPlayerInfoManager().getLevel();
int state = 1;
@ -2039,13 +2102,7 @@ public class MapLogic {
}
int eventId = mapManager.getTowerUnusedBuffer().get(towerLevel);
mapManager.consunmeTowerBuffer(towerLevel);
// MapPointConfig pointConfig = MapPointConfig.getScMapEventMap().get(mapPointId);
// int initialEventId = pointConfig.getInitialEventId();
SEventPointConfig sEventPointConfig = STableManager.getConfig(SEventPointConfig.class).get(eventId);
int[] options = sEventPointConfig.getOption();
// for(int option : options){
//
// }
SOptionConfig sOptionConfig = SOptionConfig.sOptionConfigMap.get(optionId);
int behaviorType = sOptionConfig.getBehaviorType();
int[][] behaviorTypeValues = sOptionConfig.getBehaviorTypeValues();

View File

@ -1,6 +1,5 @@
package com.ljsd.jieling.handler.map.behavior;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.googlecode.protobuf.format.JsonFormat;
import com.ljsd.fight.FightType;
import com.ljsd.jieling.db.redis.RedisKey;
@ -367,7 +366,7 @@ public class BehaviorUtil {
}
}
public static void getLevelDifficultyifficuFightInfo(User user,FightType fightType,int groupId,int teamId, int maxTime,FightInfoProto.FightStartResponse.Builder fightStartRespons,String fightKey) throws JsonProcessingException {
public static void getLevelDifficultyifficuFightInfo(User user,FightType fightType,int groupId,int teamId, int maxTime,FightInfoProto.FightStartResponse.Builder fightStartRespons,String fightKey) {
CommonProto.FightData.Builder fightData = CommonProto.FightData.newBuilder();
CommonProto.FightTeamInfo fightTeamInfo = getFightTeamInfo(user, teamId,true);
fightData.setHeroFightInfos(fightTeamInfo);
@ -380,7 +379,7 @@ public class BehaviorUtil {
fightData.addAllMonsterList(monsterGroupList).addAllMonsterList(monsterGroupList1).addAllMonsterList(monsterGroupList2);
//设置战斗随机种子
int seed = (int)(System.currentTimeMillis()/1000);
int seed = TimeUtils.nowInt();
fightData.setFightSeed(seed);
fightData.setFightType(fightType.getType());
fightData.setFightMaxTime(maxTime);

View File

@ -1081,12 +1081,12 @@ public class GuildFightLogic {
KtEventUtils.onKtEvent(user, ParamEventBean.UserGameType, KTGameType.CHALLENGE_GUILD_BOSS.getIndex(),1);
user.getTeamPosManager().setCurTeamPosId(teamId);
int monsterId = curSGuildBossConfig.getMonsterId();
String fightInfo =Integer.toString(monsterId);
String fightInfo = Integer.toString(monsterId);
String key = RedisKey.getKey(RedisKey.GUILD_MONSTER_INFO, String.valueOf(uid), false);
RedisUtil.getInstence().set(key, fightInfo, -1);
FightInfoProto.FightStartResponse.Builder fightStartResponse = FightInfoProto.FightStartResponse.newBuilder();
BehaviorUtil.getLevelDifficultyifficuFightInfo(user, FightType.GuildBossFight,monsterId, teamId, SGuildSetting.sGuildSetting.getBossTime(), fightStartResponse, RedisKey.GUILD_MONSTER_FIGHT);
BehaviorUtil.getLevelDifficultyifficuFightInfo(user, FightType.GuildBossFight, monsterId, teamId, SGuildSetting.sGuildSetting.getBossTime(), fightStartResponse, RedisKey.GUILD_MONSTER_FIGHT);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true);
}

View File

@ -121,7 +121,7 @@ public class FightUtil {
remainHp.put(0, monsterRemainHp);
List<CommonProto.FightTeamInfo> monsterfightTeamInfos = makeMonsterFightData(pveFightEvent.getMonsterGroupId(), pveFightEvent.getNums(), remainHp);
LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterfightTeamInfos);
LuaValue getOptionData = FightDataUtil.getOptionData(pveFightEvent.getAttackUid() + "");
LuaValue getOptionData = FightDataUtil.getOptionData(String.valueOf(pveFightEvent.getAttackUid()));
long[] fightResult = CheckFight.getInstance().checkFight(fightSeed, fightEvent.getMostTime(), getFightData, getOptionData, fightEvent.getFightType().getFightType());
FightResult.Builder builder = FightResult.newBuilder();
@ -249,7 +249,6 @@ public class FightUtil {
GameFightType fightType = fightEvent.getFightType();
int playerId = fightEvent.getAttackUid();
int fightTime = fightEvent.getMostTime();
String key = RedisKey.getKey(fightType.getFightTypeOfRedis(), Integer.toString(playerId), false);
Map<Object, Object> valueMap = RedisUtil.getInstence().hmget(key);
if (valueMap == null || valueMap.isEmpty()) {
@ -262,7 +261,7 @@ public class FightUtil {
CommonProto.FightTeamInfo fightTeamInfo = builder.build();
List<CommonProto.FightTeamInfo> monsterTeamList = BehaviorUtil.getFightTeamInfos(valueMap);
LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterTeamList);
LuaValue getOptionData = FightDataUtil.getOptionData(playerId + "");
LuaValue getOptionData = FightDataUtil.getOptionData(String.valueOf(playerId));
FightResult.Builder fightResult = FightResult.newBuilder();
long[] fightResultInfo = CheckFight.getInstance().checkFight(seed, fightTime, getFightData, getOptionData, fightType.getFightType());

View File

@ -55,6 +55,7 @@ public enum GameFightType {
EndlessNewTeam(FightType.ENDLESS_NEW_TEAM,new DefaultWithoutHandFightHandler(),null),
TreasureTeam(FightType.TREASURE_TEAM,new DefaultWithoutHandFightHandler(),null),
DuoduiFight(FightType.DUODUI_FIGHT,new DuoduiTowerFightHandler(),null),
AutoFight(FightType.AUTO_FIGHT, new DefaultWithoutHandFightHandler(), null),
;

View File

@ -50,6 +50,8 @@ public class SMainLevelConfig implements BaseConfig {
private int storyId; // 大于 0 表示剧情关,无需战斗
private int differentiation;//区分大小关卡
/**
* map
*/
@ -181,4 +183,8 @@ public class SMainLevelConfig implements BaseConfig {
public int[][] getOpenRule() {
return openRule;
}
public int getDifferentiation() {
return differentiation;
}
}