战斗结算
parent
738252ecd5
commit
f6e0d4b8bf
|
|
@ -0,0 +1,24 @@
|
|||
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.FightInfoProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FightEndRequestHandler extends BaseHandler {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.FIGHT_END_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
byte[] message = netData.parseClientProtoNetData();
|
||||
FightInfoProto.FightEndRequest fightEndRequest = FightInfoProto.FightEndRequest.parseFrom(message);
|
||||
int monsterGroupId = fightEndRequest.getMonsterGroupId();
|
||||
MapLogic.getInstance().endFight(iSession, monsterGroupId, MessageTypeProto.MessageType.FIGHT_END_RESPONSE, monsterGroupId);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import com.ljsd.jieling.logic.dao.UserManager;
|
|||
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.*;
|
||||
|
|
@ -201,62 +202,6 @@ public class MapLogic {
|
|||
mapManager.setTypeEight(spicelMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗开始
|
||||
*/
|
||||
public List<CommonProto.HeroFightInfo> fightStart(int uid, int bigEventId, User user) throws Exception {
|
||||
String key = RedisKey.getKey(RedisKey.FIGHT, Integer.toString(uid) + RedisKey.UNDERLINE_LINE + Integer.toString(bigEventId), false);
|
||||
RedisUtil.getInstence().set(key, Integer.toString(uid), RedisKey.EXPIRE_TIME);
|
||||
Set<String> heroes = user.getMapManager().getHeroes();
|
||||
List<CommonProto.HeroFightInfo> heroFightInfos = new ArrayList<>(heroes.size());
|
||||
for (String heroId : heroes) {
|
||||
Hero hero = user.getHeroManager().getHero(heroId);
|
||||
if (hero == null || hero.getCurHp() == 0) {
|
||||
continue;
|
||||
}
|
||||
float attack = HeroLogic.getInstance().calHeroAttribute(hero, GlobalsDef.ATTACK_TYPE);
|
||||
float physicalDefence = HeroLogic.getInstance().calHeroAttribute(hero, GlobalsDef.PHYSICAL_DEFENCE_TYPE);
|
||||
float magicDefence = HeroLogic.getInstance().calHeroAttribute(hero, GlobalsDef.MAGIC_DEFENCE_TYPE);
|
||||
float hp = HeroLogic.getInstance().calHeroAttribute(hero, GlobalsDef.HP_TYPE);
|
||||
float speed = HeroLogic.getInstance().calHeroAttribute(hero, GlobalsDef.SPEED_TYPE);
|
||||
CommonProto.Hero heroProto = CBean2Proto.getHero(hero);
|
||||
CommonProto.HeroFightInfo heroFightInfo = CommonProto.HeroFightInfo
|
||||
.newBuilder()
|
||||
.setAttack(attack)
|
||||
.setPhysicalDefence(physicalDefence)
|
||||
.setMagicDefence(magicDefence)
|
||||
.setHp(hp)
|
||||
.setSpeed(speed)
|
||||
.setHero(heroProto)
|
||||
.build();
|
||||
heroFightInfos.add(heroFightInfo);
|
||||
}
|
||||
return heroFightInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结束
|
||||
*/
|
||||
public void fightEnd(ISession session, int result, List<MapInfoProto.HeroInfo> heroInfos, MessageTypeProto.MessageType messageType) throws Exception {
|
||||
int uid = session.getUid();
|
||||
String key = RedisKey.getKey(RedisKey.FIGHT, Integer.toString(uid), false);
|
||||
String fightInfo = RedisUtil.getInstence().getAndDelete(key);
|
||||
if (fightInfo == null || fightInfo.isEmpty()) {
|
||||
MessageUtil.sendErrorResponse(session, 0, messageType.getNumber(), "未开始战斗");
|
||||
return;
|
||||
}
|
||||
User user = UserManager.getUser(uid);
|
||||
MapManager mapManager = user.getMapManager();
|
||||
if (result != 1) {
|
||||
mapManager.setCurXY(0);
|
||||
Set<String> heroes = mapManager.getHeroes();
|
||||
for (String heroId : heroes) {
|
||||
Hero hero = user.getHeroManager().getHero(heroId);
|
||||
hero.setCurHp(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMap(ISession session, int curXY, List<Integer> cells, MessageTypeProto.MessageType messageType) throws Exception {
|
||||
if (cells.isEmpty()) {
|
||||
|
|
@ -541,4 +486,29 @@ public class MapLogic {
|
|||
|
||||
//在地图吃东西
|
||||
|
||||
|
||||
|
||||
public void endFight(ISession session, int result, MessageTypeProto.MessageType messageType, int monsterGroupId) throws Exception {
|
||||
int uid = session.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
// String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() , false);
|
||||
// String value = (String) RedisUtil.getInstence().get(key);
|
||||
// if (value == null || value.isEmpty()) {
|
||||
// LOGGER.info("endFight() uid=>{} not start fight", uid);
|
||||
// MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
|
||||
// return;
|
||||
// }
|
||||
SMonsterGroup sMonsterGroup = SMonsterGroup.getsMonsterGroupMap().get(monsterGroupId);
|
||||
if (sMonsterGroup == null) {
|
||||
LOGGER.info("endFight() uid=>{} monsterGroupId=>{} sMonsterGroup == null", uid, monsterGroupId);
|
||||
MessageUtil.sendErrorResponse(session,0, messageType.getNumber(), "");
|
||||
return;
|
||||
}
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, sMonsterGroup.getRewardgroup(), 1);
|
||||
FightInfoProto.FightEndResponse fightEndResponse = FightInfoProto.FightEndResponse
|
||||
.newBuilder()
|
||||
.setDrop(drop)
|
||||
.build();
|
||||
MessageUtil.sendMessage(session, 1, messageType.getNumber(), fightEndResponse, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ public class BehaviorUtil {
|
|||
*/
|
||||
public static void getFightInfo(User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
MapManager mapManager = user.getMapManager();
|
||||
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId() + RedisKey.UNDERLINE_LINE + Integer.toString(behaviorTypeValues[0][0]), false);
|
||||
RedisUtil.getInstence().set(key, user.getId(), RedisKey.EXPIRE_TIME);
|
||||
String key = RedisKey.getKey(RedisKey.FIGHT, user.getId(), false);
|
||||
RedisUtil.getInstence().set(key, Integer.toString(behaviorTypeValues[0][0]), RedisKey.EXPIRE_TIME);
|
||||
Set<String> heroes = mapManager.getHeroes();
|
||||
List<CommonProto.HeroFightInfo> heroFightInfos = new ArrayList<>(heroes.size());
|
||||
for (String heroId : heroes) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue