同步数据
parent
d6079d0964
commit
134c779373
|
@ -29,7 +29,8 @@ dependencies {
|
||||||
compile group: 'com.googlecode.protobuf-java-format', name: 'protobuf-java-format', version: '1.2'
|
compile group: 'com.googlecode.protobuf-java-format', name: 'protobuf-java-format', version: '1.2'
|
||||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
|
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
|
||||||
compile("org.luaj:luaj-jse:3.0.1")
|
compile("org.luaj:luaj-jse:3.0.1")
|
||||||
compile("org.apache.thrift:libthrift:0.9.2");
|
compile("org.apache.thrift:libthrift:0.9.2")
|
||||||
|
compile("com.alibaba:fastjson:1.2.47")
|
||||||
compile files("${System.properties['java.home']}/../lib/tools.jar")
|
compile files("${System.properties['java.home']}/../lib/tools.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.ljsd.jieling.config.reportData;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class DataMessageUtils {
|
||||||
|
|
||||||
|
static final BlockingQueue<Object> logQueue = new BlockingUniqueQueue<>();
|
||||||
|
static List<String> dataList = new CopyOnWriteArrayList<>();
|
||||||
|
//入队列
|
||||||
|
public static void addLogQueue(String info){
|
||||||
|
logQueue.offer(info);
|
||||||
|
}
|
||||||
|
//出队列
|
||||||
|
public static Object take(){
|
||||||
|
try {
|
||||||
|
return logQueue.take();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void manageData(Object take) {
|
||||||
|
List<String> sendDataList;
|
||||||
|
if(dataList.size() >= 10){
|
||||||
|
sendDataList = dataList;
|
||||||
|
dataList = new CopyOnWriteArrayList<>();
|
||||||
|
}else{
|
||||||
|
dataList.add(JSON.toJSONString(take));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
StringBuilder info = new StringBuilder("[");
|
||||||
|
for (int i =0 ; i < sendDataList.size() ; i++){
|
||||||
|
if (i <= (sendDataList.size() -1)){
|
||||||
|
info.append(sendDataList.get(i)).append(",");
|
||||||
|
}else{
|
||||||
|
info.append(sendDataList.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info.append("]");
|
||||||
|
System.out.println(info.toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
package com.ljsd.jieling.config.reportData;
|
|
||||||
|
|
||||||
public class LoginFlow {
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.ljsd.jieling.config.reportData;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class TlogThread implements Runnable {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
Object take = DataMessageUtils.take();
|
||||||
|
DataMessageUtils.manageData(take);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void startTlogThread(){
|
||||||
|
ExecutorService pool = Executors.newCachedThreadPool();
|
||||||
|
for (int i = 0; i <= 5 ; i++){
|
||||||
|
TlogThread myThread = new TlogThread();
|
||||||
|
pool.execute(myThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.ljsd.jieling.handler;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||||
|
import com.ljsd.jieling.logic.item.ItemLogic;
|
||||||
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
|
import com.ljsd.jieling.protocols.HeroInfoProto;
|
||||||
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
|
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RefreshItemNumHandler extends BaseHandler {
|
||||||
|
@Override
|
||||||
|
public MessageTypeProto.MessageType getMessageCode() {
|
||||||
|
return MessageTypeProto.MessageType.REFRESH_ITEM_NUM_REQUEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||||
|
PlayerInfoProto.RefreshItemNumRequest refreshItemNumRequest = PlayerInfoProto.RefreshItemNumRequest.parseFrom(netData.parseClientProtoNetData());
|
||||||
|
List<Integer> itemIdList = refreshItemNumRequest.getItemIdList();
|
||||||
|
ItemLogic.getInstance().refreshItemNum(iSession,itemIdList);
|
||||||
|
}
|
||||||
|
}
|
|
@ -257,8 +257,8 @@ public class MapManager extends MongoBase {
|
||||||
if (addValue != 0) {
|
if (addValue != 0) {
|
||||||
int curEnergy = MathUtils.setBetweenWithMax(itemNum + addValue, 0, playerInfoManager.getMaxStamina());
|
int curEnergy = MathUtils.setBetweenWithMax(itemNum + addValue, 0, playerInfoManager.getMaxStamina());
|
||||||
item.setItemNum(curEnergy > playerInfoManager.getMaxStamina() ? playerInfoManager.getMaxStamina() : curEnergy);
|
item.setItemNum(curEnergy > playerInfoManager.getMaxStamina() ? playerInfoManager.getMaxStamina() : curEnergy);
|
||||||
setLastUpdateEnergyTime(item, updateTime, lastUpdateEnergyTime);
|
|
||||||
}
|
}
|
||||||
|
setLastUpdateEnergyTime(item, updateTime, lastUpdateEnergyTime);
|
||||||
} else {
|
} else {
|
||||||
setLastUpdateEnergyTime(item, updateTime, lastUpdateEnergyTime);
|
setLastUpdateEnergyTime(item, updateTime, lastUpdateEnergyTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.ljsd.jieling.network.session.ISession;
|
||||||
import com.ljsd.jieling.protocols.CommonProto;
|
import com.ljsd.jieling.protocols.CommonProto;
|
||||||
import com.ljsd.jieling.protocols.FightInfoProto;
|
import com.ljsd.jieling.protocols.FightInfoProto;
|
||||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
|
import com.ljsd.jieling.util.CBean2Proto;
|
||||||
import com.ljsd.jieling.util.ItemUtil;
|
import com.ljsd.jieling.util.ItemUtil;
|
||||||
import com.ljsd.jieling.util.MessageUtil;
|
import com.ljsd.jieling.util.MessageUtil;
|
||||||
import com.ljsd.jieling.util.StringUtil;
|
import com.ljsd.jieling.util.StringUtil;
|
||||||
|
@ -104,6 +105,7 @@ public class SweepLogic {
|
||||||
LOGGER.info("sweepFight=>uid={},sweepTimes={},exp={}",uid,sweepTimes,sLevelDifficultyConfig.getExp());
|
LOGGER.info("sweepFight=>uid={},sweepTimes={},exp={}",uid,sweepTimes,sLevelDifficultyConfig.getExp());
|
||||||
FightInfoProto.SweepRightResponse.Builder builder = FightInfoProto.SweepRightResponse.newBuilder();
|
FightInfoProto.SweepRightResponse.Builder builder = FightInfoProto.SweepRightResponse.newBuilder();
|
||||||
builder.addAllDrop(dropList);
|
builder.addAllDrop(dropList);
|
||||||
|
builder.setItemInfo(CBean2Proto.getItemInfo(user.getItemManager().getItemMap().get(Global.STAMINA)));
|
||||||
levelDifficulty.setChallengeTimes(levelDifficulty.getChallengeTimes() +sweepTimes);
|
levelDifficulty.setChallengeTimes(levelDifficulty.getChallengeTimes() +sweepTimes);
|
||||||
user.getUserMissionManager().onGameEvent(user, GameEvent.STORY_FIGHT, fightId, 0,sweepTimes);
|
user.getUserMissionManager().onGameEvent(user, GameEvent.STORY_FIGHT, fightId, 0,sweepTimes);
|
||||||
MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
|
MessageUtil.sendMessage(session, 1, messageType.getNumber(), builder.build(), true);
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.ljsd.jieling.logic.item;
|
||||||
|
|
||||||
import com.ljsd.jieling.config.*;
|
import com.ljsd.jieling.config.*;
|
||||||
import com.ljsd.jieling.globals.BIReason;
|
import com.ljsd.jieling.globals.BIReason;
|
||||||
|
import com.ljsd.jieling.globals.Global;
|
||||||
|
import com.ljsd.jieling.handler.map.MapManager;
|
||||||
import com.ljsd.jieling.logic.dao.*;
|
import com.ljsd.jieling.logic.dao.*;
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||||
|
@ -14,6 +16,7 @@ import com.sun.org.apache.regexp.internal.RE;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -247,4 +250,36 @@ public class ItemLogic {
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步刷新道具数量
|
||||||
|
* @param iSession
|
||||||
|
* @param itemIdList
|
||||||
|
*/
|
||||||
|
public void refreshItemNum(ISession iSession, List<Integer> itemIdList) throws Exception {
|
||||||
|
int msgId = MessageTypeProto.MessageType.REFRESH_ITEM_NUM_RESPONSE_VALUE;
|
||||||
|
int uid = iSession.getUid();
|
||||||
|
User user = UserManager.getUser(uid);
|
||||||
|
Map<Integer, Item> itemMap = user.getItemManager().getItemMap();
|
||||||
|
List<Item> itemList = new ArrayList<>();
|
||||||
|
for (Integer itemId :itemIdList){
|
||||||
|
SItem sItem = SItem.getsItemMap().get(itemId);
|
||||||
|
if (sItem == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (itemId == Global.STAMINA){
|
||||||
|
MapManager.getEnergy(user);
|
||||||
|
itemList.add(itemMap.get(itemId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerInfoProto.RefreshItemNumResponse.Builder builder = PlayerInfoProto.RefreshItemNumResponse.newBuilder();
|
||||||
|
List<CommonProto.ItemInfo> itemInfos = new ArrayList<>();
|
||||||
|
if (itemList.size() != 0){
|
||||||
|
for (Item item : itemList){
|
||||||
|
itemInfos.add(CBean2Proto.getItemInfo(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.addAllItemInfo(itemInfos);
|
||||||
|
MessageUtil.sendMessage(iSession,1, msgId,builder.build(),true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
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();
|
int msgId = packetNetData.getMsgId();
|
||||||
LOGGER.info("uid={},msgId={},index={}",packetNetData.getUserId(),msgId,packetNetData.getIndex());
|
// LOGGER.info("uid={},msgId={},index={}",packetNetData.getUserId(),msgId,packetNetData.getIndex());
|
||||||
// MessageTypeProto.MessageType messageType = MessageTypeProto.MessageType.valueOf(msgId);
|
// MessageTypeProto.MessageType messageType = MessageTypeProto.MessageType.valueOf(msgId);
|
||||||
// FileWriter fw = null;
|
// FileWriter fw = null;
|
||||||
// if (!gameMessageForLogin.containsKey(messageType)){
|
// if (!gameMessageForLogin.containsKey(messageType)){
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.jieling.util;
|
package com.ljsd.jieling.util;
|
||||||
|
|
||||||
|
import com.ljsd.jieling.config.SGameSetting;
|
||||||
import com.ljsd.jieling.config.SMonsterConfig;
|
import com.ljsd.jieling.config.SMonsterConfig;
|
||||||
import com.ljsd.jieling.handler.map.Cell;
|
import com.ljsd.jieling.handler.map.Cell;
|
||||||
import com.ljsd.jieling.handler.map.MapManager;
|
import com.ljsd.jieling.handler.map.MapManager;
|
||||||
|
@ -317,4 +318,13 @@ public class CBean2Proto {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CommonProto.ItemInfo getItemInfo(Item item) {
|
||||||
|
CommonProto.ItemInfo.Builder builder = CommonProto.ItemInfo.newBuilder();
|
||||||
|
builder.setTemplateId(item.getItemId());
|
||||||
|
builder.setOverlap(item.getItemNum());
|
||||||
|
int[] energyRecoverSpeed = SGameSetting.getGameSetting().getEnergyRecoverSpeed();
|
||||||
|
builder.setNextRefreshTime(item.getEndingTime() + energyRecoverSpeed[1]*60);
|
||||||
|
System.out.println("===============" +(item.getEndingTime() + energyRecoverSpeed[1]*60));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue