戒灵地图

back_recharge
jiahuiwen 2019-01-04 13:39:02 +08:00
parent 6a39b09166
commit 11cd52dbd8
14 changed files with 208 additions and 155 deletions

View File

@ -1,3 +0,0 @@
id length width
int int int
1 10 20

View File

@ -1,6 +1,7 @@
package com.ljsd.jieling; package com.ljsd.jieling;
import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.netty.server.NettyGameServer; import com.ljsd.jieling.netty.server.NettyGameServer;
import com.ljsd.jieling.network.NettyProperties; import com.ljsd.jieling.network.NettyProperties;
import com.ljsd.jieling.network.NettyServerAutoConfiguration; import com.ljsd.jieling.network.NettyServerAutoConfiguration;
@ -34,7 +35,7 @@ public class GameApplication {
public static String coreIp; public static String coreIp;
public static boolean start = false; public static boolean start = false;
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws Exception {
start = true; start = true;
app = new SpringApplication(GameApplication.class); app = new SpringApplication(GameApplication.class);
app.setRegisterShutdownHook(false); app.setRegisterShutdownHook(false);
@ -52,7 +53,7 @@ public class GameApplication {
for (BaseHandler handler : gameHanderMap.values()) { for (BaseHandler handler : gameHanderMap.values()) {
protocolsManager.addHandler(handler); protocolsManager.addHandler(handler);
} }
STableManager.initialize("com.ljsd.jieling.models");
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class); final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
NettyProperties properties = netServerConfig.getNettyProperties(); NettyProperties properties = netServerConfig.getNettyProperties();
try { try {

View File

@ -1,6 +1,8 @@
package com.ljsd.jieling.logic; package com.ljsd.jieling.logic;
import com.ljsd.jieling.util.StringUtil;
import com.ljsd.jieling.util.SysUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -105,7 +107,6 @@ public class STableManager {
break; break;
} }
lineNum++; lineNum++;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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;
}
/** /**
* *
*/ */

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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()
}
}
}

View File

@ -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;
}
}

View File

@ -7,31 +7,31 @@ import com.ljsd.jieling.logic.Table;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Table(name = "s_c_map2_size") @Table(name = "s_c_map_size")
public class sCMapSize2 implements BaseConfig { public class SCMapSize implements BaseConfig {
public static Map<Integer, sCMapSize2> sCMapSize1; public Map<Integer, SCMapSize> sCMapSize;
public static Map<Integer, sCMapSize2> sCardMapSizeById; public Map<Integer, SCMapSize> sCardMapSizeById;
private int id; private int id;
private int length; private int length;
private int width; private int width;
@Override @Override
public void init() throws Exception { public void init() throws Exception {
sCMapSize1 = STableManager.getConfig(sCMapSize2.class); sCMapSize = STableManager.getConfig(SCMapSize.class);
sCardMapSizeById = new HashMap<>(); 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()); sCardMapSizeById.put(entry.getValue().getId(), entry.getValue());
} }
} }
public int getId() { public int getId() {
return id; return id;
} }
public static Map<Integer, sCMapSize2> getsCMapSize1() { public Map<Integer, SCMapSize> getsCMapSize() {
return sCMapSize1; return sCMapSize;
} }
public static Map<Integer, sCMapSize2> getsCardMapSizeById() { public Map<Integer, SCMapSize> getsCardMapSizeById() {
return sCardMapSizeById; return sCardMapSizeById;
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,4 +1,4 @@
package com.ljsd.jieling.logic; package com.ljsd.jieling.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package com.ljsd.jieling.logic; package com.ljsd.jieling.util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;