back_recharge
jiahuiwen 2019-01-18 15:38:07 +08:00
parent 96c9a573b8
commit 5fa0f5b0f4
9 changed files with 119 additions and 57 deletions

View File

@ -57,7 +57,10 @@ public class MongoUpdateCache {
valueDBObj.append(request.fullKey, ljsdMongoTemplate.convertToMongoType(request.value));
request.mongoBase.set_save(false);
}
if (!valueDBObj.isEmpty()) {
dbobj.append("$set", valueDBObj);
}
if (!removedbobj.isEmpty()) {
dbobj.append("$unset", removedbobj);
}

View File

@ -39,7 +39,7 @@ public class SCHero implements BaseConfig{
@Override
public void init() throws Exception {
sCHero = STableManager.getConfig(SCHero.class);
// sCHero = STableManager.getConfig(SCHero.class);
}

View File

@ -6,7 +6,7 @@ import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name = "1.Map")
@Table(name = "Map")
public class SCMap implements BaseConfig {
public static Map<Integer, Map<Integer, SCMap>> sCMap;
private int id;

View File

@ -3,16 +3,17 @@ package com.ljsd.jieling.handler.map;
public class EventType {
/**
*
* 1 2 3 4 5 6 7 8
* 1 2 3 4 5 6 7 8
*/
public static final int enter = 0;
public static final int monster = 1;
public static final int mine = 2;
public static final int enter = 3;
public static final int exit = 4;
public static final int continuity = 5;
public static final int businessman = 6;
public static final int box = 7;
public static final int obstacle = 8;
public static final int portal = 3;
public static final int continuity = 4;
public static final int businessman = 5;
public static final int box = 6;
public static final int hinder = 7;
public static final int allEvents = 8;
/**
*

View File

@ -1,11 +1,13 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.config.SCMap;
import com.ljsd.jieling.config.SCMapEventsItemConfig;
import com.ljsd.jieling.logic.dao.MapManager;
import com.ljsd.jieling.logic.dao.User;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
@ -20,7 +22,9 @@ public class MapLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
private MapLogic(){}
private MapLogic() {
}
/**
*
*
@ -36,6 +40,7 @@ public class MapLogic {
/**
*
*
* @param mapId
*/
public void enterMap(ISession iSession, int mapId, MessageTypeProto.MessageType messageType) throws Exception {
@ -43,35 +48,55 @@ public class MapLogic {
User user = UserManager.getUser(uid);
MapManager mapManager = user.getMapManager();
if (mapManager.getCurMapId() == 0) {
mapManager = initMap( 1);
user.getPlayerInfoManager().setMapId(101);
mapManager.setCurMapId(101);
initMap(mapManager);
user.setMapManager(mapManager);
} else {
if (mapId > mapManager.getCurMapId()) {
mapManager = initMap(mapManager.getCurMapId());
} else {
mapManager = initMap(mapId);
if (mapManager == null) {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
if (scMap == null) {
return;
}
if (mapId > mapManager.getCurMapId()) {
return;
}
if (mapId != mapManager.getCurMapId()) {
initMap(mapManager);
user.setMapManager(mapManager);
}
}
List<CommonProto.Common.Cell> cells = new ArrayList<>(mapManager.getMapInfo().size());
for (Map.Entry<Integer, Cell> entry : mapManager.getMapInfo().entrySet()) {
List<CommonProto.Common.CellEvent> cellEvents = new ArrayList<>();
Cell cell = entry.getValue();
for (Map.Entry<Integer, Integer> cellEntry : cell.getEventIds().entrySet()) {
CommonProto.Common.CellEvent cellEvent = CommonProto.Common.CellEvent
.newBuilder()
.setEventId(cellEntry.getKey())
.setState(cellEntry.getValue())
.build();
cellEvents.add(cellEvent);
}
CommonProto.Common.Cell cellProto = CommonProto.Common.Cell
.newBuilder()
.setCellId(entry.getKey())
.addAllCellEvents(cellEvents)
.build();
cells.add(cellProto);
}
MapInfoProto.MapInfo.MapEnterResponse mapEnterResponse = MapInfoProto.MapInfo.MapEnterResponse
.newBuilder()
.addAllMapList(cells)
.setCurXY(mapManager.getCurXY())
.build();
MessageUtil.sendMessage(iSession, 1, messageType.getNumber(), mapEnterResponse, true);
}
private MapManager initMap(int mapId) throws Exception {
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapId);
if (scMap == null) {
return null;
}
MapManager mapManager = new MapManager();
mapManager.setCurMapId(mapId);
Map<Integer, Cell> mapInfo = mapManager.getMapInfo();
mapInfo.clear();
private void initMap(MapManager mapManager) 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();
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
@ -85,14 +110,20 @@ public class MapLogic {
if (scMapEvent.getStyle() == EventType.enter) {
mapManager.setCurXY(xy);
}
mapInfo.put(xy, cellValue);
if (scMapEvent.getStyle() == EventType.allEvents) {
spicelMap.put(xy, cellValue);
} else {
newMap.put(xy, cellValue);
}
return mapManager;
}
mapManager.setMapInfo(newMap);
mapManager.setTypeEight(spicelMap);
}
/**
*
*
* @param uid
* @param xy
*/
@ -165,7 +196,8 @@ public class MapLogic {
case EventType.eatBuff: {
break;
} default:{
}
default: {
return;
}
}
@ -186,8 +218,8 @@ public class MapLogic {
// }
// crossMapInfos.get(cMap.getCurMapId()).addAll(cell.getEventIds());
// }
if (scMapEvent.getStyle() == EventType.exit) {
initMap(mapManager.getCurMapId() + 1);
if (scMapEvent.getStyle() == EventType.portal) {
user.getPlayerInfoManager().setMapId(user.getPlayerInfoManager().getMapId() + 1);
return;
}
}

View File

@ -6,11 +6,11 @@ import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
@Component
//@Component
public class MapUpdateEventRequestHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.MAP_ENTER_REQUEST;
return null;
}
@Override

View File

@ -159,7 +159,7 @@ public class STableManager {
lineNum++;
}
map.put(i, mapConf);
tableName = tableName.substring(0, 5);
tableName = tableName.substring(0, 3);
}
return map;
}

View File

@ -18,6 +18,8 @@ public class MapManager extends MongoBase {
private Map<Integer, Cell> mapInfo = new ConcurrentHashMap<>();
private Map<Integer, Cell> typeEight = new ConcurrentHashMap<>();
private Map<Integer, List<Integer>> crossMapInfos = new ConcurrentHashMap<>();
public Map<Integer, Cell> getMapInfo() {
@ -33,7 +35,7 @@ public class MapManager extends MongoBase {
}
public void setCurMapId(int curMapId) throws Exception {
updateString("curMapId", curXY);
updateString("curMapId", curMapId);
this.curMapId = curMapId;
}
@ -47,13 +49,26 @@ public class MapManager extends MongoBase {
}
public void addOrUpdateCell(int key, Cell cell) throws Exception {
updateString(getMongoKey() + ".mapInfo." + key, mapInfo);
updateString( "mapInfo." + key, cell);
this.mapInfo.put(key, cell);
}
public void removeCell(int key) {
removeString(getMongoKey() + ".mapInfo." + key);
this.mapInfo.remove(key);
public void setMapInfo(Map<Integer, Cell> mapInfo) throws Exception {
updateString( "mapInfo", mapInfo);
this.mapInfo = mapInfo;
}
public void removeAllCell() {
removeString("mapInfo");
this.mapInfo.clear();
}
public Map<Integer, Cell> getTypeEight() {
return typeEight;
}
public void setTypeEight(Map<Integer, Cell> typeEight) throws Exception {
updateString( "typeEight", typeEight);
this.typeEight = typeEight;
}
}

View File

@ -23,6 +23,8 @@ public class PlayerManager extends MongoBase {
private int chargeGem;
private int mapId;
public String getNickName() {
return nickName;
@ -104,4 +106,13 @@ public class PlayerManager extends MongoBase {
updateString("chargeGem", chargeGem);
this.chargeGem = chargeGem;
}
public int getMapId() {
return mapId;
}
public void setMapId(int mapId) throws Exception {
updateString("mapId", mapId);
this.mapId = mapId;
}
}