优化地图中行为类型
parent
57898ddc91
commit
99ca55edba
|
@ -5,6 +5,7 @@ import com.ljsd.jieling.config.json.ServerConfiguration;
|
|||
import com.ljsd.jieling.config.json.ServerProperties;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.logic.STableManager;
|
||||
import com.ljsd.jieling.logic.dao.MailingSystemManager;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
|
@ -76,6 +77,7 @@ public class GameApplication {
|
|||
MailingSystemManager.init(configurableApplicationContext);
|
||||
ThreadManager threadManager = new ThreadManager();
|
||||
threadManager.init(configurableApplicationContext);
|
||||
MapLogic.getInstance().init(configurableApplicationContext);
|
||||
|
||||
final NettyServerAutoConfiguration netServerConfig = configurableApplicationContext.getBean(NettyServerAutoConfiguration.class);
|
||||
NettyProperties properties = netServerConfig.getNettyProperties();
|
||||
|
|
|
@ -4,9 +4,11 @@ import com.ljsd.jieling.config.*;
|
|||
import com.ljsd.jieling.core.GlobalsDef;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.handler.map.behavior.BaseBehavior;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import com.ljsd.jieling.logic.dao.Hero;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
|
@ -15,6 +17,7 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
|
|||
import com.ljsd.jieling.util.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -22,7 +25,17 @@ public class MapLogic {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
|
||||
|
||||
private Map<Integer, BaseBehavior> baseBehaviorMap = new HashMap<>();
|
||||
|
||||
public void init(ConfigurableApplicationContext configurableApplicationContext) {
|
||||
Map<String, BaseBehavior> beansOfType = configurableApplicationContext.getBeansOfType(BaseBehavior.class);
|
||||
for (BaseBehavior baseBehavior : beansOfType.values()) {
|
||||
baseBehaviorMap.put(baseBehavior.getBehaviorType(), baseBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
private MapLogic() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +116,7 @@ public class MapLogic {
|
|||
}
|
||||
|
||||
|
||||
private void initMap(MapManager mapManager, User user) throws Exception {
|
||||
public void initMap(MapManager mapManager, User user) throws Exception {
|
||||
Map<Integer, SCMap> scMap = SCMap.sCMap.get(mapManager.getCurMapId());
|
||||
Map<Integer, Cell> newMap = new HashMap<>();
|
||||
Map<Integer, Cell> spicelMap = new HashMap<>();
|
||||
|
@ -306,175 +319,18 @@ public class MapLogic {
|
|||
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
|
||||
return;
|
||||
}
|
||||
boolean isSuccess = false;
|
||||
int behaviorType = sOptionConfig.getBehaviorType();
|
||||
int[][] behaviorTypeValues = sOptionConfig.getBehaviorTypeValues();
|
||||
CommonProto.Mission openMission = null;
|
||||
switch (behaviorType) {
|
||||
case EventType.fight: {
|
||||
// heroFightInfos = fightStart(uid, bigEventId, user);
|
||||
isSuccess = true;
|
||||
break;
|
||||
}
|
||||
case EventType.eatBuff:
|
||||
case EventType.useItem:
|
||||
case EventType.scout: {
|
||||
Map<Integer, Integer> useItems = new HashMap<>();
|
||||
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
|
||||
ItemUtil.useItem(user, useItems);
|
||||
isSuccess = true;
|
||||
break;
|
||||
}
|
||||
case EventType.leave: {
|
||||
int randomInt = MathUtils.randomInt(100) + 1;
|
||||
if (randomInt <= behaviorTypeValues[0][0]) {
|
||||
isSuccess = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EventType.dun: {
|
||||
boolean hasMission = MissionLogic.getInstance().hasMission(user, behaviorTypeValues[0][0]);
|
||||
if (hasMission) {
|
||||
break;
|
||||
}
|
||||
SCMapConfig scMapConfig = SCMapConfig.getsCMapSize().get(mapManager.getCurMapId());
|
||||
int[] mapSize = scMapConfig.getSize();
|
||||
Map<Integer, Cell> newDunEvents = new HashMap<>();
|
||||
Map<Integer, MapPointConfig> newDunEventIds = new HashMap<>();
|
||||
int i = 0;
|
||||
Random random = new Random();
|
||||
while (newDunEventIds.size() < 3) {
|
||||
int randomIndex = random.nextInt(behaviorTypeValues[0].length - 3) + 3;
|
||||
int newDunEventId = behaviorTypeValues[0][randomIndex];
|
||||
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(newDunEventId);
|
||||
newDunEventIds.put(newDunEventIds.size(), mapPointConfig);
|
||||
i++;
|
||||
if (i >= 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newDunEventIds.size() < 3) {
|
||||
break;
|
||||
}
|
||||
i = 0;
|
||||
while (newDunEvents.size() < 3) {
|
||||
int x = random.nextInt(mapSize[0]) + 1;
|
||||
int y = random.nextInt(mapSize[1]) + 1;
|
||||
int xy = CellUtil.xy2Pos(x, y);
|
||||
if (mapManager.getMapInfo().containsKey(xy)) {
|
||||
continue;
|
||||
}
|
||||
MapPointConfig mapPointConfig = newDunEventIds.get(newDunEvents.size());
|
||||
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
|
||||
newDunEvents.put(xy, cellValue);
|
||||
i++;
|
||||
if (i >= 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mapManager.getMapInfo().putAll(newDunEvents);
|
||||
Mission mission = new Mission();
|
||||
mission.setMissionId(behaviorTypeValues[0][0]);
|
||||
mission.setMissionStep(0);
|
||||
mission.getMissionInfos().putAll(newDunEvents);
|
||||
mission.setMissionInfo(mapManager.getCurXY() + "#" + behaviorTypeValues[0][2] + "#" + behaviorTypeValues[0][1]);
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
doingMissions.put(behaviorTypeValues[0][0], mission);
|
||||
user.getMissionManager().updateDoingMissions(doingMissions);
|
||||
openMission = getMission(newDunEvents, mission);
|
||||
CrossMapCell crossMapInfo = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
|
||||
if (crossMapInfo == null) {
|
||||
crossMapInfo = new CrossMapCell();
|
||||
}
|
||||
crossMapInfo.getMissionIds().add(behaviorTypeValues[0][0]);
|
||||
mapManager.updateCrossMapInfos(mapManager.getCurMapId(), crossMapInfo);
|
||||
break;
|
||||
}
|
||||
case EventType.jump: {
|
||||
isSuccess = true;
|
||||
if (behaviorTypeValues[0][0] != 0) {
|
||||
mapManager.setCurMapId(behaviorTypeValues[0][0]);
|
||||
initMap(mapManager, user);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EventType.destroyMission: {
|
||||
isSuccess = true;
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
break;
|
||||
}
|
||||
String newEventId = MissionLogic.getInstance().checkMission(mission, user);
|
||||
Map<Integer, Cell> mapInfo = new HashMap<>(mapManager.getMapInfo());
|
||||
mapInfo.remove(mapManager.getCurXY());
|
||||
if (newEventId != null && !newEventId.isEmpty()) {
|
||||
String[] split = newEventId.split("#");
|
||||
Cell cellUpdate = mapInfo.get(Integer.parseInt(split[0]));
|
||||
if (cellUpdate != null) {
|
||||
cellUpdate.setEventId(Integer.parseInt(split[1]));
|
||||
}
|
||||
}
|
||||
mapManager.setMapInfo(mapInfo);
|
||||
openMission = getMission(mission.getMissionInfos(), mission);
|
||||
break;
|
||||
}
|
||||
case EventType.monitorMission: {
|
||||
isSuccess = true;
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
break;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
openMission = getMission(mission.getMissionInfos(), mission);
|
||||
break;
|
||||
}
|
||||
case EventType.openMission: {
|
||||
isSuccess = true;
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
break;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
openMission = getMission(mission.getMissionInfos(), mission);
|
||||
// TODO 还要开新事件
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case EventType.finishMission: {
|
||||
isSuccess = true;
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
break;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
openMission = getMission(mission.getMissionInfos(), mission);
|
||||
break;
|
||||
}
|
||||
case EventType.useItemMission: {
|
||||
isSuccess = true;
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
break;
|
||||
}
|
||||
boolean checkCost = ItemUtil.itemCost(user, behaviorTypeValues);
|
||||
if (!checkCost) {
|
||||
break;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
openMission = getMission(mission.getMissionInfos(), mission);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
BaseBehavior baseBehavior = baseBehaviorMap.get(behaviorType);
|
||||
MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse = MapInfoProto.EventUpdateResponse.newBuilder();
|
||||
if (baseBehavior != null) {
|
||||
boolean isSuccess = baseBehavior.process(user, behaviorTypeValues, eventUpdateResponse);
|
||||
if (!isSuccess) {
|
||||
LOGGER.info("updateEvent() baseBehavior process fail! behaviorType=>{}", behaviorType);
|
||||
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int jumpType = sOptionConfig.getJumpType();
|
||||
int nextPoint = 0;
|
||||
int[][] jumpTypeValues = sOptionConfig.getJumpTypeValues();
|
||||
|
@ -510,39 +366,47 @@ public class MapLogic {
|
|||
return;
|
||||
}
|
||||
// 1 完成事件点,即进度100%
|
||||
if (sOptionAddConditions.getType() == 1) {
|
||||
int doneEvent = sOptionAddConditions.getValues()[0][0];
|
||||
for (Cell cell1 : mapManager.getMapInfo().values()) {
|
||||
if (cell1.getPointId() == doneEvent) {
|
||||
if (cell1.getEventId() >= sOptionAddConditions.getValues()[0][1]) {
|
||||
nextPoint = jumpTypeValues[0][0];
|
||||
switch (sOptionAddConditions.getType()) {
|
||||
case 1:{
|
||||
int doneEvent = sOptionAddConditions.getValues()[0][0];
|
||||
for (Cell cell1 : mapManager.getMapInfo().values()) {
|
||||
if (cell1.getPointId() == doneEvent) {
|
||||
if (cell1.getEventId() >= sOptionAddConditions.getValues()[0][1]) {
|
||||
nextPoint = jumpTypeValues[0][0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// 2 物品数量
|
||||
} else if (sOptionAddConditions.getType() == 2) {
|
||||
|
||||
case 2:{
|
||||
break;
|
||||
}
|
||||
// 3 角色属性
|
||||
} else if (sOptionAddConditions.getType() == 3){
|
||||
|
||||
case 3:{
|
||||
break;
|
||||
}
|
||||
// 完成某个任务的第几步
|
||||
} else if (sOptionAddConditions.getType() == 4){
|
||||
Set<Integer> finishMissions = user.getMissionManager().getFinishMissions();
|
||||
Set<Integer> takeRewardMissions = user.getMissionManager().getTakeRewardMissions();
|
||||
if (finishMissions.contains(sOptionAddConditions.getValues()[0][0]) || takeRewardMissions.contains(sOptionAddConditions.getValues()[0][0])) {
|
||||
nextPoint = jumpTypeValues[0][0];
|
||||
}
|
||||
if (nextPoint == 0) {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(sOptionAddConditions.getValues()[0][0]);
|
||||
if (mission == null || mission.getMissionStep() < jumpTypeValues[0][1]) {
|
||||
nextPoint = jumpTypeValues[0][1];
|
||||
case 4:{
|
||||
Set<Integer> finishMissions = user.getMissionManager().getFinishMissions();
|
||||
Set<Integer> takeRewardMissions = user.getMissionManager().getTakeRewardMissions();
|
||||
if (finishMissions.contains(sOptionAddConditions.getValues()[0][0]) || takeRewardMissions.contains(sOptionAddConditions.getValues()[0][0])) {
|
||||
nextPoint = jumpTypeValues[0][0];
|
||||
}
|
||||
if (nextPoint == 0) {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(sOptionAddConditions.getValues()[0][0]);
|
||||
if (mission == null || mission.getMissionStep() < jumpTypeValues[0][1]) {
|
||||
nextPoint = jumpTypeValues[0][1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
nextPoint = jumpTypeValues[0][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nextPoint == 0) {
|
||||
nextPoint = jumpTypeValues[0][1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -555,13 +419,12 @@ public class MapLogic {
|
|||
break;
|
||||
}
|
||||
}
|
||||
MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse = MapInfoProto.EventUpdateResponse.newBuilder();
|
||||
if (behaviorType != EventType.jump && behaviorType != EventType.destroyMission) {
|
||||
cell.setEventId(nextPoint);
|
||||
mapManager.addOrUpdateCell(mapManager.getCurXY(), cell);
|
||||
}
|
||||
if (behaviorType == EventType.dun && openMission != null) {
|
||||
Mission mission = user.getMissionManager().getDoingMissions().get(openMission.getItemId());
|
||||
if (behaviorType == EventType.dun && eventUpdateResponse.getMission() != null) {
|
||||
Mission mission = user.getMissionManager().getDoingMissions().get(eventUpdateResponse.getMission().getItemId());
|
||||
if (mission != null) {
|
||||
mission.updateMapPoints(cell.getPointId(), cell.getEventId());
|
||||
}
|
||||
|
@ -587,21 +450,18 @@ public class MapLogic {
|
|||
if (dropBuilder != null) {
|
||||
eventUpdateResponse.setDrop(dropBuilder);
|
||||
}
|
||||
if (openMission != null) {
|
||||
eventUpdateResponse.setMission(openMission);
|
||||
}
|
||||
LOGGER.info("updateEvent =====>success<====== xy=>{}, getPointId=>{} eventId={}, mission=>{}, nextPoint=>{}", mapManager.getCurXY(), cell.getPointId(),
|
||||
cell.getEventId(), eventUpdateResponse.getMission(), nextPoint);
|
||||
MessageUtil.sendMessage(session, 1, messageType.getNumber(), eventUpdateResponse.build(), true);
|
||||
}
|
||||
|
||||
private CommonProto.Mission getMission(Map<Integer, Cell> newDunEvents, Mission mission) {
|
||||
public CommonProto.Mission getMission(Mission mission) {
|
||||
CommonProto.Mission openMission;
|
||||
StringBuilder state = null;
|
||||
String states = "";
|
||||
if (newDunEvents != null) {
|
||||
if (mission.getMissionInfos() != null) {
|
||||
state = new StringBuilder();
|
||||
for (Map.Entry<Integer, Cell> cellEntry : newDunEvents.entrySet()) {
|
||||
for (Map.Entry<Integer, Cell> cellEntry : mission.getMissionInfos().entrySet()) {
|
||||
state.append(cellEntry.getKey());
|
||||
state.append("#");
|
||||
state.append(cellEntry.getValue().getPointId());
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
|
||||
public abstract class BaseBehavior {
|
||||
|
||||
public abstract int getBehaviorType();
|
||||
|
||||
public abstract void process(User user) throws Exception;
|
||||
public abstract boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.Cell;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class DestroyMissionBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.destroyMission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
return false;
|
||||
}
|
||||
String newEventId = MissionLogic.getInstance().checkMission(mission, user);
|
||||
Map<Integer, Cell> mapInfo = user.getMapManager().getMapInfo();
|
||||
mapInfo.remove(user.getMapManager().getCurXY());
|
||||
if (newEventId != null && !newEventId.isEmpty()) {
|
||||
String[] split = newEventId.split("#");
|
||||
Cell cellUpdate = mapInfo.get(Integer.parseInt(split[0]));
|
||||
if (cellUpdate != null) {
|
||||
cellUpdate.setEventId(Integer.parseInt(split[1]));
|
||||
}
|
||||
}
|
||||
user.getMapManager().setMapInfo(mapInfo);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.config.MapPointConfig;
|
||||
import com.ljsd.jieling.config.SCMapConfig;
|
||||
import com.ljsd.jieling.handler.map.*;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.CellUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@Component
|
||||
public class DunBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.dun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
boolean hasMission = MissionLogic.getInstance().hasMission(user, behaviorTypeValues[0][0]);
|
||||
if (hasMission) {
|
||||
return false;
|
||||
}
|
||||
MapManager mapManager = user.getMapManager();
|
||||
SCMapConfig scMapConfig = SCMapConfig.getsCMapSize().get(mapManager.getCurMapId());
|
||||
int[] mapSize = scMapConfig.getSize();
|
||||
Map<Integer, Cell> newDunEvents = new HashMap<>();
|
||||
Map<Integer, MapPointConfig> newDunEventIds = new HashMap<>();
|
||||
int i = 0;
|
||||
Random random = new Random();
|
||||
while (newDunEventIds.size() < 3) {
|
||||
int randomIndex = random.nextInt(behaviorTypeValues[0].length - 3) + 3;
|
||||
int newDunEventId = behaviorTypeValues[0][randomIndex];
|
||||
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(newDunEventId);
|
||||
newDunEventIds.put(newDunEventIds.size(), mapPointConfig);
|
||||
i++;
|
||||
if (i >= 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (newDunEventIds.size() < 3) {
|
||||
return false;
|
||||
}
|
||||
i = 0;
|
||||
while (newDunEvents.size() < 3) {
|
||||
int x = random.nextInt(mapSize[0]) + 1;
|
||||
int y = random.nextInt(mapSize[1]) + 1;
|
||||
int xy = CellUtil.xy2Pos(x, y);
|
||||
if (mapManager.getMapInfo().containsKey(xy)) {
|
||||
continue;
|
||||
}
|
||||
MapPointConfig mapPointConfig = newDunEventIds.get(newDunEvents.size());
|
||||
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
|
||||
newDunEvents.put(xy, cellValue);
|
||||
i++;
|
||||
if (i >= 1000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mapManager.getMapInfo().putAll(newDunEvents);
|
||||
Mission mission = new Mission();
|
||||
mission.setMissionId(behaviorTypeValues[0][0]);
|
||||
mission.setMissionStep(0);
|
||||
mission.getMissionInfos().putAll(newDunEvents);
|
||||
mission.setMissionInfo(mapManager.getCurXY() + "#" + behaviorTypeValues[0][2] + "#" + behaviorTypeValues[0][1]);
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
doingMissions.put(behaviorTypeValues[0][0], mission);
|
||||
user.getMissionManager().updateDoingMissions(doingMissions);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
CrossMapCell crossMapInfo = mapManager.getCrossMapInfos().get(mapManager.getCurMapId());
|
||||
if (crossMapInfo == null) {
|
||||
crossMapInfo = new CrossMapCell();
|
||||
}
|
||||
crossMapInfo.getMissionIds().add(behaviorTypeValues[0][0]);
|
||||
mapManager.updateCrossMapInfos(mapManager.getCurMapId(), crossMapInfo);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.config.SItem;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class EatBuffBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.eatBuff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
|
||||
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
|
||||
if (!isEnough) {
|
||||
return isEnough;
|
||||
}
|
||||
Map<Integer, Integer> useItems = new HashMap<>();
|
||||
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
|
||||
ItemUtil.useItem(user, useItems);
|
||||
return isEnough;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FightBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.fight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
// heroFightInfos = fightStart(uid, bigEventId, user);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class FinishMissionBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.finishMission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
return false;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class JumpBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.jump;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
if (behaviorTypeValues[0][0] != 0) {
|
||||
user.getMapManager().setCurMapId(behaviorTypeValues[0][0]);
|
||||
MapLogic.getInstance().initMap(user.getMapManager(), user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.MathUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class LeaveBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.leave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
int randomInt = MathUtils.randomInt(100) + 1;
|
||||
if (randomInt <= behaviorTypeValues[0][0]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class MonitorMissionBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.monitorMission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
return false;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class OpenMissionBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.openMission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
return false;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
// TODO 还要开新事件
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.config.SItem;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ScoutBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.scout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
|
||||
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
|
||||
if (!isEnough) {
|
||||
return isEnough;
|
||||
}
|
||||
Map<Integer, Integer> useItems = new HashMap<>();
|
||||
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
|
||||
ItemUtil.useItem(user, useItems);
|
||||
return isEnough;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.config.SItem;
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class UseItemBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.eatBuff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
SItem sItem = SItem.getsItemMap().get(behaviorTypeValues[0][0]);
|
||||
boolean isEnough = ItemUtil.checkCost(user, sItem, behaviorTypeValues[0][1]);
|
||||
if (!isEnough) {
|
||||
return isEnough;
|
||||
}
|
||||
Map<Integer, Integer> useItems = new HashMap<>();
|
||||
useItems.put(behaviorTypeValues[0][0], behaviorTypeValues[0][1]);
|
||||
ItemUtil.useItem(user, useItems);
|
||||
return isEnough;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.ljsd.jieling.handler.map.behavior;
|
||||
|
||||
import com.ljsd.jieling.handler.map.EventType;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.handler.mission.Mission;
|
||||
import com.ljsd.jieling.handler.mission.MissionLogic;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MapInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class UseItemMissionBehavior extends BaseBehavior {
|
||||
@Override
|
||||
public int getBehaviorType() {
|
||||
return EventType.useItemMission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
Map<Integer, Mission> doingMissions = user.getMissionManager().getDoingMissions();
|
||||
Mission mission = doingMissions.get(behaviorTypeValues[0][0]);
|
||||
if (mission == null) {
|
||||
return false;
|
||||
}
|
||||
boolean checkCost = ItemUtil.itemCost(user, behaviorTypeValues);
|
||||
if (!checkCost) {
|
||||
return false;
|
||||
}
|
||||
MissionLogic.getInstance().checkMission(mission, user);
|
||||
CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
|
||||
eventUpdateResponse.setMission(missionProto);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.ljsd.jieling.handler.map.jump;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
|
||||
public abstract class BaseJump {
|
||||
|
||||
public abstract int getJumpType();
|
||||
|
||||
public abstract void process(User user) throws Exception;
|
||||
|
||||
}
|
Loading…
Reference in New Issue