lvxinran 2020-05-15 00:08:14 +08:00
commit e60facdc36
8 changed files with 312 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package com.ljsd.jieling.config.clazzStaticCfg;
import com.ljsd.jieling.util.ItemUtil;
import config.SEquipConfig;
import config.SJewelConfig;
import config.SRewardGroup;
import config.SRewardItem;
import manager.AbstractClassStaticConfig;
@ -21,11 +22,15 @@ public class ItemStaticConfig extends AbstractClassStaticConfig {
private Map<Integer,Map<Integer,Integer>> euipTppes;
private Map<Integer,Map<Integer,Integer>> race2quality2soulid; //魂宝索引
private Map<Integer,Map<Integer,Integer>> race2quality2id;//灵宝索引
@Override
public void registConfigs(Set<String> registConfigs) {
registConfigs.add(SRewardItem.class.getAnnotation(Table.class).name());
registConfigs.add(SRewardGroup.class.getAnnotation(Table.class).name());
registConfigs.add(SEquipConfig.class.getAnnotation(Table.class).name());
registConfigs.add(SJewelConfig.class.getAnnotation(Table.class).name());
}
@Override
@ -48,6 +53,30 @@ public class ItemStaticConfig extends AbstractClassStaticConfig {
}catch (Exception e){
LOGGER.error("exception");
}
try {
race2quality2soulid = new HashMap<>();
race2quality2id = new HashMap<>();
Map<Integer, SJewelConfig> config = STableManager.getConfig(SJewelConfig.class);
config.forEach((k,v)->{
int type = v.getLocation();
int race = v.getRace();
if(type==1){
Map<Integer, Integer> orDefault = race2quality2soulid.getOrDefault(race, new HashMap<>());
orDefault.putIfAbsent(v.getLevel(),k);
race2quality2soulid.putIfAbsent(race,orDefault);
}else {
Map<Integer, Integer> orDefault = race2quality2id.getOrDefault(race, new HashMap<>());
orDefault.putIfAbsent(v.getLevel(),k);
race2quality2id.putIfAbsent(race,orDefault);
}
});
}catch (Exception e){
LOGGER.error("exception");
}
}
public Map<Integer, Map<Integer, Integer>> getEuipTppes() {
@ -62,4 +91,27 @@ public class ItemStaticConfig extends AbstractClassStaticConfig {
return integerIntegerMap.getOrDefault(star,0);
}
public int getJewelIdByparam(int type,int race,int level) {
if(type==1){
Map<Integer, Integer> integerIntegerMap = race2quality2soulid.get(race);
if(null == integerIntegerMap){
return 0;
}
return integerIntegerMap.getOrDefault(level,0);
}else{
Map<Integer, Integer> integerIntegerMap = race2quality2id.get(race);
if(null == integerIntegerMap){
return 0;
}
return integerIntegerMap.getOrDefault(level,0);
}
}
public Map<Integer, Map<Integer, Integer>> getRace2quality2soulid() {
return race2quality2soulid;
}
public Map<Integer, Map<Integer, Integer>> getRace2quality2id() {
return race2quality2id;
}
}

View File

@ -240,5 +240,7 @@ public interface BIReason {
int GUILD_SKILL_LEVEL_UP_CONSUME = 1056;//工会技能升级消耗
int FETE_CONSUME = 1057;//祭祀消耗
int COMPLEX_JEVEL_EQUIP_CONSUME = 1058; //合成宝器
}

View File

@ -187,7 +187,6 @@ public class ComplexEquipHandler extends BaseHandler<HeroInfoProto.ComplexEquipR
HeroInfoProto.ComplexEquipResponse.Builder response = HeroInfoProto.ComplexEquipResponse.newBuilder();
response.addAllEquipIds(equipadds);
response.setDrop(drop);
System.out.print(response.build().toString());
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.EQUIP_COMPLEX_RESPONSE_VALUE, response.build(), true);
}
}

View File

