back_recharge
mashiyu 2019-03-20 20:04:24 +08:00
commit c2b163f29c
7 changed files with 107 additions and 11 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 FIGHT_READY = "FIGHT_READY";
/**
*
*/

View File

@ -7,6 +7,7 @@ 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.map.behavior.BehaviorUtil;
import com.ljsd.jieling.handler.mission.Mission;
import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
@ -622,10 +623,65 @@ public class MapLogic {
}
/**
*
* @param session
* @param messageType
*/
public void startFight(ISession session, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
MapManager mapManager = user.getMapManager();
if (mapManager.getMapInfo() == null) {
LOGGER.info("mapManager.getMapInfo() == null");
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return;
}
Cell cell = mapManager.getMapInfo().get(mapManager.getCurXY());
if (cell == null) {
cell = mapManager.getMapInfo().get(mapManager.getTriggerXY());
if (cell == null) {
LOGGER.info("cell == null xy is wrong =>{} triggerXY=>{}", mapManager.getCurXY(), mapManager.getTriggerXY());
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return;
}
}
int bigEventId = cell.getEventId();
SEventPointConfig sEventPointConfig = SEventPointConfig.sEventPointConfigMap.get(bigEventId);
if (sEventPointConfig == null) {
LOGGER.info("sEventPointConfig == null");
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
return;
}
String fightReadyKey = RedisKey.getKey(RedisKey.FIGHT_READY, Integer.toString(uid), false);
String fightReady = (String) RedisUtil.getInstence().get(fightReadyKey);
int groupId;
if (fightReady != null) {
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();
BehaviorUtil.getFightInfo(user, groupId, fightStartResponse);
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightStartResponse.build(), true);
}
/**
*
* @param session
* @param messageType
* @throws Exception
*/
public void endFight(ISession session, String frames, MessageTypeProto.MessageType messageType) throws Exception {
int uid = session.getUid();
User user = UserManager.getUser(uid);
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false);
Map<Object , Object> valueMap = RedisUtil.getInstence().hmget(key);
if (valueMap == null || valueMap.isEmpty()) {

View File

@ -0,0 +1,22 @@
package com.ljsd.jieling.handler.map;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
@Component
public class StartFightRequestHandler extends BaseHandler{
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.FIGHT_START_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
byte[] message = netData.parseClientProtoNetData();
// FightInfoProto.FightStartRequest fightEndRequest = FightInfoProto.FightStartRequest.parseFrom(message);
MapLogic.getInstance().startFight(iSession, MessageTypeProto.MessageType.FIGHT_START_RESPONSE);
}
}

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.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.FightInfoProto;
import com.ljsd.jieling.protocols.MapInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
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 groupId
* @param eventUpdateResponse
* @param fightStartRespons
* @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();
int teamId = mapManager.getTeamId();
List<TeamPosHeroInfo> teamPosHeroInfos = user.getTeamPosManager().getTeamPosForHero().get(teamId);
List<CommonProto.FightUnitInfo> heroFightInfos = new ArrayList<>();
CommonProto.FightData.Builder fightData = CommonProto.FightData.newBuilder();
for (TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfos) {
Hero hero = user.getHeroManager().getHero(teamPosHeroInfo.getHeroId());
if (hero == null || hero.getCurHp() == 0) {
@ -109,7 +117,7 @@ public class BehaviorUtil {
.addAllFightUnitList(heroFightInfos)
.setTeamSkillList(HeroLogic.getInstance().getPokenmonSkills(user,teamId))
.build();
eventUpdateResponse.setHeroFightInfos(fightTeamInfo);
fightData.setHeroFightInfos(fightTeamInfo);
//monster
List<CommonProto.FightUnitInfo> monsterByGroup = MonsterUtil.getMonsterByGroup(groupId);
@ -121,11 +129,13 @@ public class BehaviorUtil {
.setTeamSkillList(monsterTeamSkill)
.build();
monsterGroupList.add(monsterTeamInfo);
eventUpdateResponse.addAllMonsterList(monsterGroupList);
fightData.addAllMonsterList(monsterGroupList);
//设置战斗随机种子
int seed = (int)(System.currentTimeMillis()/1000);
eventUpdateResponse.setFightSeed(seed);
fightData.setFightSeed(seed);
fightStartRespons.setFightData(fightData);
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId(), false);
Map<String,Object> fightInfo = new HashMap<>();
@ -136,8 +146,8 @@ public class BehaviorUtil {
RedisUtil.getInstence().hmset(key, fightInfo, RedisKey.EXPIRE_TIME);
ISession session = OnlineUserManager.getSessionByUid(Integer.parseInt(user.getId()));
MapLogic.getInstance().endFight(session,"", MessageTypeProto.MessageType.FIGHT_END_RESPONSE);
// ISession session = OnlineUserManager.getSessionByUid(Integer.parseInt(user.getId()));
// MapLogic.getInstance().endFight(session,"", MessageTypeProto.MessageType.FIGHT_END_RESPONSE);
}

View File

@ -15,7 +15,7 @@ public class FightAndDestroyPointBehavior extends BaseBehavior {
@Override
public boolean process(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
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]);
return true;
}

View File

@ -14,7 +14,7 @@ public class FightBehavior extends BaseBehavior {
@Override
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;
}
}

View File

@ -59,6 +59,7 @@ public class MissionLogic {
.newBuilder()
.setMissionStep(doingMission.getMissionStep())
.setItemId(doingMission.getMissionId())
.setIsOpen(doingMission.isOpen())
.setState(states)
.build();
missionGetAllResponse.addMissions(mission);
@ -69,6 +70,7 @@ public class MissionLogic {
.newBuilder()
.setMissionStep(sMissionEventsConfig.getMissionNum())
.setItemId(finishMission)
.setIsOpen(true)
.setState("")
.build();
missionGetAllResponse.addMissions(mission);
@ -111,6 +113,7 @@ public class MissionLogic {
Set<Integer> finishMissions = user.getMissionManager().getFinishMissions();
finishMissions.add(mission.getMissionId());
user.getMissionManager().updateFinishMissions(finishMissions);
mission.setOpen(true);
} else {
user.getMissionManager().updateOneDoingMissions(mission.getMissionId(), mission);
}
@ -151,7 +154,7 @@ public class MissionLogic {
Mission mission = doingMissions.get(missionId);
mission.setOpen(true);
user.getMissionManager().updateOneDoingMissions(missionId, mission);
MessageUtil.sendErrorResponse(session, 1, messageType.getNumber(), "");
MessageUtil.sendMessage(session, 1, messageType.getNumber(), null, true);
}
}