森罗环境游戏代码提交

back_recharge
lvxinran 2020-06-12 17:03:59 +08:00
parent c015b1ea18
commit 531770178a
20 changed files with 769 additions and 34 deletions

View File

@ -19,8 +19,10 @@ public class MathUtils {
public static void main(String[] args){
int i = randomFromWeight(new int[][]{{1,20},{2,30}});
System.out.println(i);
for(int j = 0 ; j <100;j++){
int i = randomInt(3);
System.out.println(i);
}
}
public static int randomForStrArray(String [] rateArray) {
return randomStrArray(rateArray, -1);
@ -85,6 +87,11 @@ public class MathUtils {
return low + ThreadLocalRandom.current().nextInt(hi - low + 1);
}
/**
* 0~n-1
* @param n
* @return
*/
public static int randomInt(int n){
return random.nextInt(n);
}

View File

@ -0,0 +1,42 @@
package com.ljsd.jieling.handler.map;
import java.util.HashSet;
import java.util.Set;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
public class MapGameInfo {
private int[] id;
private int type;
private Set<Integer> operationInfo = new HashSet<>();
public int[] getId() {
return id;
}
public void setId(int[] id) {
this.id = id;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public Set<Integer> getOperationInfo() {
return operationInfo;
}
public void setOperationInfo(Set<Integer> operationInfo) {
this.operationInfo = operationInfo;
}
}

View File

@ -18,6 +18,7 @@ import com.ljsd.jieling.handler.map.behavior.BehaviorUtil;
import com.ljsd.jieling.handler.map.mapType.AbstractMap;
import com.ljsd.jieling.handler.map.mapType.MapEnum;
import com.ljsd.jieling.handler.map.mapType.TowerMap;
import com.ljsd.jieling.handler.map.miniGame.MapGame;
import com.ljsd.jieling.handler.mission.CheckMissionReturn;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.ktbeans.KTGameType;
@ -59,6 +60,7 @@ public class MapLogic {
public static final Logger LOGGER = LoggerFactory.getLogger(MapLogic.class);
public Map<Integer, BaseBehavior> baseBehaviorMap = new HashMap<>();
public Map<Integer, MapGame> baseGameMap = new HashMap<>();
public Map<Integer, Integer> difficultyMonster;
public Map<Integer, Integer> difficultyReward;
@ -72,9 +74,14 @@ public class MapLogic {
public void init() throws Exception {
Map<String, BaseBehavior> beansOfType = ConfigurableApplicationContextManager.getBeansOfType(BaseBehavior.class);
Map<String, MapGame> beansOfMapGame = ConfigurableApplicationContextManager.getBeansOfType(MapGame.class);
for (BaseBehavior baseBehavior : beansOfType.values()) {
baseBehaviorMap.put(baseBehavior.getBehaviorType(), baseBehavior);
}
for (MapGame mapGame : beansOfMapGame.values()) {
baseGameMap.put(mapGame.getType(), mapGame);
}
setDifficult();
}
@ -3171,6 +3178,9 @@ public class MapLogic {
drop = getBoxReward(sTrialConfig.getBoxPosition(),sTrialConfig.getBoxReward(),user,curXY,type);
}
}
if(drop==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
MapInfoProto.GetTrialBoxRewardResponse response = MapInfoProto.GetTrialBoxRewardResponse.newBuilder().setBoxDrop(drop).build();
MessageUtil.sendMessage(session,1,messageType.getNumber(),response,true);
}
@ -3218,4 +3228,51 @@ public class MapLogic {
}
return drop;
}
public void getMiniGameEvent(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
MapManager mapManager = user.getMapManager();
Cell cell = mapManager.getMapInfo().get(mapManager.getCurXY());
MapPointConfig config = MapPointConfig.getScMapEventMap().get(cell.getPointId());
int style = config.getStyle();
MapGame mapGame = baseGameMap.get(style);
if(mapGame==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
//初始化
mapGame.initGame(user);
// BehaviorUtil.destoryCurPoint(user);
//回复响应
MapGameInfo mapGameInfo = mapManager.getTrialInfo().getMapGameInfo();
int[] ids = mapGameInfo.getId();
List<Integer> idList = new ArrayList<>(ids.length);
for(int id:ids){
idList.add(id);
}
MapInfoProto.MapGameResponse response = MapInfoProto.MapGameResponse.newBuilder().setType(mapGameInfo.getType()).addAllParam(idList).build();
MessageUtil.sendMessage(session,1,messageType.getNumber(),response,true);
}
/**
*
* @param session
* @param index
* @param messageType
* @throws Exception
*/
public void updateMiniGame(ISession session, int index, MessageTypeProto.MessageType messageType) throws Exception {
User user = UserManager.getUser(session.getUid());
MapManager mapManager = user.getMapManager();
MapGameInfo mapGameInfo = mapManager.getTrialInfo().getMapGameInfo();
if(mapGameInfo==null||mapGameInfo.getType()==0){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
MapGame mapGame = baseGameMap.get(mapGameInfo.getType());
if(mapGame==null){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
MapInfoProto.MapGameUpdateResponse response = mapGame.updateGame(user, index);
if(response==null)
MessageUtil.sendMessage(session,1,messageType.getNumber(),response,true);
}
}

View File

@ -812,6 +812,11 @@ public class MapManager extends MongoBase {
trialInfo.setBuffIds(ids);
updateString("trialInfo.buffIds",ids);
}
public void updateMapGameInfo(MapGameInfo info){
trialInfo.setMapGameInfo(info);
updateString("trialInfo.mapGameInfo",info);
}
}

View File

@ -33,6 +33,8 @@ public class TrialInfo {
private List<Integer> buffIds = new ArrayList<>();
private MapGameInfo mapGameInfo = new MapGameInfo();
public Set<Integer> getTowerReceivedReward() {
return towerReceivedReward;
}
@ -128,4 +130,12 @@ public class TrialInfo {
public void setBuffIds(List<Integer> buffIds) {
this.buffIds = buffIds;
}
public MapGameInfo getMapGameInfo() {
return mapGameInfo;
}
public void setMapGameInfo(MapGameInfo mapGameInfo) {
this.mapGameInfo = mapGameInfo;
}
}

View File

@ -0,0 +1,26 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.MapLogic;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/6/12
* @discribe
*/
@Component
public class MapGameUpdateHandler extends BaseHandler<MapInfoProto.MapGameUpdateRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.MAP_GAME_UPDATE_REQUEST;
}
@Override
public void processWithProto(ISession iSession, MapInfoProto.MapGameUpdateRequest proto) throws Exception {
MapLogic.getInstance().updateMiniGame(iSession,proto.getIndex(), MessageTypeProto.MessageType.MAP_GAME_UPDATE_RESPONSE);
}
}

View File

@ -0,0 +1,28 @@
package com.ljsd.jieling.handler.map.mapHandler;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.handler.map.MapLogic;
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;
/**
* @author lvxinran
* @date 2020/6/12
* @discribe
*/
@Component
public class MapGetGameHandler extends BaseHandler {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.MAP_GAME_GET_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
MapLogic.getInstance().getMiniGameEvent(iSession, MessageTypeProto.MessageType.MAP_GAME_GET_RESPONSE);
}
}

View File

@ -21,6 +21,7 @@ import com.ljsd.jieling.logic.fight.PVEFightEvent;
import com.ljsd.jieling.logic.fight.result.FightResult;
import com.ljsd.jieling.logic.hero.HeroAttributeEnum;
import com.ljsd.jieling.logic.mission.GameEvent;
import com.ljsd.jieling.logic.store.StoreLogic;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MapInfoProto;
@ -210,11 +211,13 @@ public class TowerMap extends AbstractMap {
LOGGER.info("initTrialMap() uid=>{} sChallengeConfig == null =>{} ", user.getId(), sTrialConfig.getMapId());
return;
}
Map<Integer, Cell> newMap = new HashMap<>();
Random random = new Random();
Map<Integer, Cell> newMap = new HashMap<>();
Map<Integer, SCMap> scMap = SCMap.sCMap.get(sTrialConfig.getMapId());
Map<Integer, Cell> cellMap1 = new HashMap<>(sTrialConfig.getGameCount()[0]);
Map<Integer, Cell> cellMap2 = new HashMap<>(sTrialConfig.getGameCount()[1]);
Map<Integer, Cell> cellMap3 = new HashMap<>(sTrialConfig.getGameCount()[2]);
Map<Integer, Cell> cellMap4 = new HashMap<>(4);//4个怪
/* if(mapManager.getTowerStartTime()!=0){
mapManager.setCurrTowerTime((TimeUtils.now()-mapManager.getTowerStartTime())/1000);
@ -272,11 +275,13 @@ public class TowerMap extends AbstractMap {
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
cellMap2.put(xy, cellValue);
}
} else if (scMap1.getEvent()==99){
//每层只有四个怪
} else if (scMap1.getEvent() == 3) {
//初始化商店
int storeIndex = MathUtils.randomFromWeight(STrialConfig.sTrialConfigMap.get(mapManager.getTrialInfo().getFloor()).getRandomStore());
StoreLogic.initOrUpdateOneStore(user,8,storeIndex);
int i = 0;
int[] monster = MathUtils.randomFromWeightWithTaking(sTrialConfig.getMonsterPoint(),4);
while (cellMap2.size() < 4 ) {
while (cellMap3.size() < sTrialConfig.getGameCount()[2]) {
i++;
if (i >= 10000) {
break;
}
@ -284,32 +289,47 @@ public class TowerMap extends AbstractMap {
int x = scMap1.getGroups()[randomIndex][0];
int y = scMap1.getGroups()[randomIndex][1];
int xy = CellUtil.xy2Pos(x, y);
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(sTrialConfig.getGameType()[2][1]);
if (mapPointConfig == null) {
LOGGER.info("====initTrialMap()====mapPointConfig == null======>{}", scMap1.getEvent());
continue;
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
cellMap3.put(xy, cellValue);
}
} else if (scMap1.getEvent()==99){
//每层只有四个怪
int i = 0;
int[] monster = MathUtils.randomFromWeightWithTaking(sTrialConfig.getMonsterPoint(),4);
while (cellMap4.size() < 4 ) {
if (i >= 10000) {
break;
}
int cellLength = scMap1.getGroups().length;
if(cellLength!=4){
//todo 做成随机
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
int x = scMap1.getGroups()[i][0];
int y = scMap1.getGroups()[i][1];
int xy = CellUtil.xy2Pos(x, y);
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(monster[i]);
if (mapPointConfig == null) {
LOGGER.info("====initTrialMap()====mapPointConfig == null======>{}", scMap1.getEvent());
continue;
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
cellMap2.put(xy, cellValue);
cellMap4.put(xy, cellValue);
i++;
}
}
else {
// 随机出现的事件点
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);
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(scMap1.getEvent());
if (mapPointConfig == null) {
LOGGER.info("====initTrialMap()====mapPointConfig == null======>{}", scMap1.getEvent());
continue;
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
newMap.put(xy, cellValue);
randomCreateMapPoint(newMap,scMap1);
}
newMap.putAll(cellMap1);
newMap.putAll(cellMap2);
newMap.putAll(cellMap3);
newMap.putAll(cellMap4);
}
SChallengeMapConfig challengeMapConfig = STableManager.getConfig(SChallengeMapConfig.class).get(sTrialConfig.getMapId());
int xy = CellUtil.xy2Pos(challengeMapConfig.getPosition()[0], challengeMapConfig.getPosition()[1]);
@ -322,6 +342,21 @@ public class TowerMap extends AbstractMap {
}
}
public void randomCreateMapPoint(Map<Integer, Cell> newMap,SCMap scMap1){
// 随机出现的事件点
Random random = new Random();
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);
MapPointConfig mapPointConfig = MapPointConfig.scMapEventMap.get(scMap1.getEvent());
if (mapPointConfig == null) {
LOGGER.info("====initTrialMap()====mapPointConfig == null======>{}", scMap1.getEvent());
return;
}
Cell cellValue = new Cell(xy, mapPointConfig.getInitialEventId(), mapPointConfig.getId());
newMap.put(xy, cellValue);
}
@Override
public void fastFight(int uid, FightInfoProto.FastFightResponse.Builder fastFightResponseBuilder) throws Exception {
User user = UserManager.getUser(uid);
@ -430,7 +465,7 @@ public class TowerMap extends AbstractMap {
private Cell createTransport(int floor){
int transportPoint;
//是否为5层整数倍
if(floor%2==0&&floor<10000){
if(floor%5==0&&floor<10000){
//如果是则进行随机
int[] treasureProbability = STrialSetting.sTrialSetting.getTreasureProbability();
int[] transportPointId= STrialSetting.sTrialSetting.getTransportPoint();
@ -456,17 +491,16 @@ public class TowerMap extends AbstractMap {
int currTower = mapManager.getTrialInfo().getFloor();
STrialConfig config = STrialConfig.sTrialConfigMap.get(currTower);
int type = 1;
int[][] bossType = config.getRandomBossType();
type = MathUtils.randomFromWeight(bossType);
//随机boss改为固定
// int type = 1;
// int[][] bossType = config.getRandomBossType();
//
// type = MathUtils.randomFromWeight(bossType);
// if(mapManager.getTrialInfo().getFloor()%5!=0){
// type = 3;
// }
LOGGER.info("trigger!!!!!!!!!!!!!!!!!-------->{},{}",CellUtil.pos2XY(mapManager.getCurXY())[0],CellUtil.pos2XY(mapManager.getCurXY())[1]);
int[][][] pointId = config.getRandomMapPointId();
int pointId = config.getBossMapPointId();
int mapId = config.getMapId();
SChallengeMapConfig challengeMapConfig = STableManager.getConfig(SChallengeMapConfig.class).get(mapId);
int[] mapSize = challengeMapConfig.getSize();
@ -504,12 +538,11 @@ public class TowerMap extends AbstractMap {
// }
//更改成固定boss位置
int[] bossPosition = STrialSetting.sTrialSetting.getBossPosition();
mapManager.setBossType(type);
mapManager.setBossType(1);
mapManager.setBossXY(CellUtil.xy2Pos(bossPosition[0],bossPosition[1]));
mapManager.setTrialEnergy(-1);
int randomPoint = MathUtils.randomFromWeight(pointId[type-1]);
// LOGGER.info("随机事件id==>{}",randomPoint);
Cell cell = BehaviorUtil.addBehaviorInfo(user, randomPoint, mapManager, mapManager.getCurMapId(), bossPosition[0], bossPosition[1], false);
Cell cell = BehaviorUtil.addBehaviorInfo(user, pointId, mapManager, mapManager.getCurMapId(), bossPosition[0], bossPosition[1], false);
return cell;
}
}

View File

@ -0,0 +1,16 @@
package com.ljsd.jieling.handler.map.miniGame;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
@Component
public class AnswerGame extends TrueFalseGame {
@Override
public int getType() {
return 14;
}
}

View File

@ -0,0 +1,120 @@
package com.ljsd.jieling.handler.map.miniGame;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.map.MapGameInfo;
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.ItemUtil;
import config.STrialGameConfig;
import config.STrialSetting;
import org.springframework.stereotype.Component;
import util.MathUtils;
import java.util.List;
import java.util.Random;
import java.util.Set;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe gg
*/
@Component
public class BombGame implements MapGame {
@Override
public int getType() {
return 18;
}
@Override
public void initGame(User user) {
int type = getType();
List<STrialGameConfig> configs = STrialGameConfig.trialGameMapByType.get(type);
int[] idArray = new int[configs.size()];
int index = 0 ;
for(STrialGameConfig config:configs){
idArray[index] = config.getId();
index++;
}
int gameBoomCount = STrialSetting.sTrialSetting.getGameBoomCount();
List<Integer> result = MathUtils.randomForOneArray(idArray, 16-gameBoomCount);
MapGameInfo mapGameInfo = new MapGameInfo();
int[] ids = new int[16];
for(int i = 0 ; i < result.size();i++){
ids[i] = result.get(i);
}
for(int i = gameBoomCount;i>0;i--){
ids[ids.length-i] = -1;
}
int[] shuffleId = shuffle(ids);
mapGameInfo.setId(shuffleId);
mapGameInfo.setType(type);
user.getMapManager().updateMapGameInfo(mapGameInfo);
}
@Override
public MapInfoProto.MapGameUpdateResponse updateGame(User user, Object... params) throws Exception {
MapGameInfo mapGameInfo = user.getMapManager().getTrialInfo().getMapGameInfo();
if(mapGameInfo==null){
return null;
}
Set<Integer> operationInfo = mapGameInfo.getOperationInfo();
if(operationInfo.size()==3){
//无次数了
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
int[] idInfo = mapGameInfo.getId();
if(operationInfo.isEmpty()){
//第一次把奖励随机一下
idInfo = shuffle(idInfo);
}
int resultId = idInfo[(int)params[0]-1];
int gameStatus = 0;
CommonProto.Drop.Builder drop = null;
//是否抽到炸弹
if(operationInfo.contains((int)params[0]-1)){
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
if(resultId!=-1){
//记录抽取次数
operationInfo.add((int)params[0]);
gameStatus = 3-operationInfo.size();
STrialGameConfig config = STrialGameConfig.trialGameConfigMap.get(resultId);
drop = ItemUtil.drop(user, new int[][]{{config.getRewardID(), config.getMin()}}, BIReason.MAP_EVENET_REWARD);
user.getMapManager().updateMapGameInfo(mapGameInfo);
}else{
user.getMapManager().updateMapGameInfo(null);
}
MapInfoProto.MapGameUpdateResponse response = MapInfoProto.MapGameUpdateResponse.newBuilder().setDrop(drop)
.setGameStatus(gameStatus)
.setResultId(resultId).build();
return response;
}
//乱序数组
private int [] shuffle(int [] arr) {
int [] arr2 =new int[arr.length];
int count = arr.length;
int cbRandCount = 0;// 索引
int cbPosition = 0;// 位置
int k =0;
int runCount = 0;
do {
runCount++;
Random rand = new Random();
int r = count - cbRandCount;
cbPosition = rand.nextInt(r);
arr2[k++] = arr[cbPosition];
cbRandCount++;
arr[cbPosition] = arr[r - 1];// 将最后一位数值赋值给已经被使用的cbPosition
} while (cbRandCount < count);
System.out.println("运算次数 = "+runCount);
return arr2;
}
}

View File

@ -0,0 +1,76 @@
package com.ljsd.jieling.handler.map.miniGame;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.map.MapGameInfo;
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.ItemUtil;
import config.STrialGameConfig;
import org.springframework.stereotype.Component;
import util.MathUtils;
import java.util.List;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
@Component
public class CircleGame implements MapGame {
@Override
public int getType() {
return 17;
}
@Override
public void initGame(User user) {
int type = getType();
List<STrialGameConfig> configs = STrialGameConfig.trialGameMapByType.get(type);
int[] idArray = new int[configs.size()];
int index = 0 ;
for(STrialGameConfig config:configs){
idArray[index] = config.getId();
index++;
}
List<Integer> result = MathUtils.randomForOneArray(idArray, 12);
MapGameInfo mapGameInfo = new MapGameInfo();
int[] ids = new int[result.size()];
for(int i = 0 ; i < result.size();i++){
ids[i] = result.get(i);
}
mapGameInfo.setId(ids);
mapGameInfo.setType(type);
user.getMapManager().updateMapGameInfo(mapGameInfo);
}
@Override
public MapInfoProto.MapGameUpdateResponse updateGame(User user, Object... params) throws Exception {
MapGameInfo mapGameInfo = user.getMapManager().getTrialInfo().getMapGameInfo();
if(mapGameInfo==null){
return null;
}
int[] ids = mapGameInfo.getId();
int[][] randomArray = new int[ids.length][];
for(int i = 0 ; i <ids.length;i++){
STrialGameConfig config = STrialGameConfig.trialGameConfigMap.get(ids[i]);
int[] tempArray = new int[]{ids[i],config.getWeight()};
randomArray[i] = tempArray;
}
int[] id = MathUtils.randomFromWeightWithTaking(randomArray, 1);
//todo 需要告诉前端一个拿到的id
STrialGameConfig config = STrialGameConfig.trialGameConfigMap.get(id[0]);
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{{id[0], config.getMin()}}, BIReason.MAP_EVENET_REWARD);
MapInfoProto.MapGameUpdateResponse response = MapInfoProto.MapGameUpdateResponse.newBuilder()
.setGameStatus(0)
.setResultId(id[0])
.setDrop(drop)
.build();
user.getMapManager().updateMapGameInfo(null);
return response;
}
}

View File

@ -0,0 +1,19 @@
package com.ljsd.jieling.handler.map.miniGame;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MapInfoProto;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
public interface MapGame {
int getType();
void initGame(User user);
MapInfoProto.MapGameUpdateResponse updateGame(User user , Object... params) throws Exception;
}

View File

@ -0,0 +1,63 @@
package com.ljsd.jieling.handler.map.miniGame;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.map.MapGameInfo;
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.ItemUtil;
import config.STrialGameConfig;
import org.springframework.stereotype.Component;
import util.MathUtils;
import java.util.List;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
@Component
public class MapLuckyCatGame implements MapGame {
@Override
public int getType() {
return 16;
}
@Override
public void initGame(User user) {
int type = getType();
List<STrialGameConfig> configs = STrialGameConfig.trialGameMapByType.get(type);
int[][] idArray = new int[configs.size()][];
int i = 0 ;
for(STrialGameConfig config:configs){
int[] array = new int[]{config.getId(),config.getWeight()};
idArray[i] = array;
i++;
}
int[] result = MathUtils.randomFromWeightWithTaking(idArray, 1);
MapGameInfo mapGameInfo = new MapGameInfo();
mapGameInfo.setId(result);
mapGameInfo.setType(type);
user.getMapManager().updateMapGameInfo(mapGameInfo);
}
@Override
public MapInfoProto.MapGameUpdateResponse updateGame(User user,Object... params) throws Exception {
MapGameInfo mapGameInfo = user.getMapManager().getTrialInfo().getMapGameInfo();
if(mapGameInfo==null){
return null;
}
int[] id = mapGameInfo.getId();
STrialGameConfig questionConfig = STrialGameConfig.trialGameConfigMap.get(id[0]);
int count = MathUtils.random(questionConfig.getMin(),questionConfig.getMax());
CommonProto.Drop.Builder drop = ItemUtil.drop(user, new int[][]{{questionConfig.getRewardID(), count}}, BIReason.MAP_EVENET_REWARD);
MapInfoProto.MapGameUpdateResponse response = MapInfoProto.MapGameUpdateResponse.newBuilder()
.setDrop(drop)
.setResultId(count)
.setGameStatus(0)
.build();
user.getMapManager().updateMapGameInfo(null);
return response;
}
}

View File

@ -0,0 +1,16 @@
package com.ljsd.jieling.handler.map.miniGame;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
@Component
public class SpeakGame extends TrueFalseGame {
@Override
public int getType() {
return 13;
}
}

View File

@ -0,0 +1,60 @@
package com.ljsd.jieling.handler.map.miniGame;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.map.MapGameInfo;
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.ItemUtil;
import config.STrialQuestionConfig;
import util.MathUtils;
import java.util.List;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
public abstract class TrueFalseGame implements MapGame{
public abstract int getType();
@Override
public void initGame(User user) {
int type = getType();
List<STrialQuestionConfig> sTrialQuestionConfigs = STrialQuestionConfig.questionConfigMapByType.get(type);
int index = MathUtils.randomInt(sTrialQuestionConfigs.size());
STrialQuestionConfig questionConfig = sTrialQuestionConfigs.get(index);
MapGameInfo mapGameInfo = new MapGameInfo();
mapGameInfo.setId(new int[]{questionConfig.getId()});
mapGameInfo.setType(type);
user.getMapManager().updateMapGameInfo(mapGameInfo);
}
@Override
public MapInfoProto.MapGameUpdateResponse updateGame(User user, Object... params) throws Exception {
MapGameInfo mapGameInfo = user.getMapManager().getTrialInfo().getMapGameInfo();
if(mapGameInfo==null){
return null;
}
int[] id = mapGameInfo.getId();
STrialQuestionConfig questionConfig = STrialQuestionConfig.sTrialQuestionConfigMap.get(id[0]);
int[] trueAnswer = questionConfig.getTrueAnswer();
int param = (int)params[0];
int result = trueAnswer[param - 1];
int[][] resultReward;
if(result==0){
resultReward = questionConfig.getFalseReward();
}else{
resultReward = questionConfig.getTrueReward();
}
CommonProto.Drop.Builder drop = ItemUtil.drop(user, resultReward, BIReason.MAP_EVENET_REWARD);
user.getMapManager().updateMapGameInfo(null);
MapInfoProto.MapGameUpdateResponse.Builder builder = MapInfoProto.MapGameUpdateResponse.newBuilder()
.setDrop(drop)
.setGameStatus(0)
.setResultId(result);
return builder.build();
}
}

View File

@ -0,0 +1,16 @@
package com.ljsd.jieling.handler.map.miniGame;
import org.springframework.stereotype.Component;
/**
* @author lvxinran
* @date 2020/6/11
* @discribe
*/
@Component
public class WhereIsFiveGame extends TrueFalseGame {
@Override
public int getType() {
return 15;
}
}

View File

@ -48,7 +48,7 @@ public class STrialConfig implements BaseConfig {
/**
* MapPointid
*/
private int[][][] randomMapPointId;
private int bossMapPointId;
/**
*
*/
@ -96,8 +96,8 @@ public class STrialConfig implements BaseConfig {
return normalEnergy;
}
public int[][][] getRandomMapPointId() {
return randomMapPointId;
public int getBossMapPointId() {
return bossMapPointId;
}
public int[][] getRandomStore() { return randomStore;}

View File

@ -0,0 +1,67 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Table(name ="TrialGameConfig")
public class STrialGameConfig implements BaseConfig {
private int id;
private int type;
private int rewardID;
private int weight;
private int min;
private int max;
public static Map<Integer,STrialGameConfig> trialGameConfigMap;
public static Map<Integer, List<STrialGameConfig>> trialGameMapByType;
@Override
public void init() throws Exception {
trialGameConfigMap = STableManager.getConfig(STrialGameConfig.class);
Map<Integer, List<STrialGameConfig>> tempMap = new HashMap<>();
for(Map.Entry<Integer,STrialGameConfig> entry:trialGameConfigMap.entrySet()){
tempMap.computeIfAbsent(entry.getValue().getType(),n->new ArrayList<>()).add(entry.getValue());
}
trialGameMapByType = tempMap;
}
public int getId() {
return id;
}
public int getType() {
return type;
}
public int getRewardID() {
return rewardID;
}
public int getWeight() {
return weight;
}
public int getMin() {
return min;
}
public int getMax() {
return max;
}
}

View File

@ -0,0 +1,68 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Table(name ="TrialQuestionConfig")
public class STrialQuestionConfig implements BaseConfig {
private int id;
private int type;
private String answer;
private int[] trueAnswer;
private int[][] trueReward;
private int[][] falseReward;
public static Map<Integer,STrialQuestionConfig> sTrialQuestionConfigMap;
public static Map<Integer, List<STrialQuestionConfig>> questionConfigMapByType;
@Override
public void init() throws Exception {
sTrialQuestionConfigMap = STableManager.getConfig(STrialQuestionConfig.class);
Map<Integer, List<STrialQuestionConfig>> tempMap = new HashMap<>();
for(Map.Entry<Integer,STrialQuestionConfig> entry:sTrialQuestionConfigMap.entrySet()){
tempMap.computeIfAbsent(entry.getValue().getType(),n->new ArrayList<>()).add(entry.getValue());
}
questionConfigMapByType = tempMap;
}
public int getId() {
return id;
}
public int getType() {
return type;
}
public String getAnswer() {
return answer;
}
public int[] getTrueAnswer() {
return trueAnswer;
}
public int[][] getTrueReward() {
return trueReward;
}
public int[][] getFalseReward() {
return falseReward;
}
}

View File

@ -45,6 +45,8 @@ public class STrialSetting implements BaseConfig{
//回春散
private int[] healingId;
private int gameBoomCount;
private int baseBuff;
public int getId() {
@ -94,4 +96,8 @@ public class STrialSetting implements BaseConfig{
public int getBaseBuff() {
return baseBuff;
}
public int getGameBoomCount() {
return gameBoomCount;
}
}