战斗修改

back_recharge
jiahuiwen 2019-03-20 19:50:21 +08:00
parent 60db6c0005
commit 04c60c2ac9
6 changed files with 39 additions and 17 deletions

View File

@ -15,6 +15,11 @@ public class RedisKey {
*/ */
public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO"; public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO";
/**
*
*/
public static final String FIGHT_READY = "FIGHT_READY";
/** /**
* *
*/ */

View File

@ -653,14 +653,23 @@ public class MapLogic {
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), ""); MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return; return;
} }
int[] option = sEventPointConfig.getOption(); String fightReadyKey = RedisKey.getKey(RedisKey.FIGHT_READY, Integer.toString(uid), false);
if (option == null) { String fightReady = (String) RedisUtil.getInstence().get(fightReadyKey);
LOGGER.info("option == null sEventPointConfig.getId()=>{}", sEventPointConfig.getId()); int groupId;
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), ""); if (fightReady != null) {
return; RedisUtil.getInstence().del(fightReadyKey);
groupId = Integer.parseInt(fightReady);
} else {
int[] option = sEventPointConfig.getOption();
if (option == null) {
LOGGER.info("option == null sEventPointConfig.getId()=>{}", sEventPointConfig.getId());
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return;
}
groupId = option[0];
} }
FightInfoProto.FightStartResponse.Builder fightStartResponse = FightInfoProto.FightStartResponse.newBuilder(); FightInfoProto.FightStartResponse.Builder fightStartResponse = FightInfoProto.FightStartResponse.newBuilder();
// BehaviorUtil.getFightInfo(user, option[0], fightStartResponse); BehaviorUtil.getFightInfo(user, groupId, fightStartResponse);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true); MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true);
} }
@ -673,7 +682,6 @@ public class MapLogic {
public void endFight(ISession session, String frames, MessageTypeProto.MessageType messageType) throws Exception { public void endFight(ISession session, String frames, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid(); int uid = session.getUid();
User user = UserManager.getUser(uid); User user = UserManager.getUser(uid);
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false); String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false);
Map<Object , Object> valueMap = RedisUtil.getInstence().hmget(key); Map<Object , Object> valueMap = RedisUtil.getInstence().hmget(key);
if (valueMap == null || valueMap.isEmpty()) { if (valueMap == null || valueMap.isEmpty()) {

View File

@ -3,7 +3,6 @@ package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.netty.cocdex.PacketNetData; import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -20,6 +20,7 @@ import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic; import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto; import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MapInfoProto; import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CBean2Proto; import com.ljsd.jieling.util.CBean2Proto;
@ -74,19 +75,26 @@ public class BehaviorUtil {
} }
} }
public static void fightReady(String uid, int groupId) {
String key = RedisKey.getKey(RedisKey.FIGHT_READY, uid, false);
RedisUtil.getInstence().set(key, Integer.toString(groupId), RedisKey.EXPIRE_TIME);
}
/** /**
* *
* @param user * @param user
* @param groupId * @param groupId
* @param eventUpdateResponse * @param fightStartRespons
* @throws Exception * @throws Exception
*/ */
public static void getFightInfo(User user, int groupId, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception { public static void getFightInfo(User user, int groupId, FightInfoProto.FightStartResponse.Builder fightStartRespons) throws Exception {
MapManager mapManager = user.getMapManager(); MapManager mapManager = user.getMapManager();
int teamId = mapManager.getTeamId(); int teamId = mapManager.getTeamId();
List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId); List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId);
List<CommonProto.FightUnitInfo> heroFightInfos = new ArrayList<>(); List<CommonProto.FightUnitInfo> heroFightInfos = new ArrayList<>();
CommonProto.FightData.Builder fightData = CommonProto.FightData.newBuilder();
for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfos) { for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfos) {
Hero hero = user.getHeroManager().getHero(teamPosHeroInfo.getHeroId()); Hero hero = user.getHeroManager().getHero(teamPosHeroInfo.getHeroId());
if (hero == null || hero.getCurHp() == 0) { if (hero == null || hero.getCurHp() == 0) {
@ -107,7 +115,7 @@ public class BehaviorUtil {
.addAllFightUnitList(heroFightInfos) .addAllFightUnitList(heroFightInfos)
.setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(user,teamId)) .setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(user,teamId))
.build(); .build();
eventUpdateResponse.setHeroFightInfos(fightTeamInfo); fightData.setHeroFightInfos(fightTeamInfo);
//monster //monster
List<CommonProto.FightUnitInfo> monsterByGroup = MonsterUtil.getMonsterByGroup(groupId); List<CommonProto.FightUnitInfo> monsterByGroup = MonsterUtil.getMonsterByGroup(groupId);
@ -119,11 +127,13 @@ public class BehaviorUtil {
.setTeamSkillList(monsterTeamSkill) .setTeamSkillList(monsterTeamSkill)
.build(); .build();
monsterGroupList.add(monsterTeamInfo); monsterGroupList.add(monsterTeamInfo);
eventUpdateResponse.addAllMonsterList(monsterGroupList); fightData.addAllMonsterList(monsterGroupList);
//设置战斗随机种子 //设置战斗随机种子
int seed = (int)(System.currentTimeMillis()/1000); int seed = (int)(System.currentTimeMillis()/1000);
eventUpdateResponse.setFightSeed(seed); fightData.setFightSeed(seed);
fightStartRespons.setFightData(fightData);
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId(), false); String key = RedisKey.getKey(RedisKey.FIGHT, user.getId(), false);
Map<String,Object> fightInfo = new HashMap<>(); Map<String,Object> fightInfo = new HashMap<>();
@ -134,8 +144,8 @@ public class BehaviorUtil {
RedisUtil.getInstence().hmset(key, fightInfo, RedisKey.EXPIRE_TIME); RedisUtil.getInstence().hmset(key, fightInfo, RedisKey.EXPIRE_TIME);
ISession session = OnlineUserManager.getSessionByUid(Integer.parseInt(user.getId())); // ISession session = OnlineUserManager.getSessionByUid(Integer.parseInt(user.getId()));
MapLogic.getInstance().endFight(session,"", MessageTypeProto.MessageType.FIGHT_END_RESPONSE); // MapLogic.getInstance().endFight(session,"", MessageTypeProto.MessageType.FIGHT_END_RESPONSE);
} }

View File

@ -15,7 +15,7 @@ public class FightAndDestroyPointBehavior extends BaseBehavior {
@Override @Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception { public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
BehaviorUtil.updateMission(user, behaviorTypeValues[0][0], eventUpdateResponse); BehaviorUtil.updateMission(user, behaviorTypeValues[0][0], eventUpdateResponse);
BehaviorUtil.getFightInfo(user, behaviorTypeValues[0][1], eventUpdateResponse); BehaviorUtil.fightReady(user.getId(), behaviorTypeValues[0][1]);
BehaviorUtil.distoryPoint(user, behaviorTypeValues[0][2]); BehaviorUtil.distoryPoint(user, behaviorTypeValues[0][2]);
return true; return true;
} }

View File

@ -14,7 +14,7 @@ public class FightBehavior extends BaseBehavior {
@Override @Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception { public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
BehaviorUtil.getFightInfo(user, behaviorTypeValues[0][0], eventUpdateResponse); BehaviorUtil.fightReady(user.getId(), behaviorTypeValues[0][0]);
return true; return true;
} }
} }