From 57f73449d8bd21d5877b6c1a7274bda84e3939c0 Mon Sep 17 00:00:00 2001 From: gaojie Date: Tue, 22 Jan 2019 14:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=89=E8=90=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/server/RewardGroup.txt | 3 + conf/server/RewardItemConfig.txt | 58 ++++++++ .../java/com/ljsd/jieling/config/SDrop.java | 41 ----- .../com/ljsd/jieling/config/SRewardGroup.java | 55 +++++++ .../com/ljsd/jieling/config/SRewardItem.java | 51 +++++++ .../ljsd/jieling/globals/GlobalItemType.java | 4 +- .../java/com/ljsd/jieling/util/ItemUtil.java | 140 ++++++++++++++---- .../java/com/ljsd/jieling/util/MathUtils.java | 8 +- 8 files changed, 282 insertions(+), 78 deletions(-) create mode 100644 conf/server/RewardGroup.txt create mode 100644 conf/server/RewardItemConfig.txt delete mode 100644 serverlogic/src/main/java/com/ljsd/jieling/config/SDrop.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/config/SRewardGroup.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/config/SRewardItem.java diff --git a/conf/server/RewardGroup.txt b/conf/server/RewardGroup.txt new file mode 100644 index 000000000..9a90df9ba --- /dev/null +++ b/conf/server/RewardGroup.txt @@ -0,0 +1,3 @@ +RewardGroupID Info IsUpset RewardItem RewardMaxNum Loop +int string int mut,int#int,1 int int +1 钻石招募卡池1 2 1#2#3#4#5#6#7#8#9#10#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#27#28#29#30#31#32#33#34#35#36#37#38#39#40#41#42#43#44#45#46#47#48#49#50#51#52#53#54#55#56 1 0 diff --git a/conf/server/RewardItemConfig.txt b/conf/server/RewardItemConfig.txt new file mode 100644 index 000000000..d44de6dc4 --- /dev/null +++ b/conf/server/RewardItemConfig.txt @@ -0,0 +1,58 @@ +Id ItemId Chance GrowChance RandomMin RandomMax +int int int int int int +1 10001 100 0 1 1 +2 10002 100 0 1 1 +3 10003 100 0 1 1 +4 10004 100 0 1 1 +5 10005 100 0 1 1 +6 10006 100 0 1 1 +7 10007 100 0 1 1 +8 10008 100 0 1 1 +9 10009 100 0 1 1 +10 10010 100 0 1 1 +11 10011 100 0 1 1 +12 10012 100 0 1 1 +13 10013 100 0 1 1 +14 10014 100 0 1 1 +15 10015 100 0 1 1 +16 10016 100 0 1 1 +17 10017 100 0 1 1 +18 10018 100 0 1 1 +19 10019 100 0 1 1 +20 10020 100 0 1 1 +21 10021 100 0 1 1 +22 10022 100 0 1 1 +23 10023 100 0 1 1 +24 10024 100 0 1 1 +25 10025 100 0 1 1 +26 10026 100 0 1 1 +27 10027 100 0 1 1 +28 10028 100 0 1 1 +29 10029 100 0 1 1 +30 10030 100 0 1 1 +31 10031 100 0 1 1 +32 10032 100 0 1 1 +33 10033 100 0 1 1 +34 10034 100 0 1 1 +35 10035 100 0 1 1 +36 10036 100 0 1 1 +37 10037 100 0 1 1 +38 10038 100 0 1 1 +39 10039 100 0 1 1 +40 10040 100 0 1 1 +41 10041 100 0 1 1 +42 10042 100 0 1 1 +43 10043 100 0 1 1 +44 10044 100 0 1 1 +45 10045 100 0 1 1 +46 10046 100 0 1 1 +47 10047 100 0 1 1 +48 10048 100 0 1 1 +49 10049 100 0 1 1 +50 10050 100 0 1 1 +51 10051 100 0 1 1 +52 10052 100 0 1 1 +53 10053 100 0 1 1 +54 10054 100 0 1 1 +55 10055 100 0 1 1 +56 10056 100 0 1 1 diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/SDrop.java b/serverlogic/src/main/java/com/ljsd/jieling/config/SDrop.java deleted file mode 100644 index f037e73ae..000000000 --- a/serverlogic/src/main/java/com/ljsd/jieling/config/SDrop.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.ljsd.jieling.config; - -import com.ljsd.jieling.logic.STableManager; -import com.ljsd.jieling.logic.Table; - -import java.util.Map; - -@Table(name = "drop") -public class SDrop implements BaseConfig { - public static Map sDropMap; - private int id; - private int dropType; // 掉落type - private int[][] item; - private int[] weight; - - @Override - public void init() throws Exception { - sDropMap = STableManager.getConfig(SDrop.class); - } - - - public int getId() { - return id; - } - - public int[][] getItem() { - return item; - } - - public static Map getsDropMap() { - return sDropMap; - } - - public int getDropType() { - return dropType; - } - - public int[] getWeight() { - return weight; - } -} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardGroup.java b/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardGroup.java new file mode 100644 index 000000000..636d7a0e2 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardGroup.java @@ -0,0 +1,55 @@ +package com.ljsd.jieling.config; + +import com.ljsd.jieling.logic.STableManager; +import com.ljsd.jieling.logic.Table; + +import java.util.Map; + +@Table(name = "RewardGroup") +public class SRewardGroup implements BaseConfig { + public static Map sRewardItemMap; + private int id; + /** + * 组内抽取道具规则 + * 1组内全出 + * 2按照物品在组队的占比出 + * 3按照组内道具概率,依次抽取 + */ + private int isUpset; // 掉落type + private int[] rewardGroupID; + private int rewardMaxNum; // 道具数 + /** + * 如果抽取规则选3 ,则需要设置循环轮数 + */ + private int loop ; + + @Override + public void init() throws Exception { + sRewardItemMap = STableManager.getConfig(SRewardGroup.class); + } + + + public int getId() { + return id; + } + + public static Map getsRewardItemMap() { + return sRewardItemMap; + } + + public int getIsUpset() { + return isUpset; + } + + public int[] getRewardGroupID() { + return rewardGroupID; + } + + public int getRewardMaxNum() { + return rewardMaxNum; + } + + public int getLoop() { + return loop; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardItem.java b/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardItem.java new file mode 100644 index 000000000..35f2fc23c --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/SRewardItem.java @@ -0,0 +1,51 @@ +package com.ljsd.jieling.config; + +import com.ljsd.jieling.logic.STableManager; +import com.ljsd.jieling.logic.Table; + +import java.util.Map; + +@Table(name = "RewardItemConfig") +public class SRewardItem implements BaseConfig { + public static Map sDropMap; + private int id; + private int itemId; + private int chance; //获取概率 + private int growChance; //成长概率 针对特殊处理,如果不获取,则获取概率增加 + private int randomMin; //获取数量最小值 + private int randomMax; //获取数量最大值 + + @Override + public void init() throws Exception { + sDropMap = STableManager.getConfig(SRewardItem.class); + } + + + public int getId() { + return id; + } + + public static Map getsDropMap() { + return sDropMap; + } + + public int getItemId() { + return itemId; + } + + public int getChance() { + return chance; + } + + public int getGrowChance() { + return growChance; + } + + public int getRandomMin() { + return randomMin; + } + + public int getRandomMax() { + return randomMax; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/globals/GlobalItemType.java b/serverlogic/src/main/java/com/ljsd/jieling/globals/GlobalItemType.java index fabf9ce1a..926c78229 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/globals/GlobalItemType.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/globals/GlobalItemType.java @@ -4,8 +4,10 @@ public interface GlobalItemType { //掉落物品类型 int ALL_DROP = 0; //全部掉落 int WEIGHT_DROP = 1; //随机掉落 + int SUCCESSIVELY_RANDOM = 2; // 依次随机 // 物品类型 - int ITEM = 10; //道具类型 + int ITEM = 10; //道具 + int CARD = 11; // 卡牌 } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/ItemUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/util/ItemUtil.java index 86b0e3a47..c73714d80 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/ItemUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/ItemUtil.java @@ -1,12 +1,10 @@ package com.ljsd.jieling.util; -import com.ljsd.jieling.config.SDrop; +import com.ljsd.jieling.config.SRewardItem; import com.ljsd.jieling.config.SItem; +import com.ljsd.jieling.config.SRewardGroup; import com.ljsd.jieling.globals.GlobalItemType; -import com.ljsd.jieling.logic.dao.Item; -import com.ljsd.jieling.logic.dao.ItemManager; -import com.ljsd.jieling.logic.dao.User; -import com.ljsd.jieling.logic.dao.UserManager; +import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.protocols.CommonProto; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,47 +18,108 @@ import java.util.concurrent.CopyOnWriteArrayList; public class ItemUtil { private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class); //掉落 - public static CommonProto.Drop.Builder drop(User user, int dropId, CommonProto.Drop.Builder drop) throws Exception { - SDrop sDrop = SDrop.getsDropMap().get(dropId); - if (sDrop == null){ + public static CommonProto.Drop.Builder drop(User user, int dropGroupId, CommonProto.Drop.Builder drop) throws Exception { + SRewardGroup sRewardGroup = SRewardGroup.getsRewardItemMap().get(dropGroupId); + if (sRewardGroup == null){ return drop; } - int dropType = sDrop.getDropType(); Map itemMap = new HashMap<>(); - selectDrop(sDrop, dropType, itemMap); + Map cardMap = new HashMap<>(); + + selectDrop(sRewardGroup,itemMap,cardMap); addItem(user,itemMap,drop); - + addCard(user,cardMap,drop); return drop; } - private static void selectDrop(SDrop sDrop, int dropType, Map itemMap) { - int[][] itemIds = sDrop.getItem(); - if (dropType == GlobalItemType.ALL_DROP){ - for (int[] itemId : itemIds) { - getMap(itemId, itemMap); + private static void selectDrop(SRewardGroup sRewardGroup,Map itemMap, Map cardMap) { + int[] rewardItem = sRewardGroup.getRewardGroupID(); + StringBuilder rewardStr = new StringBuilder(); + StringBuilder weight = new StringBuilder(); + for (int dropId :rewardItem){ + SRewardItem sRewardItem = SRewardItem.getsDropMap().get(dropId); + if (sRewardItem == null){ + continue; + } + if (rewardStr.length() == 0){ + rewardStr = new StringBuilder(String.valueOf(sRewardItem.getItemId())); + }else{ + rewardStr.append("#").append(sRewardItem.getItemId()); + } + if (weight.length() == 0){ + weight = new StringBuilder(String.valueOf(sRewardItem.getChance())); + }else{ + weight.append("#").append(sRewardItem.getItemId()); } - }else{ - int[] weights = sDrop.getWeight(); - int index = MathUtils.randomForStrArray(weights); - getMap(itemIds[index], itemMap); } - } - - private static void getMap(int[] itemInfo, Map itemMap) { - SItem sItem = SItem.getsItemMap().get(itemInfo[1]); - int itemType = sItem.getItemType(); - switch (itemType) { - case GlobalItemType.ITEM: - putcountMap(itemInfo, itemMap); + switch (sRewardGroup.getIsUpset()) { + case GlobalItemType.ALL_DROP: + getMap(rewardStr.toString().split("#"),itemMap,cardMap); + break; + case GlobalItemType.WEIGHT_DROP: + getRandomMap(sRewardGroup.getRewardMaxNum(),rewardStr.toString().split("#"),weight.toString().split("#"),itemMap,cardMap); + break; + case GlobalItemType.SUCCESSIVELY_RANDOM: + getSuccessivelyRandmoMap(sRewardGroup,rewardStr.toString().split("#"),weight.toString().split("#"),itemMap,cardMap); break; default: break; } } - private static void putcountMap(int[] itemInfo, Map map) { - map.merge(itemInfo[0], itemInfo[1], (a, b) -> b + a); + private static void getSuccessivelyRandmoMap(SRewardGroup sRewardGroup,String[] rewardArr,String[] weightArr, Map itemMap, Map cardMap) { + for (int i = 0 ; i < sRewardGroup.getRewardMaxNum();i++){ + int itemId = 0; + for (int j = 0 ; j < sRewardGroup.getLoop();i++){ + int index = MathUtils.randomForStrArray(weightArr); + itemId = Integer.parseInt(rewardArr[index]); + if (itemId ==Integer.parseInt(rewardArr[j])){ + break; + } + } + if (0 == itemId){ + int index = MathUtils.randomForStrArray(weightArr); + itemId = Integer.parseInt(rewardArr[index]); + } + SRewardItem sRewardItem = SRewardItem.getsDropMap().get(itemId); + getMap(itemId,itemMap, cardMap, sRewardItem); + } + } + + private static void getRandomMap(int randomItemNum ,String[] rewardArr,String[] weightArr, Map itemMap, Map cardMap) { + for (int i = 0 ; i < randomItemNum;i++){ + int index = MathUtils.randomForStrArray(weightArr); + int itemId = Integer.parseInt(rewardArr[index]); + SRewardItem sRewardItem = SRewardItem.getsDropMap().get(itemId); + getMap(itemId,itemMap, cardMap, sRewardItem); + } + } + + private static void getMap(String[] itemInfo, Map itemMap,Map cardMap) { + for (String itemId :itemInfo){ + SRewardItem sRewardItem = SRewardItem.getsDropMap().get(Integer.parseInt(itemId)); + getMap(Integer.parseInt(itemId),itemMap, cardMap, sRewardItem); + } + } + + private static void getMap(int itemId ,Map itemMap, Map cardMap, SRewardItem sRewardItem) { + int itemNum = MathUtils.random(sRewardItem.getRandomMin(), sRewardItem.getRandomMax()); + SItem sItem = SItem.getsItemMap().get(itemId); + switch (sItem.getItemType()) { + case GlobalItemType.ITEM: + putcountMap(itemId,itemNum,itemMap); + break; + case GlobalItemType.CARD: + putcountMap(itemId,itemNum,cardMap); + break; + default: + break; + } + } + + private static void putcountMap(int itemId,int itemNum, Map map) { + map.merge(itemId, itemNum, (a, b) -> b + a); } /** @@ -83,8 +142,7 @@ public class ItemUtil { } } if (dropBuilder != null) { - CommonProto.Item itemProto = CommonProto.Item.newBuilder().setItemId(item.getItemId()).setItemNum(item.getItemNum()).build(); - itemProtoList.add(itemProto); + itemProtoList.add(CBean2Proto.getItem(item)); } } dropBuilder.addAllItemlist(itemProtoList); @@ -124,4 +182,22 @@ public class ItemUtil { return itemList; } + + public static void addCard(User user,Map cardMap,CommonProto.Drop.Builder dropBuilder) throws Exception { + List heroList = new CopyOnWriteArrayList<>(); + for (Map.Entry entry : cardMap.entrySet()) { + int count = entry.getValue(); + for (int i = 0; i < count; i++) { + addCard(user, entry.getKey(),heroList); + } + } + } + + public static void addCard(User user,int cardId,List heroList) throws Exception { + HeroManager heroManager = user.getHeroManager(); + Hero hero = new Hero(user.getId(),cardId); + heroManager.addHero(hero); + heroList.add(CBean2Proto.getHero(hero)); + } + } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/MathUtils.java b/serverlogic/src/main/java/com/ljsd/jieling/util/MathUtils.java index 118319da1..cb2975f9e 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/MathUtils.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/MathUtils.java @@ -22,10 +22,10 @@ public class MathUtils { * @param rateArray * @return */ - public static int randomForStrArray(int[] rateArray) { + public static int randomForStrArray(String [] rateArray) { return randomStrArray(rateArray, -1); } - public static int randomStrArray(int[] rateArray, int minSum) { + public static int randomStrArray(String [] rateArray, int minSum) { if (null == rateArray) { throw new IllegalArgumentException( "The random array must not be null!"); @@ -42,11 +42,11 @@ public class MathUtils { for (int i = 0; i < arrayLength; i++) { - if (rateArray[i] < 0) { + if (Integer.parseInt(rateArray[i]) < 0) { throw new IllegalArgumentException( "The array's element must not be equal or greater than zero!"); } - rateSum += rateArray[i]; + rateSum += Integer.parseInt(rateArray[i]); rateSumArray[i] = rateSum; } if (rateSum <= 0) {