妖兽来袭

back_recharge
zhangshanxue 2019-08-16 10:09:39 +08:00
parent d6a6f25e82
commit aa102c8d29
11 changed files with 280 additions and 5 deletions

View File

@ -0,0 +1,43 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.Map;
@Table(name ="FloodConfig")
public class SFloodConfig implements BaseConfig {
private int id;
private int monster;
private int[] reward;
private int battleTime;
@Override
public void init() throws Exception {
}
public int getId() {
return id;
}
public int getMonster() {
return monster;
}
public int[] getReward() {
return reward;
}
public int getBattleTime() {
return battleTime;
}
}

View File

@ -76,9 +76,11 @@ public class RedisKey {
public static final String LEVE_DIFFICULTY_INFO = "LEVE_DIFFICULTY_INFO";
public static final String CHALLENGE_MONSTER_INFO = "CHALLENGE_MONSTER_INFO";
public static final String LEVE_DIFFICULTY_FIGHT = "LEVE_DIFFICULTY_FIGHT";
public static final String SUDDLENLY_FIGHT = "SUDDLENLY_FIGHT";
public static final String CHALLENGE_MONSTER_ATTACK = "CHALLENGE_MONSTER_ATTACK";
@ -121,6 +123,8 @@ public class RedisKey {
public static final String OPERATE_FAMILY_APPLY = "OPERATE_FAMILY_APPLY";
public static final String OPERATE_FAMILY_APPLY_JOIN = "OPERATE_FAMILY_APPLY_JOIN";
public static final String MONSTER_ATTACK_RANK = "MONSTER_ATTACK_RANK";
public static String getKey(String type, String key, boolean withoutServerId) {
if (withoutServerId) {
return GameApplication.areaId + Delimiter_colon + type + Delimiter_colon + String.valueOf(key);

View File

@ -70,6 +70,10 @@ public interface BIReason {
int SUDDENLY_REWARD = 43; // 精英怪奖励
int MONSTERATTACK_REWARD = 44; // 妖兽来袭奖励
int MONSTERATTACK_BACK = 45; // 妖兽来袭预扣归还
//道具消耗原因 1000开头
int ADVENTURE_UPLEVEL_CONSUME = 1000; //秘境升级
int SECRETBOX_CONSUME = 1001; //秘盒抽卡
@ -120,4 +124,5 @@ public interface BIReason {
int CREATE_GUILD_CONSUME = 1030; // 创建宗门消耗
int ENDLESS_CONSUME_EXECUTION = 1031; //无尽副本消耗行动力
}

View File

@ -3,6 +3,7 @@ package com.ljsd.jieling.globals;
public interface Global {
int STAMINA = 2; // 体力id
int EXECUTION = 3;//行动力id
int DROP = 53;//水滴
int HEROSTORY_TICKET = 28; //精英入场券
int GENERALSTORY_TICKET = 27; //普通入场券
int INVASIONBOSS_TICKET = 44; //外敌挑战券

View File

@ -123,6 +123,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
.setHadBuyTreasure(playerInfoManager.getHadBuyTreasure())
.setTreasureScore(playerInfoManager.getTreasureScore())
.setSignInInfo(CommonProto.SignInInfo.newBuilder().setDays(playerInfoManager.getSign()+1).setState(playerInfoManager.getSignTotay()).build())
.setMonsterAttackTime(user.getMapManager().getLastMonsterAttack())
.build();
try {
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_PLAYERINFO_RESPONSE_VALUE, getPlayerInfoResponse, true);

View File

@ -15,6 +15,7 @@ import com.ljsd.jieling.ktbeans.KTGameType;
import com.ljsd.jieling.ktbeans.KtEventUtils;
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.activity.event.StoryEvent;
import com.ljsd.jieling.logic.dao.*;
@ -2094,10 +2095,7 @@ public class MapLogic {
int[] checkResult = CheckFight.getInstance().checkFight(seed, sLevelDifficultyConfig.getRankTime(), getFightData, getOptionData);
// List<Integer> remainHp = new ArrayList<>(5);
// for (int i = 1; i < checkResult.length; i++) {
// remainHp.add(checkResult[i]);
// }
LevelDifficultyManager levelDifficultyManager = user.getLevelDifficultyManager();
//校验结果码 1胜利
int resultCode = checkResult[0];
@ -2144,6 +2142,137 @@ public class MapLogic {
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse.build(), true);
}
/**
*
*
* @param session
* @param fightId
*/
public void startMonsterAttackFight(ISession session, int fightId, int teamId, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
if(user.getMapManager().getLastMonsterAttack()!=fightId){
LOGGER.info("endFight() uid=>{} fightId=>{} SLevelDifficultyConfig == null", uid, fightId, teamId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "fightId 有误");
return;
}
SFloodConfig sFloodConfig = STableManager.getConfig(SFloodConfig.class).get(fightId);
if (sFloodConfig == null) {
LOGGER.info("endFight() uid=>{} fightId=>{} SLevelDifficultyConfig == null", uid, fightId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "");
return;
}
int[][] cost = new int[1][];
int[] temp = new int[2];
temp[0] = Global.DROP;
temp[1] = 1;
cost[0] = temp;
boolean flag = ItemUtil.fightItemCost(user, cost);
if (!flag) {
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "道具不足");
return;
}
List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId);
if (teamPosHeroInfos == null || teamPosHeroInfos.size() == 0) {
LOGGER.info("startLevelDifficultyFight==> uid={},fightId={},teamId={}", uid, fightId, teamId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "阵容有误!!");
return;
}
ItemUtil.itemCost(user,cost, BIReason.START_DIFFICULT, fightId);
KtEventUtils.onKtEvent(user, ParamEventBean.UserGameType, KTGameType.CHALLENGE_MONSTERATTACK.getIndex(), fightId);
user.getTeamPosManager().setCurTeamPosId(teamId);
String fightInfo = fightId + "#" + teamId;
String key = RedisKey.getKey(RedisKey.CHALLENGE_MONSTER_INFO, String.valueOf(uid), false);
RedisUtil.getInstence().set(key, fightInfo, sFloodConfig.getBattleTime() + 100);
FightInfoProto.FightStartResponse.Builder fightStartResponse = FightInfoProto.FightStartResponse.newBuilder();
BehaviorUtil.getLevelDifficultyifficuFightInfo(user, sFloodConfig.getMonster(), teamId, sFloodConfig.getBattleTime(), fightStartResponse, RedisKey.CHALLENGE_MONSTER_ATTACK);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true);
}
/**
*
*/
public void endMonsterAttackFight(ISession session, String frames, int fightId, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
String fightKey = RedisKey.getKey(RedisKey.CHALLENGE_MONSTER_INFO, String.valueOf(uid), false);
String fightInfos = (String) RedisUtil.getInstence().get(fightKey);
if (fightInfos.isEmpty()) {
LOGGER.info("endFight() uid=>{} fightKey={},fightId={} fightInfos == null", uid, fightKey, fightId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "");
return;
}
String[] split = fightInfos.split("#");
int checkFightId = Integer.parseInt(split[0]);
if (fightId != checkFightId) {
LOGGER.info("endFight() uid=>{} fightId=>{},checkFightId={}", uid, fightId, checkFightId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "");
return;
}
String key = RedisKey.getKey(RedisKey.CHALLENGE_MONSTER_ATTACK, Integer.toString(user.getId()), false);
Map<Object, Object> valueMap = RedisUtil.getInstence().hmget(key);
RedisUtil.getInstence().del(key);
if (valueMap == null || valueMap.isEmpty()) {
LOGGER.info("endFight() uid=>{} not start fight", uid);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "此战斗已结算过 !");
return;
}
int seed = Integer.parseInt((String) valueMap.get(RedisKey.FIGHT_SEED));
CommonProto.FightTeamInfo.Builder builder = CommonProto.FightTeamInfo.newBuilder();
JsonFormat.merge((String) valueMap.get(RedisKey.FIGHT_HEROES), builder);
CommonProto.FightTeamInfo fightTeamInfo = builder.build();
List<CommonProto.FightTeamInfo> monsterTeamList = BehaviorUtil.getFightTeamInfos(valueMap);
SFloodConfig sFloodConfig = STableManager.getConfig(SFloodConfig.class).get(fightId);
if (sFloodConfig == null) {
LOGGER.info("endFight() uid=>{} fightId=>{} SLevelDifficultyConfig == null", uid, fightId);
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "");
return;
}
LuaValue getFightData = FightDataUtil.getFinalFightData(fightTeamInfo, monsterTeamList);
LuaValue getOptionData = FightDataUtil.getOptionData(frames);
int[] checkResult = CheckFight.getInstance().checkFight(seed, sFloodConfig.getBattleTime(), getFightData, getOptionData);
//校验结果码 1胜利
int resultCode = checkResult[0];
if (resultCode == -1) {
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "战斗异常!");
return;
} else if (resultCode == 0) {
CommonProto.Drop.Builder dropBuilder = CommonProto.Drop.newBuilder();
FightInfoProto.FightEndResponse fightEndResponse = FightInfoProto.FightEndResponse
.newBuilder()
.setResult(resultCode)
.setEnventDrop(dropBuilder)
.build();
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse, true);
return;
}
//归还水滴
Map<Integer,Integer> itemMap = new HashMap<>(1);
itemMap.put( Global.DROP,1);
ItemUtil.addItem(user,itemMap,null,BIReason.MONSTERATTACK_BACK);
CommonProto.Drop.Builder drop = ItemUtil.drop(user, sFloodConfig.getReward(), 1, 0, BIReason.MONSTERATTACK_REWARD);
FightInfoProto.FightEndResponse.Builder fightEndResponse = FightInfoProto.FightEndResponse.newBuilder();
fightEndResponse.setEnventDrop(drop);
fightEndResponse.setResult(resultCode);
fightEndResponse.build();
user.getMapManager().setLastMonsterAttack(fightId < STableManager.getConfig(SFloodConfig.class).size() ? fightId + 1 : fightId);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse.build(), true);
}
/**
*
*

View File

@ -117,6 +117,8 @@ public class MapManager extends MongoBase {
private int lastXY; // 上一步坐标点
private int lastMonsterAttack =1;//兽潮来袭波数
public MapManager() {
this.setRootCollection(User._COLLECTION_NAME);
}
@ -751,6 +753,15 @@ public class MapManager extends MongoBase {
updateString("lastXY",lastXY);
this.lastXY = lastXY;
}
public int getLastMonsterAttack() {
return lastMonsterAttack;
}
public void setLastMonsterAttack(int lastMonsterAttack) {
this.lastMonsterAttack = lastMonsterAttack;
updateString("lastMonsterAttack",lastMonsterAttack);
}
}

View File

@ -31,6 +31,8 @@ public class FightEndRequestHandler extends BaseHandler {
MapLogic.getInstance().endFight(iSession, frames, MessageTypeProto.MessageType.FIGHT_END_RESPONSE,dropout);
}else if(type == 3){
MapLogic.getInstance().endSuddlenlyFight(iSession, frames, MessageTypeProto.MessageType.FIGHT_END_RESPONSE);
}else if(type == 5){
MapLogic.getInstance().endMonsterAttackFight(iSession, frames,fightId,MessageTypeProto.MessageType.FIGHT_END_RESPONSE);
} else {
// MapLogic.getInstance().endFight(iSession, frames, MessageTypeProto.MessageType.FIGHT_END_RESPONSE);

View File

@ -42,6 +42,8 @@ public class StartFightRequestHandler extends BaseHandler{
}else if(type == 3){
MapLogic.getInstance().startSuddlenlyFight(iSession,teamId, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
}else if(type == 5){
MapLogic.getInstance().startMonsterAttackFight(iSession,fightId,teamId, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
} else {
// MapLogic.getInstance().startLevelDifficultyFight(iSession,fightId,teamId,type,MessageTypeProto.MessageType.FIGHT_START_RESPONSE);

View File

@ -0,0 +1,76 @@
package com.ljsd.jieling.handler.monsterAttack;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.PlayerManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.MessageUtil;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@Component
public class GetMonsterAttackRankHandler extends BaseHandler<PlayerInfoProto.GetMonsterRankInfoRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.GET_MONSTER_RANK_INFO_REQUEST;
}
@Override
public void processWithProto(ISession iSession, PlayerInfoProto.GetMonsterRankInfoRequest proto) throws Exception {
int start = 0;
List<CommonProto.MonsterRankInfo> monsterRankInfos = new LinkedList<>();
Set<ZSetOperations.TypedTuple<String>> rankInfo = RedisUtil.getInstence().getZsetreverseRangeWithScores(RedisKey.MONSTER_ATTACK_RANK, "", 0, 100);
for (ZSetOperations.TypedTuple<String> item : rankInfo) {
String value = item.getValue();
int score = item.getScore().intValue();
int uid = Integer.parseInt(value);
User user = UserManager.getUser(uid);
PlayerManager playerInfoManager = user.getPlayerInfoManager();
CommonProto.MonsterRankInfo monsterRankInfo = CommonProto.MonsterRankInfo.newBuilder()
.setName(playerInfoManager.getNickName())
.setScore(score)
.setLevel(playerInfoManager.getLevel())
.setHeadFrame(playerInfoManager.getHeadFrame())
.setHead(0)
.setRank(++start)
.build();
monsterRankInfos.add(monsterRankInfo);
}
if (rankInfo.size() > 800) {
//删除多余数据 预留一些 长度maxSize
String key = RedisKey.getKey(RedisKey.MONSTER_ATTACK_RANK, "", false);
int size = RedisUtil.getInstence().getZsetSize(key);
RedisUtil.getInstence().removeZSetRangeByRank(key, 300, size);
}
int uid = iSession.getUid();
int score = RedisUtil.getInstence().getZSetScore(RedisKey.MONSTER_ATTACK_RANK, "", Integer.toString(uid)).intValue();
int myRank = RedisUtil.getInstence().getZSetreverseRank(RedisKey.MONSTER_ATTACK_RANK, "", Integer.toString(uid)).intValue();
if(myRank>300){
score=-1;
myRank=-1;
}
PlayerInfoProto.GetMonsterRankInfoResponse buildResponse = PlayerInfoProto.GetMonsterRankInfoResponse.newBuilder()
.setMyRank(myRank)
.addAllMonster(monsterRankInfos)
.setMyScore(score)
.build();
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_MONSTER_RANK_INFO_RESPONSE_VALUE, buildResponse, true);
}
}

View File

@ -7,7 +7,8 @@ public enum KTGameType {
STORY("故事副本", 4),
ARENA("竞技场",5),
CHALLENGE_SECURE("挑战秘境BOSS",6),
TAKE_SECURE_REWARD("领取秘境奖励",7);
TAKE_SECURE_REWARD("领取秘境奖励",7),
CHALLENGE_MONSTERATTACK("挑战兽潮",8);
// 成员变量
private String name;
private int index;