Task 【ID1006033】【新战斗版本】后端装备合成系统
parent
8e8cc31b08
commit
64fabcd9d7
|
@ -0,0 +1,194 @@
|
|||
package com.ljsd.jieling.handler.equip;
|
||||
|
||||
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.Equip;
|
||||
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.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.SEquipStarsConfig;
|
||||
import manager.STableManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Description: 合成装备
|
||||
* Author: zsx
|
||||
* CreateDate: 2020/4/2 15:48
|
||||
*/
|
||||
public class ComplexEquipHandler extends BaseHandler<HeroInfoProto.ComplexEquipRequest> {
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.EQUIP_COMPLEX_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, HeroInfoProto.ComplexEquipRequest proto) throws Exception {
|
||||
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
if (user == null) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
if (proto.getStar() != 0) {//手动合成
|
||||
//check param and cnf
|
||||
if (proto.getNum() <= 0) {
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_DEFINE);
|
||||
}
|
||||
int needStar = proto.getStar() - 1;
|
||||
if (needStar <= 0) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
int targetEquip = STableManager.getFigureConfig(ItemStaticConfig.class).getEquipByStar(proto.getType(), proto.getStar());
|
||||
if (targetEquip == 0) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
int equipId = STableManager.getFigureConfig(ItemStaticConfig.class).getEquipByStar(proto.getType(), needStar);
|
||||
if (equipId == 0) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
Set<String> equipByIDs = ItemLogic.getEquipByID(user, equipId);
|
||||
|
||||
SEquipStarsConfig sEquipStarsConfig = STableManager.getConfig(SEquipStarsConfig.class).get(needStar);
|
||||
if (null == sEquipStarsConfig) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
SEquipStarsConfig sTargetEquipStarsConfig = STableManager.getConfig(SEquipStarsConfig.class).get(proto.getStar());
|
||||
if (null == sTargetEquipStarsConfig) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
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_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] = targetEquip;
|
||||
dropItems[0][1] = proto.getNum();
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, dropItems, BIReason.COMPLEX_EQUIP);
|
||||
HeroInfoProto.ComplexEquipResponse.Builder response = HeroInfoProto.ComplexEquipResponse.newBuilder();
|
||||
|
||||
//remove hero
|
||||
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.sendMessage(iSession, 1, MessageTypeProto.MessageType.EQUIP_COMPLEX_RESPONSE_VALUE, response.build(), true);
|
||||
|
||||
} else {
|
||||
|
||||
Map<Integer, Map<Integer, Integer>> euipTppes = STableManager.getFigureConfig(ItemStaticConfig.class).getEuipTppes();
|
||||
Map<Integer, Integer> integerIntegerMap = new TreeMap<>(euipTppes.getOrDefault(proto.getType(), new HashMap<>()));
|
||||
|
||||
Set<String> equipadds =new HashSet<>();
|
||||
Map<Integer, Integer> consumeMap = new HashMap<>();
|
||||
List< CommonProto.Equip> equips = new LinkedList<>();
|
||||
Set<String> newids = new HashSet<>();
|
||||
for (Map.Entry<Integer, Integer> entry : integerIntegerMap.entrySet()) {
|
||||
//star conf
|
||||
int targetstar = entry.getKey()+1;
|
||||
SEquipStarsConfig sTargetEquipStarsConfig = STableManager.getConfig(SEquipStarsConfig.class).get(targetstar);
|
||||
if (null == sTargetEquipStarsConfig) {
|
||||
break;
|
||||
}
|
||||
SEquipStarsConfig sEquipStarsConfig = STableManager.getConfig(SEquipStarsConfig.class).get(entry.getKey());
|
||||
if (null == sEquipStarsConfig) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
|
||||
int targetEquipId = STableManager.getFigureConfig(ItemStaticConfig.class).getEquipByStar(proto.getType(), targetstar);
|
||||
if (targetEquipId == 0) {
|
||||
break;
|
||||
}
|
||||
int equipId = STableManager.getFigureConfig(ItemStaticConfig.class).getEquipByStar(proto.getType(),entry.getKey());
|
||||
if (equipId == 0) {
|
||||
throw new ErrorCodeException(ErrorCode.CFG_NULL);
|
||||
}
|
||||
|
||||
|
||||
TreeSet<String> equipByIDs = ItemLogic.getEquipByID(user, equipId);
|
||||
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();
|
||||
Map<Integer, Integer> consumeMapTem = new HashMap<>();
|
||||
HeroLogic.getInstance().combinedAttribute(sumConsume, consumeMapTem);
|
||||
enough = ItemUtil.checkCost(user, consumeMapTem);
|
||||
if (!enough) {
|
||||
break;
|
||||
}
|
||||
|
||||
//生成装备 混合消耗
|
||||
Equip equip = new Equip(user.getId(),targetEquipId);
|
||||
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);
|
||||
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.sendMessage(iSession, 1, MessageTypeProto.MessageType.EQUIP_COMPLEX_RESPONSE_VALUE, response.build(), true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name ="EquipStarsConfig")
|
||||
public class SEquipStarsConfig implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int rankupCount;
|
||||
|
||||
private int[][] rankupResources;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getRankupCount() {
|
||||
return rankupCount;
|
||||
}
|
||||
|
||||
public int[][] getRankupResources() {
|
||||
return rankupResources;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue