逍遥游逻辑

back_recharge
lvxinran 2020-10-16 14:19:16 +08:00
parent 10011c4027
commit 663b3c9723
25 changed files with 1522 additions and 18 deletions

View File

@ -147,6 +147,9 @@ public interface BIReason {
int SITUATION_CHALLENGE_REWARD = 81;//轩辕宝镜获得
int HERO_CHANGE= 82;//抽卡
int JOURNEY_COMMON_REWARD = 83;//逍遥游基础奖励
int JOURNEY_FIGHT_REWARD = 84;//逍遥游击杀boss奖励
int JOURNEY_RANDOM_REWARD = 85;//逍遥游转盘奖励
int ADVENTURE_UPLEVEL_CONSUME = 1000;//秘境升级
int SECRETBOX_CONSUME = 1001;//秘盒抽卡
@ -266,6 +269,7 @@ public interface BIReason {
int DAILY_SCORE_CONSUME = 1063;//删除日常任务积分
int EQUIP_WEAR_CONSUME = 1064;
int GUILD_CHALLENGE_BUFF_BUY_CONSUME = 1065;//公会副本购买buff
int JOURNEY_FIGHT_CONCUME = 1066;//逍遥游攻击boss消耗

View File

@ -24,6 +24,7 @@ public interface GlobalGm {
int TREASURE_FINISH = 20;//戒灵秘宝一键完成
int FULL_OF = 21; //一键全满
int EXPEDITION_SCORE = 23;//天宫秘宝积分
int JOURNEY_GM = 24;//逍遥游GM操作
// int TECNOLOGY_MAX = 21;//科技树一键满级
// int POKEMAN_MAX = 22;//一键获得所有满级异妖

View File

@ -14,7 +14,7 @@ import com.ljsd.jieling.globals.Global;
import com.ljsd.jieling.globals.GlobalGm;
import com.ljsd.jieling.globals.GlobalItemType;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.map.*;
import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.fight.CombatLogic;
@ -34,6 +34,7 @@ import config.*;
import manager.STableManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import util.MathUtils;
import util.StringUtil;
import util.TimeUtils;
@ -44,6 +45,7 @@ import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Component
public class GMRequestHandler extends BaseHandler{
@ -373,6 +375,55 @@ public class GMRequestHandler extends BaseHandler{
case GlobalGm.EXPEDITION_SCORE:
cUser.getExpeditionManager().addScore(prarm2);
break;
case GlobalGm.JOURNEY_GM:
prarm2 = Integer.parseInt(commandArray[2]);
prarm3 = "";
if(commandArray.length>3){
prarm3 = commandArray[3];
}
PathInfo pathInfo = cUser.getMapManager().getJourneyInfo().get(prarm2);
SFreeTravel travelConfig = SFreeTravel.journeyMapByMapId.get(prarm2);
switch (prarm1){
case 1:
int bossId;
if(!prarm3.isEmpty()){
bossId = Integer.valueOf(prarm3);
}else{
int[] freeTravelBoss = travelConfig.getFreeTravelBoss();
bossId = MathUtils.randomFromArray(freeTravelBoss);
}
int[] freeTravelBossReward = travelConfig.getFreeTravelBossReward();
int bossReward = MathUtils.randomFromArray(freeTravelBossReward);
JourneyMonster monster = new JourneyMonster(bossId, (int)((TimeUtils.now()+TimeUtils.HOUR*2)/1000),0,bossReward);
Map<Integer, List<Integer>> monsterHpByGroup = MonsterUtil.getMonsterHpByGroup(bossId);
List<Integer> list = monsterHpByGroup.get(0);
Map<Integer,Integer> hpMap = new HashMap<>();
for(int i = 1;i<=list.size();i++){
hpMap.put(i,list.get(i-1));
}
monster.setRemainHp(hpMap);
pathInfo.addMonster(TimeUtils.nowInt(),monster);
break;
case 2:
if(pathInfo.getRandomReward()==null){
//初始化转盘数组
pathInfo.setRandomReward(JourneyMap.getInstance().initRandom(travelConfig));
}
pathInfo.setRamainRandomAmount(pathInfo.getRamainRandomAmount()+1);
pathInfo.setRemainRandomTime((int)((TimeUtils.now()+TimeUtils.HOUR*2)/1000));
break;
case 3:
List<SFreeTravelStore> sFreeTravelStores = SFreeTravelStore.storeMapByMapId.get(prarm2);
int[] goodsArray = new int[sFreeTravelStores.size()];
for(int i = 0 ; i <sFreeTravelStores.size();i++){
goodsArray[i] = sFreeTravelStores.get(i).getID();
}
int goodsId = MathUtils.randomFromArray(goodsArray);
pathInfo.addGoods(TimeUtils.nowInt(),new JourneyGoods(goodsId,(int)((TimeUtils.now()+TimeUtils.HOUR*2)/1000)));
break;
}
cUser.getMapManager().updateJourneyInfoByMapId(prarm2,pathInfo);
break;
default:
break;
}

View File

@ -15,6 +15,13 @@ public class EventType {
public static final int hinder = 8;
public static final int towerBuff = 9;
public static final int suddenlyBoss = 11; //精英怪
public static final int reward = 23; //逍遥游宝箱
public static final int random = 24; //逍遥游转盘
public static final int journeyBoss = 25; //逍遥游boss
public static final int journeyStore = 26; //逍遥游招募神将
public static final int diceEvent = 27; //双倍骰子
public static final int doubleReward = 28; //双倍奖励
public static final int journeyFinal = 29; //终极大奖
/**
*

View File

@ -0,0 +1,34 @@
package com.ljsd.jieling.handler.map;
/**
* @author lvxinran
* @date 2020/10/15
* @discribe
*/
public class JourneyGoods {
private int goodsId;
private int goodsRemainTime;
public int getGoodsId() {
return goodsId;
}
public void setGoodsId(int goodsId) {
this.goodsId = goodsId;
}
public int getGoodsRemainTime() {
return goodsRemainTime;
}
public void setGoodsRemainTime(int goodsRemainTime) {
this.goodsRemainTime = goodsRemainTime;
}
public JourneyGoods(int goodsId, int goodsRemainTime) {
this.goodsId = goodsId;
this.goodsRemainTime = goodsRemainTime;
}
}

View File

@ -0,0 +1,555 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.fight.FightDispatcher;
import com.ljsd.jieling.logic.fight.GameFightType;
import com.ljsd.jieling.logic.fight.PVEFightEvent;
import com.ljsd.jieling.logic.fight.result.FightResult;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil;
import com.ljsd.jieling.util.MonsterUtil;
import config.MapPointConfig;
import config.SCMap;
import config.SFreeTravel;
import config.SFreeTravelStore;
import manager.STableManager;
import util.CellUtil;
import util.MathUtils;
import util.TimeUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author lvxinran
* @date 2020/10/13
* @discribe
*/
public class JourneyMap {
public static JourneyMap getInstance() {
return Instance.instance;
}
public static class Instance {
public final static JourneyMap instance = new JourneyMap();
}
public static void init(User user,int mapId){
Path[] paths ;
Map<Integer,SCMap> scMap = SCMap.sCMap.get(mapId);
Map<Integer, SCMap> point = new HashMap<>();
for(Map.Entry<Integer,SCMap> entry:scMap.entrySet()){
if(entry.getValue().getLocation().length>1||entry.getValue().getLocation()[0]==0){
continue;
}
point.put(entry.getValue().getLocation()[0],entry.getValue());
}
paths = new Path[point.size()];
Map<Integer, List<SCMap>> randomPoint = new HashMap<>();
for(Map.Entry<Integer,SCMap> entry:point.entrySet()){
int[][] groups = entry.getValue().getGroups();
for(int[] cell:groups){
int cellId = CellUtil.xy2Pos(cell[0], cell[1]);
if(entry.getValue().getIsMustAppear()==1) {
paths[entry.getValue().getLocation()[0]-1] = new Path(cellId,entry.getValue().getLocation()[0],entry.getValue().getEvent());
}else{
if(!randomPoint.containsKey(entry.getValue().getEvent())){
randomPoint.put(entry.getValue().getEvent(),new ArrayList<>());
}
randomPoint.get(entry.getValue().getEvent()).add(entry.getValue());
}
}
}
int[][] tempArray = SFreeTravel.journeyMapByMapId.get(mapId).getAdventureNumber();
SFreeTravel travelConfig = SFreeTravel.journeyMapByMapId.get(mapId);
for(int[] array:tempArray){
if(!randomPoint.containsKey(array[0])){
continue;
}
int num = MathUtils.random(array[1], array[2]);
int[] randomArray = new int[randomPoint.get(array[0]).size()];
for(int i = 0 ; i < randomArray.length;i++) {
randomArray[i] = randomPoint.get(array[0]).get(i).getLocation()[0];
}
List<Integer> randomLocation = MathUtils.randomForOneArray(randomArray, num);
randomPoint.get(array[0]).forEach(p->{
if(randomLocation.contains(p.getLocation()[0])){
paths[p.getLocation()[0]-1] = new Path(CellUtil.xy2Pos(p.getGroups()[0][0], p.getGroups()[0][1]),p.getLocation()[0],p.getEvent());
if(MapPointConfig.getScMapEventMap().get(p.getEvent()).getStyle()==EventType.reward){
paths[p.getLocation()[0]-1].setRewardId(getOneReward(travelConfig));
};
}else{
paths[p.getLocation()[0]-1] = new Path(CellUtil.xy2Pos(p.getGroups()[0][0], p.getGroups()[0][1]),p.getLocation()[0],0);
}
});
}
PathInfo pathInfo = user.getMapManager().getJourneyInfo().get(mapId);
if(pathInfo ==null) {
pathInfo = new PathInfo();
}
pathInfo.setDiceNum(1);
pathInfo.setCurrentPath(1);
pathInfo.setAllPathInfo(paths);
user.getMapManager().updateJourneyInfoByMapId(mapId,pathInfo);
System.out.println("初始化逍遥游完成");
}
/**
*
* @param session
* @param messageType
*/
public void getAllInfo(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
MapInfoProto.JourneyGetInfoResponse.Builder response = MapInfoProto.JourneyGetInfoResponse.newBuilder();
journeyInfo.forEach((k,v)->{
CommonProto.JourneyInfo info = CommonProto.JourneyInfo.newBuilder()
.setMapId(k)
.setProcess(v.getCurrentPath()*100/v.getAllPathInfo().length).build();
response.addInfos(info);
});
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
/**
*
* @param session
* @param mapId
* @param messageType
* @throws Exception
*/
public void getOneJourneyInfo(ISession session,int mapId, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
user.getMapManager().setCurrentJourneyId(mapId);
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
if(!journeyInfo.containsKey(mapId)){
init(user,mapId);
}
MapInfoProto.JourneyGetOneInfoResponse.Builder response = MapInfoProto.JourneyGetOneInfoResponse.newBuilder();
PathInfo pathInfo = journeyInfo.get(mapId);
if(pathInfo.getCurrentPath()>=pathInfo.getAllPathInfo().length){
init(user,mapId);
}
//地图格子信息
Arrays.stream(pathInfo.getAllPathInfo()).forEach(path->{
CommonProto.JourneyCell cell = CommonProto.JourneyCell.newBuilder()
.setCellId(path.getCellId())
.setCellIndex(path.getCellIndex())
.setPointId(path.getMapPointId())
.setRewardId(path.getRewardId())
.build();
response.addCell(cell);
});
response.setLocation(pathInfo.getCurrentPath());//当前位置
response.setDiceNum(1);//当前骰子个数
//怪物信息
if(pathInfo.getMonsterMap()!=null&&pathInfo.getMonsterMap().size()>0){
pathInfo.getMonsterMap().forEach((k,v)->{
Map<Integer, Integer> remainHp = v.getRemainHp();
long allHp = 0;
Collection<Integer> values = remainHp.values();
for(int value:values){
allHp+=value;
}
CommonProto.JourneyMonsterInfo monsterInfo = CommonProto.JourneyMonsterInfo.newBuilder()
.setMonsterHp(allHp)
.setMonsterId(v.getMonsterId())
.setMonsterIndex(k)
.setRemainTime(v.getRemainTime())
.setAttackNum(v.getAttackNum())
.setRewardShow(v.getReward())
.build();
response.addMonsterInfo(monsterInfo);
});
}
//转盘信息
if(pathInfo.getRandomReward()!=null&&pathInfo.getRandomReward().length>0&&pathInfo.getRemainRandomTime()>TimeUtils.nowInt()&&pathInfo.getRamainRandomAmount()>0){
List<Integer> rewardList = Arrays.stream(pathInfo.getRandomReward()).boxed().collect(Collectors.toList());
response.addAllRandomItem(rewardList);
response.setRandomTime(pathInfo.getRemainRandomTime());
response.setRandomNum(pathInfo.getRamainRandomAmount());
}
if(!pathInfo.getGoodsMap().isEmpty()){
for(Map.Entry<Integer,JourneyGoods> entry:pathInfo.getGoodsMap().entrySet()){
CommonProto.JourneyGoodsInfo info = CommonProto.JourneyGoodsInfo.newBuilder()
.setGoodsId(entry.getValue().getGoodsId())
.setRemainTime(entry.getValue().getGoodsRemainTime())
.setGoodsIndex(entry.getKey()).build();
response.addGoodsInfo(info);
}
}
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
/**
*
* @param session
* @param messageType
*/
public void doJourney(ISession session,int mapId, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
if(mapId!=user.getMapManager().getCurrentJourneyId()){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
PathInfo pathInfo = journeyInfo.get(mapId);
if(pathInfo.getCurrentPath()>=pathInfo.getAllPathInfo().length){
throw new ErrorCodeException(ErrorCode.DAILY_ALREADY_PASS);
}
SFreeTravel travelConfig = SFreeTravel.journeyMapByMapId.get(mapId);
int diceNum = pathInfo.getDiceNum();
List<Integer> randomNum = new ArrayList<>();
if(diceNum==0||diceNum==1){
randomNum.add(MathUtils.random(1, 6));
}else if(diceNum==2){
randomNum.add(MathUtils.random(1, 6));
randomNum.add(MathUtils.random(1, 6));
}else{
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
//骰子总点数
int diceAmount = 0;
for(int one:randomNum){
diceAmount+=one;
}
//取总点数和最大格子数,算出走的步数
diceAmount =Math.min(diceAmount,pathInfo.getAllPathInfo().length-pathInfo.getCurrentPath());
if(diceAmount==0){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
pathInfo.setCurrentPath(pathInfo.getCurrentPath()+diceAmount);
Path arrivePath = pathInfo.getAllPathInfo()[pathInfo.getCurrentPath() - 1];
int mapPointId = arrivePath.getMapPointId();
MapInfoProto.JourneyDoResponse.Builder builder = MapInfoProto.JourneyDoResponse.newBuilder().addAllPointes(randomNum);
//基础奖励
int common = travelConfig.getCommonReward();
int[] commonRewardArray = new int[diceAmount];
Arrays.stream(commonRewardArray).forEach(n->n=common);
CommonProto.Drop.Builder drop = ItemUtil.drop(user,commonRewardArray,1,0, BIReason.JOURNEY_COMMON_REWARD);
//地图点判断
if(mapPointId==0){
builder.setPathType(0);
}else{
int pathType = 0;
MapPointConfig config = MapPointConfig.getScMapEventMap().get(mapPointId);
switch (config.getStyle()){
case EventType.reward:
//奖励节点完成
commonRewardArray = new int[diceAmount+1];
Arrays.stream(commonRewardArray).forEach(n->n=common);
// int[][] treasureChest = travelConfig.getTreasureChest();
// int[] reward = MathUtils.randomFromWeightWithTaking(treasureChest, 1);
// commonRewardArray[commonRewardArray.length-1] = reward[0];
commonRewardArray[commonRewardArray.length-1] = arrivePath.getRewardId();
drop = ItemUtil.drop(user,commonRewardArray,1,0, BIReason.JOURNEY_COMMON_REWARD);
pathType = 1;
break;
case EventType.random:
//转盘节点添加
if(pathInfo.getRandomReward()==null){
//初始化转盘数组
pathInfo.setRandomReward(initRandom(travelConfig));
}
pathInfo.setRamainRandomAmount(pathInfo.getRamainRandomAmount()+1);
pathInfo.setRemainRandomTime((int)((TimeUtils.now()+TimeUtils.HOUR*2)/1000));
List<Integer> rewardList = Arrays.stream(pathInfo.getRandomReward()).boxed().collect(Collectors.toList());
builder.addAllRandom(rewardList);
builder.setOverTime(pathInfo.getRemainRandomTime());
pathType = 6;
break;
case EventType.journeyBoss:
//怪物节点添加
int[] freeTravelBoss = travelConfig.getFreeTravelBoss();
int[] freeTravelBossReward = travelConfig.getFreeTravelBossReward();
int bossId = MathUtils.randomFromArray(freeTravelBoss);
int bossReward = MathUtils.randomFromArray(freeTravelBossReward);
JourneyMonster monster = new JourneyMonster(bossId, (int)((TimeUtils.now()+TimeUtils.HOUR*2)/1000),0,bossReward);
Map<Integer, List<Integer>> monsterHpByGroup = MonsterUtil.getMonsterHpByGroup(bossId);
List<Integer> list = monsterHpByGroup.get(0);
Map<Integer,Integer> hpMap = new HashMap<>();
for(int i = 1;i<=list.size();i++){
hpMap.put(i,list.get(i-1));
}
monster.setRemainHp(hpMap);
long allHp =0;
for(Map.Entry<Integer,Integer> hp:monster.getRemainHp().entrySet()){
allHp+=hp.getValue();
}
pathInfo.addMonster(TimeUtils.nowInt(),monster);
builder.setMonster(CommonProto.JourneyMonsterInfo.newBuilder().setAttackNum(monster.getAttackNum())
.setMonsterHp(allHp)
.setMonsterId(monster.getMonsterId())
.setMonsterIndex(pathInfo.getMonsterMap().size())
.setRewardShow(monster.getReward()));
builder.setOverTime(monster.getRemainTime());
pathType = 5;
break;
case EventType.journeyStore:
List<SFreeTravelStore> sFreeTravelStores = SFreeTravelStore.storeMapByMapId.get(mapId);
int[] goodsArray = new int[sFreeTravelStores.size()];
for(int i = 0 ; i <sFreeTravelStores.size();i++){
goodsArray[i] = sFreeTravelStores.get(i).getID();
}
int goodsId = MathUtils.randomFromArray(goodsArray);
JourneyGoods journeyGoods = new JourneyGoods(goodsId, (int) ((TimeUtils.now() + TimeUtils.HOUR * 2) / 1000));
int index = TimeUtils.nowInt();
pathInfo.addGoods(index,journeyGoods);
builder.setGoodsInfo(CommonProto.JourneyGoodsInfo.newBuilder().setGoodsId(goodsId).setGoodsIndex(index).setRemainTime(journeyGoods.getGoodsRemainTime()).build());
pathType = 4;
break;
case EventType.diceEvent:
pathType = 3;
pathInfo.setDiceNum(2);
break;
case EventType.doubleReward:
//倍数
int mutiNum = config.getInitialEventId();
List<CommonProto.Item> itemlistList = drop.getItemlistList();
itemlistList.forEach(item->{
item.toBuilder().setItemNum(item.getItemNum()*mutiNum).build();
});
pathType = 2;
break;
case EventType.journeyFinal:
pathType = 1;
commonRewardArray = new int[diceAmount+1];
Arrays.stream(commonRewardArray).forEach(n->n=common);
int finalReward = travelConfig.getFinalReward();
commonRewardArray[commonRewardArray.length-1] = finalReward;
drop = ItemUtil.drop(user,commonRewardArray,1,0, BIReason.JOURNEY_COMMON_REWARD);
break;
default:
break;
}
builder.setPathType(pathType);
}
builder.setDrop(drop);
arrivePath.setMapPointId(0);
user.getMapManager().updateJourneyInfoByMapId(mapId,pathInfo);
MessageUtil.sendMessage(session,1,messageType.getNumber(),builder.build(),true);
}
/**
*
*/
private static int getOneReward(SFreeTravel travelConfig){
int[][] treasureChest = travelConfig.getTreasureChest();
int[] reward = MathUtils.randomFromWeightWithTaking(treasureChest, 1);
return reward[0];
}
/**
* boss
* @param session
* @param mapId
* @param bossIndex
* @param messageType
*/
public void fightToBoss(ISession session, int mapId, int bossIndex, MessageTypeProto.MessageType messageType) throws Exception{
User user = UserManager.getUser(session.getUid());
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
if(user.getMapManager().getCurrentJourneyId()!=mapId||!journeyInfo.containsKey(mapId)){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
PathInfo pathInfo = journeyInfo.get(mapId);
JourneyMonster monster = pathInfo.getMonsterMap().get(bossIndex);
if(monster==null||monster.getRemainTime()<TimeUtils.nowInt()){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
SFreeTravel freeTravel = SFreeTravel.journeyMapByMapId.get(mapId);
int[] bossConsume;
if(monster.getAttackNum()<freeTravel.getBossConsume().length){
bossConsume = freeTravel.getBossConsume()[monster.getAttackNum()];
}else{
bossConsume = freeTravel.getBossConsume()[freeTravel.getBossConsume().length-1];
}
Map<Integer,Integer> map = new HashMap<>();
map.put(bossConsume[0], bossConsume[1]);
boolean b = ItemUtil.checkCost(user, map);
if(!b){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
PVEFightEvent pveFightEvent = new PVEFightEvent(session.getUid(), GlobalsDef.FORMATION_NORMAL, 10, "", GameFightType.MapFastFight, monster.getMonsterId(), 3);
FightResult fightResult = FightDispatcher.dispatcher(pveFightEvent);
int[] checkResult = fightResult.getCheckResult();
Map<Integer, Integer> remainHp = monster.getRemainHp();
List<Integer> hps = new ArrayList<>(remainHp.values());
pveFightEvent.setMonsterRemainHp(hps);
MapInfoProto.JourneyFightResponse.Builder response =MapInfoProto.JourneyFightResponse.newBuilder();
if(checkResult[0]==1){
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[]{monster.getReward()}, 1, 0, BIReason.JOURNEY_FIGHT_REWARD);
response.setDrop(drop);
pathInfo.removeMonster(bossIndex);
}else if(checkResult[0]==0){
for(int i = 2;i<checkResult.length;i++){
remainHp.put(i-1,checkResult[i]);
}
monster.setRemainHp(remainHp);
CommonProto.JourneyMonsterInfo monsterInfo = CommonProto.JourneyMonsterInfo.newBuilder()
.setAttackNum(monster.getAttackNum()+1)
.setRemainTime(monster.getRemainTime())
.setMonsterIndex(bossIndex)
.setMonsterId(monster.getMonsterId())
.setRewardShow(monster.getReward()).build();
response.setMonster(monsterInfo);
}else{
throw new ErrorCodeException(ErrorCode.FIGHT_EXCEPTION);
}
ItemUtil.itemCost(user,new int[][]{bossConsume},BIReason.JOURNEY_FIGHT_CONCUME,1);
response.setFightData(fightResult.getFightData());
monster.setAttackNum(monster.getAttackNum()+1);
user.getMapManager().updateJourneyInfoByMapId(mapId, pathInfo);
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
/**
*
* @param session
* @param messageType
*/
public void random(ISession session,int mapId, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
if(user.getMapManager().getCurrentJourneyId()!=mapId||!journeyInfo.containsKey(mapId)){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
PathInfo pathInfo = journeyInfo.get(mapId);
if(pathInfo.getRandomReward()==null||pathInfo.getRamainRandomAmount()<1||pathInfo.getRemainRandomTime()<TimeUtils.nowInt()){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
MapInfoProto.JourneyRandomResponse.Builder response = MapInfoProto.JourneyRandomResponse.newBuilder();
SFreeTravel freeTravel = SFreeTravel.journeyMapByMapId.get(mapId);
int[] turntableProbability = freeTravel.getTurntableProbability();
int[][] randomArray = new int[turntableProbability.length][];
for(int i = 0 ;i<randomArray.length;i++){
int[] tempArray = new int[2];
tempArray[0] = i+1;
tempArray[1] = turntableProbability[i];
randomArray[i] =tempArray;
}
pathInfo.setRamainRandomAmount(pathInfo.getRamainRandomAmount()-1);
int position = MathUtils.randomFromWeight(randomArray);
int reward = pathInfo.getRandomReward()[position - 1];
//判断是否还有次数
if(pathInfo.getRamainRandomAmount()!=0) {
response.setCount(pathInfo.getRamainRandomAmount());
int[] nextRandom = initRandom(freeTravel);
pathInfo.setRandomReward(nextRandom);
List<Integer> rewardList = Arrays.stream(nextRandom).boxed().collect(Collectors.toList());
response.addAllNextRandom(rewardList);
}else {
pathInfo.setRandomReward(null);
}
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[]{reward}, 1, 0, BIReason.JOURNEY_RANDOM_REWARD);
response.setDrop(drop);
response.setLocation(position);
user.getMapManager().updateJourneyInfoByMapId(mapId,pathInfo);
MessageUtil.sendMessage(session,1,messageType.getNumber(),response.build(),true);
}
//初始化一个转盘
public int[] initRandom(SFreeTravel travelConfig){
int[] rewardArray = new int[12];
int[][] turntablePosition = travelConfig.getTurntablePosition();
int[][] turntableGoods = travelConfig.getTurntableGoods();
for(int i = 0 ; i< turntablePosition.length;i++){
int length = turntablePosition[i].length;
int[] turntableGood = turntableGoods[i];
List<Integer> randomGoods = MathUtils.randomForOneArray(turntableGood,length);
for(int j = 0 ; j<length;j++){
rewardArray[turntablePosition[i][j]-1] = randomGoods.get(j);
}
}
return rewardArray;
}
/**
*
* @param session
* @param messageType
*/
public void buyJourney(ISession session,int mapId,int index, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
Map<Integer, PathInfo> journeyInfo = user.getMapManager().getJourneyInfo();
if(user.getMapManager().getCurrentJourneyId()!=mapId||!journeyInfo.containsKey(mapId)){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
PathInfo pathInfo = journeyInfo.get(mapId);
JourneyGoods journeyGoods = pathInfo.getGoodsMap().get(index);
if(journeyGoods==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
SFreeTravelStore freeTravelStore = STableManager.getConfig(SFreeTravelStore.class).get(journeyGoods.getGoodsId());
int[] cost = freeTravelStore.getCost();
if(!ItemUtil.itemCost(user,new int[][]{cost},BIReason.STORE_BUY_ITEM,1)){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{freeTravelStore.getGoods()},BIReason.STORE_BUY_ITEM);
pathInfo.removeGoods(index);
user.getMapManager().updateJourneyInfoByMapId(mapId,pathInfo);
MapInfoProto.JourneyBuyResponse response = MapInfoProto.JourneyBuyResponse.newBuilder().setDrop(drop).build();
MessageUtil.sendMessage(session,1,messageType.getNumber(),response,true);
}
}

View File

@ -0,0 +1,69 @@
package com.ljsd.jieling.handler.map;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/10/13
* @discribe
*/
public class JourneyMonster {
private int monsterId;
private int remainTime;
private int attackNum;
private int reward;
private Map<Integer,Integer> remainHp = new HashMap<>(6);
public int getMonsterId() {
return monsterId;
}
public void setMonsterId(int monsterId) {
this.monsterId = monsterId;
}
public int getRemainTime() {
return remainTime;
}
public void setRemainTime(int remainTime) {
this.remainTime = remainTime;
}
public int getAttackNum() {
return attackNum;
}
public void setAttackNum(int attackNum) {
this.attackNum = attackNum;
}
public int getReward() {
return reward;
}
public void setReward(int reward) {
this.reward = reward;
}
public Map<Integer, Integer> getRemainHp() {
return remainHp;
}
public void setRemainHp(Map<Integer, Integer> remainHp) {
this.remainHp = remainHp;
}
public JourneyMonster(int monsterId, int remainTime, int attackNum, int reward) {
this.monsterId = monsterId;
this.remainTime = remainTime;
this.attackNum = attackNum;
this.reward = reward;
}
}

View File

@ -113,6 +113,10 @@ public class MapManager extends MongoBase {
private int curMapType;
private Map<Integer,PathInfo> journeyInfo = new HashMap<>();
private int currentJourneyId;
public MapManager() {
this.setRootCollection(User._COLLECTION_NAME);
}
@ -837,6 +841,29 @@ public class MapManager extends MongoBase {
updateString("curMapType",curMapType);
}
public Map<Integer, PathInfo> getJourneyInfo() {
return journeyInfo;
}
public void setJourneyInfo(Map<Integer, PathInfo> journeyInfo) {
this.journeyInfo = journeyInfo;
updateString("journeyInfo",journeyInfo);
}
public void updateJourneyInfoByMapId(int mapId ,PathInfo info){
journeyInfo.put(mapId,info);
updateString("journeyInfo",journeyInfo);
}
public int getCurrentJourneyId() {
return currentJourneyId;
}
public void setCurrentJourneyId(int currentJourneyId) {
this.currentJourneyId = currentJourneyId;
updateString("currentJourneyId",currentJourneyId);
}
}

View File

@ -0,0 +1,52 @@
package com.ljsd.jieling.handler.map;
/**
* @author lvxinran
* @date 2020/10/30
* @discribe
*/
public class Path {
private int cellId;
private int cellIndex;
private int mapPointId;
private int rewardId;
public Path(int cellId, int cellIndex, int mapPointId) {
this.cellId = cellId;
this.cellIndex = cellIndex;
this.mapPointId = mapPointId;
}
public int getCellId() {
return cellId;
}
public void setCellId(int cellId) {
this.cellId = cellId;
}
public int getCellIndex() {
return cellIndex;
}
public void setCellIndex(int cellIndex) {
this.cellIndex = cellIndex;
}
public int getMapPointId() {
return mapPointId;
}
public void setMapPointId(int mapPointId) {
this.mapPointId = mapPointId;
}
public int getRewardId() {
return rewardId;
}
public void setRewardId(int rewardId) {
this.rewardId = rewardId;
}
}

View File

@ -0,0 +1,106 @@
package com.ljsd.jieling.handler.map;
import util.TimeUtils;
import java.util.HashMap;
import java.util.Map;
/**
* @author lvxinran
* @date 2020/10/30
* @discribe
*/
public class PathInfo {
private Path[] allPathInfo;
private int currentPath;
private Map<Integer,JourneyMonster> monsterMap = new HashMap<>();
private Map<Integer,JourneyGoods> goodsMap = new HashMap<>();
private int diceNum;
private int[] randomReward;
private int ramainRandomAmount;
private int remainRandomTime;
public int getDiceNum() {
return diceNum;
}
public void setDiceNum(int diceNum) {
this.diceNum = diceNum;
}
public Path[] getAllPathInfo() {
return allPathInfo;
}
public void setAllPathInfo(Path[] allPathInfo) {
this.allPathInfo = allPathInfo;
}
public int getCurrentPath() {
return currentPath;
}
public void setCurrentPath(int currentPath) {
this.currentPath = currentPath;
}
public Map<Integer, JourneyMonster> getMonsterMap() {
return monsterMap;
}
public void setMonsterMap(Map<Integer, JourneyMonster> monsterMap) {
this.monsterMap = monsterMap;
}
public void addMonster(int bossIndex,JourneyMonster monster){
monsterMap.put(bossIndex,monster);
}
public void removeMonster(int bossIndex){
monsterMap.remove(bossIndex);
}
public int[] getRandomReward() {
return randomReward;
}
public void setRandomReward(int[] randomReward) {
this.randomReward = randomReward;
}
public int getRamainRandomAmount() {
return ramainRandomAmount;
}
public void setRamainRandomAmount(int ramainRandomAmount) {
this.ramainRandomAmount = ramainRandomAmount;
}
public int getRemainRandomTime() {
return remainRandomTime;
}
public void setRemainRandomTime(int remainRandomTime) {
this.remainRandomTime = remainRandomTime;
}
public Map<Integer, JourneyGoods> getGoodsMap() {
return goodsMap;
}
public void addGoods(int goodsIndex,JourneyGoods journeyGoods){
goodsMap.put(goodsIndex,journeyGoods);
}
public void removeGoods(int goodsIndex){
goodsMap.remove(goodsIndex);
}
public void setGoodsMap(Map<Integer, JourneyGoods> goodsMap) {
this.goodsMap = goodsMap;
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/15
* @discribe
*/
@Component
public class JourneyBuyHandler extends BaseHandler<MapInfoProto.JourneyBuyRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_BUY_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.JourneyBuyRequest proto) throws Exception {
JourneyMap.getInstance().buyJourney(iSession,proto.getMapId(),proto.getGoodsIndex(), MessageTypeProto.MessageType.JOURNEY_BUY_RESPONSE);
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/13
* @discribe
*/
@Component
public class JourneyDoHandler extends BaseHandler<MapInfoProto.JourneyDoRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_DO_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.JourneyDoRequest proto) throws Exception {
JourneyMap.getInstance().doJourney(iSession,proto.getMapId(),MessageTypeProto.MessageType.JOURNEY_DO_RESPONSE);
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/15
* @discribe
*/
@Component
public class JourneyFightHandler extends BaseHandler<MapInfoProto.JourneyFightRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_FIGHT_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.JourneyFightRequest proto) throws Exception {
JourneyMap.getInstance().fightToBoss(iSession,proto.getMapId(),proto.getMonsterIndex(), MessageTypeProto.MessageType.JOURNEY_FIGHT_RESPONSE);
}
}

View File

@ -0,0 +1,28 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/13
* @discribe
*/
@Component
public class JourneyGetInfoHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_GET_INFO_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
JourneyMap.getInstance().getAllInfo(iSession,MessageTypeProto.MessageType.JOURNEY_GET_INFO_RESPONSE);
}
}

View File

@ -0,0 +1,27 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/13
* @discribe
*/
@Component
public class JourneyGetOneInfoHandler extends BaseHandler<MapInfoProto.JourneyGetOneInfoRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_GET_ONE_INFO_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.JourneyGetOneInfoRequest proto) throws Exception {
JourneyMap.getInstance().getOneJourneyInfo(iSession,proto.getMapId(), MessageTypeProto.MessageType.JOURNEY_GET_ONE_INFO_RESPONSE);
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.JourneyMap;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/10/15
* @discribe
*/
@Component
public class JourneyRandomHandler extends BaseHandler<MapInfoProto.JourneyRandomRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.JOURNEY_RANDOM_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.JourneyRandomRequest proto) throws Exception {
JourneyMap.getInstance().random(iSession,proto.getMapId(),MessageTypeProto.MessageType.JOURNEY_RANDOM_RESPONSE);
}
}

View File

@ -127,7 +127,12 @@ public class MonsterUtil {
for(int[] groupItem: groupIds){
List<Integer> bossHps = new ArrayList<>(groupItem.length);
for (int monsterId : groupItem) {
if(monsterId==0){
bossHps.add(0);
continue;
}
bossHps.add( STableManager.getConfig(SMonsterConfig.class).get(monsterId).getHp());
}
hps.put(index++,bossHps);
}

View File

@ -15,7 +15,7 @@ public class SCMap implements BaseConfig {
private int event;
private int[][] groups;
private int isMustAppear;
private int[] location;
@Override
public void init() throws Exception {
sCMap = STableManager.getMapConfig(SCMap.class);
@ -36,4 +36,7 @@ public class SCMap implements BaseConfig {
public int getIsMustAppear() {
return isMustAppear;
}
public int[] getLocation() {
return location;
}
}

View File

@ -0,0 +1,110 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.HashMap;
import java.util.Map;
@Table(name ="FreeTravel")
public class SFreeTravel implements BaseConfig {
private int id;
private int mapID;
private int unlockLevel;
private int[][] adventureNumber;
private int[] consume;
private int commonReward;
private int finalReward;
private int[][] treasureChest;
private int[][] bossConsume;
private int[] freeTravelBoss;
private int[] freeTravelBossReward;
private int[] turntableProbability;
private int[][] turntablePosition;
private int[][] turntableGoods;
public static Map<Integer,SFreeTravel> journeyMapByMapId;
@Override
public void init() throws Exception {
Map<Integer, SFreeTravel> config = STableManager.getConfig(SFreeTravel.class);
Map<Integer,SFreeTravel> journeyMapByMapIdTemp = new HashMap<>();
for(Map.Entry<Integer, SFreeTravel> entry:config.entrySet()){
journeyMapByMapIdTemp.put(entry.getValue().getMapID(),entry.getValue());
}
journeyMapByMapId = journeyMapByMapIdTemp;
}
public int getID() {
return id;
}
public int getMapID() {
return mapID;
}
public int getUnlockLevel() {
return unlockLevel;
}
public int[][] getAdventureNumber() {
return adventureNumber;
}
public int[] getConsume() {
return consume;
}
public int getCommonReward() {
return commonReward;
}
public int getFinalReward() {
return finalReward;
}
public int[][] getTreasureChest() {
return treasureChest;
}
public int[][] getBossConsume() {
return bossConsume;
}
public int[] getFreeTravelBoss() {
return freeTravelBoss;
}
public int[] getFreeTravelBossReward() {
return freeTravelBossReward;
}
public int[] getTurntableProbability() {
return turntableProbability;
}
public int[][] getTurntablePosition() {
return turntablePosition;
}
public int[][] getTurntableGoods() {
return turntableGoods;
}
}

View File

@ -0,0 +1,61 @@
package config;
import manager.STableManager;
import manager.Table;
import util.MathUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Table(name ="FreeTravelStore")
public class SFreeTravelStore implements BaseConfig {
private int id;
private int mapID;
private int weight;
private int[] goods;
private int[] cost;
public static Map<Integer, List<SFreeTravelStore>> storeMapByMapId = new HashMap<>();
@Override
public void init() throws Exception {
Map<Integer, SFreeTravelStore> configMap = STableManager.getConfig(SFreeTravelStore.class);
Map<Integer, List<SFreeTravelStore>> storeMapByMapIdTemp = new HashMap<>();
for(Map.Entry<Integer, SFreeTravelStore> entry:configMap.entrySet()){
storeMapByMapIdTemp.putIfAbsent(entry.getValue().getMapID(),new ArrayList<>());
storeMapByMapIdTemp.get(entry.getValue().getMapID()).add(entry.getValue());
}
storeMapByMapId = storeMapByMapIdTemp;
}
public int getID() {
return id;
}
public int getMapID() {
return mapID;
}
public int getWeight() {
return weight;
}
public int[] getGoods() {
return goods;
}
public int[] getCost() {
return cost;
}
}

View File

@ -0,0 +1,91 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="GodSacrificeSetting")
public class SGodSacrificeSetting implements BaseConfig {
private int id;
private int activityId;
private int[] activityItems;
private int activityMoney;
private int[] rankType;
private int[] rewardItemChangRate;
private int qAId;
private int itemDelete;
private int timeRewardNum;
private int[] timePointList;
private int timeRewardGroup;
private int lastTime;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int getActivityId() {
return activityId;
}
public int[] getActivityItems() {
return activityItems;
}
public int getActivityMoney() {
return activityMoney;
}
public int[] getRankType() {
return rankType;
}
public int[] getRewardItemChangRate() {
return rewardItemChangRate;
}
public int getQAId() {
return qAId;
}
public int getItemDelete() {
return itemDelete;
}
public int getTimeRewardNum() {
return timeRewardNum;
}
public int[] getTimePointList() {
return timePointList;
}
public int getTimeRewardGroup() {
return timeRewardGroup;
}
public int getLastTime() {
return lastTime;
}
}

View File

@ -0,0 +1,43 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="SpiritAnimalBook")
public class SSpiritAnimalBook implements BaseConfig {
private int id;
private int[][] teamers;
private int[][] activePara;
private int activeForce;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int[][] getTeamers() {
return teamers;
}
public int[][] getActivePara() {
return activePara;
}
public int getActiveForce() {
return activeForce;
}
}

View File

@ -0,0 +1,55 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="SpiritAnimalLevel")
public class SSpiritAnimalLevel implements BaseConfig {
private int id;
private int level;
private int quality;
private int[][] characterLevelPara;
private int[][] consume;
private int[][] sumConsume;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int getLevel() {
return level;
}
public int getQuality() {
return quality;
}
public int[][] getCharacterLevelPara() {
return characterLevelPara;
}
public int[][] getConsume() {
return consume;
}
public int[][] getSumConsume() {
return sumConsume;
}
}

View File

@ -0,0 +1,61 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="SpiritAnimalStar")
public class SSpiritAnimalStar implements BaseConfig {
private int id;
private int star;
private int quality;
private int[][] starPara;
private int consumeItemNum;
private int consumeRes;
private int sumConsume;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int getStar() {
return star;
}
public int getQuality() {
return quality;
}
public int[][] getStarPara() {
return starPara;
}
public int getConsumeItemNum() {
return consumeItemNum;
}
public int getConsumeRes() {
return consumeRes;
}
public int getSumConsume() {
return sumConsume;
}
}

View File

@ -8,7 +8,7 @@ import java.util.*;
public class ExcelUtils {
private static boolean isWrite = true;
private static String excelPath ="F:/work2/data_execl/base_data/"; //excel 文件
private static String excelPath ="D:/excelData/master_develop/base_data/"; //excel 文件
// private static String excelPath ="D:/excel/0.94/data_execl/Map_data/"; //excel 文件
private static String path = "conf/server/";
private static Set<String> oldFileNames = new HashSet<>();
@ -20,17 +20,17 @@ public class ExcelUtils {
oldFileNames.addAll(Arrays.asList(list));
readExcelData();
//只加载新文件
Set<String> newFileNames = new HashSet<>();
File newfile = new File(path);
String[] newList = newfile.list();
newFileNames.addAll(Arrays.asList(newList));
newFileNames.removeAll(oldFileNames);
if(!newFileNames.isEmpty()) {
for (String newFileName : newFileNames) {
String finalNewFileName = newFileName.replaceAll(".txt", "");
genJavaFile(finalNewFileName);
}
}
// Set<String> newFileNames = new HashSet<>();
// File newfile = new File(path);
// String[] newList = newfile.list();
// newFileNames.addAll(Arrays.asList(newList));
// newFileNames.removeAll(oldFileNames);
// if(!newFileNames.isEmpty()) {
// for (String newFileName : newFileNames) {
// String finalNewFileName = newFileName.replaceAll(".txt", "");
// genJavaFile(finalNewFileName);
// }
// }
}
public static void genJavaFile(String fileName){
@ -323,27 +323,37 @@ public class ExcelUtils {
String[] split = entry.getKey().toString().split("#");
Object npc = entry.getKey();
Object isMustAppear = 0;
Object location = 0;
if (split.length >= 3){
npc = split[1];
isMustAppear = split[2];
}
if(split.length==4){
location = split[3];
}
List<Object> value = entry.getValue();
StringBuilder groups = new StringBuilder();
StringBuilder locations = new StringBuilder();
for (Object info :value){
if (groups.length() == 0){
groups = new StringBuilder((String) info);
}else{
groups.append("|").append(info);
}
if (locations.length() == 0){
locations = new StringBuilder(String.valueOf(location));
}else{
locations.append("#").append(location);
}
}
if (i == 0){
out.write("id\tEvent\tGroups\tisMustAppear");
out.write("id\tEvent\tGroups\tisMustAppear\tlocation");
out.write("\r\n");
out.write("int"+"\t"+"int"+"\t"+"mut,int#int,2"+"\t"+"int");
out.write("int"+"\t"+"int"+"\t"+"mut,int#int,2"+"\t"+"int"+"\t"+"mut,int#int,1");
out.write("\r\n");
}
i = i +1 ;
out.write( i+"\t"+npc+"\t"+groups.toString()+"\t" + isMustAppear);
out.write( i+"\t"+npc+"\t"+groups.toString()+"\t" + isMustAppear+"\t"+locations.toString());
out.write("\r\n");
}
}
@ -369,7 +379,7 @@ public class ExcelUtils {
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
return wb;