back_recharge
parent
eaea13a4b3
commit
ea6d17712d
|
@ -1,34 +0,0 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
public class CCell {
|
||||
|
||||
private int coordinateX;
|
||||
|
||||
private int coordinateY;
|
||||
|
||||
private int eventType;
|
||||
|
||||
public int getCoordinateX() {
|
||||
return coordinateX;
|
||||
}
|
||||
|
||||
public void setCoordinateX(int coordinateX) {
|
||||
this.coordinateX = coordinateX;
|
||||
}
|
||||
|
||||
public int getCoordinateY() {
|
||||
return coordinateY;
|
||||
}
|
||||
|
||||
public void setCoordinateY(int coordinateY) {
|
||||
this.coordinateY = coordinateY;
|
||||
}
|
||||
|
||||
public int getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public void setEventType(int eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import org.springframework.data.annotation.Id;
|
|||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
@ -13,11 +14,17 @@ public class CMap {
|
|||
@Id
|
||||
private int id;
|
||||
|
||||
@Field(value = "curMapId")
|
||||
private int curMapId;
|
||||
|
||||
@Field(value = "curXY")
|
||||
private int curXY;
|
||||
|
||||
@Field(value = "mapInfo")
|
||||
private Map<Integer, CCell> mapInfo = new ConcurrentHashMap<>();
|
||||
private Map<Integer, Cell> mapInfo = new ConcurrentHashMap<>();
|
||||
|
||||
@Field(value = "crossMapInfos")
|
||||
private Map<Integer, Integer> crossMapInfos = new ConcurrentHashMap<>();
|
||||
private Map<Integer, List<Integer>> crossMapInfos = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public void setId(int id) {
|
||||
|
@ -28,11 +35,27 @@ public class CMap {
|
|||
return id;
|
||||
}
|
||||
|
||||
public Map<Integer, CCell> getMapInfo() {
|
||||
public Map<Integer, Cell> getMapInfo() {
|
||||
return mapInfo;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getCrossMapInfos() {
|
||||
public Map<Integer, List<Integer>> getCrossMapInfos() {
|
||||
return crossMapInfos;
|
||||
}
|
||||
|
||||
public int getCurMapId() {
|
||||
return curMapId;
|
||||
}
|
||||
|
||||
public void setCurMapId(int curMapId) {
|
||||
this.curMapId = curMapId;
|
||||
}
|
||||
|
||||
public int getCurXY() {
|
||||
return curXY;
|
||||
}
|
||||
|
||||
public void setCurXY(int curXY) {
|
||||
this.curXY = curXY;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
public class CellValue {
|
||||
|
||||
private int eventType;
|
||||
|
||||
public int getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public void setEventType(int eventType) {
|
||||
this.eventType = eventType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
public class EventType {
|
||||
// 事件点类型 1怪物 2怪物群 3矿 4入口 5出口 6一次性事件 7重复事件 8npc 9地图boss
|
||||
public static final int monster = 1;
|
||||
public static final int monsters = 2;
|
||||
public static final int mine = 3;
|
||||
public static final int enter = 4;
|
||||
public static final int exit = 5;
|
||||
public static final int disposable = 6;
|
||||
public static final int repeated = 7;
|
||||
public static final int npc = 8;
|
||||
public static final int boss = 8;
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
import com.ljsd.jieling.models.SCMap;
|
||||
import com.ljsd.jieling.models.SCMapEvent;
|
||||
import com.ljsd.jieling.util.ToolsUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class MapLogic {
|
||||
|
||||
|
@ -24,8 +29,22 @@ public class MapLogic {
|
|||
public final static MapLogic instance = new MapLogic();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地图信息
|
||||
* @param uid
|
||||
*/
|
||||
public void getMapInfo(int uid) {
|
||||
// get db
|
||||
CMap cMap = null;
|
||||
if (cMap == null) {
|
||||
initMap(uid, 1);
|
||||
}
|
||||
|
||||
public void initMap(int uid, int mapId) {
|
||||
// save db
|
||||
}
|
||||
|
||||
|
||||
private void initMap(int uid, int mapId) {
|
||||
if (mapId == 0) {
|
||||
mapId = 1;
|
||||
}
|
||||
|
@ -35,10 +54,59 @@ public class MapLogic {
|
|||
}
|
||||
CMap cMap = new CMap();
|
||||
cMap.setId(uid);
|
||||
cMap.setCurMapId(mapId);
|
||||
Map<Integer, Cell> mapInfo = cMap.getMapInfo();
|
||||
mapInfo.clear();
|
||||
Random random = new Random();
|
||||
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
|
||||
// cMap.getMapInfo().put()
|
||||
SCMap scMap1 = entry.getValue();
|
||||
Cell cellValue = new Cell();
|
||||
cellValue.getEventIds().add(scMap1.getEvent());
|
||||
int randomIndex = random.nextInt(scMap1.getGroups().length);
|
||||
int x = scMap1.getGroups()[randomIndex][0];
|
||||
int y = scMap1.getGroups()[randomIndex][1];
|
||||
int xy = ToolsUtil.xy2Pos(x, y);
|
||||
SCMapEvent scMapEvent = SCMapEvent.scMapEventMap.get(scMap1.getEvent());
|
||||
if (scMapEvent.getStyle() == EventType.enter) {
|
||||
cMap.setCurXY(xy);
|
||||
}
|
||||
mapInfo.put(xy, cellValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 完成事件,保存事件点
|
||||
* @param uid
|
||||
* @param xy
|
||||
*/
|
||||
public void finishEvent(int uid, int xy) {
|
||||
// get db
|
||||
CMap cMap = null;
|
||||
Cell cell = cMap.getMapInfo().get(xy);
|
||||
if (cell == null) {
|
||||
return;
|
||||
}
|
||||
if (cell.getEventIds().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
cMap.setCurXY(xy);
|
||||
cell.setFinish(true);
|
||||
SCMapEvent scMapEvent = SCMapEvent.scMapEventMap.get(cell.getEventIds());
|
||||
// 如果是出口开启跳转到下个关卡
|
||||
if (scMapEvent.getStyle() == EventType.disposable) {
|
||||
Map<Integer, List<Integer>> crossMapInfos = cMap.getCrossMapInfos();
|
||||
if (!crossMapInfos.containsKey(cMap.getCurMapId())) {
|
||||
crossMapInfos.put(cMap.getCurMapId(), new ArrayList<>());
|
||||
}
|
||||
crossMapInfos.get(cMap.getCurMapId()).addAll(cell.getEventIds());
|
||||
}
|
||||
if (scMapEvent.getStyle() == EventType.exit) {
|
||||
initMap(uid, cMap.getCurMapId() + 1);
|
||||
return;
|
||||
}
|
||||
cell.setFinish(true);
|
||||
// save db
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map_event")
|
||||
public class SCMapEvent implements BaseConfig{
|
||||
|
||||
public static Map<Integer, SCMapEvent> scMapEventMap;
|
||||
|
||||
private int id;
|
||||
/**
|
||||
* "事件点类型
|
||||
* 1怪物 2怪物群 3矿 4入口 5出口 6一次性事件 7重复事件 8npc 9地图boss "
|
||||
*/
|
||||
private int style;
|
||||
/**
|
||||
* 时间点的刷新规则
|
||||
* 1每日刷新
|
||||
* 2探索刷新
|
||||
* 3一次性
|
||||
*/
|
||||
private int refrsh;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
scMapEventMap = STableManager.getConfig(SCMapEvent.class);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
public int getRefrsh() {
|
||||
return refrsh;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue