diff --git a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java index 7bbe84ae5..81d1406ea 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java @@ -122,6 +122,10 @@ public class RedisKey { public static final String FAMILY_FIGHT_STAR_RANK = "FAMILY_FIGHT_STAR_RANK"; //公会战公会统计 public static final String FAMILY_FIGHT_CAL_STAR = "FAMILY_FIGHT_CAL_STAR"; + //公会战buff缓存 + public static final String FAMILY_FIGHT_BUFF = "FAMILY_FIGHT_BUFF"; + //公会战进攻次数缓存 + public static final String FAMILY_FIGHT_ATTACK_COUNT = "FAMILY_FIGHT_ATTACK_COUNT"; public static final String OPERATE_FAMILY = "OPERATE_FAMILY"; public static final String OPERATE_FAMILY_APPLY = "OPERATE_FAMILY_APPLY"; diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/GuildMyInfo.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/GuildMyInfo.java index 0554ac98b..e5fefe1a8 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/GuildMyInfo.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/GuildMyInfo.java @@ -24,7 +24,6 @@ public class GuildMyInfo extends MongoBase { private List path = new ArrayList<>(); //行走路线 private int curPos=initPos;//当前位置 private long preMoveTimestamp; //上次更新时间 - private int attackCount;//公会战进攻次数 public void clearOfLevelGuild(){ path.clear(); @@ -99,12 +98,4 @@ public class GuildMyInfo extends MongoBase { return preMoveTimestamp; } - public int getAttackCount() { - return attackCount; - } - - public void updateAttackCount(int count){ - updateString("attackCount",count); - this.attackCount = count; - } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/family/GuildFightLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/family/GuildFightLogic.java index f8f36ce52..a762e1db2 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/family/GuildFightLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/family/GuildFightLogic.java @@ -1,5 +1,6 @@ package com.ljsd.jieling.logic.family; +import com.google.gson.Gson; import com.ljsd.jieling.config.SGuildSetting; import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisUtil; @@ -9,6 +10,7 @@ import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.logic.dao.root.GuildInfo; import com.ljsd.jieling.logic.dao.root.User; import com.ljsd.jieling.logic.fight.CheckFight; +import com.ljsd.jieling.logic.fight.CombatLogic; import com.ljsd.jieling.logic.hero.HeroAttributeEnum; import com.ljsd.jieling.logic.hero.HeroLogic; import com.ljsd.jieling.network.session.ISession; @@ -20,6 +22,7 @@ import com.ljsd.jieling.util.MathUtils; import com.ljsd.jieling.util.MessageUtil; import com.ljsd.jieling.util.TimeUtils; import org.luaj.vm2.LuaValue; +import org.luaj.vm2.ast.Str; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.ZSetOperations; @@ -157,6 +160,8 @@ public class GuildFightLogic { private static Family.FamilyFightInfo familyFightDetailInfo(int guildId) throws Exception { + RedisUtil redisUtil = RedisUtil.getInstence(); + Map buffCache = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT_BUFF, String.valueOf(guildId), String.class, int[].class); GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId); Map defendInfo = guildInfo.getDefendInfo(); Map fightValues = RedisUtil.getInstence().getMapValues(RedisKey.FAMILY_FIGHT, String.valueOf(guildId), Integer.class, FamilyFightInfo.class); @@ -165,7 +170,10 @@ public class GuildFightLogic { for (int i = 0; i < 3; i++) { Family.FamilyBuildBuffInfo.Builder buffInfo = Family.FamilyBuildBuffInfo.newBuilder(); buffInfo.setBuildId(i + 1); - buffInfo.setBuffId(i + 1); + int[] buildBuffs = buffCache.get(String.valueOf(i + 1)); + for(Integer buff:buildBuffs){ + buffInfo.addBuffId(buff); + } fightInfo.addBuildBuff(buffInfo); } for (Map.Entry entry : defendInfo.entrySet()) { @@ -219,6 +227,7 @@ public class GuildFightLogic { RedisUtil redisUtil = RedisUtil.getInstence(); String key = RedisKey.getKey(RedisKey.FAMILY_FIGHT_RANK, "", false); Set rank = redisUtil.getZset(key, 0, redisUtil.getZsetSize(key)); + SGuildSetting guildSetting = SGuildSetting.sGuildSetting; for (Integer gid : guildIds) { //匹配处理 GuildInfo guildInfo = GuilidManager.guildInfoMap.get(gid); @@ -237,9 +246,18 @@ public class GuildFightLogic { if (defendInfo == null || defendInfo.size() < 1) { continue; } - + //buff随机 + for(int i = 0;i<3;i++){ + int[][] buildingBuff = guildSetting.getBuildingBuff(); + int[] buff = buildingBuff[i]; + int[][] randomBuff = new int[buff.length-1][]; + for(int j = 1 ; j entry : defendInfo.entrySet()) { User user = UserManager.getUser(entry.getKey()); int memberType = GuildLogic.getMemberType(entry.getKey(), guildInfo.getMembers()); @@ -253,6 +271,13 @@ public class GuildFightLogic { TeamPosHeroInfo heroInfo = it.next(); Hero hero = heroManager.getHero(heroInfo.getHeroId()); Map heroAttributeMap = HeroLogic.getInstance().calHeroNotBufferAttribute(user, hero, false, 501); + //加防守buff + int[] buffInfo = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_BUFF, gid.toString(), entry.getValue().toString(), int[].class); + if(buffInfo.length>0){ + for(int i = 0 ; i < buffInfo.length ; i++){ + heroAttributeMap = CombatLogic.getInstance().bufferOneHeroAttrAfterEat(heroAttributeMap,buffInfo[i]); + } + } heroAllAttribute.put(heroInfo.getHeroId(), new FamilyHeroInfo(hero.getTemplateId(), hero.getLevel(), heroAttributeMap)); } fightInfo.setHeroAttribute(heroAllAttribute); @@ -310,12 +335,16 @@ public class GuildFightLogic { */ public static void familyFightResult(ISession session, int defendUid, MessageTypeProto.MessageType messageType) throws Exception { User userAttack = UserManager.getUser(session.getUid()); + RedisUtil redisUtil = RedisUtil.getInstence(); //战斗次数 - userAttack.getGuildMyInfo().updateAttackCount(userAttack.getGuildMyInfo().getAttackCount()+1); + Integer attackCount = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_ATTACK_COUNT,"",String.valueOf(userAttack.getId()),Integer.class); + if(attackCount==null){ + attackCount = 0; + } + redisUtil.putMapEntry(RedisKey.FAMILY_FIGHT_ATTACK_COUNT,"",String.valueOf(userAttack.getId()),attackCount+1); User userDefend = UserManager.getUser(defendUid); int defendGuildId = userDefend.getPlayerInfoManager().getGuildId(); int defendBuildId = GuilidManager.guildInfoMap.get(defendGuildId).getDefendInfo().get(defendUid); - RedisUtil redisUtil = RedisUtil.getInstence(); FamilyFightInfo defendInfo = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT, String.valueOf(defendGuildId), String.valueOf(userDefend.getId()), FamilyFightInfo.class); Map heroAttribute = defendInfo.getHeroAttribute(); int seed = (int) (System.currentTimeMillis() / 1000); @@ -390,7 +419,10 @@ public class GuildFightLogic { //获得星数处理 int attackGuildId = userAttack.getPlayerInfoManager().getGuildId(); String attackRankKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), false); - Double starCount = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), String.valueOf(userAttack.getId())); + int starCount = redisUtil.getZSetScore(RedisKey.FAMILY_FIGHT_STAR_RANK, String.valueOf(attackGuildId), String.valueOf(userAttack.getId())).intValue(); + if(starCount==-1){ + starCount = 0; + } redisUtil.zsetAddOne(attackRankKey,String.valueOf(userAttack.getId()),starCount+getStar); //建筑星数 Integer haveGotStar = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_CAL_STAR, String.valueOf(attackGuildId), String.valueOf(defendBuildId), int.class); @@ -409,6 +441,7 @@ public class GuildFightLogic { * @param messageType */ public static void getFamilyFightRoundInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception { + RedisUtil redisUtil = RedisUtil.getInstence(); int startFightTime; int roundStartTime = 0; int roundEndTime = 0; @@ -434,18 +467,26 @@ public class GuildFightLogic { roundEndTime = (int) (TimeUtils.getAppointTime(FamilyRound.FAMILY_FIGHT_END) / 1000); } int enemyFamily = getEnemyFamily(UserManager.getUser(session.getUid()).getPlayerInfoManager().getGuildId()); - + Integer attackCount = redisUtil.getMapEntry(RedisKey.FAMILY_FIGHT_ATTACK_COUNT,"",session.getId(),Integer.class); + if(attackCount==null){ + attackCount = 0; + } Family.FamilyFightRoundResponse.Builder response = Family.FamilyFightRoundResponse.newBuilder() .setType(status) .setStartTime(startFightTime) .setRoundStartTime(roundStartTime) .setRoundEndTime(roundEndTime) - .setAttackCount(UserManager.getUser(session.getUid()).getGuildMyInfo().getAttackCount()) + .setAttackCount(attackCount) .setJoinType(1); if (enemyFamily != -1) { GuildInfo guildInfo = GuilidManager.guildInfoMap.get(enemyFamily); Family.EnemyFamily familyInfo = Family.EnemyFamily.newBuilder().setId(guildInfo.getId()).setLevel(guildInfo.getLevel()).setName(guildInfo.getName()).setPictureId(1).build(); response.setEnemy(familyInfo); + }else{ + if(!startMatching){ + response.setType(-1); + response.setRoundEndTime((int) (TimeUtils.getAppointTime(FamilyRound.FAMILY_FIGHT_END) / 1000)); + } } MessageUtil.sendMessage(session, 1, messageType.getNumber(), response.build(), true); @@ -491,9 +532,19 @@ public class GuildFightLogic { *公会战结束删除匹配信息 */ private static void removeMatchingInfo(){ + startMatching = true; RedisUtil redisUtil = RedisUtil.getInstence(); + //匹配信息 String matchingKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK,"",false); -// Set matchingRank = redisUtil.getZset(RedisKey.FAMILY_FIGHT_MATCHING_RANK, 0, redisUtil.getZsetSize(matchingKey)); + //攻击次数信息 + String attackCountKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_ATTACK_COUNT, "", false); + //布防信息 + String familyFightKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT, "", false); + //建筑buff信息 + String familyBuffKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_MATCHING_RANK, "", false); + //获得星数信息 + String familyFightCalStarKey = RedisKey.getKey(RedisKey.FAMILY_FIGHT_CAL_STAR, "", false); + redisUtil.del(attackCountKey,matchingKey,familyFightKey,familyBuffKey,familyFightCalStarKey); // for(String index:matchingRank){ // Map fightDefend = redisUtil.getMapValues(RedisKey.FAMILY_FIGHT, index, Integer.class, FamilyFightInfo.class); // for (Map.Entry defendEntry:fightDefend.entrySet()){ @@ -511,7 +562,7 @@ public class GuildFightLogic { // } // } //删除匹配信息 - redisUtil.removeZSetRangeByRank(matchingKey,0,redisUtil.getZsetSize(matchingKey)); +// redisUtil.removeZSetRangeByRank(matchingKey,0,redisUtil.getZsetSize(matchingKey)); } /** * 公会战结算 diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/CombatLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/CombatLogic.java index 5df965d7a..eedb73534 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/CombatLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/fight/CombatLogic.java @@ -18,7 +18,6 @@ import com.ljsd.jieling.logic.activity.event.Poster; import com.ljsd.jieling.logic.activity.event.SecretEvent; import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.logic.dao.root.User; -import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.logic.hero.HeroAttributeEnum; import com.ljsd.jieling.logic.mail.MailLogic; import com.ljsd.jieling.logic.mission.GameEvent; @@ -32,6 +31,7 @@ import org.luaj.vm2.LuaValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.ZSetOperations; + import java.util.*; public class CombatLogic { @@ -52,73 +52,75 @@ public class CombatLogic { } - public void bufferAddByEatFoodOrEventTrigger(MapManager mapManager,int foodIdOrEventId) throws Exception { - SFoodsConfig sFoodsConfig = SFoodsConfig.getsFoodsConfigByFoodId(foodIdOrEventId); - int contiue = sFoodsConfig.getContiue(); - if(contiue == 0){ - int typeTmp = sFoodsConfig.getType(); - int targetTmp = sFoodsConfig.getTarget(); - if( typeTmp== GlobalsDef.FOOD_ADDITION_BATTLE_TYPE && targetTmp==GlobalsDef.FOOD_EAT_AFFECT_TEAM ){ - boolean change = false; - int[][] effectParas = sFoodsConfig.getEffectPara(); - Map> heroAllAttributeMap = mapManager.getHeroAllAttributeMap(); - for(Map.Entry> item : heroAllAttributeMap.entrySet()){ - Map value = item.getValue(); - if(value.get(HeroAttributeEnum.CurHP.getPropertyId()) == 0){ - continue; + public Map bufferOneHeroAttrAfterEat(Map value,int foodId){ + SFoodsConfig sFoodsConfig = SFoodsConfig.getsFoodsConfigByFoodId(foodId); + if(value.get(HeroAttributeEnum.CurHP.getPropertyId()) == 0){ + return value; + } + for(int[] effectPara : sFoodsConfig.getEffectPara()){ + int effectId = effectPara[0]; + int effectValue = effectPara[1]; + SPropertyConfig sPropertyConfig = SPropertyConfig.getsPropertyConfigByPID(effectId); + if( sPropertyConfig.getStyle() == GlobalsDef.PERCENT_TYPE){ + if(effectId == HeroAttributeEnum.CurHpExtra.getPropertyId()){ + effectId = HeroAttributeEnum.CurHP.getPropertyId(); + effectValue = value.get(HeroAttributeEnum.Hp.getPropertyId()) * effectValue/10000; + }else{ + if(sPropertyConfig.getTargetPropertyId()!=0){ + effectId = sPropertyConfig.getTargetPropertyId(); + effectValue = value.get(effectId) + effectValue/10000; + }else{ + int baseValue = 0; + if(value.containsKey(effectId)){ + baseValue = value.get(effectId); + } + effectValue = baseValue + effectValue/10000; } - for(int[] effectPara : effectParas){ - int effectId = effectPara[0]; - int effectValue = effectPara[1]; - SPropertyConfig sPropertyConfig = SPropertyConfig.getsPropertyConfigByPID(effectId); - if( sPropertyConfig.getStyle() == GlobalsDef.PERCENT_TYPE){ - if(effectId == HeroAttributeEnum.CurHpExtra.getPropertyId()){ - effectId = HeroAttributeEnum.CurHP.getPropertyId(); - effectValue = value.get(HeroAttributeEnum.Hp.getPropertyId()) * effectValue/10000; - }else{ - if(sPropertyConfig.getTargetPropertyId()!=0){ - effectId = sPropertyConfig.getTargetPropertyId(); - effectValue = value.get(effectId) + effectValue/10000; - }else{ - int baseValue = 0; - if(value.containsKey(effectId)){ - baseValue = value.get(effectId); - } - effectValue = baseValue + effectValue/10000; - } - } - } - - if(!value.containsKey(effectId)){ - value.put(effectId,effectValue); - continue; - } - int finalValue = value.get(effectId) + effectValue; - if(finalValue < 0){ - finalValue = 0; - } - if(effectId == HeroAttributeEnum.CurHP.getPropertyId()){ - Integer maxValue = value.get(HeroAttributeEnum.Hp.getPropertyId()); - if(finalValue>maxValue){ - finalValue = maxValue; - } - if(finalValue == 0){ - finalValue =1; - } - } - value.put( effectId,finalValue ); - change = true; - } - } - if(change){ - mapManager.setHeroAllAttributeMap(heroAllAttributeMap); } } + + if(!value.containsKey(effectId)){ + value.put(effectId,effectValue); + continue; + } + int finalValue = value.get(effectId) + effectValue; + if(finalValue < 0){ + finalValue = 0; + } + if(effectId == HeroAttributeEnum.CurHP.getPropertyId()){ + Integer maxValue = value.get(HeroAttributeEnum.Hp.getPropertyId()); + if(finalValue>maxValue){ + finalValue = maxValue; + } + if(finalValue == 0){ + finalValue =1; + } + } + value.put( effectId,finalValue ); } - if(contiue == 0){ - contiue = -1; + return value; + } + public Map> bufferAddByEatFoodOrEventTrigger(int foodIdOrEventId, Map> heroAllAttributeMap ) throws Exception { + SFoodsConfig sFoodsConfig = SFoodsConfig.getsFoodsConfigByFoodId(foodIdOrEventId); + int typeTmp = sFoodsConfig.getType(); + int targetTmp = sFoodsConfig.getTarget(); + if( typeTmp== GlobalsDef.FOOD_ADDITION_BATTLE_TYPE && targetTmp==GlobalsDef.FOOD_EAT_AFFECT_TEAM ){ + for(Map.Entry> item : heroAllAttributeMap.entrySet()){ + bufferOneHeroAttrAfterEat(item.getValue(),foodIdOrEventId); + } + } + + return heroAllAttributeMap; + } + public void bufferAddByEatFoodOrEventTrigger(MapManager mapManager,int foodIdOrEventId) throws Exception { + Map> heroAllAttributeMap = bufferAddByEatFoodOrEventTrigger(foodIdOrEventId, mapManager.getHeroAllAttributeMap()); + mapManager.setHeroAllAttributeMap(heroAllAttributeMap); + SFoodsConfig sFoodsConfig = SFoodsConfig.getsFoodsConfigByFoodId(foodIdOrEventId); + int contiue = sFoodsConfig.getContiue(); + if(contiue==0){ + contiue=-1; } mapManager.eatFood(foodIdOrEventId,contiue); } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/StoreLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/StoreLogic.java index c16b17c41..60dbc75c1 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/StoreLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/StoreLogic.java @@ -126,8 +126,9 @@ public class StoreLogic { public static void checkStoreRefresh(User user,Map storeInfoMap) throws Exception { long nowTime = System.currentTimeMillis(); StoreManager storeManager = user.getStoreManager(); - for (Map.Entry entry:storeInfoMap.entrySet()){ - StoreInfo storeInfo = entry.getValue(); + Iterator> it = storeInfoMap.entrySet().iterator(); + while(it.hasNext()){ + StoreInfo storeInfo = it.next().getValue(); SStoreTypeConfig sStoreTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeInfo.getId()); if (sStoreTypeConfig.getStoreOpenRule() ==2){ if (nowTime > storeInfo.getEndTime()){