@ -0,0 +1,210 @@
package com.ljsd.jieling.handler.equip;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.config.clazzStaticCfg.ItemStaticConfig;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.Jewel;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.logic.item.ItemLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil;
import config.SJewelConfig;
import manager.STableManager;
import java.util.*;
/**
* Description:
* Author: zsx
* CreateDate: 2020/5/8 11:51
*/
public class ComplexJewelEquipRequestHandler extends BaseHandler<HeroInfoProto.ComplexJewelEquipRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return null;
}
@Override
public void processWithProto(ISession iSession, HeroInfoProto.ComplexJewelEquipRequest proto) throws Exception {
User user = UserManager.getUser(iSession.getUid());
if (user == null) {
throw new ErrorCodeException(ErrorCode.UNKNOWN);
}
if (proto.getTargetleve() != 0) {//手动合成
//check param and cnf
if (proto.getNum() <= 0) {
throw new ErrorCodeException(ErrorCode.SERVER_DEFINE);
}
int needLeve = proto.getTargetleve() - 1;
if (needLeve <= 0) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
int targetEquip = STableManager.getFigureConfig(ItemStaticConfig.class).getJewelIdByparam(proto.getType(),proto.getRance(), proto.getTargetleve());
if (targetEquip == 0) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
int needEquip = STableManager.getFigureConfig(ItemStaticConfig.class).getJewelIdByparam(proto.getType(),proto.getRance(), needLeve);
if (needEquip == 0) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
SJewelConfig sEquipStarsConfig = STableManager.getConfig(SJewelConfig.class).get(needEquip);
if (null == sEquipStarsConfig) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
SJewelConfig sTargetEquipStarsConfig = STableManager.getConfig(SJewelConfig.class).get(targetEquip);
if (null == sTargetEquipStarsConfig) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
// Set<String> equipByIDs = ItemLogic.getJewelEquip(user, sEquipStarsConfig.getLocation(),sEquipStarsConfig.getRace());
TreeSet<String> equipByIDs = ItemLogic.getJewelEquipWithLeve(user, sEquipStarsConfig.getLocation(),sEquipStarsConfig.getRace(),needLeve);
int needcount = sEquipStarsConfig.getRankupCount();
if (equipByIDs.size() / needcount < proto.getNum()) {
//数据不够
throw new ErrorCodeException(ErrorCode.UNKNOWN);
}
//check cost
Map<Integer, Integer> consumeMap = new HashMap<>();
for (int i = 0; i < proto.getNum(); i++) {
int[][] sumConsume = sTargetEquipStarsConfig.getRankupResources();
HeroLogic.getInstance().combinedAttribute(sumConsume, consumeMap);
}
boolean enough = ItemUtil.itemCost(user, consumeMap, BIReason.COMPLEX_JEVEL_EQUIP_CONSUME, 0);
if (!enough) {
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
//drop
int[][] dropItems = new int[1][];
dropItems[0] = new int[2];
dropItems[0][0] = sTargetEquipStarsConfig.getId();
dropItems[0][1] = proto.getNum();
CommonProto.Drop.Builder drop = ItemUtil.drop(user, dropItems, BIReason.COMPLEX_EQUIP);
HeroInfoProto.ComplexJewelEquipResponse.Builder response = HeroInfoProto.ComplexJewelEquipResponse.newBuilder();
//remove old 宝器
int i = 1;
for (String id : equipByIDs) {
if (i > proto.getNum() * needcount) {
break;
}
response.addEquipIds(id);
user.getEquipManager().remove(id);
i++;
}
response.setDrop(drop);
MessageUtil.sendIndicationMessage(user.getId(), response.build());
} else {
Map<Integer, Map<Integer, Integer>> race2quality2soulid = STableManager.getFigureConfig(ItemStaticConfig.class).getRace2quality2soulid();
Map<Integer, Map<Integer, Integer>> race2quality2id = STableManager.getFigureConfig(ItemStaticConfig.class).getRace2quality2id();
Map<Integer, Integer> soulInnerMap = new TreeMap<>(race2quality2soulid.getOrDefault(proto.getRance(), new HashMap<>()));
Map<Integer, Integer> innerMap = new TreeMap<>(race2quality2id.getOrDefault(proto.getRance(), new HashMap<>()));
Set<String> equipadds =new HashSet<>();
List< CommonProto.Equip> equips = new LinkedList<>();
combineEquip(user,soulInnerMap,equips,equipadds);
combineEquip(user,innerMap,equips,equipadds);
CommonProto.Drop.Builder drop = CommonProto.Drop.newBuilder().addAllSoulEquip(equips);
HeroInfoProto.ComplexJewelEquipResponse.Builder response = HeroInfoProto.ComplexJewelEquipResponse.newBuilder();
response.addAllEquipIds(equipadds);
response.setDrop(drop);
MessageUtil.sendIndicationMessage(user.getId(), response.build());
}
}
private void combineEquip(User user, Map<Integer, Integer> integerIntegerMap ,List<CommonProto.Equip> equips,Set<String> equipadds) throws Exception {
Map<Integer, Integer> consumeMap = new HashMap<>();
Set<String> newids = new HashSet<>();
Map<Integer, Integer> consumeMapTem = new HashMap<>();
for (Map.Entry<Integer, Integer> entry : integerIntegerMap.entrySet()) {
//star conf
int targetstar = entry.getKey()+1;
if(!integerIntegerMap.containsKey(targetstar)){
break;
}
SJewelConfig sTargetEquipStarsConfig = STableManager.getConfig(SJewelConfig.class).get(integerIntegerMap.get(targetstar));
if (null == sTargetEquipStarsConfig) {
break;
}
SJewelConfig sEquipStarsConfig = STableManager.getConfig(SJewelConfig.class).get(entry.getValue());
if (null == sEquipStarsConfig) {
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
TreeSet<String> equipByIDs = ItemLogic.getJewelEquipWithLeve(user, sEquipStarsConfig.getLocation(),sEquipStarsConfig.getRace(),entry.getKey());
int canConNum =equipByIDs.size()/sEquipStarsConfig.getRankupCount();
if(canConNum<=0){
continue;
}
//check cost
boolean enough;
int needcount=0;
for (int i = 0; i < canConNum; i++) {
int[][] sumConsume = sEquipStarsConfig.getRankupResources();
HeroLogic.getInstance().combinedAttribute(sumConsume, consumeMapTem);
enough = ItemUtil.checkCost(user, consumeMapTem);
if (!enough) {
break;
}
//生成装备 混合消耗
Jewel equip = new Jewel(user.getId(),sTargetEquipStarsConfig.getId());
user.getEquipManager().addEquip(user,equip);
newids.add(equip.getId());//后面合成可能会被删除
needcount += sEquipStarsConfig.getRankupCount();
HeroLogic.getInstance().combinedAttribute(sumConsume, consumeMap);
}
//消耗装备
int i = 1;
for (String id : equipByIDs.descendingSet()) {
if (i > needcount) {
break;
}
if(!newids.contains(id)){
equipadds.add(id);
}else {
newids.remove(id);
}
user.getEquipManager().remove(id);
i++;
}
}
for (String id:newids) {
equips.add(CBean2Proto.getEquipProto( user.getEquipManager().getEquipMap().get(id)));
}
ItemUtil.itemCost(user, consumeMap, BIReason.COMPLEX_EQUIP_CONSUME, 0);
}
}

View File

@ -75,7 +75,7 @@ public class GuildLogic {
int guildId = user.getPlayerInfoManager().getGuildId();
if(guildId == 0){
throw new ErrorCodeException(ErrorCode.FAMILY_NO);
return;
}
//check 最近一次公会id

View File

@ -28,6 +28,7 @@ import util.MathUtils;
import util.StringUtil;
import java.util.*;
import java.util.stream.Collectors;
public class ItemLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemLogic.class);
@ -499,6 +500,34 @@ public class ItemLogic {
return equiplist;
}
/**
*
*/
public static TreeSet<String> getJewelEquip(User user, int type, int rance) {
return user.getEquipManager().getEquipMap().entrySet().stream().filter(stringEquipEntry ->
StringUtil.isEmpty(stringEquipEntry.getValue().getHeroId())
).filter(stringPropertyItemEntry -> stringPropertyItemEntry.getValue() instanceof Jewel).filter(stringPropertyItemEntry -> {
SJewelConfig config = STableManager.getConfig(SJewelConfig.class).get(stringPropertyItemEntry.getValue().getEquipId());
if (config == null) {
return false;
}
return config.getLocation() == type && config.getRace() == rance;
}).map(Map.Entry::getKey).collect(Collectors.toCollection(TreeSet::new));
}
public static TreeSet<String> getJewelEquipWithLeve(User user, int type, int rance,int leve) {
return user.getEquipManager().getEquipMap().entrySet().stream().filter(stringEquipEntry ->
StringUtil.isEmpty(stringEquipEntry.getValue().getHeroId())
).filter(stringPropertyItemEntry -> stringPropertyItemEntry.getValue() instanceof Jewel).filter(stringPropertyItemEntry -> {
SJewelConfig config = STableManager.getConfig(SJewelConfig.class).get(stringPropertyItemEntry.getValue().getEquipId());
if (config == null) {
return false;
}
return config.getLocation() == type && config.getRace() == rance&&config.getLevel()==leve;
}).map(Map.Entry::getKey).collect(Collectors.toCollection(TreeSet::new));
}
/**
*
* @param iSession

View File

@ -1,9 +1,7 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.Map;
@Table(name ="JewelConfig")
public class SJewelConfig implements BaseConfig {
@ -22,6 +20,10 @@ public class SJewelConfig implements BaseConfig {
private int[] max;
private int rankupCount;
private int[][] rankupResources;
@Override
public void init() throws Exception {
@ -57,5 +59,13 @@ public class SJewelConfig implements BaseConfig {
return max;
}
public int getRankupCount() {
return rankupCount;
}
public int[][] getRankupResources() {
return rankupResources;
}
}

View File

@ -175,10 +175,15 @@ public class ExcelUtils {
continue;
}
Cell cell = row.getCell(j);
Cell cell1 = row4.getCell(j);
if (cell == null){
Cell cell1 = row4.getCell(j);
info = getStringBuilder(row2, info, j, cell1);
}else{
//添加默认值
if (cell.toString().isEmpty()&&(cell1!=null)&&(!cell1.toString().isEmpty())){
info = getStringBuilder(row2, info, j, cell1);
continue;
}
if (getCellFormatValue(row1.getCell(j),null).toString().isEmpty()){
continue;
}