行为类型7

back_recharge
wangyuan 2019-07-15 14:35:38 +08:00
parent fb2b2ff379
commit 36b1071efc
2 changed files with 33 additions and 52 deletions

View File

@ -2,9 +2,13 @@ package com.ljsd.jieling.handler.map.behavior;
import com.ljsd.jieling.handler.map.*;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.util.MathUtils;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class DunBehavior extends BaseBehavior {
@Override
@ -14,57 +18,21 @@ public class DunBehavior extends BaseBehavior {
@Override
public boolean process(int optionId, 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;
// }
// // 开新事件
// BehaviorUtil.addBehaviorInfo(mapManager.getCurMapId(), mapManager, mapPointConfig.getId(), x, y);
// }
// mapManager.getMapInfo().putAll(newDunEvents);
// Mission mission = new Mission();
// mission.setMissionId(behaviorTypeValues[0][0]);
// mission.setMissionStep(0);
// mission.setMissionInfo(mapManager.getCurXY() + "#" + behaviorTypeValues[0][2]);
// user.getMissionManager().updateOneDoingMissions(behaviorTypeValues[0][0], mission);
// CommonProto.Mission missionProto = MapLogic.getInstance().getMission(mission);
// eventUpdateResponse.addMission(missionProto);
// return true;
return false;
int[] behaviorTypeValue = behaviorTypeValues[0];
int randomANums = behaviorTypeValue[0];
int randomBNums = behaviorTypeValue[1];
if(randomANums!=0 || randomBNums!=0){
List<Integer> randomAEvents = MathUtils.randomForOneArray(behaviorTypeValues[1], randomANums);
List<Integer> randomBEvents = MathUtils.randomForOneArray(behaviorTypeValues[2], randomBNums);
randomBEvents.addAll(randomAEvents);
List<Integer> randomABPosList = MathUtils.randomForOneArray(behaviorTypeValues[3], randomBNums);
for(Integer pos : randomABPosList){
eventUpdateResponse.addAddMapInfo(CommonProto.Cell.newBuilder()
.setCellId(pos)
.setPointId(randomBEvents.remove(0))
.build());
}
}
return true;
}
}

View File

@ -1,8 +1,11 @@
package com.ljsd.jieling.util;
import com.sun.nio.sctp.PeerAddressChangeNotification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@ -169,4 +172,14 @@ public class MathUtils {
return result;
}
public static List<Integer> randomForOneArray(int sourceArray[], int randomNums) {
List<Integer> result = new ArrayList<>();
int length = sourceArray.length;
while (randomNums>0){
result.add(sourceArray[randomInt(length)]);
randomNums--;
}
return result;
}
}