From ad4a55b2cecd08dbe891b571dbe4301eb6775731 Mon Sep 17 00:00:00 2001 From: wangyuan Date: Tue, 26 Nov 2019 17:41:38 +0800 Subject: [PATCH] fight opti --- .../ljsd/jieling/handler/map/MapLogic.java | 23 ++----- .../handler/map/behavior/BehaviorUtil.java | 41 +++++++++++ .../QuickStartMonsterFighter.java | 9 +-- .../ljsd/jieling/logic/arena/ArenaLogic.java | 13 ++-- .../jieling/logic/family/GuildFightLogic.java | 69 ++++--------------- .../jieling/logic/fight/DefFightSnapData.java | 31 +++++++++ .../jieling/logic/fight/FightDispatcher.java | 7 +- .../ljsd/jieling/logic/fight/FightEvent.java | 18 ++--- .../ljsd/jieling/logic/fight/FightUtil.java | 60 +++++++++++----- .../jieling/logic/fight/GameFightType.java | 61 ++++++++++++++++ .../jieling/logic/fight/PVEFightEvent.java | 2 +- .../jieling/logic/fight/PVPFightEvent.java | 20 +++++- .../DefaultOfRedisCacheFightHandler.java | 1 + .../fight/eventhandler/PVPFightHandler.java | 12 ++++ .../src/main/java/config/SLotterySetting.java | 2 + 15 files changed, 252 insertions(+), 117 deletions(-) create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/fight/DefFightSnapData.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/fight/GameFightType.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/PVPFightHandler.java diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java index 93ecf6576..2383c44ec 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java @@ -1226,7 +1226,7 @@ public class MapLogic { SChallengeConfig sChallengeConfig = SChallengeConfig.sChallengeConfigs.get(user.getMapManager().getCurMapId()); int mostTime = sChallengeConfig.getMostTime(); - PVEFightEvent pveFightEvent = new PVEFightEvent(uid, mapManager.getTeamId(), mostTime, "", FightType.MapExploreFight, groupId, 3); + PVEFightEvent pveFightEvent = new PVEFightEvent(uid, mapManager.getTeamId(), mostTime, "", GameFightType.MapFastFight, groupId, 3); FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent); int[] checkResult = fightResult.getCheckResult(); @@ -1435,7 +1435,6 @@ public class MapLogic { User user = UserManager.getUser(uid); String key = RedisKey.getKey(RedisKey.FIGHT, Integer.toString(uid), false); Map valueMap = RedisUtil.getInstence().hmget(key); - RedisUtil.getInstence().del(key); if (valueMap == null || valueMap.isEmpty()) { LOGGER.info("endFight() uid=>{} not start fight", uid); throw new ErrorCodeException(ErrorCode.newDefineCode("此战斗已结算过")); @@ -1460,8 +1459,10 @@ public class MapLogic { int monsterGroupId=0; SMonsterGroup sMonsterGroup=null; if(dropout ==0){ + monsterGroupId = Integer.parseInt((String) valueMap.get(RedisKey.FIGHT_GROUPID)); + sMonsterGroup = SMonsterGroup.getsMonsterGroupMap().get(monsterGroupId); int mostTime = SChallengeConfig.sChallengeConfigs.get(mapManager.getCurMapId()).getMostTime(); - FightEvent fightEvent = new FightEvent(uid, -1, mostTime,frames, FightType.MapExploreFight); + FightEvent fightEvent = new FightEvent(uid, -1, mostTime,frames, GameFightType.MapEndFight); FightResult fightResult = FightDispatcher.dispatcher(fightEvent); //校验结果码 1:胜利 checkResult = fightResult.getCheckResult(); @@ -1962,8 +1963,7 @@ public class MapLogic { User user = UserManager.getUser(uid); MapManager mapManager = user.getMapManager(); SChallengeConfig sChallengeConfig = SChallengeConfig.sChallengeConfigs.get(mapManager.getFindSuddenlyBossMapId()); - FightEvent fightEvent = new FightEvent(uid, -1, sChallengeConfig.getMostTime(),frames, FightType.MapExploreFight); - fightEvent.setExtraParm(RedisKey.SUDDLENLY_FIGHT); + FightEvent fightEvent = new FightEvent(uid, -1, sChallengeConfig.getMostTime(),frames,GameFightType.EndSuddlenlyFight); FightResult fightResult = FightDispatcher.dispatcher(fightEvent); //校验结果码 1:胜利 int[] checkResult = fightResult.getCheckResult(); @@ -2088,17 +2088,8 @@ public class MapLogic { LOGGER.info("endFight() uid=>{} fightId=>{},checkFightId={}", uid, fightId, checkFightId); throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); } - String key = RedisKey.getKey(RedisKey.LEVE_DIFFICULTY_FIGHT, Integer.toString(user.getId()), false); - Map valueMap = RedisUtil.getInstence().hmget(key); - RedisUtil.getInstence().del(key,fightKey); - if (valueMap == null || valueMap.isEmpty()) { - LOGGER.info("endFight() uid=>{} not start fight", uid); - throw new ErrorCodeException(ErrorCode.newDefineCode("此战斗已结算过 !")); - } - - SMainLevelConfig sMainLevelConfig = SMainLevelConfig.config.get(fightId); - FightEvent fightEvent = new FightEvent(uid, -1, sMainLevelConfig.getRankTime(),frames, FightType.StoryFight); + FightEvent fightEvent = new FightEvent(uid, -1, sMainLevelConfig.getRankTime(),frames, GameFightType.StoryFight); FightResult fightResult = FightDispatcher.dispatcher(fightEvent); //校验结果码 1:胜利 int resultCode = fightResult.getCheckResult()[0]; @@ -2305,7 +2296,7 @@ public class MapLogic { throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); } - FightEvent fightEvent = new FightEvent(uid, -1, sFloodConfig.getBattleTime(),frames, FightType.MapExploreFight); + FightEvent fightEvent = new FightEvent(uid, -1, sFloodConfig.getBattleTime(),frames, GameFightType.EndMonsterAttackFight); FightResult fightResult = FightDispatcher.dispatcher(fightEvent); //校验结果码 1:胜利 int[] checkResult = fightResult.getCheckResult(); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/behavior/BehaviorUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/behavior/BehaviorUtil.java index f34b29103..d5bb588ca 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/behavior/BehaviorUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/behavior/BehaviorUtil.java @@ -1,6 +1,7 @@ package com.ljsd.jieling.handler.map.behavior; import com.googlecode.protobuf.format.JsonFormat; +import com.ljsd.jieling.logic.hero.HeroAttributeEnum; import com.ljsd.jieling.util.CBean2Proto; import config.MapPointConfig; import com.ljsd.jieling.db.redis.RedisKey; @@ -243,6 +244,46 @@ public class BehaviorUtil { .build(); } + /** + * 获取FightUnitInfo + * @param user + * @param teamId + * @param attackBloodMap 血量百分比 + * @return + */ + public static CommonProto.FightTeamInfo getFightTeamInfo(User user, int teamId, Map attackBloodMap) { + user.getTeamPosManager().setCurTeamPosId(teamId); + List heroFightInfos = new ArrayList<>(); + List teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId); + for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfos) { + Hero hero = user.getHeroManager().getHero(teamPosHeroInfo.getHeroId()); + if (hero == null) { + continue; + } + Map heroAttributeMap = HeroLogic.getInstance().calHeroNotBufferAttribute(user, hero, false, teamId); + if(attackBloodMap.containsKey(teamPosHeroInfo.getHeroId())){ + heroAttributeMap.put(HeroAttributeEnum.CurHP.getPropertyId(),heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())-attackBloodMap.get(teamPosHeroInfo.getHeroId())*heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())/100); + } + StringBuilder skillSb = new StringBuilder(); + StringBuilder propertySb = new StringBuilder(); + String heroSkill = HeroLogic.getInstance().getHeroSkills(user,hero,skillSb).toString(); + String property = HeroLogic.getInstance().getHeroPropertyBuilder(propertySb, hero, heroAttributeMap).toString(); + CommonProto.FightUnitInfo heroFightInfo = CommonProto.FightUnitInfo + .newBuilder() + .setUnitId(Integer.toString(hero.getTemplateId())) + .setUnitSkillIds(heroSkill.substring(0,heroSkill.length()-1)) + .setProperty(property.substring(0, property.length()-1)) + .build(); + heroFightInfos.add(heroFightInfo); + } + return CommonProto.FightTeamInfo. + newBuilder() + .addAllFightUnitList(heroFightInfos) + .setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(user,teamId)) + .setTeamPassiveList(HeroLogic.getInstance().getPokenmonPassiveSkills(user,teamId)) + .build(); + } + public static CommonProto.FightTeamInfo getRobotFightTeamInfo(SArenaRobotConfig sArenaRobotConfig) { List heroFightInfos = new ArrayList<>(); Map heroStarsMap = sArenaRobotConfig.getStarOfHeroMap(); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/monsterAttack/QuickStartMonsterFighter.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/monsterAttack/QuickStartMonsterFighter.java index f57c58a9b..bb7f14434 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/monsterAttack/QuickStartMonsterFighter.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/monsterAttack/QuickStartMonsterFighter.java @@ -17,10 +17,7 @@ import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean; import com.ljsd.jieling.logic.dao.TeamPosHeroInfo; import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.logic.dao.root.User; -import com.ljsd.jieling.logic.fight.CheckFight; -import com.ljsd.jieling.logic.fight.FightDispatcher; -import com.ljsd.jieling.logic.fight.FightType; -import com.ljsd.jieling.logic.fight.PVEFightEvent; +import com.ljsd.jieling.logic.fight.*; import com.ljsd.jieling.logic.fight.result.FightResult; import com.ljsd.jieling.logic.mission.GameEvent; import com.ljsd.jieling.network.session.ISession; @@ -91,7 +88,7 @@ public class QuickStartMonsterFighter extends BaseHandler heroAttackFightInfos = new ArrayList<>(); - Map attackBloodMap = redisUtil.getMapValues(RedisKey.FAMILY_ATTACK_BLOOD, String.valueOf(userAttack.getId()), String.class, String.class); - List teamAttack = userAttack.getTeamPosManager().getTeamPosForHero().get(502); - if(attackBloodMap!=null&&attackBloodMap.size()>0){ - for(TeamPosHeroInfo teamHero: teamAttack){ - Hero hero = userAttack.getHeroManager().getHero(teamHero.getHeroId()); - if (hero == null) { - continue; - } - StringBuilder skillSb = new StringBuilder(); - StringBuilder propertySb = new StringBuilder(); - String heroSkill = HeroLogic.getInstance().getHeroSkills(userAttack, hero, skillSb).toString(); - Map heroAttributeMap = HeroLogic.getInstance().calHeroNotBufferAttribute(userAttack, hero, false, 502); - for(Map.Entry blood:attackBloodMap.entrySet()){ - if(teamHero.getHeroId().equals(blood.getKey())){ - heroAttributeMap.put(HeroAttributeEnum.CurHP.getPropertyId(),heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())-Integer.parseInt(blood.getValue())*heroAttributeMap.get(HeroAttributeEnum.Hp.getPropertyId())/100); - break; - } - } - String property = HeroLogic.getInstance().getHeroPropertyBuilder(propertySb, hero, heroAttributeMap).toString(); - CommonProto.FightUnitInfo heroFightInfo = CommonProto.FightUnitInfo - .newBuilder() - .setUnitId(Integer.toString(hero.getTemplateId())) - .setUnitSkillIds(heroSkill.substring(0, heroSkill.length() - 1)) - .setProperty(property.substring(0, property.length() - 1)) - .build(); - heroAttackFightInfos.add(heroFightInfo); - } - CommonProto.FightTeamInfo.Builder fightAttackTeamInfoBuilder = CommonProto.FightTeamInfo.newBuilder().addAllFightUnitList(heroAttackFightInfos) - .setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(userAttack, 1)).setTeamPassiveList(HeroLogic.getInstance().getPokenmonPassiveSkills(userAttack,1)); - fightAttackTeamInfo = fightAttackTeamInfoBuilder.build(); - }else{ - fightAttackTeamInfo = BehaviorUtil.getFightTeamInfo(userAttack,502,true); - } + Map attackBloodMap = redisUtil.getMapValues(RedisKey.FAMILY_ATTACK_BLOOD, String.valueOf(userAttack.getId()), String.class, Integer.class); + PVPFightEvent pvpFightEvent = new PVPFightEvent(userAttack.getId(),502, SGuildSetting.sGuildSetting.getWarTime(),"", GameFightType.GuildFight,defendUid,-1); + pvpFightEvent.setAttackBloodMap(attackBloodMap); + pvpFightEvent.setDefFightSnapData(new DefFightSnapData(defendInfo.getHeroAttribute(),defendInfo.getHeroSkills(),defendInfo.getPokenmonSkills())); + FightResult dispatcher = FightDispatcher.dispatcher(pvpFightEvent); + int[] fightResult = dispatcher.getCheckResult(); - LuaValue getFightData = FightDataUtil.getFinalPlayerFightData(fightAttackTeamInfo, fightDefendTeamInfo); - LuaValue getOptionData = FightDataUtil.getOptionData(""); - int seed = (int) (System.currentTimeMillis() / 1000); - CommonProto.FightData fightData = CommonProto.FightData.newBuilder() - .setFightMaxTime(SGuildSetting.sGuildSetting.getWarTime()) - .setFightSeed(seed) - .setHeroFightInfos(fightAttackTeamInfo) - .addMonsterList(fightDefendTeamInfo) - .build(); - int[] fightResult = CheckFight.getInstance().checkFight(seed, SGuildSetting.sGuildSetting.getWarTime(), getFightData, getOptionData, FightType.GuildFight); - for (int i = 0; i < fightResult.length; i++) { - System.out.println(fightResult[i]); - } int aliveCount = 0; // 战斗之后数据处理 @@ -495,8 +450,8 @@ public class GuildFightLogic { defendInfo.setHeroAttribute(BloodLogic.getInstance().afterBattleRecord(heroAttribute,fightResult)); //获得星数 int getStar; + List teamAttack = userAttack.getTeamPosManager().getTeamPosForHero().get(502); if (fightResult[0] == 1) { - getStar = defendInfo.getStarCount(); defendInfo.setStarCount(0); int indexAttack =2; @@ -540,6 +495,12 @@ public class GuildFightLogic { haveGotStar = 0; } redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_CAL_STAR,String.valueOf(attackGuildId),String.valueOf(defendInfo.getBuildId()),haveGotStar+getStar); + CommonProto.FightData fightData = CommonProto.FightData.newBuilder() + .setFightMaxTime(SGuildSetting.sGuildSetting.getWarTime()) + .setFightSeed(dispatcher.getSeed()) + .setHeroFightInfos(dispatcher.getFightTeamInfo()) + .addMonsterList(dispatcher.getDefFightTeamInfo()) + .build(); Family.FamilyFightAttackResponse response = Family.FamilyFightAttackResponse.newBuilder().setResult(fightResult[0]).setStarCount(getStar).setData(fightData).build(); userAttack.getUserMissionManager().onGameEvent(userAttack, GameEvent.FAMILY_FIGHT_ATTACK); MessageUtil.sendMessage(session, 1, messageType.getNumber(), response, true); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/DefFightSnapData.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/DefFightSnapData.java new file mode 100644 index 000000000..ed9281338 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/DefFightSnapData.java @@ -0,0 +1,31 @@ +package com.ljsd.jieling.logic.fight; + +import com.ljsd.jieling.logic.dao.FamilyHeroInfo; + +import java.util.HashMap; +import java.util.Map; + +public class DefFightSnapData { + private Map heroAttribute; + private Map heroSkills = new HashMap<>(); + private String pokenmonSkills; + + + public DefFightSnapData(Map heroAttribute, Map heroSkills, String pokenmonSkills) { + this.heroAttribute = heroAttribute; + this.heroSkills = heroSkills; + this.pokenmonSkills = pokenmonSkills; + } + + public Map getHeroAttribute() { + return heroAttribute; + } + + public Map getHeroSkills() { + return heroSkills; + } + + public String getPokenmonSkills() { + return pokenmonSkills; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightDispatcher.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightDispatcher.java index f4ad3bd04..83be55678 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightDispatcher.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightDispatcher.java @@ -4,9 +4,8 @@ import com.ljsd.jieling.logic.fight.result.FightResult; public class FightDispatcher { - - - public static FightResult dispatcher(FightEvent fightEvent){ - return null; + public static FightResult dispatcher(FightEvent fightEvent) throws Exception { + GameFightType fightType = fightEvent.getFightType(); + return fightType.getFightEventProcesor().process(fightEvent); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightEvent.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightEvent.java index 0d5f56a8f..78d7a5eb8 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightEvent.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightEvent.java @@ -1,14 +1,16 @@ package com.ljsd.jieling.logic.fight; +import java.util.Map; + public class FightEvent { private int attackUid; private int teamId; private int mostTime; private String frames; - private FightType fightType; - private String extraParm; + private GameFightType fightType; + private Map attackBloodMap; - public FightEvent(int attackUid, int teamId,int mostTime,String frams, FightType fightType) { + public FightEvent(int attackUid, int teamId,int mostTime,String frams, GameFightType fightType) { this.attackUid = attackUid; this.teamId = teamId; this.fightType = fightType; @@ -16,12 +18,12 @@ public class FightEvent { this.frames = frams; } - public String getExtraParm() { - return extraParm; + public Map getAttackBloodMap() { + return attackBloodMap; } - public void setExtraParm(String extraParm) { - this.extraParm = extraParm; + public void setAttackBloodMap(Map attackBloodMap) { + this.attackBloodMap = attackBloodMap; } public int getAttackUid() { @@ -32,7 +34,7 @@ public class FightEvent { return teamId; } - public FightType getFightType() { + public GameFightType getFightType() { return fightType; } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightUtil.java index 659ad2006..32f5a7037 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/FightUtil.java @@ -6,6 +6,7 @@ import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.exception.ErrorCode; import com.ljsd.jieling.exception.ErrorCodeException; import com.ljsd.jieling.handler.map.behavior.BehaviorUtil; +import com.ljsd.jieling.logic.blood.BloodLogic; import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.logic.dao.root.User; import com.ljsd.jieling.logic.fight.result.FightResult; @@ -23,15 +24,19 @@ import java.util.Map; public class FightUtil { - public static Map redisTypeOfFightType = new HashMap<>(); - static { - redisTypeOfFightType.put(FightType.StoryFight,RedisKey.LEVE_DIFFICULTY_FIGHT); + public static CommonProto.FightTeamInfo makePersonFightData(User player,int teamId,Map attackBloodMap){ + if(attackBloodMap ==null || attackBloodMap.isEmpty()){ + return BehaviorUtil.getFightTeamInfo(player,teamId,true); + } + return BehaviorUtil.getFightTeamInfo(player,teamId,attackBloodMap); } - public static CommonProto.FightTeamInfo makePersonFightData(User player,int teamId){ - return BehaviorUtil.getFightTeamInfo(player,teamId,true); + public static CommonProto.FightTeamInfo makeFightWithSnapData(DefFightSnapData defFightSnapData){ + return BloodLogic.getInstance().fightDataMakeUp(defFightSnapData.getHeroSkills(),defFightSnapData.getHeroAttribute(),defFightSnapData.getPokenmonSkills()); } + + public static Map> makeMonsterGroup(int bossGroupId,Map> hps){ return MonsterUtil.getMonsterByGroup(bossGroupId,hps); } @@ -63,12 +68,12 @@ public class FightUtil { public static FightResult getFightForPVE(FightEvent fightEvent){ PVEFightEvent pveFightEvent = (PVEFightEvent)fightEvent; User userInMem = UserManager.getUserInMem(pveFightEvent.getAttackUid()); - CommonProto.FightTeamInfo fightTeamInfo = makePersonFightData(userInMem, pveFightEvent.getTeamId()); + CommonProto.FightTeamInfo fightTeamInfo = makePersonFightData(userInMem, pveFightEvent.getTeamId(),pveFightEvent.getAttackBloodMap()); int fightSeed =getFightSeed(); List monsterfightTeamInfos = makeMonsterFightData(pveFightEvent.getMonsterGroupId(), pveFightEvent.getNums()); LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterfightTeamInfos); LuaValue getOptionData = FightDataUtil.getOptionData(fightEvent.getFrames()); - int[] fightResult = CheckFight.getInstance().checkFight(fightSeed, fightEvent.getMostTime(), getFightData, getOptionData, fightEvent.getFightType()); + int[] fightResult = CheckFight.getInstance().checkFight(fightSeed, fightEvent.getMostTime(), getFightData, getOptionData, fightEvent.getFightType().getFightType()); FightResult.Builder builder = FightResult.newBuilder(); builder.setCheckResult(fightResult); @@ -78,26 +83,43 @@ public class FightUtil { return builder.build(); } + public static FightResult getFightForPVP(FightEvent fightEvent){ + PVPFightEvent pvpFightEvent = (PVPFightEvent)fightEvent; + User userInMem = UserManager.getUserInMem(pvpFightEvent.getAttackUid()); + CommonProto.FightTeamInfo fightTeamInfo = makePersonFightData(userInMem, pvpFightEvent.getTeamId(),pvpFightEvent.getAttackBloodMap()); + int fightSeed =getFightSeed(); + CommonProto.FightTeamInfo deffightTeamInfo = null; + if(pvpFightEvent.getDefFightSnapData()!=null){ + deffightTeamInfo = makeFightWithSnapData(pvpFightEvent.getDefFightSnapData()); + }else{ + if(fightEvent.getFightType() == GameFightType.ArenaPersonFight){ + User defInMem = UserManager.getUserInMem(pvpFightEvent.getDefUid()); + deffightTeamInfo = makePersonFightData(defInMem, pvpFightEvent.getDefTeamId(),null); + }else{ + deffightTeamInfo = makeRobotFightData(pvpFightEvent.getDefUid()); + } + } + LuaValue getFightData = FightDataUtil.getFinalPlayerFightData(fightTeamInfo, deffightTeamInfo); + LuaValue getOptionData = FightDataUtil.getOptionData(fightEvent.getFrames()); + int[] fightResult = CheckFight.getInstance().checkFight(fightSeed, fightEvent.getMostTime(), getFightData, getOptionData, fightEvent.getFightType().getFightType()); - public void mergeFightData(){ - /* LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterTeamList); - - LuaValue getFightData = FightDataUtil.getFinalPlayerFightData(fightTeamInfo, deffightTeamInfo);*/ + FightResult.Builder builder = FightResult.newBuilder(); + builder.setCheckResult(fightResult); + builder.setSeed(fightSeed); + builder.setFightTeamInfo(fightTeamInfo); + builder.setDefFightTeamInfo(deffightTeamInfo); + return builder.build(); } public static int[] getFightFromRedis(FightEvent fightEvent) throws Exception { - FightType fightType = fightEvent.getFightType(); + GameFightType fightType = fightEvent.getFightType(); int playerId = fightEvent.getAttackUid(); String frames = fightEvent.getFrames(); int fightTime = fightEvent.getMostTime(); - String extraParm = fightEvent.getExtraParm(); - String fightTypeOfRedis = FightUtil.redisTypeOfFightType.get(fightType); - if(!StringUtil.isEmpty(extraParm)){ - fightTypeOfRedis = extraParm; - } - String key = RedisKey.getKey(fightTypeOfRedis, Integer.toString(playerId), false); + + String key = RedisKey.getKey(fightType.getFightTypeOfRedis(), Integer.toString(playerId), false); Map valueMap = RedisUtil.getInstence(). hmget(key); if (valueMap == null || valueMap.isEmpty()) { @@ -111,7 +133,7 @@ public class FightUtil { List monsterTeamList = BehaviorUtil.getFightTeamInfos(valueMap); LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterTeamList); LuaValue getOptionData = FightDataUtil.getOptionData(frames); - return CheckFight.getInstance().checkFight(seed,fightTime, getFightData, getOptionData,fightType); + return CheckFight.getInstance().checkFight(seed,fightTime, getFightData, getOptionData,fightType.getFightType()); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/GameFightType.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/GameFightType.java new file mode 100644 index 000000000..be2ddaa16 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/GameFightType.java @@ -0,0 +1,61 @@ +package com.ljsd.jieling.logic.fight; + +import com.ljsd.jieling.db.redis.RedisKey; +import com.ljsd.jieling.logic.fight.eventhandler.DefaultOfRedisCacheFightHandler; +import com.ljsd.jieling.logic.fight.eventhandler.DefaultWithoutHandFightHandler; +import com.ljsd.jieling.logic.fight.eventhandler.IFightEventProcesor; +import com.ljsd.jieling.logic.fight.eventhandler.PVPFightHandler; + + +/** + * StoryFight(1), //故事副本 + * MapExploreFight(2), // 地图探索 + * ArenaFight(3), //竞技场 + * InvasionBossFight(4),//秘境boss + * AdventureLock(5), // 解锁秘境 + * GuildFight(6), // 公会站 + * BloodyFight(7), // 血战 + * MonterFight(8), // 兽潮 + */ +public enum GameFightType { + StoryFight(FightType.StoryFight,new DefaultOfRedisCacheFightHandler(), RedisKey.LEVE_DIFFICULTY_FIGHT), + + MapFastFight(FightType.MapExploreFight,new DefaultWithoutHandFightHandler(),null), + + MapEndFight(FightType.MapExploreFight,new DefaultOfRedisCacheFightHandler(),RedisKey.FIGHT), + EndSuddlenlyFight(FightType.MapExploreFight,new DefaultOfRedisCacheFightHandler(),RedisKey.SUDDLENLY_FIGHT), + EndMonsterAttackFight(FightType.MapExploreFight,new DefaultOfRedisCacheFightHandler(),RedisKey.CHALLENGE_MONSTER_ATTACK), + + ArenaPersonFight(FightType.ArenaFight,new PVPFightHandler(),null), + ArenaRobotFight(FightType.ArenaFight,new PVPFightHandler(),null), + + MonterFight(FightType.MonterFight,new DefaultWithoutHandFightHandler(),null), + + GuildFight(FightType.GuildFight,new PVPFightHandler(),null), + + ; + + + private FightType fightType; + private IFightEventProcesor fightEventProcesor; + private String fightTypeOfRedis; + + + GameFightType(FightType fightType, IFightEventProcesor fightEventProcesor,String fightTypeOfRedis) { + this.fightType = fightType; + this.fightEventProcesor = fightEventProcesor; + this.fightTypeOfRedis = fightTypeOfRedis; + } + + public FightType getFightType() { + return fightType; + } + + public IFightEventProcesor getFightEventProcesor() { + return fightEventProcesor; + } + + public String getFightTypeOfRedis() { + return fightTypeOfRedis; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVEFightEvent.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVEFightEvent.java index 46c98e843..ac3980aee 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVEFightEvent.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVEFightEvent.java @@ -4,7 +4,7 @@ public class PVEFightEvent extends FightEvent{ private int monsterGroupId; private int nums; - public PVEFightEvent(int attackUid, int teamId, int mostTime,String frams, FightType fightType, int monsterGroupId, int nums) { + public PVEFightEvent(int attackUid, int teamId, int mostTime,String frams, GameFightType fightType, int monsterGroupId, int nums) { super(attackUid, teamId, mostTime,frams, fightType); this.monsterGroupId = monsterGroupId; this.nums = nums; diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVPFightEvent.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVPFightEvent.java index 5e9a9ff82..994ad1b22 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVPFightEvent.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/PVPFightEvent.java @@ -4,10 +4,28 @@ public class PVPFightEvent extends FightEvent { private int defUid; private int defTeamId; + //对手快照 + private DefFightSnapData defFightSnapData; - public PVPFightEvent(int attackUid, int teamId, int mostTime, String frams, FightType fightType, int defUid, int defTeamId) { + public PVPFightEvent(int attackUid, int teamId, int mostTime, String frams, GameFightType fightType, int defUid, int defTeamId) { super(attackUid, teamId, mostTime, frams, fightType); this.defUid = defUid; this.defTeamId = defTeamId; } + + public int getDefUid() { + return defUid; + } + + public int getDefTeamId() { + return defTeamId; + } + + public DefFightSnapData getDefFightSnapData() { + return defFightSnapData; + } + + public void setDefFightSnapData(DefFightSnapData defFightSnapData) { + this.defFightSnapData = defFightSnapData; + } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/DefaultOfRedisCacheFightHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/DefaultOfRedisCacheFightHandler.java index 1e63574b7..3b75cceb1 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/DefaultOfRedisCacheFightHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/DefaultOfRedisCacheFightHandler.java @@ -9,6 +9,7 @@ public class DefaultOfRedisCacheFightHandler implements IFightEventProcesor { @Override public FightResult process(FightEvent fightEvent) throws Exception { + System.out.println(this); int[] fightResult = FightUtil.getFightFromRedis(fightEvent); return FightResult.newBuilder().setCheckResult(fightResult).build(); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/PVPFightHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/PVPFightHandler.java new file mode 100644 index 000000000..bb1dbf206 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/eventhandler/PVPFightHandler.java @@ -0,0 +1,12 @@ +package com.ljsd.jieling.logic.fight.eventhandler; + +import com.ljsd.jieling.logic.fight.FightEvent; +import com.ljsd.jieling.logic.fight.FightUtil; +import com.ljsd.jieling.logic.fight.result.FightResult; + +public class PVPFightHandler implements IFightEventProcesor{ + @Override + public FightResult process(FightEvent fightEvent) throws Exception { + return FightUtil.getFightForPVP(fightEvent); + } +} diff --git a/tablemanager/src/main/java/config/SLotterySetting.java b/tablemanager/src/main/java/config/SLotterySetting.java index b778dca74..85dcbf193 100644 --- a/tablemanager/src/main/java/config/SLotterySetting.java +++ b/tablemanager/src/main/java/config/SLotterySetting.java @@ -35,6 +35,8 @@ public class SLotterySetting implements BaseConfig { private int[][] tenTimesMustGetBox; + private int activityId; + @Override public void init() throws Exception {