Merge branch 'master' of http://60.1.1.230/backend/jieling_server
commit
f7a3f9dff4
|
@ -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
|
|
@ -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
|
|
@ -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<Integer, SDrop> 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<Integer, SDrop> getsDropMap() {
|
|
||||||
return sDropMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDropType() {
|
|
||||||
return dropType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getWeight() {
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<Integer, SRewardGroup> 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<Integer, SRewardGroup> getsRewardItemMap() {
|
||||||
|
return sRewardItemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsUpset() {
|
||||||
|
return isUpset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getRewardGroupID() {
|
||||||
|
return rewardGroupID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRewardMaxNum() {
|
||||||
|
return rewardMaxNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLoop() {
|
||||||
|
return loop;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Integer, SRewardItem> 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<Integer, SRewardItem> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,8 +4,10 @@ public interface GlobalItemType {
|
||||||
//掉落物品类型
|
//掉落物品类型
|
||||||
int ALL_DROP = 0; //全部掉落
|
int ALL_DROP = 0; //全部掉落
|
||||||
int WEIGHT_DROP = 1; //随机掉落
|
int WEIGHT_DROP = 1; //随机掉落
|
||||||
|
int SUCCESSIVELY_RANDOM = 2; // 依次随机
|
||||||
|
|
||||||
// 物品类型
|
// 物品类型
|
||||||
int ITEM = 10; //道具类型
|
int ITEM = 10; //道具
|
||||||
|
int CARD = 11; // 卡牌
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package com.ljsd.jieling.util;
|
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.SItem;
|
||||||
|
import com.ljsd.jieling.config.SRewardGroup;
|
||||||
import com.ljsd.jieling.globals.GlobalItemType;
|
import com.ljsd.jieling.globals.GlobalItemType;
|
||||||
import com.ljsd.jieling.logic.dao.Item;
|
import com.ljsd.jieling.logic.dao.*;
|
||||||
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.protocols.CommonProto;
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -20,47 +18,108 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
public class ItemUtil {
|
public class ItemUtil {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class);
|
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 {
|
public static CommonProto.Drop.Builder drop(User user, int dropGroupId, CommonProto.Drop.Builder drop) throws Exception {
|
||||||
SDrop sDrop = SDrop.getsDropMap().get(dropId);
|
SRewardGroup sRewardGroup = SRewardGroup.getsRewardItemMap().get(dropGroupId);
|
||||||
if (sDrop == null){
|
if (sRewardGroup == null){
|
||||||
return drop;
|
return drop;
|
||||||
}
|
}
|
||||||
int dropType = sDrop.getDropType();
|
|
||||||
Map<Integer, Integer> itemMap = new HashMap<>();
|
Map<Integer, Integer> itemMap = new HashMap<>();
|
||||||
selectDrop(sDrop, dropType, itemMap);
|
Map<Integer, Integer> cardMap = new HashMap<>();
|
||||||
|
|
||||||
|
selectDrop(sRewardGroup,itemMap,cardMap);
|
||||||
|
|
||||||
addItem(user,itemMap,drop);
|
addItem(user,itemMap,drop);
|
||||||
|
addCard(user,cardMap,drop);
|
||||||
return drop;
|
return drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void selectDrop(SDrop sDrop, int dropType, Map<Integer, Integer> itemMap) {
|
private static void selectDrop(SRewardGroup sRewardGroup,Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap) {
|
||||||
int[][] itemIds = sDrop.getItem();
|
int[] rewardItem = sRewardGroup.getRewardGroupID();
|
||||||
if (dropType == GlobalItemType.ALL_DROP){
|
StringBuilder rewardStr = new StringBuilder();
|
||||||
for (int[] itemId : itemIds) {
|
StringBuilder weight = new StringBuilder();
|
||||||
getMap(itemId, itemMap);
|
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{
|
}else{
|
||||||
int[] weights = sDrop.getWeight();
|
rewardStr.append("#").append(sRewardItem.getItemId());
|
||||||
int index = MathUtils.randomForStrArray(weights);
|
}
|
||||||
getMap(itemIds[index], itemMap);
|
if (weight.length() == 0){
|
||||||
|
weight = new StringBuilder(String.valueOf(sRewardItem.getChance()));
|
||||||
|
}else{
|
||||||
|
weight.append("#").append(sRewardItem.getItemId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch (sRewardGroup.getIsUpset()) {
|
||||||
private static void getMap(int[] itemInfo, Map<Integer, Integer> itemMap) {
|
case GlobalItemType.ALL_DROP:
|
||||||
SItem sItem = SItem.getsItemMap().get(itemInfo[1]);
|
getMap(rewardStr.toString().split("#"),itemMap,cardMap);
|
||||||
int itemType = sItem.getItemType();
|
break;
|
||||||
switch (itemType) {
|
case GlobalItemType.WEIGHT_DROP:
|
||||||
case GlobalItemType.ITEM:
|
getRandomMap(sRewardGroup.getRewardMaxNum(),rewardStr.toString().split("#"),weight.toString().split("#"),itemMap,cardMap);
|
||||||
putcountMap(itemInfo, itemMap);
|
break;
|
||||||
|
case GlobalItemType.SUCCESSIVELY_RANDOM:
|
||||||
|
getSuccessivelyRandmoMap(sRewardGroup,rewardStr.toString().split("#"),weight.toString().split("#"),itemMap,cardMap);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void putcountMap(int[] itemInfo, Map<Integer, Integer> map) {
|
private static void getSuccessivelyRandmoMap(SRewardGroup sRewardGroup,String[] rewardArr,String[] weightArr, Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap) {
|
||||||
map.merge(itemInfo[0], itemInfo[1], (a, b) -> b + a);
|
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<Integer, Integer> itemMap, Map<Integer, Integer> 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<Integer, Integer> itemMap,Map<Integer, Integer> 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<Integer, Integer> itemMap, Map<Integer, Integer> 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<Integer, Integer> map) {
|
||||||
|
map.merge(itemId, itemNum, (a, b) -> b + a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,8 +142,7 @@ public class ItemUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dropBuilder != null) {
|
if (dropBuilder != null) {
|
||||||
CommonProto.Item itemProto = CommonProto.Item.newBuilder().setItemId(item.getItemId()).setItemNum(item.getItemNum()).build();
|
itemProtoList.add(CBean2Proto.getItem(item));
|
||||||
itemProtoList.add(itemProto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dropBuilder.addAllItemlist(itemProtoList);
|
dropBuilder.addAllItemlist(itemProtoList);
|
||||||
|
@ -124,4 +182,22 @@ public class ItemUtil {
|
||||||
return itemList;
|
return itemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void addCard(User user,Map<Integer,Integer> cardMap,CommonProto.Drop.Builder dropBuilder) throws Exception {
|
||||||
|
List<CommonProto.Hero> heroList = new CopyOnWriteArrayList<>();
|
||||||
|
for (Map.Entry<Integer, Integer> 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<CommonProto.Hero> heroList) throws Exception {
|
||||||
|
HeroManager heroManager = user.getHeroManager();
|
||||||
|
Hero hero = new Hero(user.getId(),cardId);
|
||||||
|
heroManager.addHero(hero);
|
||||||
|
heroList.add(CBean2Proto.getHero(hero));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ public class MathUtils {
|
||||||
* @param rateArray
|
* @param rateArray
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int randomForStrArray(int[] rateArray) {
|
public static int randomForStrArray(String [] rateArray) {
|
||||||
return randomStrArray(rateArray, -1);
|
return randomStrArray(rateArray, -1);
|
||||||
}
|
}
|
||||||
public static int randomStrArray(int[] rateArray, int minSum) {
|
public static int randomStrArray(String [] rateArray, int minSum) {
|
||||||
if (null == rateArray) {
|
if (null == rateArray) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"The random array must not be null!");
|
"The random array must not be null!");
|
||||||
|
@ -42,11 +42,11 @@ public class MathUtils {
|
||||||
|
|
||||||
for (int i = 0; i < arrayLength; i++) {
|
for (int i = 0; i < arrayLength; i++) {
|
||||||
|
|
||||||
if (rateArray[i] < 0) {
|
if (Integer.parseInt(rateArray[i]) < 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"The array's element must not be equal or greater than zero!");
|
"The array's element must not be equal or greater than zero!");
|
||||||
}
|
}
|
||||||
rateSum += rateArray[i];
|
rateSum += Integer.parseInt(rateArray[i]);
|
||||||
rateSumArray[i] = rateSum;
|
rateSumArray[i] = rateSum;
|
||||||
}
|
}
|
||||||
if (rateSum <= 0) {
|
if (rateSum <= 0) {
|
||||||
|
|
Loading…
Reference in New Issue