Merge branch 'master' of 60.1.1.230:backend/jieling_server
# Conflicts: # serverlogic/src/main/java/com/ljsd/jieling/db/mongo/MongoKey.java # serverlogic/src/main/java/com/ljsd/jieling/logic/dao/root/User.javaback_recharge
commit
ac3585efc3
|
@ -9,4 +9,5 @@ serverlogic/src/main/java/com/ljsd/jieling/protocols
|
||||||
*.class
|
*.class
|
||||||
out
|
out
|
||||||
build
|
build
|
||||||
out
|
out
|
||||||
|
tmp/
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -113,6 +114,7 @@ public class GameApplication {
|
||||||
serverConfig = serverConfigTmp;
|
serverConfig = serverConfigTmp;
|
||||||
KeyGenUtils.setMachineNum(serverConfiguration.getServerProperties().getNum());
|
KeyGenUtils.setMachineNum(serverConfiguration.getServerProperties().getNum());
|
||||||
ActivityLogic.getInstance().checkActiviyStatus();
|
ActivityLogic.getInstance().checkActiviyStatus();
|
||||||
|
// ProtocolsManager.ps = new PrintStream("tmp/login.txt");
|
||||||
HeroLogic.getInstance().afterSet();
|
HeroLogic.getInstance().afterSet();
|
||||||
try {
|
try {
|
||||||
LOGGER.info("main->CoreApplication start...");
|
LOGGER.info("main->CoreApplication start...");
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,4 +31,6 @@ public class MongoKey {
|
||||||
public final static String arenaManager = "arenaManager";
|
public final static String arenaManager = "arenaManager";
|
||||||
|
|
||||||
public final static String secretBoxManager = "secretBoxManager";
|
public final static String secretBoxManager = "secretBoxManager";
|
||||||
|
|
||||||
|
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,7 +38,11 @@ public class User {
|
||||||
|
|
||||||
private ArenaManager arenaManager;
|
private ArenaManager arenaManager;
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
private SecretBoxManager secretBoxManager;
|
private SecretBoxManager secretBoxManager;
|
||||||
|
=======
|
||||||
|
private StoreManager storeManager;
|
||||||
|
>>>>>>> 08935d2c7e00852ea7f3cb4951827c00faac6902
|
||||||
|
|
||||||
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
//构造函数必须要声明,否则从mongodb读出来反编译成类不通过
|
||||||
public User(){
|
public User(){
|
||||||
|
@ -60,6 +64,7 @@ public class User {
|
||||||
this.activityManager = new ActivityManager();
|
this.activityManager = new ActivityManager();
|
||||||
this.arenaManager = new ArenaManager();
|
this.arenaManager = new ArenaManager();
|
||||||
this.secretBoxManager = new SecretBoxManager();
|
this.secretBoxManager = new SecretBoxManager();
|
||||||
|
this.storeManager = new StoreManager();
|
||||||
|
|
||||||
//綁定关系
|
//綁定关系
|
||||||
this.playerManager.init(id, MongoKey.playerManager);
|
this.playerManager.init(id, MongoKey.playerManager);
|
||||||
|
@ -76,6 +81,7 @@ public class User {
|
||||||
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.secretBoxManager.init(id, MongoKey.secretBoxManager);
|
this.secretBoxManager.init(id, MongoKey.secretBoxManager);
|
||||||
|
this.storeManager.init(id,MongoKey.storeManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -170,7 +176,12 @@ public class User {
|
||||||
return arenaManager;
|
return arenaManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
public SecretBoxManager getSecretBoxManager() {
|
public SecretBoxManager getSecretBoxManager() {
|
||||||
return secretBoxManager;
|
return secretBoxManager;
|
||||||
|
=======
|
||||||
|
public StoreManager getStoreManager() {
|
||||||
|
return storeManager;
|
||||||
|
>>>>>>> 08935d2c7e00852ea7f3cb4951827c00faac6902
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.setId(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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.jieling.network.server;
|
package com.ljsd.jieling.network.server;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import com.google.protobuf.GeneratedMessage;
|
import com.google.protobuf.GeneratedMessage;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import com.ljsd.GameApplication;
|
import com.ljsd.GameApplication;
|
||||||
|
@ -20,6 +21,7 @@ import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||||
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
||||||
import com.ljsd.jieling.network.session.ISession;
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
import com.ljsd.jieling.protocol.ProtocolsAbstract;
|
import com.ljsd.jieling.protocol.ProtocolsAbstract;
|
||||||
|
@ -31,7 +33,10 @@ import com.ljsd.jieling.util.TimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import sun.misc.BASE64Encoder;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -45,9 +50,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
public class ProtocolsManager implements ProtocolsAbstract {
|
public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolsManager.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolsManager.class);
|
||||||
|
|
||||||
private static ProtocolsManager instance = new ProtocolsManager();
|
private static ProtocolsManager instance = new ProtocolsManager();
|
||||||
|
public static PrintStream ps= null;// 创建文件输出流
|
||||||
private Map<Integer, BaseHandler> handlers = new HashMap<>();
|
private Map<Integer, BaseHandler> handlers = new HashMap<>();
|
||||||
|
|
||||||
private ProtocolsManager() {
|
private ProtocolsManager() {
|
||||||
|
@ -94,15 +98,18 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
}
|
}
|
||||||
iSession.setHeartBreatNums(heartBreatNums);
|
iSession.setHeartBreatNums(heartBreatNums);
|
||||||
}
|
}
|
||||||
|
Gson gson = new Gson();
|
||||||
@Override
|
@Override
|
||||||
public void processMessage(GameSession gameSession, Object obj) throws InvalidProtocolBufferException {
|
public void processMessage(GameSession gameSession, Object obj) {
|
||||||
|
|
||||||
if (!GameApplication.start) {
|
if (!GameApplication.start) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ISession session = (ISession) gameSession;
|
final ISession session = (ISession) gameSession;
|
||||||
PacketNetData packetNetData = new PacketNetData((byte[])obj);
|
PacketNetData packetNetData = new PacketNetData((byte[]) obj);
|
||||||
|
// int msgId = packetNetData.getMsgId();
|
||||||
|
// MessageTypeProto.MessageType messageType = MessageTypeProto.MessageType.valueOf(msgId);
|
||||||
|
// ps.println(messageType + "=" + gson.toJson(obj));
|
||||||
if (packetNetData.getMsgId()==1000){
|
if (packetNetData.getMsgId()==1000){
|
||||||
dealHeartBeat(session);
|
dealHeartBeat(session);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2,6 +2,8 @@ package network.client;
|
||||||
|
|
||||||
import com.ljsd.jieling.netty.cocdex.ByteBufDecoder;
|
import com.ljsd.jieling.netty.cocdex.ByteBufDecoder;
|
||||||
import com.ljsd.jieling.netty.cocdex.ByteBufEncoder;
|
import com.ljsd.jieling.netty.cocdex.ByteBufEncoder;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.TeaDecoder;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.TeaEncoder;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
@ -17,8 +19,8 @@ public class NettyTCPClientInitializer extends ChannelInitializer<SocketChannel>
|
||||||
protected void initChannel(SocketChannel ch) throws Exception {
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
|
|
||||||
ChannelPipeline p = ch.pipeline();
|
ChannelPipeline p = ch.pipeline();
|
||||||
p.addLast(new ByteBufDecoder());
|
p.addLast(new TeaDecoder());
|
||||||
p.addLast(new ByteBufEncoder());
|
p.addLast(new TeaEncoder());
|
||||||
p.addLast(new NettyTCPClientHandler());
|
p.addLast(new NettyTCPClientHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue