地图只能放一个事件

back_recharge
jiahuiwen 2019-01-22 12:03:27 +08:00
parent 20aa0dbe48
commit ab03ce293e
4 changed files with 53 additions and 37 deletions

View File

@ -1,13 +1,40 @@
package com.ljsd.jieling.handler.map;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class Cell {
private Map<Integer, Integer> eventIds = new ConcurrentHashMap();
private int cellId;
public Map<Integer, Integer> getEventIds() {
return eventIds;
private int eventId;
private int state;
public Cell(int cellId, int eventId, int state) {
this.cellId = cellId;
this.eventId = eventId;
this.state = state;
}
public int getCellId() {
return cellId;
}
public void setCellId(int cellId) {
this.cellId = cellId;
}
public int getEventId() {
return eventId;
}
public void setEventId(int eventId) {
this.eventId = eventId;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
}

View File

@ -3,17 +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 9)
*/
public static final int enter = 0;
public static final int monster = 1;
public static final int mine = 2;
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;
public static final int enter = 3;
public static final int portal = 4;
public static final int continuity = 5;
public static final int businessman = 6;
public static final int box = 7;
public static final int hinder = 8;
public static final int allEvents = 9;
/**
*

View File

@ -7,6 +7,8 @@ import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class MapEnterRequestHandler extends BaseHandler{
@Override
@ -18,6 +20,7 @@ public class MapEnterRequestHandler extends BaseHandler{
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] message = netData.parseClientProtoNetData();
MapInfoProto.MapEnterRequest mapEnterRequest = MapInfoProto.MapEnterRequest.parseFrom(message);
MapLogic.getInstance().enterMap(iSession, mapEnterRequest.getMapId(), MessageTypeProto.MessageType.MAP_ENTER_RESPONSE);
List<MapInfoProto.HeroInfo> heroInfosList = mapEnterRequest.getHeroInfosList();
MapLogic.getInstance().enterMap(iSession, mapEnterRequest.getMapId(), heroInfosList, MessageTypeProto.MessageType.MAP_ENTER_RESPONSE);
}
}

View File

@ -45,7 +45,7 @@ public class MapLogic {
*
* @param mapId
*/
public void enterMap(ISession iSession, int mapId, MessageTypeProto.MessageType messageType) throws Exception {
public void enterMap(ISession iSession, int mapId, List<MapInfoProto.HeroInfo> heroInfosList, MessageTypeProto.MessageType messageType) throws Exception {
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
MapManager mapManager = user.getMapManager();
@ -69,20 +69,12 @@ public class MapLogic {
}
List<CommonProto.Cell> cells = new ArrayList<>(mapManager.getMapInfo().size());
for (Map.Entry<Integer, Cell> entry : mapManager.getMapInfo().entrySet()) {
List<CommonProto.CellEvent> cellEvents = new ArrayList<>();
Cell cell = entry.getValue();
for (Map.Entry<Integer, Integer> cellEntry : cell.getEventIds().entrySet()) {
CommonProto.CellEvent cellEvent = CommonProto.CellEvent
.newBuilder()
.setEventId(cellEntry.getKey())
.setState(cellEntry.getValue())
.build();
cellEvents.add(cellEvent);
}
CommonProto.Cell cellProto = CommonProto.Cell
.newBuilder()
.setCellId(entry.getKey())
.addAllCellEvents(cellEvents)
.setEventId(cell.getEventId())
.setState(cell.getState())
.build();
cells.add(cellProto);
}
@ -102,12 +94,11 @@ public class MapLogic {
Random random = new Random();
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
Cell cellValue = new Cell();
cellValue.getEventIds().put(scMap1.getEvent(), 0);
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);
Cell cellValue = new Cell(xy, scMap1.getEvent(), 0);
SCMapEventsConfig scMapEvent = SCMapEventsConfig.scMapEventMap.get(scMap1.getEvent());
if (scMapEvent.getStyle() == EventType.enter) {
mapManager.setCurXY(xy);
@ -178,17 +169,12 @@ public class MapLogic {
LOGGER.info("xy is wrong =>{}", xy);
return;
}
if (cell.getEventIds().isEmpty()) {
LOGGER.info("no event eventId");
return;
}
mapManager.setCurXY(xy);
Map<Integer, Integer> eventIds = cell.getEventIds();
if (!eventIds.containsKey(bigEventId)) {
if (cell.getEventId() != bigEventId) {
LOGGER.info("no this event eventId=>{}", bigEventId);
return;
}
int schedule = eventIds.get(bigEventId);
int schedule = cell.getState();
if (schedule == -1) {
LOGGER.info("event is finished,bigEventId=>{} smallEventId=>{}", bigEventId, -1);
return;
@ -239,13 +225,13 @@ public class MapLogic {
}
}
if (scMapEventsItemConfig.getJump() == null || scMapEventsItemConfig.getJump().length == 0) {
cell.getEventIds().put(bigEventId, schedule + 1);
cell.setState(schedule + 1);
} else {
int[][] jumps = scMapEventsItemConfig.getJump();
for (int i = 0; i < jumps.length; i++) {
int[] jump = jumps[i];
if (jump[0] == choice - 1) {
cell.getEventIds().put(bigEventId, jump[1]);
cell.setState(jump[1]);
break;
}
}