From 06ba20787b0e7d360ffc06de0fb0d7855b7976d3 Mon Sep 17 00:00:00 2001 From: lvxinran Date: Thu, 18 Jun 2020 20:39:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8D=A1=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ljsd/jieling/logic/dao/HeroManager.java | 28 ++- .../ljsd/jieling/logic/hero/HeroLogic.java | 210 ++++++++++++------ .../java/config/SLotterySpecialConfig.java | 29 +-- 3 files changed, 181 insertions(+), 86 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/HeroManager.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/HeroManager.java index a06a558d2..5ebd80808 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/HeroManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/HeroManager.java @@ -15,7 +15,9 @@ public class HeroManager extends MongoBase { Map totalCount; - Map randomPoolByType; + private Map> randomPoolByType; + + private Map mustRandomCount; Map heroHandBook; @@ -27,6 +29,7 @@ public class HeroManager extends MongoBase { totalCount = new HashMap(); heroHandBook = new HashMap<>(); randomPoolByType = new HashMap<>(); + mustRandomCount = new HashMap<>(); this.setRootCollection(User._COLLECTION_NAME); } @@ -35,9 +38,15 @@ public class HeroManager extends MongoBase { totalCount.put(type,count); } - public void updateRandPoolTypeCount(int mergePool,int count){ - updateString("randomPoolByType." + mergePool, count); - randomPoolByType.put(mergePool,count); + public void updateRandPoolTypeCount(int type,int profession,int count){ + updateString("randomPoolByType." + type+"."+profession, count); + randomPoolByType.get(type).put(profession,count); + } + + public void updateRandomPoolByType(int type,Map map){ + randomPoolByType.put(type,map); + updateString("randomPoolByType." + type, map); + } public Map getItemMap() { @@ -104,7 +113,16 @@ public class HeroManager extends MongoBase { } - public Map getRandomPoolByType() { + public Map> getRandomPoolByType() { return randomPoolByType; } + + public Map getMustRandomCount() { + return mustRandomCount; + } + + public void setMustRandomCount(Map mustRandomCount) { + this.mustRandomCount = mustRandomCount; + updateString("mustRandomCount",mustRandomCount); + } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java index 62a2eeba2..901c41a21 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/hero/HeroLogic.java @@ -5,8 +5,6 @@ import com.ljsd.jieling.chat.logic.ChatLogic; import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.HeroStaticConfig; import com.ljsd.jieling.core.GlobalsDef; -import com.ljsd.jieling.core.SimpleTransaction; -import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.exception.ErrorCode; @@ -45,6 +43,7 @@ import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; public class HeroLogic{ @@ -248,81 +247,158 @@ public class HeroLogic{ // else{ // user.getPlayerInfoManager().updateVipPrivilage(privilege, 1); // } - //额外获取 - int length = perCount; - int[][] tenTimesMustGetItem = null; - if(sLotterySetting.getTenTimesMustGetItem()!=null &&sLotterySetting.getTenTimesMustGetItem().length>0){ - tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem(); - length+=tenTimesMustGetItem.length; + int[][] tenTimesMustGetItem = new int[perCount][]; + for(int i = 0 ;i totalCountMap = heroManager.getTotalCount(); - Map randomPoolByType = heroManager.getRandomPoolByType(); - if (totalCountMap.containsKey(type)) { - randCount = totalCountMap.get(type); - } - if (randomPoolByType.containsKey(sLotterySetting.getMergePool())) { - poolCount = randomPoolByType.get(sLotterySetting.getMergePool()); - } - int totalCount = 0; - for(Integer count : totalCountMap.values()){ - totalCount+=count; - } - - int j=0; -// //标记是否触发保底 -// boolean specialTrigger=false; - for(int i=0;i0){ +// tenTimesMustGetItem = sLotterySetting.getTenTimesMustGetItem(); +// length+=tenTimesMustGetItem.length; +// } +// int[][] dropHeroAndItem = new int[length][]; +// int randCount = 0; +// int poolCount = 0; +// Map totalCountMap = heroManager.getTotalCount(); +// Map randomPoolByType = heroManager.getRandomPoolByType(); +// if (totalCountMap.containsKey(type)) { +// randCount = totalCountMap.get(type); +// } +// if (randomPoolByType.containsKey(sLotterySetting.getMergePool())) { +// poolCount = randomPoolByType.get(sLotterySetting.getMergePool()); +// } +// int totalCount = 0; +// for(Integer count : totalCountMap.values()){ +// totalCount+=count; +// } +// +// int j=0; +//// //标记是否触发保底 +//// boolean specialTrigger=false; +// for(int i=0;i specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool); + HeroManager heroManager = user.getHeroManager(); + //设置必出计数器 + if(specialConfigs!=null&&!specialConfigs.isEmpty()){ + for(SLotterySpecialConfig config:specialConfigs){ + if(!heroManager.getRandomPoolByType().containsKey(mergePool)){ + Map map = new HashMap<>(); + map.put(config.getDifferentType(),0); + heroManager.getRandomPoolByType().put(mergePool,new HashMap<>()); + } +// heroManager.getRandomPoolByType().computeIfAbsent(mergePool,n->new HashMap<>()).put(config.getId(),0); + } + } + Map countMap = heroManager.getRandomPoolByType().get(mergePool); + Set mustSet = new HashSet<>(); + //次数计算 + for(Map.Entry countEntry:countMap.entrySet()){ + SLotterySpecialConfig config = null; + if(specialConfigs==null||specialConfigs.isEmpty()){ + continue; + } + for(SLotterySpecialConfig everyConfig:specialConfigs){ + if(everyConfig.getDifferentType()!=countEntry.getKey()){ + continue; + } + config = everyConfig; + } + if(config==null){ + throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE); + } + if(countEntry.getValue()+1 mustRandomCount = heroManager.getMustRandomCount(); + if(mustRandomCount.containsKey(countEntry.getKey())) { + if(mustRandomCount.get(countEntry.getKey())>=config.getMin_num()) { + continue; + }else{ + mustRandomCount.put(countEntry.getKey(), mustRandomCount.get(countEntry.getKey())+1); + } + }else{ + mustRandomCount.put(countEntry.getKey(),1); + } + heroManager.setMustRandomCount(mustRandomCount); + mustSet.add(countEntry.getKey()); + } + + SLotteryRewardConfig sLotteryRewardConfig; + //是否有必出 + if(mustSet.isEmpty()){ + sLotteryRewardConfig = randomHeroByPoolId(getPooId(sLotterySetting), 1, user.getPlayerInfoManager().getLevel()); + int star = sLotteryRewardConfig.getStar(); + for(int key:countMap.keySet()){ + if(star==key){ + countMap.put(key,0); + }else{ + countMap.put(key,countMap.get(key)+1); + } + } + }else{ + int maxId = 0; + for(int mustId:mustSet){ + maxId = mustId; + } + + sLotteryRewardConfig = randomHeroByPoolId(STableManager.getConfig(SLotterySpecialConfig.class).get(maxId).getpool_id(), 1, user.getPlayerInfoManager().getLevel()); + countMap.put(maxId,0); + } + heroManager.updateRandomPoolByType(mergePool,countMap); + int result = sLotteryRewardConfig.getReward()[0]; + System.out.print(result+"、"); + return result; + } private int getSpecialPoolByRandcount(SLotterySetting sLotterySetting, int randCount,int poolCount) { int id = sLotterySetting.getId(); - List list = SLotterySpecialConfig.getLotterySpecialConfigListByType(1,id); + List list = SLotterySpecialConfig.getLotterySpecialConfigListByType(id); if (list == null) { - list = SLotterySpecialConfig.getLotterySpecialConfigListByType(2,sLotterySetting.getMergePool()); + list = SLotterySpecialConfig.getLotterySpecialConfigListByType(sLotterySetting.getMergePool()); if(list == null){ return 0; } diff --git a/tablemanager/src/main/java/config/SLotterySpecialConfig.java b/tablemanager/src/main/java/config/SLotterySpecialConfig.java index 6aa4e87a9..a9562a438 100644 --- a/tablemanager/src/main/java/config/SLotterySpecialConfig.java +++ b/tablemanager/src/main/java/config/SLotterySpecialConfig.java @@ -26,32 +26,33 @@ public class SLotterySpecialConfig implements BaseConfig { private int pool_id; - private static Map>> lotterySpecialConfigMap; + private static Map> lotterySpecialConfigMap; @Override public void init() throws Exception { Map config = STableManager.getConfig(SLotterySpecialConfig.class); - Map>> lotterySpecialConfigMapTmp = new HashMap<>(); + Map> lotterySpecialConfigMapTmp = new HashMap<>(); for(SLotterySpecialConfig sLotterySpecialConfig : config.values()){ - int differentType = sLotterySpecialConfig.getDifferentType(); - if(!lotterySpecialConfigMapTmp.containsKey(differentType)){ - lotterySpecialConfigMapTmp.put(differentType,new HashMap<>()); - } - int type = sLotterySpecialConfig.getType(); - if(!lotterySpecialConfigMapTmp.get(differentType).containsKey(type)){ - lotterySpecialConfigMapTmp.get(differentType).put(type,new ArrayList<>()); - } - lotterySpecialConfigMapTmp.get(differentType).get(type).add(sLotterySpecialConfig); +// int differentType = sLotterySpecialConfig.getDifferentType(); +// if(!lotterySpecialConfigMapTmp.containsKey(differentType)){ +// lotterySpecialConfigMapTmp.put(differentType,new HashMap<>()); +// } +// int type = sLotterySpecialConfig.getType(); +// if(!lotterySpecialConfigMapTmp.get(differentType).containsKey(type)){ +// lotterySpecialConfigMapTmp.get(differentType).put(type,new ArrayList<>()); +// } +// lotterySpecialConfigMapTmp.get(differentType).get(type).add(sLotterySpecialConfig); + lotterySpecialConfigMapTmp.computeIfAbsent(sLotterySpecialConfig.getType(),n->new ArrayList<>()).add(sLotterySpecialConfig); } lotterySpecialConfigMap = lotterySpecialConfigMapTmp; } - public static List getLotterySpecialConfigListByType(int differentType,int type) { - if(!lotterySpecialConfigMap.containsKey(differentType)){ + public static List getLotterySpecialConfigListByType(int type) { + if(!lotterySpecialConfigMap.containsKey(type)){ return null; } - return lotterySpecialConfigMap.get(differentType).get(type); + return lotterySpecialConfigMap.get(type); } public int getId() {