Merge branch 'master' of 60.1.1.230:backend/jieling_server

back_recharge
wangyuan 2019-02-25 18:04:45 +08:00
commit a598b1dd9c
23 changed files with 600 additions and 215 deletions

View File

@ -5,6 +5,7 @@ import com.ljsd.jieling.config.json.ServerConfiguration;
import com.ljsd.jieling.config.json.ServerProperties; import com.ljsd.jieling.config.json.ServerProperties;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.logic.STableManager; import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.dao.MailingSystemManager; import com.ljsd.jieling.logic.dao.MailingSystemManager;
import com.ljsd.jieling.logic.dao.UserManager; import com.ljsd.jieling.logic.dao.UserManager;
@ -76,6 +77,7 @@ public class GameApplication {
MailingSystemManager.init(configurableApplicationContext); MailingSystemManager.init(configurableApplicationContext);
ThreadManager threadManager = new ThreadManager(); ThreadManager threadManager = new ThreadManager();
threadManager.init(configurableApplicationContext); threadManager.init(configurableApplicationContext);
MapLogic.getInstance().init(configurableApplicationContext);
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class); final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
NettyProperties properties = netServerConfig.getNettyProperties(); NettyProperties properties = netServerConfig.getNettyProperties();

View File

@ -0,0 +1,14 @@
package com.ljsd.jieling.handler.map;
import java.util.HashSet;
import java.util.Set;
public class CrossMapCell {
// missionId 存在某个地图的任务
private Set<Integer> missionIds = new HashSet<>();
public Set<Integer> getMissionIds() {
return missionIds;
}
}

View File

