From 1224c2606b4f126b7cb7f080393285f6c4d177b3 Mon Sep 17 00:00:00 2001 From: jiahuiwen <1024696487@qq.com> Date: Tue, 22 Jan 2019 09:45:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jieling/config/SCMapEventsItemConfig.java | 36 ++++++++++--- .../com/ljsd/jieling/db/redis/RedisKey.java | 11 +++- .../com/ljsd/jieling/db/redis/RedisUtil.java | 6 +++ .../handler/map/MapEnterRequestHandler.java | 2 +- .../map/MapFightEndRequestHandler.java | 18 +++++++ .../ljsd/jieling/handler/map/MapLogic.java | 54 ++++++++++++------- .../map/MapUpdateEventRequestHandler.java | 9 ++-- .../ljsd/jieling/logic/dao/MapManager.java | 6 ++- 8 files changed, 110 insertions(+), 32 deletions(-) create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapFightEndRequestHandler.java diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/SCMapEventsItemConfig.java b/serverlogic/src/main/java/com/ljsd/jieling/config/SCMapEventsItemConfig.java index 49c342a3c..fa55e24ce 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/config/SCMapEventsItemConfig.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/SCMapEventsItemConfig.java @@ -20,8 +20,8 @@ public class SCMapEventsItemConfig implements BaseConfig{ private int eventsId; /** * 排序 - * */ - private int sort; + */ + private int order; /** * 事件内容 */ @@ -31,6 +31,16 @@ public class SCMapEventsItemConfig implements BaseConfig{ */ private String reward; + /** + * 结果跳转 + */ + private String jump; + + /** + * 开启条件 + */ + private String openRules; + @Override public void init() throws Exception { scMapEventsItemConfigMap = STableManager.getConfig(SCMapEventsItemConfig.class); @@ -39,7 +49,7 @@ public class SCMapEventsItemConfig implements BaseConfig{ if (!scMapEventsItemConfigs.containsKey(eventsItemConfigEntry.getEventId())) { scMapEventsItemConfigs.put(eventsItemConfigEntry.getEventId(), new HashMap<>()); } - scMapEventsItemConfigs.get(eventsItemConfigEntry.getEventId()).put(eventsItemConfigEntry.getSort(), eventsItemConfigEntry); + scMapEventsItemConfigs.get(eventsItemConfigEntry.getEventId()).put(eventsItemConfigEntry.getOrder(), eventsItemConfigEntry); } } @@ -51,10 +61,6 @@ public class SCMapEventsItemConfig implements BaseConfig{ return eventsId; } - public int getSort() { - return sort; - } - public String getContents() { return contents; } @@ -62,4 +68,20 @@ public class SCMapEventsItemConfig implements BaseConfig{ public String getReward() { return reward; } + + public int getEventsId() { + return eventsId; + } + + public int getOrder() { + return order; + } + + public String getJump() { + return jump; + } + + public String getOpenRules() { + return openRules; + } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java index cb0792623..990100cf9 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisKey.java @@ -8,12 +8,21 @@ public class RedisKey { public static final String TOKEN = "JL_TOKEN"; + public static final String UNDERLINE_LINE = "_"; + /** * 最近登录服务器列表 */ public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO"; - + /** + * 战斗缓存 + */ + public static final String FIGHT = "FIGHT"; + /** + * 过期事件 + */ + public static final int EXPIRE_TIME = 3600 * 24; public static String getKey(String type, String key, boolean withServerId) { diff --git a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisUtil.java b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisUtil.java index db83f12d8..389dc4602 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisUtil.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/db/redis/RedisUtil.java @@ -113,6 +113,12 @@ public class RedisUtil { return key == null ? null : redisTemplate.opsForValue().get(key); } + public String getAndDelete(String key) { + String value = redisTemplate.opsForValue().get(key); + del(key); + return value; + } + /** * 普通缓存放入 * diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapEnterRequestHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapEnterRequestHandler.java index 65df67fce..d896cb0c6 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapEnterRequestHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapEnterRequestHandler.java @@ -17,7 +17,7 @@ public class MapEnterRequestHandler extends BaseHandler{ @Override public void process(ISession iSession, PacketNetData netData) throws Exception { byte[] message = netData.parseClientProtoNetData(); - MapInfoProto.MapInfo.MapEnterRequest mapEnterRequest = MapInfoProto.MapInfo.MapEnterRequest.parseFrom(message); + MapInfoProto.MapEnterRequest mapEnterRequest = MapInfoProto.MapEnterRequest.parseFrom(message); MapLogic.getInstance().enterMap(iSession, mapEnterRequest.getMapId(), MessageTypeProto.MessageType.MAP_ENTER_RESPONSE); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapFightEndRequestHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapFightEndRequestHandler.java new file mode 100644 index 000000000..08ef71229 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapFightEndRequestHandler.java @@ -0,0 +1,18 @@ +package com.ljsd.jieling.handler.map; + +import com.ljsd.jieling.handler.BaseHandler; +import com.ljsd.jieling.netty.cocdex.PacketNetData; +import com.ljsd.jieling.network.session.ISession; +import com.ljsd.jieling.protocols.MessageTypeProto; + +public class MapFightEndRequestHandler extends BaseHandler { + @Override + public MessageTypeProto.MessageType getMessageCode() { + return MessageTypeProto.MessageType.FIGHT_END_REQUEST; + } + + @Override + public void process(ISession iSession, PacketNetData netData) throws Exception { + + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java index 534532ce3..09e92c6ae 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapLogic.java @@ -3,6 +3,8 @@ package com.ljsd.jieling.handler.map; import com.ljsd.jieling.config.SCMap; import com.ljsd.jieling.config.SCMapEventsConfig; import com.ljsd.jieling.config.SCMapEventsItemConfig; +import com.ljsd.jieling.db.redis.RedisKey; +import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.logic.dao.MapManager; import com.ljsd.jieling.logic.dao.User; import com.ljsd.jieling.logic.dao.UserManager; @@ -10,6 +12,7 @@ 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.ItemUtil; import com.ljsd.jieling.util.MessageUtil; import com.ljsd.jieling.util.ToolsUtil; import org.slf4j.Logger; @@ -83,7 +86,7 @@ public class MapLogic { .build(); cells.add(cellProto); } - MapInfoProto.MapInfo.MapEnterResponse mapEnterResponse = MapInfoProto.MapInfo.MapEnterResponse + MapInfoProto.MapEnterResponse mapEnterResponse = MapInfoProto.MapEnterResponse .newBuilder() .addAllMapList(cells) .setCurXY(mapManager.getCurXY()) @@ -122,28 +125,33 @@ public class MapLogic { /** * 战斗开始 */ - public void fightStart(ISession session, int bigEventId){ - + public void fightStart(int uid, int bigEventId){ + String key = RedisKey.getKey(RedisKey.FIGHT, Integer.toString(uid) + RedisKey.UNDERLINE_LINE + Integer.toString(bigEventId), false); + RedisUtil.getInstence().set(key, Integer.toString(uid), RedisKey.EXPIRE_TIME); } /** * 战斗结束 */ - public void fightEnd(ISession session, int bigEventId){ - + public void fightEnd(int uid) { + String key = RedisKey.getKey(RedisKey.FIGHT, Integer.toString(uid), false); + String fightInfo = RedisUtil.getInstence().getAndDelete(key); + if (fightInfo == null || fightInfo.isEmpty()) { + return; + } } /** * 使用物品(包括侦察和吃buff) */ - public void useItem(ISession session, int bigEventId){ + public void useItem(int uid){ } /** * 离开 */ - public void leave(ISession session, int bigEventId){ + public void leave(int uid){ } @@ -156,7 +164,7 @@ public class MapLogic { * @param session * @param xy */ - public void updateEvent(ISession session, int xy, int bigEventId, int choice, List cells) throws Exception { + public void updateEvent(ISession session, int xy, int bigEventId, int choice, List cells, MessageTypeProto.MessageType messageType) throws Exception { Set cellSet = new HashSet<>(cells); if (cells.size() != cellSet.size()) { LOGGER.info("cells has repeated"); @@ -199,16 +207,19 @@ public class MapLogic { String[] eventArr = contents[choice].split("#"); switch (Integer.parseInt(eventArr[0])) { case EventType.fight: { - fightStart(session, bigEventId); + fightStart(uid, bigEventId); break; } case EventType.attribute: { break; } + case EventType.eatBuff: case EventType.useItem: case EventType.scout: { - + Map useItems = new HashMap<>(); + useItems.put(Integer.parseInt(eventArr[1]), Integer.parseInt(eventArr[2])); + ItemUtil.useItem(user, useItems); break; } case EventType.leave: { @@ -223,20 +234,27 @@ public class MapLogic { break; } - case EventType.eatBuff: { - - break; - } default: { return; } } - if (schedule + 1 >= contents.length - 1) { - cell.getEventIds().put(bigEventId, -1); - } else { + if (scMapEventsItemConfig.getJump() == null || scMapEventsItemConfig.getJump().isEmpty()) { cell.getEventIds().put(bigEventId, schedule + 1); + } else { + String[] jumps = scMapEventsItemConfig.getJump().split("\\|"); + for (int i = 0; i < jumps.length; i++) { + String[] jump = jumps[i].split("#"); + if (Integer.parseInt(jump[0]) == choice - 1) { + cell.getEventIds().put(bigEventId, Integer.parseInt(jump[1])); + break; + } + } + } + String reward = scMapEventsItemConfig.getReward(); + if (reward != null && !reward.isEmpty()) { + Map itemMap = new HashMap<>(); + ItemUtil.addItem(user, itemMap); } - // 如果是传送门开启跳转到下个关卡 // if (scMapEvent.getStyle() == EventType.exit) { // Map> crossMapInfos = cMap.getCrossMapInfos(); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapUpdateEventRequestHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapUpdateEventRequestHandler.java index bfbb4ed5a..53d1b8d3c 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapUpdateEventRequestHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/map/MapUpdateEventRequestHandler.java @@ -3,18 +3,21 @@ package com.ljsd.jieling.handler.map; import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.netty.cocdex.PacketNetData; import com.ljsd.jieling.network.session.ISession; +import com.ljsd.jieling.protocols.MapInfoProto; import com.ljsd.jieling.protocols.MessageTypeProto; import org.springframework.stereotype.Component; -//@Component +@Component public class MapUpdateEventRequestHandler extends BaseHandler { @Override public MessageTypeProto.MessageType getMessageCode() { - return null; + return MessageTypeProto.MessageType.MAP_UDPATE_EVENT_REQUEST; } @Override public void process(ISession iSession, PacketNetData netData) throws Exception { - + byte[] message = netData.parseClientProtoNetData(); + MapInfoProto.MapUpdateEventRequest mapEnterRequest = MapInfoProto.MapUpdateEventRequest.parseFrom(message); + MapLogic.getInstance().updateEvent(iSession, mapEnterRequest.getCurXY(), mapEnterRequest.getBigEventId(), mapEnterRequest.getChoice(), mapEnterRequest.getCellsList(), MessageTypeProto.MessageType.MAP_UDPATE_EVENT_RESPONSE); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/MapManager.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/MapManager.java index 4c9086302..2d9efd9c4 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/MapManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/MapManager.java @@ -16,9 +16,11 @@ public class MapManager extends MongoBase { private int curXY; - private Map mapInfo = new ConcurrentHashMap<>(); + private Map heroHps; - private Map typeEight = new ConcurrentHashMap<>(); + private Map mapInfo; + + private Map typeEight; private Map> crossMapInfos = new ConcurrentHashMap<>();