命格脚本优化
parent
b8de907745
commit
9060e00553
|
@ -35,84 +35,84 @@ public class LifeStoneUpRequestHandler extends BaseHandler<HeroInfoProto.LifeSto
|
|||
public void processWithProto(ISession session, HeroInfoProto.LifeStoneUpRequest proto) throws Exception {
|
||||
int uid = session.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
int type= proto.getType();
|
||||
Map<Integer, Long>costItemMap=new HashMap<>();
|
||||
Map<Integer, Long>addItemMap=new HashMap<>();
|
||||
int equipLifeStoneId=0;
|
||||
ItemManager itemManager=user.getItemManager();
|
||||
int type = proto.getType();
|
||||
Map<Integer, Long> costItemMap = new HashMap<>();
|
||||
Map<Integer, Long> addItemMap = new HashMap<>();
|
||||
int equipLifeStoneId = 0;
|
||||
ItemManager itemManager = user.getItemManager();
|
||||
//操作类型 1:批量合成 2:一键合成 3:命石单个合成 4:快速合成
|
||||
if (type==1) {
|
||||
int itemId=proto.getCurGemId();
|
||||
int itemNum=proto.getSelectNum();
|
||||
SGemConfig gemConfig=STableManager.getConfig(SGemConfig.class).get(itemId);
|
||||
long upNum=itemNum/gemConfig.getUpgradeNum();
|
||||
long costGold=upNum*gemConfig.getUpgradeCost()[1];
|
||||
costItemMap.put(gemConfig.getUpgradeCost()[0],costGold);
|
||||
costItemMap.put(itemId,(long)itemNum);
|
||||
addItemMap.put(gemConfig.getNextGem(),upNum);
|
||||
}else if(type==2){
|
||||
if (type == 1) {
|
||||
int itemId = proto.getCurGemId();
|
||||
int itemNum = proto.getSelectNum();
|
||||
SGemConfig gemConfig = STableManager.getConfig(SGemConfig.class).get(itemId);
|
||||
long upNum = itemNum / gemConfig.getUpgradeNum();
|
||||
long costGold = upNum * gemConfig.getUpgradeCost()[1];
|
||||
costItemMap.put(gemConfig.getUpgradeCost()[0], costGold);
|
||||
costItemMap.put(itemId, (long) itemNum);
|
||||
addItemMap.put(gemConfig.getNextGem(), upNum);
|
||||
} else if (type == 2) {
|
||||
for (Map.Entry<Integer, TreeMap<Integer, SGemConfig>> integerTreeMapEntry : SGemConfig.gemConfigMapByType.entrySet()) {
|
||||
boolean isCost=LifeStoneAllUp(itemManager,integerTreeMapEntry.getValue(),costItemMap,addItemMap);
|
||||
boolean isCost = LifeStoneAllUp(itemManager, integerTreeMapEntry.getValue(), costItemMap, addItemMap);
|
||||
if (!isCost) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else if (type==3){
|
||||
int itemId=proto.getCurGemId();
|
||||
int itemNum=proto.getSelectNum();
|
||||
SGemConfig gemConfig=STableManager.getConfig(SGemConfig.class).get(itemId);
|
||||
costItemMap.put(gemConfig.getUpgradeCost()[0],(long)gemConfig.getUpgradeCost()[1]);
|
||||
if (proto.getGridId()>0){
|
||||
costItemMap.put(itemId,(long)itemNum);
|
||||
equipLifeStoneId=gemConfig.getNextGem();
|
||||
}else{
|
||||
costItemMap.put(itemId,(long)itemNum+1);
|
||||
addItemMap.put(gemConfig.getNextGem(),1L);
|
||||
} else if (type == 3) {
|
||||
int itemId = proto.getCurGemId();
|
||||
int itemNum = proto.getSelectNum();
|
||||
SGemConfig gemConfig = STableManager.getConfig(SGemConfig.class).get(itemId);
|
||||
costItemMap.put(gemConfig.getUpgradeCost()[0], (long) gemConfig.getUpgradeCost()[1]);
|
||||
if (proto.getGridId() > 0) {
|
||||
costItemMap.put(itemId, (long) itemNum);
|
||||
equipLifeStoneId = gemConfig.getNextGem();
|
||||
} else {
|
||||
costItemMap.put(itemId, (long) itemNum + 1);
|
||||
addItemMap.put(gemConfig.getNextGem(), 1L);
|
||||
}
|
||||
|
||||
}else if (type==4){
|
||||
SGemConfig gemConfig=STableManager.getConfig(SGemConfig.class).get(proto.getCurGemId());
|
||||
TreeMap<Integer,SGemConfig>gemConfigMap=SGemConfig.gemConfigMapByType.get(gemConfig.getType());
|
||||
if (LifeStoneQuickUp(itemManager,gemConfigMap,costItemMap,gemConfig.getLevel())) {
|
||||
int[]curUpCost=gemConfig.getUpgradeCost();
|
||||
long allGoldCost= costItemMap.get(curUpCost[0])+curUpCost[1];
|
||||
costItemMap.put(curUpCost[0],allGoldCost);
|
||||
if (proto.getGridId()>0){
|
||||
equipLifeStoneId=gemConfig.getNextGem();
|
||||
}else {
|
||||
addItemMap.put(gemConfig.getNextGem(),1L);
|
||||
costItemMap.put(proto.getCurGemId(),1L);
|
||||
} else if (type == 4) {
|
||||
SGemConfig gemConfig = STableManager.getConfig(SGemConfig.class).get(proto.getCurGemId());
|
||||
TreeMap<Integer, SGemConfig> gemConfigMap = SGemConfig.gemConfigMapByType.get(gemConfig.getType());
|
||||
if (LifeStoneQuickUp(itemManager, gemConfigMap, costItemMap, gemConfig.getLevel())) {
|
||||
int[] curUpCost = gemConfig.getUpgradeCost();
|
||||
long allGoldCost = costItemMap.get(curUpCost[0]) + curUpCost[1];
|
||||
costItemMap.put(curUpCost[0], allGoldCost);
|
||||
if (proto.getGridId() > 0) {
|
||||
equipLifeStoneId = gemConfig.getNextGem();
|
||||
} else {
|
||||
addItemMap.put(gemConfig.getNextGem(), 1L);
|
||||
costItemMap.put(proto.getCurGemId(), 1L);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
LOGGER.error("命石合成材料不足");
|
||||
throw new ErrorCodeException(ErrorCode.HANDLE_FAILED);
|
||||
}
|
||||
}
|
||||
if (costItemMap.isEmpty()){
|
||||
if (costItemMap.isEmpty()) {
|
||||
LOGGER.error("命石合成异常,请联系后端");
|
||||
throw new ErrorCodeException(ErrorCode.HANDLE_FAILED);
|
||||
}
|
||||
boolean isTrue= ItemUtil.itemCostLong(user,costItemMap,BIReason.LIFE_STONE_UP,type);
|
||||
if (!isTrue){
|
||||
boolean isTrue = ItemUtil.itemCostLong(user, costItemMap, BIReason.LIFE_STONE_UP, type);
|
||||
if (!isTrue) {
|
||||
LOGGER.error("命石合成材料不足");
|
||||
throw new ErrorCodeException(ErrorCode.HANDLE_FAILED);
|
||||
}
|
||||
HeroInfoProto.LifeStoneUpResponse.Builder response=HeroInfoProto.LifeStoneUpResponse.newBuilder();
|
||||
HeroInfoProto.LifeStoneUpResponse.Builder response = HeroInfoProto.LifeStoneUpResponse.newBuilder();
|
||||
///大于0说明是在命格系统操作
|
||||
if (equipLifeStoneId>0){
|
||||
CommonProto.LifeGridInfo lifeGridInfo=CommonProto.LifeGridInfo.newBuilder()
|
||||
if (equipLifeStoneId > 0) {
|
||||
CommonProto.LifeGridInfo lifeGridInfo = CommonProto.LifeGridInfo.newBuilder()
|
||||
.setGridId(proto.getGridId())
|
||||
.setGridIndex(proto.getGridIndex())
|
||||
.setItemId(equipLifeStoneId)
|
||||
.build();
|
||||
response.setLifeGridInfo(lifeGridInfo);
|
||||
user.getHeroManager().setLifeGridMap(proto.getGridId(),proto.getGridIndex(),equipLifeStoneId);
|
||||
}else{
|
||||
long[][]addItem=ItemUtil.mapToLongArray(addItemMap);
|
||||
CommonProto.Drop.Builder drop=ItemUtil.drop(user,addItem,BIReason.LIFE_STONE_UP);
|
||||
user.getHeroManager().setLifeGridMap(proto.getGridId(), proto.getGridIndex(), equipLifeStoneId);
|
||||
} else {
|
||||
long[][] addItem = ItemUtil.mapToLongArray(addItemMap);
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, addItem, BIReason.LIFE_STONE_UP);
|
||||
response.setDrop(drop.build());
|
||||
}
|
||||
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.LIFE_STONE_UP_RESPONSE_VALUE,response.build(),true);
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.LIFE_STONE_UP_RESPONSE_VALUE, response.build(), true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,76 +124,84 @@ public class LifeStoneUpRequestHandler extends BaseHandler<HeroInfoProto.LifeSto
|
|||
* @param addItemMap
|
||||
* @return
|
||||
*/
|
||||
public boolean LifeStoneAllUp(ItemManager itemManager,TreeMap<Integer,SGemConfig>gemConfigMap, Map<Integer, Long>costItemMap, Map<Integer, Long>addItemMap){
|
||||
long addCount=0;//一个循环合成数量
|
||||
long costGoldNum=0;//合成金币总消耗
|
||||
int costGoldId=gemConfigMap.get(1).getUpgradeCost()[0];//获取消耗材料id
|
||||
if(costItemMap.containsKey(costGoldId)){
|
||||
costGoldNum=costItemMap.get(costGoldId);
|
||||
private boolean LifeStoneAllUp(ItemManager itemManager, TreeMap<Integer, SGemConfig> gemConfigMap, Map<Integer, Long> costItemMap, Map<Integer, Long> addItemMap) {
|
||||
long addCount = 0;//一个循环合成数量
|
||||
long costGoldNum = 0;//合成金币总消耗
|
||||
int costGoldId = gemConfigMap.get(1).getUpgradeCost()[0];//获取消耗材料id
|
||||
if (costItemMap.containsKey(costGoldId)) {
|
||||
costGoldNum = costItemMap.get(costGoldId);
|
||||
}
|
||||
for (Map.Entry<Integer, SGemConfig> gemConfigEntry : gemConfigMap.entrySet()) {
|
||||
SGemConfig gemConfig=gemConfigEntry.getValue();
|
||||
SGemConfig gemConfig = gemConfigEntry.getValue();
|
||||
///升到满级
|
||||
if (gemConfig.getNextGem()==0){
|
||||
if (addCount>0){
|
||||
addItemMap.put(gemConfig.getId(),addCount);
|
||||
if (gemConfig.getNextGem() == 0) {
|
||||
if (addCount > 0) {
|
||||
addItemMap.put(gemConfig.getId(), addCount);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Item curItem= itemManager.getItem(gemConfig.getId());
|
||||
long costNum=addCount;
|
||||
if (curItem!=null){
|
||||
costNum=curItem.getItemNum()+addCount;
|
||||
Item curItem = itemManager.getItem(gemConfig.getId());
|
||||
long costNum = addCount;
|
||||
if (curItem != null) {
|
||||
costNum = curItem.getItemNum() + addCount;
|
||||
}
|
||||
///命石不足
|
||||
if (costNum< gemConfig.getUpgradeNum()){
|
||||
if (addCount>0){
|
||||
addItemMap.put(gemConfig.getId(),addCount);
|
||||
addCount=0;
|
||||
if (costNum < gemConfig.getUpgradeNum()) {
|
||||
if (addCount > 0) {
|
||||
addItemMap.put(gemConfig.getId(), addCount);
|
||||
addCount = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int stoneNum=gemConfig.getUpgradeNum();
|
||||
int[]costGold=gemConfig.getUpgradeCost();
|
||||
long remainNum=costNum%stoneNum;
|
||||
if (remainNum!=0){
|
||||
costNum-=remainNum;
|
||||
int stoneNum = gemConfig.getUpgradeNum();
|
||||
int[] costGold = gemConfig.getUpgradeCost();
|
||||
long remainNum = costNum % stoneNum;
|
||||
if (remainNum != 0) {
|
||||
costNum -= remainNum;
|
||||
}
|
||||
if (costNum>0){
|
||||
//本次合成消耗
|
||||
long needCostGoldNum=costNum/stoneNum*costGold[1];
|
||||
long haveGoldNum=0;
|
||||
if (itemManager.getItem(costGold[0])!=null){
|
||||
haveGoldNum=itemManager.getItem(costGold[0]).getItemNum();
|
||||
}
|
||||
///金币不足情况中断合成
|
||||
if (needCostGoldNum+costGoldNum>haveGoldNum){
|
||||
long upNum= (haveGoldNum-costGoldNum)/costGold[1];
|
||||
costItemMap.put(gemConfig.getId(),upNum*stoneNum);
|
||||
addItemMap.put(gemConfig.getNextGem(),upNum);
|
||||
costGoldNum+=upNum*costGold[1];
|
||||
//刷新消耗金币数量
|
||||
costItemMap.put(costGold[0],costGoldNum);
|
||||
return false;
|
||||
}
|
||||
//计算累计消耗金币
|
||||
costGoldNum+=needCostGoldNum;
|
||||
if (curItem!=null){
|
||||
long bagCost=curItem.getItemNum()-remainNum;
|
||||
//刷新消耗命石数量
|
||||
costItemMap.put(gemConfig.getId(),bagCost);
|
||||
long addNum=remainNum-curItem.getItemNum();
|
||||
if (addNum>0){
|
||||
addItemMap.put(gemConfig.getId(),addNum);
|
||||
}
|
||||
}
|
||||
//保存累计消耗金币数量
|
||||
costItemMap.put(costGold[0],costGoldNum);
|
||||
if (costNum <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (curItem==null){
|
||||
addItemMap.put(gemConfig.getId(),remainNum);
|
||||
//本次合成消耗
|
||||
long needCostGoldNum = costNum / stoneNum * costGold[1];
|
||||
long haveGoldNum = 0;
|
||||
if (itemManager.getItem(costGold[0]) != null) {
|
||||
haveGoldNum = itemManager.getItem(costGold[0]).getItemNum();
|
||||
}
|
||||
addCount=costNum/stoneNum;
|
||||
///金币不足情况中断合成
|
||||
if (needCostGoldNum + costGoldNum > haveGoldNum) {
|
||||
long upNum = (haveGoldNum - costGoldNum) / costGold[1];
|
||||
long endCostNum = upNum * stoneNum;
|
||||
long haveCostNum = endCostNum - addCount;
|
||||
if (haveCostNum > 0) {
|
||||
costItemMap.put(gemConfig.getId(), haveCostNum);
|
||||
} else {
|
||||
addItemMap.put(gemConfig.getId(), -haveCostNum);
|
||||
}
|
||||
addItemMap.put(gemConfig.getNextGem(), upNum);
|
||||
costGoldNum += upNum * costGold[1];
|
||||
//刷新消耗金币数量
|
||||
costItemMap.put(costGold[0], costGoldNum);
|
||||
return false;
|
||||
}
|
||||
//计算累计消耗金币
|
||||
costGoldNum += needCostGoldNum;
|
||||
if (curItem != null) {
|
||||
long bagCost = curItem.getItemNum() - remainNum;
|
||||
//刷新消耗命石数量
|
||||
costItemMap.put(gemConfig.getId(), bagCost);
|
||||
long addNum = remainNum - curItem.getItemNum();
|
||||
if (addNum > 0) {
|
||||
addItemMap.put(gemConfig.getId(), addNum);
|
||||
}
|
||||
}
|
||||
//保存累计消耗金币数量
|
||||
costItemMap.put(costGold[0], costGoldNum);
|
||||
|
||||
if (curItem == null) {
|
||||
addItemMap.put(gemConfig.getId(), remainNum);
|
||||
}
|
||||
addCount = costNum / stoneNum;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -206,73 +214,74 @@ public class LifeStoneUpRequestHandler extends BaseHandler<HeroInfoProto.LifeSto
|
|||
* @param selectGemLv
|
||||
* @return
|
||||
*/
|
||||
public boolean LifeStoneQuickUp(ItemManager itemManager,TreeMap<Integer,SGemConfig>gemConfigMap, Map<Integer, Long>costItemMap,int selectGemLv){
|
||||
long addCount=0;//一个循环合成数量
|
||||
long costGoldNum=0;//合成金币总消耗
|
||||
private boolean LifeStoneQuickUp(ItemManager itemManager, TreeMap<Integer, SGemConfig> gemConfigMap, Map<Integer, Long> costItemMap, int selectGemLv) {
|
||||
long addCount = 0;//一个循环合成数量
|
||||
long costGoldNum = 0;//合成金币总消耗
|
||||
for (Map.Entry<Integer, SGemConfig> gemConfigEntry : gemConfigMap.entrySet()) {
|
||||
SGemConfig gemConfig=gemConfigEntry.getValue();
|
||||
SGemConfig gemConfig = gemConfigEntry.getValue();
|
||||
///如果命石等级大于当前选中的命石等级跳过
|
||||
if (gemConfig.getLevel()>=selectGemLv){
|
||||
break;
|
||||
if (gemConfig.getLevel() >= selectGemLv) {
|
||||
break;
|
||||
}
|
||||
|
||||
Item curItem= itemManager.getItem(gemConfig.getId());
|
||||
long costNum=addCount;
|
||||
if (curItem!=null){
|
||||
costNum=curItem.getItemNum()+addCount;
|
||||
Item curItem = itemManager.getItem(gemConfig.getId());
|
||||
long costNum = addCount;
|
||||
if (curItem != null) {
|
||||
costNum = curItem.getItemNum() + addCount;
|
||||
}
|
||||
int[]costGold=gemConfig.getUpgradeCost();
|
||||
int stoneNum=gemConfig.getUpgradeNum();
|
||||
if (costNum<stoneNum){
|
||||
int[] costGold = gemConfig.getUpgradeCost();
|
||||
int stoneNum = gemConfig.getUpgradeNum();
|
||||
if (costNum < stoneNum) {
|
||||
costItemMap.clear();
|
||||
costGoldNum=0;
|
||||
addCount=0;
|
||||
costGoldNum = 0;
|
||||
addCount = 0;
|
||||
continue;
|
||||
}
|
||||
long needNum= GetNeedLifeStoneNum(gemConfig.getType(),gemConfig.getLevel(),selectGemLv);
|
||||
long needNum = GetNeedLifeStoneNum(gemConfig.getType(), gemConfig.getLevel(), selectGemLv);
|
||||
//剩余数量
|
||||
long remainNum=costNum%stoneNum;
|
||||
if (costNum>needNum){
|
||||
costNum=needNum;
|
||||
remainNum=costNum-needNum;
|
||||
long remainNum = costNum % stoneNum;
|
||||
if (costNum > needNum) {
|
||||
remainNum = costNum - needNum;
|
||||
costNum = needNum;
|
||||
}
|
||||
addCount=costNum/stoneNum;
|
||||
addCount = costNum / stoneNum;
|
||||
//本次合成消耗金币
|
||||
long needCostGoldNum=addCount*costGold[1];
|
||||
long needCostGoldNum = addCount * costGold[1];
|
||||
//计算累计消耗金币
|
||||
costGoldNum+=needCostGoldNum;
|
||||
costItemMap.put(costGold[0],costGoldNum);
|
||||
if (curItem!=null){
|
||||
long bagCost=curItem.getItemNum()-remainNum;
|
||||
costGoldNum += needCostGoldNum;
|
||||
costItemMap.put(costGold[0], costGoldNum);
|
||||
if (curItem != null) {
|
||||
long bagCost = curItem.getItemNum() - remainNum;
|
||||
//刷新消耗命石数量
|
||||
costItemMap.put(gemConfig.getId(),bagCost);
|
||||
costItemMap.put(gemConfig.getId(), bagCost);
|
||||
}
|
||||
long haveGoldNum=itemManager.getItem(costGold[0]).getItemNum();
|
||||
if (costGoldNum>haveGoldNum){
|
||||
long haveGoldNum = itemManager.getItem(costGold[0]).getItemNum();
|
||||
if (costGoldNum > haveGoldNum) {
|
||||
LOGGER.error("命石快速合成金币不足");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return addCount==1;
|
||||
return addCount == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取升级到目标等级获取消耗指定命石需要数量
|
||||
* @param stoneType 命石类型
|
||||
* @param costStoneLv 消耗命石等级
|
||||
* @param stoneType 命石类型
|
||||
* @param costStoneLv 消耗命石等级
|
||||
* @param targetStoneLv 目标等级
|
||||
* @return
|
||||
*/
|
||||
private long GetNeedLifeStoneNum(int stoneType, int costStoneLv,int targetStoneLv){
|
||||
long needNum=1;
|
||||
TreeMap<Integer,SGemConfig>stoneLvMap= SGemConfig.gemConfigMapByType.get(stoneType);
|
||||
private long GetNeedLifeStoneNum(int stoneType, int costStoneLv, int targetStoneLv) {
|
||||
long needNum = 1;
|
||||
TreeMap<Integer, SGemConfig> stoneLvMap = SGemConfig.gemConfigMapByType.get(stoneType);
|
||||
for (Map.Entry<Integer, SGemConfig> gemConfigEntry : stoneLvMap.entrySet()) {
|
||||
if (gemConfigEntry.getKey()<costStoneLv){
|
||||
if (gemConfigEntry.getKey() < costStoneLv) {
|
||||
continue;
|
||||
}
|
||||
if (gemConfigEntry.getValue().getLevel()==targetStoneLv){
|
||||
if (gemConfigEntry.getValue().getLevel() == targetStoneLv) {
|
||||
break;
|
||||
}
|
||||
needNum*=gemConfigEntry.getValue().getUpgradeNum();
|
||||
needNum *= gemConfigEntry.getValue().getUpgradeNum();
|
||||
}
|
||||
return needNum;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue