diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/clazzStaticCfg/ItemStaticConfig.java b/serverlogic/src/main/java/com/ljsd/jieling/config/clazzStaticCfg/ItemStaticConfig.java index 8627d5e8b..99be32a5e 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/config/clazzStaticCfg/ItemStaticConfig.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/clazzStaticCfg/ItemStaticConfig.java @@ -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> euipTppes; + private Map> race2quality2soulid; //魂宝索引 + private Map> race2quality2id;//灵宝索引 + @Override public void registConfigs(Set 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 config = STableManager.getConfig(SJewelConfig.class); + config.forEach((k,v)->{ + int type = v.getLocation(); + int race = v.getRace(); + if(type==1){ + + Map orDefault = race2quality2soulid.getOrDefault(race, new HashMap<>()); + orDefault.putIfAbsent(v.getLevel(),k); + race2quality2soulid.putIfAbsent(race,orDefault); + }else { + Map orDefault = race2quality2id.getOrDefault(race, new HashMap<>()); + orDefault.putIfAbsent(v.getLevel(),k); + race2quality2id.putIfAbsent(race,orDefault); + } + + }); + }catch (Exception e){ + LOGGER.error("exception"); + } + } public Map> 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 integerIntegerMap = race2quality2soulid.get(race); + if(null == integerIntegerMap){ + return 0; + } + return integerIntegerMap.getOrDefault(level,0); + }else{ + Map integerIntegerMap = race2quality2id.get(race); + if(null == integerIntegerMap){ + return 0; + } + return integerIntegerMap.getOrDefault(level,0); + } + } + + public Map> getRace2quality2soulid() { + return race2quality2soulid; + } + + public Map> getRace2quality2id() { + return race2quality2id; + } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/handler/equip/ComplexEquipHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/handler/equip/ComplexEquipHandler.java index e0adc012d..de4b3f631 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/handler/equip/ComplexEquipHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/handler/equip/ComplexEquipHandler.java @@ -187,7 +187,6 @@ public class ComplexEquipHandler extends BaseHandler { + @Override + public MessageTypeProto.MessageType getMessageCode() { + return null; + } + + @Override + public GeneratedMessage processWithProto(int uid, HeroInfoProto.ComplexJewelEquipRequest proto) throws Exception { + + User user = UserManager.getUser(uid); + 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 equipByIDs = ItemLogic.getJewelEquip(user, sEquipStarsConfig.getLocation(),sEquipStarsConfig.getRace()); + + int needcount = sEquipStarsConfig.getRankupCount(); + if (equipByIDs.size() / needcount < proto.getNum()) { + //数据不够 + throw new ErrorCodeException(ErrorCode.UNKNOWN); + } + + //check cost + Map 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.ComplexEquipResponse.Builder response = HeroInfoProto.ComplexEquipResponse.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(uid, response.build()); + + } else { + + Map> race2quality2soulid = STableManager.getFigureConfig(ItemStaticConfig.class).getRace2quality2soulid(); + Map> race2quality2id = STableManager.getFigureConfig(ItemStaticConfig.class).getRace2quality2id(); + + Map soulInnerMap = new TreeMap<>(race2quality2soulid.getOrDefault(1, new HashMap<>())); + Map innerMap = new TreeMap<>(race2quality2id.getOrDefault(2, new HashMap<>())); + + Set 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().addAllEquipId(equips); + HeroInfoProto.ComplexEquipResponse.Builder response = HeroInfoProto.ComplexEquipResponse.newBuilder(); + response.addAllEquipIds(equipadds); + response.setDrop(drop); + System.out.print(response.build().toString()); + MessageUtil.sendIndicationMessage(uid, response.build()); + } + + return HeroInfoProto.ComplexEquipResponse.newBuilder().build(); + } + + + + private void combineEquip(User user, Map integerIntegerMap ,List equips,Set equipadds) throws Exception { + + Map consumeMap = new HashMap<>(); + Set newids = new HashSet<>(); + Map consumeMapTem = new HashMap<>(); + for (Map.Entry entry : integerIntegerMap.entrySet()) { + //star conf + int targetstar = entry.getKey()+1; + + if(!integerIntegerMap.containsKey(targetstar)){ + break; + } + + SJewelConfig sTargetEquipStarsConfig = STableManager.getConfig(SJewelConfig.class).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 equipByIDs = ItemLogic.getJewelEquip(user, sEquipStarsConfig.getLocation(),sEquipStarsConfig.getRace()); + 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); + } + +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/item/ItemLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/item/ItemLogic.java index a35a1667d..7ed660f0d 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/item/ItemLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/item/ItemLogic.java @@ -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,22 @@ public class ItemLogic { return equiplist; } + + /** + * 获取 指定类型和属性的宝器 + */ + public static TreeSet 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)); + } + /** * 宝器强化 精炼 * @param iSession diff --git a/tablemanager/src/main/java/config/SJewelConfig.java b/tablemanager/src/main/java/config/SJewelConfig.java index 8d3721107..b58c9d2ca 100644 --- a/tablemanager/src/main/java/config/SJewelConfig.java +++ b/tablemanager/src/main/java/config/SJewelConfig.java @@ -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; + } + } \ No newline at end of file diff --git a/test/src/main/java/ExcelUtils.java b/test/src/main/java/ExcelUtils.java index 7fb243181..c064ea888 100644 --- a/test/src/main/java/ExcelUtils.java +++ b/test/src/main/java/ExcelUtils.java @@ -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; }