获取商店信息
parent
9f25f8bd12
commit
93beaecf89
|
|
@ -4,3 +4,7 @@ int string int int mut,int#int,1 mut,int#int,1 int mut,int#int,2 int int int
|
||||||
2 1000金币 2 1 1#100 14#1000 100 14|0#0#0#100 2 0 0
|
2 1000金币 2 1 1#100 14#1000 100 14|0#0#0#100 2 0 0
|
||||||
3 10000金币 3 1 1#100 14#10000 100 14|0#0#0#100 3 0 0
|
3 10000金币 3 1 1#100 14#10000 100 14|0#0#0#100 3 0 0
|
||||||
4 55555金币 1 1 1#100 14#5555 100 14|0#0#0#100 4 1 2
|
4 55555金币 1 1 1#100 14#5555 100 14|0#0#0#100 4 1 2
|
||||||
|
101 100金币 1 2 1#100 14#100 100 14|0#0#0#100 1 0 0
|
||||||
|
102 1000金币 2 2 1#100 14#1000 100 14|0#0#0#100 2 0 0
|
||||||
|
103 10000金币 3 2 1#100 14#10000 100 14|0#0#0#100 3 0 0
|
||||||
|
104 55555金币 1 2 1#100 14#5555 100 14|0#0#0#100 4 1 2
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
Id RefreshItem RefreshType StoreOpenRule StartTime EndTime
|
Id Number RefreshItem RefreshType StoreOpenRule StartTime EndTime
|
||||||
int mut,int#int,2 mut,int#int,1 int sting string
|
int int mut,int#int,2 mut,int#int,1 int string string
|
||||||
1 14|0#0#0#10000 2#5 1 0 0
|
1 3 14|0#0#0#10000 2#5 1 0 0
|
||||||
2 14|0#0#0#10000 3#2 1 0 0
|
2 3 14|0#0#0#10000 3#2 1 0 0
|
||||||
3 14|0#0#0#10000 1#0 2 0 30
|
3 3 14|0#0#0#10000 1#0 2 0 30
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.ljsd.jieling.config;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.logic.STableManager;
|
||||||
|
import com.ljsd.jieling.logic.Table;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Table(name ="StoreConfig")
|
||||||
|
public class SStoreConfig implements BaseConfig {
|
||||||
|
static Map<Integer, SStoreConfig> sStoreConfigMap;
|
||||||
|
//key: type 商店类型
|
||||||
|
static Map<Integer, List<SStoreConfig>> sStoreConfigMapBuyType;
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String goodsName;
|
||||||
|
|
||||||
|
private int sort;
|
||||||
|
|
||||||
|
private int storeId;
|
||||||
|
|
||||||
|
private int[] openLv;
|
||||||
|
|
||||||
|
private int[] goods;
|
||||||
|
|
||||||
|
private int weight;
|
||||||
|
|
||||||
|
private int[][] cost;
|
||||||
|
|
||||||
|
private int limit;
|
||||||
|
|
||||||
|
private int isDiscount;
|
||||||
|
|
||||||
|
private int discountDegree;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
sStoreConfigMap = STableManager.getConfig(SStoreConfig.class);
|
||||||
|
Map<Integer, List<SStoreConfig>> sStoreConfigMapBuyType = new ConcurrentHashMap<>();
|
||||||
|
for (Map.Entry<Integer, SStoreConfig> entry :sStoreConfigMap.entrySet()){
|
||||||
|
SStoreConfig data = entry.getValue();
|
||||||
|
if (!sStoreConfigMapBuyType.containsKey(data.getStoreId())) {
|
||||||
|
sStoreConfigMapBuyType.put((data.getStoreId()), new ArrayList<SStoreConfig>());
|
||||||
|
}
|
||||||
|
sStoreConfigMapBuyType.get(data.getStoreId()).add(data);
|
||||||
|
}
|
||||||
|
this.sStoreConfigMapBuyType = sStoreConfigMapBuyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Integer, SStoreConfig> getSstoreConfigMap () {
|
||||||
|
return sStoreConfigMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SStoreConfig> getSstoreConfigBuyStore (int storeId) {
|
||||||
|
return sStoreConfigMapBuyType.get(storeId);
|
||||||
|
}
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodsName() {
|
||||||
|
return goodsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSort() {
|
||||||
|
return sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStoreId() {
|
||||||
|
return storeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getOpenLv() {
|
||||||
|
return openLv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getGoods() {
|
||||||
|
return goods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[][] getCost() {
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsDiscount() {
|
||||||
|
return isDiscount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDiscountDegree() {
|
||||||
|
return discountDegree;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.ljsd.jieling.config;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.logic.STableManager;
|
||||||
|
import com.ljsd.jieling.logic.Table;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Table(name ="StoreTypeConfig")
|
||||||
|
public class SStoreTypeConfig implements BaseConfig {
|
||||||
|
static Map<Integer, SStoreTypeConfig> sStoreTypeConfigMap;
|
||||||
|
private int id;
|
||||||
|
private int number;
|
||||||
|
private int[][] refreshItem;
|
||||||
|
|
||||||
|
private int[] refreshType;
|
||||||
|
|
||||||
|
private int storeOpenRule;
|
||||||
|
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws Exception {
|
||||||
|
sStoreTypeConfigMap = STableManager.getConfig(SStoreTypeConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Integer, SStoreTypeConfig> getSstoreTypeConfigMap (){
|
||||||
|
return sStoreTypeConfigMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[][] getRefreshItem() {
|
||||||
|
return refreshItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getRefreshType() {
|
||||||
|
return refreshType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStoreOpenRule() {
|
||||||
|
return storeOpenRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -30,4 +30,6 @@ public class MongoKey {
|
||||||
|
|
||||||
public final static String arenaManager = "arenaManager";
|
public final static String arenaManager = "arenaManager";
|
||||||
|
|
||||||
|
public final static String storeManager = "storeManager";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.ljsd.jieling.handler.store;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.handler.BaseHandler;
|
||||||
|
import com.ljsd.jieling.logic.item.ItemLogic;
|
||||||
|
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
|
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class GetAllStoreHandler extends BaseHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageTypeProto.MessageType getMessageCode() {
|
||||||
|
return MessageTypeProto.MessageType.GET_STARE_INFOS_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||||
|
StoreLogic.getAllStoreInfo(iSession);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StoreInfo extends MongoBase {
|
||||||
|
private int id ; // 商店id
|
||||||
|
|
||||||
|
private long lastRefreshTime; // 上次刷新时间
|
||||||
|
|
||||||
|
private int refreshNum; // 刷新次数
|
||||||
|
|
||||||
|
private long startTime; // 开启时间
|
||||||
|
|
||||||
|
private long endTime ; // 结束时间
|
||||||
|
|
||||||
|
private Map<Integer,Integer> itemNumMap;
|
||||||
|
|
||||||
|
public StoreInfo(int id,long startTime,long endTime,Map<Integer,Integer> itemNumMap ){
|
||||||
|
// this.setRootCollection(User._COLLECTION_NAME);
|
||||||
|
this.id = id;
|
||||||
|
this.lastRefreshTime = System.currentTimeMillis();
|
||||||
|
this.refreshNum = 0;
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
this.itemNumMap = itemNumMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastRefreshTime(long lastRefreshTime) {
|
||||||
|
updateString("lastRefreshTime", lastRefreshTime);
|
||||||
|
this.lastRefreshTime = lastRefreshTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefreshNum(int refreshNum) {
|
||||||
|
updateString("refreshNum", refreshNum);
|
||||||
|
this.refreshNum = refreshNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemNumMap(Map<Integer, Integer> itemNumMap) {
|
||||||
|
this.itemNumMap = itemNumMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastRefreshTime() {
|
||||||
|
return lastRefreshTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRefreshNum() {
|
||||||
|
return refreshNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, Integer> getItemNumMap() {
|
||||||
|
return itemNumMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.ljsd.jieling.logic.dao;
|
||||||
|
|
||||||
|
import com.ljsd.common.mogodb.MongoBase;
|
||||||
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
||||||
|
public class StoreManager extends MongoBase {
|
||||||
|
//key :商店id
|
||||||
|
private Map<Integer,StoreInfo> storeInfoMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public StoreManager() {
|
||||||
|
this.setRootCollection(User._COLLECTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, StoreInfo> getStoreInfoMap() {
|
||||||
|
return storeInfoMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStoreInfo(StoreInfo storeInfo) throws Exception {
|
||||||
|
storeInfo.init(this.getRootId(), getMongoKey() + ".storeInfoMap." + storeInfo.getId());
|
||||||
|
updateString("storeInfoMap." + storeInfo.getId(), storeInfo);
|
||||||
|
storeInfoMap.put(storeInfo.getId(), storeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeStoreInfo(Integer key) {
|
||||||
|
StoreInfo storeInfo= storeInfoMap.get(key);
|
||||||
|
if (storeInfo!=null){
|
||||||
|
storeInfoMap.remove(key);
|
||||||
|
removeString(getMongoKey() + ".storeInfoMap." + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoreInfo newStoreInfo(int id,long startTime,long endTime,Map<Integer,Integer> itemNumMap) throws Exception {
|
||||||
|
StoreInfo storeInfo = new StoreInfo(id,startTime,endTime,itemNumMap);
|
||||||
|
addStoreInfo(storeInfo);
|
||||||
|
return storeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -38,6 +38,8 @@ public class User {
|
||||||
|
|
||||||
private ArenaManager arenaManager;
|
private ArenaManager arenaManager;
|
||||||
|
|
||||||
|
private StoreManager storeManager;
|
||||||
|
|
||||||
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
||||||
public User(){
|
public User(){
|
||||||
}
|
}
|
||||||
|
|
@ -57,6 +59,7 @@ public class User {
|
||||||
this.levelDifficultyManager = new LevelDifficultyManager();
|
this.levelDifficultyManager = new LevelDifficultyManager();
|
||||||
this.activityManager = new ActivityManager();
|
this.activityManager = new ActivityManager();
|
||||||
this.arenaManager = new ArenaManager();
|
this.arenaManager = new ArenaManager();
|
||||||
|
this.storeManager = new StoreManager();
|
||||||
|
|
||||||
//綁定关系
|
//綁定关系
|
||||||
this.playerManager.init(id, MongoKey.playerManager);
|
this.playerManager.init(id, MongoKey.playerManager);
|
||||||
|
|
@ -72,6 +75,7 @@ public class User {
|
||||||
this.levelDifficultyManager.init(id, MongoKey.levelDifficultyManager);
|
this.levelDifficultyManager.init(id, MongoKey.levelDifficultyManager);
|
||||||
this.activityManager.init(id, MongoKey.activityManager);
|
this.activityManager.init(id, MongoKey.activityManager);
|
||||||
this.arenaManager.init(id, MongoKey.arenaManager);
|
this.arenaManager.init(id, MongoKey.arenaManager);
|
||||||
|
this.storeManager.init(id,MongoKey.storeManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
|
@ -165,4 +169,8 @@ public class User {
|
||||||
public ArenaManager getArenaManager() {
|
public ArenaManager getArenaManager() {
|
||||||
return arenaManager;
|
return arenaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StoreManager getStoreManager() {
|
||||||
|
return storeManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.ljsd.jieling.logic.store;
|
||||||
|
|
||||||
|
import ch.qos.logback.core.util.TimeUtil;
|
||||||
|
import com.ljsd.jieling.config.SStoreConfig;
|
||||||
|
import com.ljsd.jieling.config.SStoreTypeConfig;
|
||||||
|
import com.ljsd.jieling.handler.store.GetAllStoreHandler;
|
||||||
|
import com.ljsd.jieling.logic.dao.StoreInfo;
|
||||||
|
import com.ljsd.jieling.logic.dao.StoreManager;
|
||||||
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
|
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||||
|
import com.ljsd.jieling.util.MessageUtil;
|
||||||
|
import com.ljsd.jieling.util.TimeUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class StoreLogic {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(StoreLogic.class);
|
||||||
|
|
||||||
|
public static void getAllStoreInfo(ISession iSession) throws Exception {
|
||||||
|
int msgId = MessageTypeProto.MessageType.GET_STARE_INFOS_RESPONSE_VALUE;
|
||||||
|
int uid = iSession.getUid();
|
||||||
|
User user = UserManager.getUser(uid);
|
||||||
|
StoreManager storeManager = user.getStoreManager();
|
||||||
|
if (storeManager.getStoreInfoMap().size() == 0){
|
||||||
|
initStoreInfo(storeManager);
|
||||||
|
}
|
||||||
|
PlayerInfoProto.GetStoreInfos.Builder builder = PlayerInfoProto.GetStoreInfos.newBuilder();
|
||||||
|
Map<Integer, StoreInfo> storeInfoMap = storeManager.getStoreInfoMap();
|
||||||
|
List<CommonProto.StoreInfo> storeInfos = new CopyOnWriteArrayList<>();
|
||||||
|
for (Map.Entry<Integer, StoreInfo> entry: storeInfoMap.entrySet()){
|
||||||
|
CommonProto.StoreInfo.Builder storeBuilder = CommonProto.StoreInfo.newBuilder();
|
||||||
|
StoreInfo storeInfo = entry.getValue();
|
||||||
|
storeBuilder.setId(storeInfo.getId());
|
||||||
|
storeBuilder.setLastRefreshTime(storeInfo.getLastRefreshTime());
|
||||||
|
storeBuilder.setRefreshNum(storeInfo.getRefreshNum());
|
||||||
|
storeBuilder.setStartTime(storeInfo.getStartTime());
|
||||||
|
storeBuilder.setEndTime(storeInfo.getEndTime());
|
||||||
|
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||||
|
List<CommonProto.StoreItem> builderList = new CopyOnWriteArrayList<>();
|
||||||
|
for (Map.Entry<Integer, Integer> entry1: itemNumMap.entrySet()){
|
||||||
|
int itemId = entry1.getKey();
|
||||||
|
int buyNum = entry1.getValue();
|
||||||
|
CommonProto.StoreItem.Builder storeItemBuilder = CommonProto.StoreItem.newBuilder();
|
||||||
|
storeItemBuilder.setItemId(itemId);
|
||||||
|
storeItemBuilder.setBuyNum(buyNum);
|
||||||
|
builderList.add(storeItemBuilder.build());
|
||||||
|
}
|
||||||
|
storeBuilder.addAllStoreItem(builderList);
|
||||||
|
storeInfos.add(storeBuilder.build());
|
||||||
|
}
|
||||||
|
builder.addAllStoreInfo(storeInfos);
|
||||||
|
MessageUtil.sendMessage(iSession, 1,msgId, builder.build(), true);
|
||||||
|
}
|
||||||
|
//初始化商店
|
||||||
|
private static void initStoreInfo(StoreManager storeManager) throws Exception {
|
||||||
|
Map<Integer, SStoreTypeConfig> sstoreTypeConfigMap = SStoreTypeConfig.getSstoreTypeConfigMap();
|
||||||
|
for ( Map.Entry<Integer, SStoreTypeConfig> entry :sstoreTypeConfigMap.entrySet()){
|
||||||
|
SStoreTypeConfig sStoreTypeConfig = entry.getValue();
|
||||||
|
if (sStoreTypeConfig.getStoreOpenRule() == 1){ //固定商店
|
||||||
|
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig.getNumber());
|
||||||
|
long startTime = 0;
|
||||||
|
long endTime = 0;
|
||||||
|
if (!sStoreTypeConfig.getStartTime().equals("0")){
|
||||||
|
startTime = TimeUtils.parseTimeToMiles(sStoreTypeConfig.getStartTime(), "YYYYMMdd hhmmss");
|
||||||
|
}
|
||||||
|
if (!sStoreTypeConfig.getEndTime().equals("0")){
|
||||||
|
endTime = TimeUtils.parseTimeToMiles(sStoreTypeConfig.getEndTime(), "YYYYMMdd hhmmss");
|
||||||
|
}
|
||||||
|
storeManager.newStoreInfo(sStoreTypeConfig.getId(),startTime,endTime,itemNumMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 随机获得商店物品
|
||||||
|
*/
|
||||||
|
private static Map<Integer,Integer> getStoreItem(int storeId,int itemNum) {
|
||||||
|
Map<Integer, Integer> itemNumMap = new ConcurrentHashMap<>();
|
||||||
|
for (int i = 1; i <= itemNum; i ++){
|
||||||
|
int rewardId = getRewardId(storeId,i);
|
||||||
|
itemNumMap.put(rewardId, 0);
|
||||||
|
}
|
||||||
|
return itemNumMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getRewardId(int storeId,int sort) {
|
||||||
|
List<SStoreConfig> sstoreConfigBuyStore = SStoreConfig.getSstoreConfigBuyStore(storeId);
|
||||||
|
List<SStoreConfig> randomSstoreConfigList = new CopyOnWriteArrayList<>();
|
||||||
|
int totalWeight = 0;
|
||||||
|
for (SStoreConfig sStoreConfig : sstoreConfigBuyStore) {
|
||||||
|
if (sort != sStoreConfig.getSort()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
totalWeight += sStoreConfig.getWeight();
|
||||||
|
randomSstoreConfigList.add(sStoreConfig);
|
||||||
|
}
|
||||||
|
int weight = 0;
|
||||||
|
int rewardId = 0;
|
||||||
|
Random random = new Random();
|
||||||
|
int randomWeight = random.nextInt(totalWeight) + 1;
|
||||||
|
for (SStoreConfig sStoreConfig : randomSstoreConfigList) {
|
||||||
|
weight += sStoreConfig.getWeight();
|
||||||
|
if (weight >= randomWeight) {
|
||||||
|
rewardId = sStoreConfig.getId();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rewardId;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue