戒灵地图
parent
6a39b09166
commit
11cd52dbd8
|
@ -1,3 +0,0 @@
|
|||
id length width
|
||||
int int int
|
||||
1 10 20
|
|
@ -1,6 +1,7 @@
|
|||
package com.ljsd.jieling;
|
||||
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.netty.server.NettyGameServer;
|
||||
import com.ljsd.jieling.network.NettyProperties;
|
||||
import com.ljsd.jieling.network.NettyServerAutoConfiguration;
|
||||
|
@ -34,7 +35,7 @@ public class GameApplication {
|
|||
public static String coreIp;
|
||||
public static boolean start = false;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
public static void main(String[] args) throws Exception {
|
||||
start = true;
|
||||
app = new SpringApplication(GameApplication.class);
|
||||
app.setRegisterShutdownHook(false);
|
||||
|
@ -52,7 +53,7 @@ public class GameApplication {
|
|||
for (BaseHandler handler : gameHanderMap.values()) {
|
||||
protocolsManager.addHandler(handler);
|
||||
}
|
||||
|
||||
STableManager.initialize("com.ljsd.jieling.models");
|
||||
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
|
||||
NettyProperties properties = netServerConfig.getNettyProperties();
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
|
||||
|
||||
import com.ljsd.jieling.util.StringUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -105,7 +107,6 @@ public class STableManager {
|
|||
break;
|
||||
}
|
||||
lineNum++;
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -114,6 +115,49 @@ public class STableManager {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取配置表到内存
|
||||
*/
|
||||
public static <T> Map<Integer, Map<Integer, T>> getMapConfig(Class<T> clazz) throws Exception {
|
||||
Map<Integer, Map<Integer, T>> map = new HashMap<>();
|
||||
String tableName = clazz.getAnnotation(Table.class).name();
|
||||
for (int i = 1; i < 100; i++) {
|
||||
Map<Integer, T> mapConf = new HashMap<>();
|
||||
tableName = tableName + i;
|
||||
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
break;
|
||||
}
|
||||
String line;
|
||||
List<String> key = new ArrayList<>();
|
||||
List<String> type = new ArrayList<>();
|
||||
int lineNum = 0;
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
|
||||
LOGGER.info("initMap:{}", tableName);
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
T obj = clazz.newInstance();
|
||||
String[] prarms = line.split("\\t");
|
||||
switch (lineNum) {
|
||||
case 0:
|
||||
prarms = StringUtil.fieldHandle(prarms);
|
||||
key.addAll(Arrays.asList(prarms));
|
||||
break;
|
||||
case 1:
|
||||
type.addAll(Arrays.asList(prarms));
|
||||
break;
|
||||
default:
|
||||
dealParams(clazz, mapConf, key, type, obj, prarms);
|
||||
break;
|
||||
}
|
||||
lineNum++;
|
||||
}
|
||||
map.put(i, mapConf);
|
||||
tableName = tableName.substring(0, 7);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理参数
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
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.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Document(collection = "c_map")
|
||||
public class CMap {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@Field(value = "mapInfo")
|
||||
private Map<Integer, CCell> mapInfo = new ConcurrentHashMap<>();
|
||||
|
||||
@Field(value = "crossMapInfos")
|
||||
private Map<Integer, Integer> crossMapInfos = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<Integer, CCell> getMapInfo() {
|
||||
return mapInfo;
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getCrossMapInfos() {
|
||||
return crossMapInfos;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.ljsd.jieling.logic.map;
|
||||
|
||||
import com.ljsd.jieling.models.SCMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MapLogic {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
|
||||
|
||||
private MapLogic(){}
|
||||
/**
|
||||
* 获取单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static MapLogic getInstance() {
|
||||
return Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static MapLogic instance = new MapLogic();
|
||||
}
|
||||
|
||||
|
||||
public void initMap(int uid, int mapId) {
|
||||
if (mapId == 0) {
|
||||
mapId = 1;
|
||||
}
|
||||
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
|
||||
if (scMap == null) {
|
||||
return;
|
||||
}
|
||||
CMap cMap = new CMap();
|
||||
cMap.setId(uid);
|
||||
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
|
||||
// cMap.getMapInfo().put()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
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")
|
||||
public class SCMap implements BaseConfig {
|
||||
public static Map<Integer, Map<Integer, SCMap>> sCMap;
|
||||
private int id;
|
||||
private int event;
|
||||
private int[][] groups;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMap = STableManager.getMapConfig(SCMap.class);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public int[][] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
|
@ -7,31 +7,31 @@ import com.ljsd.jieling.logic.Table;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map2_size")
|
||||
public class sCMapSize2 implements BaseConfig {
|
||||
public static Map<Integer, sCMapSize2> sCMapSize1;
|
||||
public static Map<Integer, sCMapSize2> sCardMapSizeById;
|
||||
@Table(name = "s_c_map_size")
|
||||
public class SCMapSize implements BaseConfig {
|
||||
public Map<Integer, SCMapSize> sCMapSize;
|
||||
public Map<Integer, SCMapSize> sCardMapSizeById;
|
||||
private int id;
|
||||
private int length;
|
||||
private int width;
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMapSize1 = STableManager.getConfig(sCMapSize2.class);
|
||||
sCMapSize = STableManager.getConfig(SCMapSize.class);
|
||||
sCardMapSizeById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMapSize2> entry : sCMapSize1.entrySet()) {
|
||||
for (Map.Entry<Integer, SCMapSize> entry : sCMapSize.entrySet()) {
|
||||
sCardMapSizeById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMapSize2> getsCMapSize1() {
|
||||
return sCMapSize1;
|
||||
public Map<Integer, SCMapSize> getsCMapSize() {
|
||||
return sCMapSize;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMapSize2> getsCardMapSizeById() {
|
||||
public Map<Integer, SCMapSize> getsCardMapSizeById() {
|
||||
return sCardMapSizeById;
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map1")
|
||||
public class sCMap1 implements BaseConfig {
|
||||
public static Map<Integer, sCMap1> sCMap1;
|
||||
public static Map<Integer, sCMap1> sCardMapById;
|
||||
private int id;
|
||||
private int event;
|
||||
private int[][] groups;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMap1 = STableManager.getConfig(sCMap1.class);
|
||||
sCardMapById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMap1> entry : sCMap1.entrySet()) {
|
||||
sCardMapById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap1> getsCMap1() {
|
||||
return sCMap1;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap1> getsCardMapById() {
|
||||
return sCardMapById;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public int[][] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map2")
|
||||
public class sCMap2 implements BaseConfig {
|
||||
public static Map<Integer, sCMap2> sCMap1;
|
||||
public static Map<Integer, sCMap2> sCardMapById;
|
||||
private int id;
|
||||
private int event;
|
||||
private int[][] groups;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMap1 = STableManager.getConfig(sCMap2.class);
|
||||
sCardMapById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMap2> entry : sCMap1.entrySet()) {
|
||||
sCardMapById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap2> getsCMap1() {
|
||||
return sCMap1;
|
||||
}
|
||||
|
||||
public static Map<Integer, sCMap2> getsCardMapById() {
|
||||
return sCardMapById;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
public int[][] getGroups() {
|
||||
return groups;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package com.ljsd.jieling.models;
|
||||
|
||||
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.Table;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name = "s_c_map1_size")
|
||||
public class sCMapSize1 implements BaseConfig {
|
||||
public static Map<Integer, sCMapSize1> sCMapSize1;
|
||||
public static Map<Integer, sCMapSize1> sCardMapSizeById;
|
||||
private int id;
|
||||
private int length;
|
||||
private int width;
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
sCMapSize1 = STableManager.getConfig(sCMapSize1.class);
|
||||
sCardMapSizeById = new HashMap<>();
|
||||
for (Map.Entry<Integer, sCMapSize1> entry : sCMapSize1.entrySet()) {
|
||||
sCardMapSizeById.put(entry.getValue().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static Map<Integer, com.ljsd.jieling.models.sCMapSize1> getsCMapSize1() {
|
||||
return sCMapSize1;
|
||||
}
|
||||
|
||||
public static Map<Integer, com.ljsd.jieling.models.sCMapSize1> getsCardMapSizeById() {
|
||||
return sCardMapSizeById;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
package com.ljsd.jieling.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
|||
package com.ljsd.jieling.logic;
|
||||
package com.ljsd.jieling.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
Loading…
Reference in New Issue