装备:修改合成方案
This commit is contained in:
@@ -3,12 +3,12 @@ import { EquipModel, RandMain, RandSe } from "../db/Equip";
|
||||
import { HeroModel, HeroType } from "../db/Hero";
|
||||
import { getGoodById, gameData, getJewelById, getQuenchGradeByValue, getQuenchConsume, getQuenchByQualityAndGrade } from "../pubUtils/data";
|
||||
import { calPlayerCeAndSave } from "./playerCeService";
|
||||
import { HERO_SYSTEM_TYPE, TASK_TYPE } from "../consts";
|
||||
import { CONSUME_TYPE, HERO_SYSTEM_TYPE, ITID, TASK_TYPE } from "../consts";
|
||||
import { EquipType } from "../db/Equip";
|
||||
import { calEquipSeids } from '../pubUtils/playerCe';
|
||||
import { checkTask, checkTaskWithHero, checkTaskWithEquip, checkActivityTask } from './taskService';
|
||||
import { handleCost } from './rewardService';
|
||||
import { DicGoods } from '../pubUtils/dictionary/DicGoods';
|
||||
import { dicGoods, DicGoods } from '../pubUtils/dictionary/DicGoods';
|
||||
import { QuenchLogParam } from '../domain/roleField/equip';
|
||||
import { QUENCH } from '../pubUtils/dicParam';
|
||||
import { DicQuenchQuality } from '../pubUtils/dictionary/DicQuenchQuality';
|
||||
@@ -20,36 +20,50 @@ import { DicQuenchQuality } from '../pubUtils/dictionary/DicQuenchQuality';
|
||||
* @param jewelCount
|
||||
*/
|
||||
export function checkMaterialEnough(consumes: Array<{ id: number, count: number }>, jewel: number, jewelCount: number) {
|
||||
let comJewelMap = {};
|
||||
consumes = mergeSameGoods(consumes);
|
||||
let needConsumes: Array<{ id: number, count: number }> = [];
|
||||
let gidJewelInfo = getGoodById(jewel);//目标宝石信息
|
||||
for (let { id, count } of consumes) {
|
||||
let jewelInfo = getJewelById(id);
|
||||
if (!jewelInfo || !jewelInfo.count) //筛选出特殊材料,特殊材料没有合成下一级需要的count数量
|
||||
continue;
|
||||
comJewelMap[id] = count + (comJewelMap[id] || 0);
|
||||
for (let i = jewelInfo.lvLimited; i < gidJewelInfo.lvLimited; i++) {//当前消耗的宝石升级到目标宝石的消耗
|
||||
if (((comJewelMap[id] || 0) % jewelInfo.count != 0)) {//jewelInfo的count,表示宝石id合成下一级需要的数量
|
||||
break;//数量有余,跳出循环,等待下次合成
|
||||
}
|
||||
let comcount = Math.floor(((comJewelMap[id] || 0)) / jewelInfo.count);
|
||||
if (comcount < 1) {
|
||||
break;//不能合成,跳出循环,等待下次合成
|
||||
}
|
||||
comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0);//jewelInfo的nextJewelId,表示宝石id合成下一级的宝石good_id
|
||||
delete comJewelMap[id];
|
||||
for(let origin of gidJewelInfo.composeMaterial) {
|
||||
needConsumes.push({ id: origin.id, count: origin.count * jewelCount });
|
||||
}
|
||||
id = jewelInfo.nextJewelId;
|
||||
|
||||
jewelInfo = getJewelById(jewelInfo.nextJewelId);
|
||||
let comJewelMap = new Map<number, number>(); // good_id => count
|
||||
let needConsumes:{ id: number, count: number, ratio?: number }[] = []
|
||||
for(let {id, count} of consumes) {
|
||||
if(!comJewelMap.has(id)) {
|
||||
comJewelMap.set(id, count);
|
||||
} else {
|
||||
comJewelMap.set(id, comJewelMap.get(id) + count);
|
||||
}
|
||||
}
|
||||
if (comJewelMap[jewel] != jewelCount || Object.keys(comJewelMap).length != 1)//检查最终是否可以合成目标宝石jewel,以及对应的数量jewelCount
|
||||
return false;
|
||||
return needConsumes;
|
||||
|
||||
function checkCurMeterial(target: number, targetCount: number) {
|
||||
let dic = getGoodById(target);
|
||||
if(!dic) return false;
|
||||
let { composeMaterial } = dic;
|
||||
|
||||
let isEnough = true;
|
||||
for(let { id, count } of composeMaterial) {
|
||||
let consumeCount = comJewelMap.get(id)||0;
|
||||
let dicGood = getGoodById(id);
|
||||
if(!dicGoods) { isEnough = false; break; }
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if(dicItid.type != CONSUME_TYPE.JEWEL) {
|
||||
if(consumeCount < count * targetCount) {
|
||||
isEnough = false; break;
|
||||
} else {
|
||||
comJewelMap.set(id, consumeCount - count * targetCount);
|
||||
needConsumes.push({ id, count: count * targetCount });
|
||||
}
|
||||
} else {
|
||||
if(consumeCount < count * targetCount) {
|
||||
comJewelMap.set(id, 0);
|
||||
isEnough = checkCurMeterial(id, count * targetCount - consumeCount);
|
||||
} else {
|
||||
comJewelMap.set(id, consumeCount - count * targetCount);
|
||||
needConsumes.push({ id, count: consumeCount - count * targetCount });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return isEnough
|
||||
}
|
||||
|
||||
let isEnough = checkCurMeterial(jewel, jewelCount);
|
||||
return isEnough? needConsumes: false;
|
||||
}
|
||||
/**
|
||||
* 将装备卸载下来,并检查是否有替换装备的武将,若有则替换
|
||||
|
||||
@@ -107,7 +107,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
// 2. 道具处理
|
||||
if(items.length > 0) {
|
||||
let { items: itemInfos } = await addBags(roleId, roleName, items);
|
||||
for (let item of itemInfos) {
|
||||
for (let item of items) {
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
}
|
||||
//背包除去装备推送
|
||||
|
||||
Reference in New Issue
Block a user