@ -4,9 +4,11 @@ import com.ljsd.jieling.config.*;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.map.behavior.BaseBehavior;
import com.ljsd.jieling.handler.mission.Mission; import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic; import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.hero.HeroLogic; import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto; import com.ljsd.jieling.protocols.CommonProto;
@ -15,6 +17,7 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.*; import com.ljsd.jieling.util.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.*; import java.util.*;
@ -22,7 +25,17 @@ public class MapLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class); private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
private Map<Integer, BaseBehavior> baseBehaviorMap = new HashMap<>();
public void init(ConfigurableApplicationContext configurableApplicationContext) {
Map<String, BaseBehavior> beansOfType = configurableApplicationContext.getBeansOfType(BaseBehavior.class);
for (BaseBehavior baseBehavior : beansOfType.values()) {
baseBehaviorMap.put(baseBehavior.getBehaviorType(), baseBehavior);
}
}
private MapLogic() { private MapLogic() {
} }
/** /**
@ -66,7 +79,7 @@ public class MapLogic {
mapManager.setHeroes(heroes); mapManager.setHeroes(heroes);
user.getPlayerInfoManager().setMapId(101); user.getPlayerInfoManager().setMapId(101);
mapManager.setCurMapId(101); mapManager.setCurMapId(101);
initMap(mapManager); initMap(mapManager, user);
user.setMapManager(mapManager); user.setMapManager(mapManager);
} else { } else {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId); Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
@ -77,7 +90,7 @@ public class MapLogic {
return; return;
} }
if (mapId != mapManager.getCurMapId()) { if (mapId != mapManager.getCurMapId()) {
initMap(mapManager); initMap(mapManager, user);
user.setMapManager(mapManager); user.setMapManager(mapManager);
} }
} }
@ -103,11 +116,22 @@ public class MapLogic {
} }
private void initMap(MapManager mapManager) throws Exception { public void initMap(MapManager mapManager, User user) throws Exception {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapManager.getCurMapId()); Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapManager.getCurMapId());
Map<Integer, Cell> newMap = new HashMap<>(); Map<Integer, Cell> newMap = new HashMap<>();
Map<Integer, Cell> spicelMap = new HashMap<>(); Map<Integer, Cell> spicelMap = new HashMap<>();
Random random = new Random(); Random random = new Random();
CrossMapCell crossMapCell1 = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
Set<Mission> missions = new HashSet<>();
if (crossMapCell1 != null) {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
for (Integer doingMissionId : crossMapCell1.getMissionIds()) {
if (doingMissions.containsKey(doingMissionId)) {
Mission mission = doingMissions.get(doingMissionId);
missions.add(mission);
}
}
}
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) { for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue(); SCMap scMap1 = entry.getValue();
int randomIndex = random.nextInt(scMap1.getGroups().length); int randomIndex = random.nextInt(scMap1.getGroups().length);
@ -116,9 +140,19 @@ public class MapLogic {
int xy = CellUtil.xy2Pos(x, y); int xy = CellUtil.xy2Pos(x, y);
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(scMap1.getEvent()); MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(scMap1.getEvent());
if (mapPointConfig == null) { if (mapPointConfig == null) {
LOGGER.info("========scMap1.getEvent()======>{}", scMap1.getEvent()); LOGGER.info("====initMap()====mapPointConfig == null======>{}", scMap1.getEvent());
continue; continue;
} }
for (Mission mission : missions) {
if (mission.getMapPoints().containsKey(mapPointConfig.getId())) {
for (Map.Entry<Integer, Cell> missionEntry : mission.getMissionInfos().entrySet()) {
newMap.put(missionEntry.getKey(), missionEntry.getValue());
}
Cell cellValue = new Cell(xy, mission.getMapPoints().get(mapPointConfig.getId()), mapPointConfig.getId());
newMap.put(xy, cellValue);
break;
}
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId()); Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
if (mapPointConfig.getStyle() == EventType.enter) { if (mapPointConfig.getStyle() == EventType.enter) {
mapManager.setCurXY(xy); mapManager.setCurXY(xy);
@ -285,169 +319,18 @@ public class MapLogic {
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), ""); MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return; return;
} }
boolean isSuccess = false;
int behaviorType = sOptionConfig.getBehaviorType(); int behaviorType = sOptionConfig.getBehaviorType();
int[][] behaviorTypeValues = sOptionConfig.getBehaviorTypeValues(); int[][] behaviorTypeValues = sOptionConfig.getBehaviorTypeValues();
CommonProto.Mission openMission = null; BaseBehavior baseBehavior = baseBehaviorMap.get(behaviorType);
switch (behaviorType) { MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse = MapInfoProto.EventUpdateResponse.newBuilder();
case EventType.fight: { if (baseBehavior != null) {
// heroFightInfos = fightStart(uid, bigEventId, user); boolean isSuccess = baseBehavior.process(user, behaviorTypeValues, eventUpdateResponse);
isSuccess = true; if (!isSuccess) {
break; LOGGER.info("updateEvent() baseBehavior process fail! behaviorType=>{}", behaviorType);
} MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
case EventType.eatBuff: return;
case EventType.useItem:
case EventType.scout: {
Map<Integer, Integer> useItems = new HashMap<>();
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
ItemUtil.useItem(user, useItems);
isSuccess = true;
break;
}
case EventType.leave: {
int randomInt = MathUtils.randomInt(100) + 1;
if (randomInt <= behaviorTypeValues[0][0]) {
isSuccess = true;
}
break;
}
case EventType.dun: {
boolean hasMission = MissionLogic.getInstance().hasMission(user, behaviorTypeValues[0][0]);
if (hasMission) {
break;
}
SCMapConfig scMapConfig = SCMapConfig.getsCMapSize().get(mapManager.getCurMapId());
int[] mapSize = scMapConfig.getSize();
Map<Integer, Cell> newDunEvents = new HashMap<>();
Map<Integer, MapPointConfig> newDunEventIds = new HashMap<>();
int i = 0;
Random random = new Random();
while (newDunEventIds.size() < 3) {
int randomIndex = random.nextInt(behaviorTypeValues[0].length - 3) + 3;
int newDunEventId = behaviorTypeValues[0][randomIndex];
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(newDunEventId);
newDunEventIds.put(newDunEventIds.size(), mapPointConfig);
i++;
if (i >= 1000) {
break;
}
}
if (newDunEventIds.size() < 3) {
break;
}
i = 0;
while (newDunEvents.size() < 3) {
int x = random.nextInt(mapSize[0]) + 1;
int y = random.nextInt(mapSize[1]) + 1;
int xy = CellUtil.xy2Pos(x, y);
if (mapManager.getMapInfo().containsKey(xy)) {
continue;
}
MapPointConfig mapPointConfig = newDunEventIds.get(newDunEvents.size());
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
newDunEvents.put(xy, cellValue);
i++;
if (i >= 1000) {
break;
}
}
mapManager.getMapInfo().putAll(newDunEvents);
Mission mission = new Mission();
mission.setMissionId(behaviorTypeValues[0][0]);
mission.setMissionStep(0);
mission.getMissionInfos().putAll(newDunEvents);
mission.setMissionInfo(mapManager.getCurXY() + "#" + behaviorTypeValues[0][2] + "#" + behaviorTypeValues[0][1]);
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
doingMissions.put(behaviorTypeValues[0][0], mission);
user.getMissionManager().updateDoingMissions(doingMissions);
openMission = getMission(newDunEvents, mission);
break;
}
case EventType.jump: {
isSuccess = true;
if (behaviorTypeValues[0][0] != 0) {
mapManager.setCurMapId(behaviorTypeValues[0][0]);
initMap(mapManager);
}
break;
}
case EventType.destroyMission: {
isSuccess = true;
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
break;
}
String newEventId = MissionLogic.getInstance().checkMission(mission, user);
Map<Integer, Cell> mapInfo = new HashMap<>(mapManager.getMapInfo());
mapInfo.remove(mapManager.getCurXY());
if (newEventId != null && !newEventId.isEmpty()) {
String[] split = newEventId.split("#");
Cell cellUpdate = mapInfo.get(Integer.parseInt(split[0]));
if (cellUpdate != null) {
cellUpdate.setEventId(Integer.parseInt(split[1]));
}
}
mapManager.setMapInfo(mapInfo);
openMission = getMission(null, mission);
break;
}
case EventType.monitorMission: {
isSuccess = true;
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
break;
}
MissionLogic.getInstance().checkMission(mission, user);
openMission = getMission(null, mission);
break;
}
case EventType.openMission: {
isSuccess = true;
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
break;
}
MissionLogic.getInstance().checkMission(mission, user);
openMission = getMission(null, mission);
// TODO 还要开新事件
break;
}
case EventType.finishMission: {
isSuccess = true;
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
break;
}
MissionLogic.getInstance().checkMission(mission, user);
openMission = getMission(null, mission);
break;
}
case EventType.useItemMission: {
isSuccess = true;
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
break;
}
boolean checkCost = ItemUtil.itemCost(user, behaviorTypeValues);
if (!checkCost) {
break;
}
MissionLogic.getInstance().checkMission(mission, user);
openMission = getMission(null, mission);
break;
}
default: {
break;
} }
} }
int jumpType = sOptionConfig.getJumpType(); int jumpType = sOptionConfig.getJumpType();
int nextPoint = 0; int nextPoint = 0;
int[][] jumpTypeValues = sOptionConfig.getJumpTypeValues(); int[][] jumpTypeValues = sOptionConfig.getJumpTypeValues();
@ -483,40 +366,7 @@ public class MapLogic {
return; return;
} }
// 1 完成事件点即进度100% // 1 完成事件点即进度100%
if (sOptionAddConditions.getType() == 1) { nextPoint = getNextPoint(user, mapManager, jumpTypeValues, sOptionAddConditions);
int doneEvent = sOptionAddConditions.getValues()[0][0];
for (Cell cell1 : mapManager.getMapInfo().values()) {
if (cell1.getPointId() == doneEvent) {
if (cell1.getEventId() >= sOptionAddConditions.getValues()[0][1]) {
nextPoint = jumpTypeValues[0][0];
}
break;
}
}
// 2 物品数量
} else if (sOptionAddConditions.getType() == 2) {
// 3 角色属性
} else if (sOptionAddConditions.getType() == 3){
// 完成某个任务的第几步
} else if (sOptionAddConditions.getType() == 4){
Set<Integer> finishMissions = user.getMissionManager().getFinishMissions();
Set<Integer> takeRewardMissions = user.getMissionManager().getTakeRewardMissions();
if (finishMissions.contains(sOptionAddConditions.getValues()[0][0]) || takeRewardMissions.contains(sOptionAddConditions.getValues()[0][0])) {
nextPoint = jumpTypeValues[0][0];
}
if (nextPoint == 0) {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(sOptionAddConditions.getValues()[0][0]);
if (mission == null || mission.getMissionStep() < jumpTypeValues[0][1]) {
nextPoint = jumpTypeValues[0][1];
}
}
}
if (nextPoint == 0) {
nextPoint = jumpTypeValues[0][1];
}
break; break;
} }
// 4 不跳转,关闭界面 // 4 不跳转,关闭界面
@ -528,11 +378,16 @@ public class MapLogic {
break; break;
} }
} }
MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse = MapInfoProto.EventUpdateResponse.newBuilder();
if (behaviorType != EventType.jump && behaviorType != EventType.destroyMission) { if (behaviorType != EventType.jump && behaviorType != EventType.destroyMission) {
cell.setEventId(nextPoint); cell.setEventId(nextPoint);
mapManager.addOrUpdateCell(mapManager.getCurXY(), cell); mapManager.addOrUpdateCell(mapManager.getCurXY(), cell);
} }
if (behaviorType == EventType.dun && eventUpdateResponse.getMission() != null) {
Mission mission = user.getMissionManager().getDoingMissions().get(eventUpdateResponse.getMission().getItemId());
if (mission != null) {
mission.updateMapPoints(cell.getPointId(), cell.getEventId());
}
}
int[] reward = {sOptionConfig.getReward()}; int[] reward = {sOptionConfig.getReward()};
CommonProto.Drop.Builder dropBuilder = ItemUtil.drop(user, reward, 1); CommonProto.Drop.Builder dropBuilder = ItemUtil.drop(user, reward, 1);
List<CommonProto.EventBehaviorValues> eventBehaviorValuesList = new ArrayList<>(); List<CommonProto.EventBehaviorValues> eventBehaviorValuesList = new ArrayList<>();
@ -554,21 +409,65 @@ public class MapLogic {
if (dropBuilder != null) { if (dropBuilder != null) {
eventUpdateResponse.setDrop(dropBuilder); eventUpdateResponse.setDrop(dropBuilder);
} }
if (openMission != null) {
eventUpdateResponse.setMission(openMission);
}
LOGGER.info("updateEvent =====>success<====== xy=>{}, getPointId=>{} eventId={}, mission=>{}, nextPoint=>{}", mapManager.getCurXY(), cell.getPointId(), LOGGER.info("updateEvent =====>success<====== xy=>{}, getPointId=>{} eventId={}, mission=>{}, nextPoint=>{}", mapManager.getCurXY(), cell.getPointId(),
cell.getEventId(), eventUpdateResponse.getMission(), nextPoint); cell.getEventId(), eventUpdateResponse.getMission(), nextPoint);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), eventUpdateResponse.build(), true); MessageUtil.sendMessage(session, 1, messageType.getNumber(), eventUpdateResponse.build(), true);
} }
private CommonProto.Mission getMission(Map<Integer, Cell> newDunEvents, Mission mission) { private int getNextPoint(User user, MapManager mapManager, int[][] jumpTypeValues, SOptionAddCondition sOptionAddConditions) {
int nextPoint = 0;
switch (sOptionAddConditions.getType()) {
case 1:{
int doneEvent = sOptionAddConditions.getValues()[0][0];
for (Cell cell1 : mapManager.getMapInfo().values()) {
if (cell1.getPointId() == doneEvent) {
if (cell1.getEventId() >= sOptionAddConditions.getValues()[0][1]) {
nextPoint = jumpTypeValues[0][0];
}
break;
}
}
break;
}
// 2 物品数量
case 2:{
break;
}
// 3 角色属性
case 3:{
break;
}
// 完成某个任务的第几步
case 4:{
Set<Integer> finishMissions = user.getMissionManager().getFinishMissions();
Set<Integer> takeRewardMissions = user.getMissionManager().getTakeRewardMissions();
if (finishMissions.contains(sOptionAddConditions.getValues()[0][0]) || takeRewardMissions.contains(sOptionAddConditions.getValues()[0][0])) {
nextPoint = jumpTypeValues[0][0];
}
if (nextPoint == 0) {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(sOptionAddConditions.getValues()[0][0]);
if (mission == null || mission.getMissionStep() < jumpTypeValues[0][1]) {
nextPoint = jumpTypeValues[0][1];
}
}
break;
}
default: {
nextPoint = jumpTypeValues[0][1];
break;
}
}
return nextPoint;
}
public CommonProto.Mission getMission(Mission mission) {
CommonProto.Mission openMission; CommonProto.Mission openMission;
StringBuilder state = null; StringBuilder state = null;
String states = ""; String states = "";
if (newDunEvents != null) { if (mission.getMissionInfos() != null) {
state = new StringBuilder(); state = new StringBuilder();
for (Map.Entry<Integer, Cell> cellEntry : newDunEvents.entrySet()) { for (Map.Entry<Integer, Cell> cellEntry : mission.getMissionInfos().entrySet()) {
state.append(cellEntry.getKey()); state.append(cellEntry.getKey());
state.append("#"); state.append("#");
state.append(cellEntry.getValue().getPointId()); state.append(cellEntry.getValue().getPointId());

View File

@ -1,4 +1,4 @@
package com.ljsd.jieling.logic.dao; package com.ljsd.jieling.handler.map;
@ -28,16 +28,21 @@ public class MapManager extends MongoBase {
private Set<Integer> walkCells; private Set<Integer> walkCells;
private Map<Integer, List<Integer>> crossMapInfos = new ConcurrentHashMap<>(); private Map<Integer, CrossMapCell> crossMapInfos = new ConcurrentHashMap<>();
public Map<Integer, Cell> getMapInfo() { public Map<Integer, Cell> getMapInfo() {
return mapInfo; return mapInfo;
} }
public Map<Integer, List<Integer>> getCrossMapInfos() { public Map<Integer, CrossMapCell> getCrossMapInfos() {
return crossMapInfos; return crossMapInfos;
} }
public void updateCrossMapInfos(int key, CrossMapCell crossMapCell) throws Exception {
updateString( "mapInfo." + key, crossMapCell);
crossMapInfos.put(key, crossMapCell);
}
public int getCurMapId() { public int getCurMapId() {
return curMapId; return curMapId;
} }

View File

@ -1,4 +1,12 @@
package com.ljsd.jieling.handler.map.behavior; package com.ljsd.jieling.handler.map.behavior;
public interface BaseBehavior { import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
public abstract class BaseBehavior {
public abstract int getBehaviorType();
public abstract boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception;
} }

View File

@ -0,0 +1,44 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.Cell;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class DestroyMissionBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.destroyMission;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
return false;
}
String newEventId = MissionLogic.getInstance().checkMission(mission, user);
Map<Integer, Cell> mapInfo = user.getMapManager().getMapInfo();
mapInfo.remove(user.getMapManager().getCurXY());
if (newEventId != null && !newEventId.isEmpty()) {
String[] split = newEventId.split("#");
Cell cellUpdate = mapInfo.get(Integer.parseInt(split[0]));
if (cellUpdate != null) {
cellUpdate.setEventId(Integer.parseInt(split[1]));
}
}
user.getMapManager().setMapInfo(mapInfo);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
return true;
}
}

View File

@ -0,0 +1,86 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.config.MapPointConfig;
import com.ljsd.jieling.config.SCMapConfig;
import com.ljsd.jieling.handler.map.*;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.CellUtil;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@Component
public class DunBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.dun;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
boolean hasMission = MissionLogic.getInstance().hasMission(user, behaviorTypeValues[0][0]);
if (hasMission) {
return false;
}
MapManager mapManager = user.getMapManager();
SCMapConfig scMapConfig = SCMapConfig.getsCMapSize().get(mapManager.getCurMapId());
int[] mapSize = scMapConfig.getSize();
Map<Integer, Cell> newDunEvents = new HashMap<>();
Map<Integer, MapPointConfig> newDunEventIds = new HashMap<>();
int i = 0;
Random random = new Random();
while (newDunEventIds.size() < 3) {
int randomIndex = random.nextInt(behaviorTypeValues[0].length - 3) + 3;
int newDunEventId = behaviorTypeValues[0][randomIndex];
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(newDunEventId);
newDunEventIds.put(newDunEventIds.size(), mapPointConfig);
i++;
if (i >= 1000) {
break;
}
}
if (newDunEventIds.size() < 3) {
return false;
}
i = 0;
while (newDunEvents.size() < 3) {
int x = random.nextInt(mapSize[0]) + 1;
int y = random.nextInt(mapSize[1]) + 1;
int xy = CellUtil.xy2Pos(x, y);
if (mapManager.getMapInfo().containsKey(xy)) {
continue;
}
MapPointConfig mapPointConfig = newDunEventIds.get(newDunEvents.size());
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
newDunEvents.put(xy, cellValue);
i++;
if (i >= 1000) {
break;
}
}
mapManager.getMapInfo().putAll(newDunEvents);
Mission mission = new Mission();
mission.setMissionId(behaviorTypeValues[0][0]);
mission.setMissionStep(0);
mission.getMissionInfos().putAll(newDunEvents);
mission.setMissionInfo(mapManager.getCurXY() + "#" + behaviorTypeValues[0][2] + "#" + behaviorTypeValues[0][1]);
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
doingMissions.put(behaviorTypeValues[0][0], mission);
user.getMissionManager().updateDoingMissions(doingMissions);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
CrossMapCell crossMapInfo = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
if (crossMapInfo == null) {
crossMapInfo = new CrossMapCell();
}
crossMapInfo.getMissionIds().add(behaviorTypeValues[0][0]);
mapManager.updateCrossMapInfos(mapManager.getCurMapId(), crossMapInfo);
return true;
}
}

View File

@ -0,0 +1,32 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.ItemUtil;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class EatBuffBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.eatBuff;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
if (!isEnough) {
return isEnough;
}
Map<Integer, Integer> useItems = new HashMap<>();
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
ItemUtil.useItem(user, useItems);
return isEnough;
}
}

View File

@ -0,0 +1,20 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
@Component
public class FightBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.fight;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
// heroFightInfos = fightStart(uid, bigEventId, user);
return true;
}
}

View File

@ -0,0 +1,33 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class FinishMissionBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.finishMission;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
return false;
}
MissionLogic.getInstance().checkMission(mission, user);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
return true;
}
}

View File

@ -0,0 +1,25 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
@Component
public class JumpBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.jump;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
if (behaviorTypeValues[0][0] != 0) {
user.getMapManager().setCurMapId(behaviorTypeValues[0][0]);
MapLogic.getInstance().initMap(user.getMapManager(), user);
return true;
}
return false;
}
}

View File

@ -0,0 +1,24 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.MathUtils;
import org.springframework.stereotype.Component;
@Component
public class LeaveBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.leave;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
int randomInt = MathUtils.randomInt(100) + 1;
if (randomInt <= behaviorTypeValues[0][0]) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,33 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class MonitorMissionBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.monitorMission;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
return false;
}
MissionLogic.getInstance().checkMission(mission, user);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
return true;
}
}

View File

@ -0,0 +1,35 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class OpenMissionBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.openMission;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
return false;
}
MissionLogic.getInstance().checkMission(mission, user);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
// TODO 还要开新事件
return true;
}
}

View File

@ -0,0 +1,32 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.ItemUtil;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class ScoutBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.scout;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
if (!isEnough) {
return isEnough;
}
Map<Integer, Integer> useItems = new HashMap<>();
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
ItemUtil.useItem(user, useItems);
return isEnough;
}
}

View File

@ -0,0 +1,32 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.config.SItem;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.ItemUtil;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class UseItemBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.eatBuff;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
if (!isEnough) {
return isEnough;
}
Map<Integer, Integer> useItems = new HashMap<>();
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
ItemUtil.useItem(user, useItems);
return isEnough;
}
}

View File

@ -0,0 +1,38 @@
package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.EventType;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.handler.mission.MissionLogic;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.ItemUtil;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class UseItemMissionBehavior extends BaseBehavior {
@Override
public int getBehaviorType() {
return EventType.useItemMission;
}
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
if (mission == null) {
return false;
}
boolean checkCost = ItemUtil.itemCost(user, behaviorTypeValues);
if (!checkCost) {
return false;
}
MissionLogic.getInstance().checkMission(mission, user);
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
eventUpdateResponse.setMission(missionProto);
return true;
}
}

View File

@ -1,4 +0,0 @@
package com.ljsd.jieling.handler.map.jump;
public class BaseJump {
}

View File

@ -14,6 +14,10 @@ public class Mission extends MongoBase {
private String missionInfo; private String missionInfo;
// pointId, eventId
private Map<Integer, Integer> mapPoints = new ConcurrentHashMap<>();
// 地图坐标,事件点
private Map<Integer, Cell> missionInfos = new ConcurrentHashMap<>(); private Map<Integer, Cell> missionInfos = new ConcurrentHashMap<>();
public int getMissionId() { public int getMissionId() {
@ -36,6 +40,11 @@ public class Mission extends MongoBase {
return missionInfos; return missionInfos;
} }
public void updateMissionInfos(int xy, Cell cell) throws Exception {
updateString("missionInfos." + xy, cell);
this.missionInfos.put(xy, cell);
}
public String getMissionInfo() { public String getMissionInfo() {
return missionInfo; return missionInfo;
} }
@ -44,4 +53,13 @@ public class Mission extends MongoBase {
updateString("missionInfo", missionInfo); updateString("missionInfo", missionInfo);
this.missionInfo = missionInfo; this.missionInfo = missionInfo;
} }
public Map<Integer, Integer> getMapPoints() {
return mapPoints;
}
public void updateMapPoints(int pointId, int eventId) throws Exception {
updateString("mapPoints." + pointId, eventId);
this.mapPoints.put(pointId, eventId);
}
} }

View File

@ -94,6 +94,13 @@ public class MissionLogic {
String[] split1 = mission.getMissionInfo().split("#"); String[] split1 = mission.getMissionInfo().split("#");
int needCount = Integer.parseInt(split1[2]); int needCount = Integer.parseInt(split1[2]);
mission.setMissionStep(mission.getMissionStep() + 1); mission.setMissionStep(mission.getMissionStep() + 1);
Map<Integer, Cell> missionInfos = mission.getMissionInfos();
int curXY = user.getMapManager().getCurXY();
if (missionInfos.containsKey(curXY)) {
Cell cell = missionInfos.get(curXY);
cell.setEventId(-1);
mission.updateMissionInfos(curXY, cell);
}
String newEventId = null; String newEventId = null;
if (mission.getMissionStep() >= needCount) { if (mission.getMissionStep() >= needCount) {
if (mission.getMissionInfo() != null) { if (mission.getMissionInfo() != null) {

View File

@ -2,6 +2,7 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.LjsdMongoTemplate; import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoRoot; import com.ljsd.common.mogodb.MongoRoot;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.handler.mission.MissionManager; import com.ljsd.jieling.handler.mission.MissionManager;
public class User extends MongoRoot { public class User extends MongoRoot {

View File

@ -3,6 +3,7 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.LjsdMongoTemplate; import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.jieling.config.SGameSetting; import com.ljsd.jieling.config.SGameSetting;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.util.ItemUtil; import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.TimeUtils; import com.ljsd.jieling.util.TimeUtils;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;

View File

@ -7,7 +7,7 @@ import java.util.*;
public class ExcelUtils { public class ExcelUtils {
private static boolean isWrite = true; private static boolean isWrite = true;
private static String excelPath ="D:/tmp/"; //excel 文件 private static String excelPath ="D:/jieling_client/data_execl/map/"; //excel 文件
private static String path = "conf/server/"; private static String path = "conf/server/";
private static Set<String> oldFileNames = new HashSet<>(); private static Set<String> oldFileNames = new HashSet<>();
private static String javaFilePath = "serverlogic/src/main/java/com/ljsd/jieling/config/"; private static String javaFilePath = "serverlogic/src/main/java/com/ljsd/jieling/config/";