保存地图里的主线任务

back_recharge
jiahuiwen 2019-02-25 13:44:42 +08:00
parent 7610346352
commit 007a004f01
9 changed files with 79 additions and 10 deletions

View File

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

View File

@ -66,7 +66,7 @@ public class MapLogic {
mapManager.setHeroes(heroes);
user.getPlayerInfoManager().setMapId(101);
mapManager.setCurMapId(101);
initMap(mapManager);
initMap(mapManager, user);
user.setMapManager(mapManager);
} else {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
@ -77,7 +77,7 @@ public class MapLogic {
return;
}
if (mapId != mapManager.getCurMapId()) {
initMap(mapManager);
initMap(mapManager, user);
user.setMapManager(mapManager);
}
}
@ -103,20 +103,35 @@ public class MapLogic {
}
private void initMap(MapManager mapManager) throws Exception {
private void initMap(MapManager mapManager, User user) throws Exception {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapManager.getCurMapId());
Map<Integer, Cell> newMap = new HashMap<>();
Map<Integer, Cell> spicelMap = new HashMap<>();
Random random = new Random();
CrossMapCell crossMapCell1 = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
Map<Integer, Cell> missionInfos = new HashMap<>(3);
if (crossMapCell1 != null) {
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
for (Integer doingMissionId : crossMapCell1.getMissionIds()) {
if (doingMissions.containsKey(doingMissionId)) {
Mission mission = doingMissions.get(doingMissionId);
missionInfos.putAll(mission.getMissionInfos());
}
}
}
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
int randomIndex = random.nextInt(scMap1.getGroups().length);
int x = scMap1.getGroups()[randomIndex][0];
int y = scMap1.getGroups()[randomIndex][1];
int xy = CellUtil.xy2Pos(x, y);
if (missionInfos.containsKey(xy)) {
newMap.put(xy, missionInfos.get(xy));
continue;
}
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(scMap1.getEvent());
if (mapPointConfig == null) {
LOGGER.info("========scMap1.getEvent()======>{}", scMap1.getEvent());
LOGGER.info("====initMap()====mapPointConfig == null======>{}", scMap1.getEvent());
continue;
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
@ -361,13 +376,19 @@ public class MapLogic {
doingMissions.put(behaviorTypeValues[0][0], mission);
user.getMissionManager().updateDoingMissions(doingMissions);
openMission = getMission(newDunEvents, mission);
CrossMapCell crossMapInfo = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
if (crossMapInfo == null) {
crossMapInfo = new CrossMapCell();
}
crossMapInfo.getMissionIds().add(behaviorTypeValues[0][0]);
mapManager.updateCrossMapInfos(mapManager.getCurMapId(), crossMapInfo);
break;
}
case EventType.jump: {
isSuccess = true;
if (behaviorTypeValues[0][0] != 0) {
mapManager.setCurMapId(behaviorTypeValues[0][0]);
initMap(mapManager);
initMap(mapManager, user);
}
break;
}

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 Map<Integer, List<Integer>> crossMapInfos = new ConcurrentHashMap<>();
private Map<Integer, CrossMapCell> crossMapInfos = new ConcurrentHashMap<>();
public Map<Integer, Cell> getMapInfo() {
return mapInfo;
}
public Map<Integer, List<Integer>> getCrossMapInfos() {
public Map<Integer, CrossMapCell> getCrossMapInfos() {
return crossMapInfos;
}
public void updateCrossMapInfos(int key, CrossMapCell crossMapCell) throws Exception {
updateString( "mapInfo." + key, crossMapCell);
crossMapInfos.put(key, crossMapCell);
}
public int getCurMapId() {
return curMapId;
}

View File

@ -1,4 +1,11 @@
package com.ljsd.jieling.handler.map.behavior;
public interface BaseBehavior {
import com.ljsd.jieling.logic.dao.User;
public abstract class BaseBehavior {
public abstract int getBehaviorType();
public abstract void process(User user) throws Exception;
}

View File

@ -1,4 +1,11 @@
package com.ljsd.jieling.handler.map.jump;
public class BaseJump {
import com.ljsd.jieling.logic.dao.User;
public abstract class BaseJump {
public abstract int getJumpType();
public abstract void process(User user) throws Exception;
}

View File

@ -36,6 +36,11 @@ public class Mission extends MongoBase {
return missionInfos;
}
public void updateMissionInfos(int xy, Cell cell) throws Exception {
updateString("missionInfos." + xy, cell);
this.missionInfos.put(xy, cell);
}
public String getMissionInfo() {
return missionInfo;
}

View File

@ -94,6 +94,13 @@ public class MissionLogic {
String[] split1 = mission.getMissionInfo().split("#");
int needCount = Integer.parseInt(split1[2]);
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;
if (mission.getMissionStep() >= needCount) {
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.MongoRoot;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.handler.mission.MissionManager;
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.jieling.config.SGameSetting;
import com.ljsd.jieling.handler.map.MapManager;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.TimeUtils;
import org.springframework.context.ConfigurableApplicationContext;