feat(玉石一键合成): 新增
This commit is contained in:
@@ -739,6 +739,12 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 玉石一键合成
|
||||
* @param msg
|
||||
* @param session
|
||||
* @returns
|
||||
*/
|
||||
public async composeStoneByItId(msg: { itId: number }, session: BackendSession) {
|
||||
let { itId } = msg;
|
||||
let roleId: string = session.get('roleId');
|
||||
@@ -753,7 +759,7 @@ export class EquipHandler {
|
||||
}
|
||||
|
||||
let { allCostItem, allAddItem } = await getComposeStoneCostAndAdd(curItem, itId)
|
||||
if (allCostItem.size == 0 || allAddItem.size == 0) {
|
||||
if (!allCostItem || allCostItem.size == 0 || !allAddItem || allAddItem.size == 0) {
|
||||
// console.log("---composeStoneByItId-- allCostItem=%s, allAddItem=%s", allCostItem, allAddItem);
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
@@ -225,17 +225,14 @@ export async function getComposeStoneNeedCost(id: number) {
|
||||
|
||||
/**
|
||||
* 获取当前类型6品以下玉石升级相关道具
|
||||
* @param roleId
|
||||
* @param itId
|
||||
* @param {string} roleId
|
||||
* @param {number} itId
|
||||
* @returns
|
||||
*/
|
||||
export async function getCurItem(roleId: string, itId: number) {
|
||||
//记录升品所需要的当前已有道具
|
||||
let curItem = new Map<number, number>();
|
||||
let stoneLvId = new Map<number, number>();
|
||||
let stoneItId = gameData.stoneItId.get(itId);
|
||||
for (const { good_id, lv } of stoneItId) {
|
||||
// stoneLvId.set(lv, good_id);
|
||||
if (lv >= ITID_STONE_LIMIT) continue;
|
||||
let nextLvMaterial = await getComposeStoneNeedCost(good_id);
|
||||
if (!nextLvMaterial) continue;
|
||||
@@ -246,10 +243,6 @@ export async function getCurItem(roleId: string, itId: number) {
|
||||
curItem.set(material.id, item.count);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('---------------- curItem', curItem);
|
||||
// console.log('---------------- stoneLvId', stoneLvId);
|
||||
|
||||
return curItem;
|
||||
}
|
||||
|
||||
@@ -260,67 +253,76 @@ export async function getCurItem(roleId: string, itId: number) {
|
||||
* @returns
|
||||
*/
|
||||
export async function getComposeStoneCostAndAdd(curItem, itId) {
|
||||
let allAddItem = new Map<number, number>();//Array<ItemInter> = [];//总产出
|
||||
let allCostItem = new Map<number, number>();//Array<ItemInter> = [];//总消耗
|
||||
let allAddItem = new Map<number, number>();
|
||||
let allCostItem = new Map<number, number>();
|
||||
|
||||
//计算升品所需消耗
|
||||
for (let lv = ITID_STONE_LIMIT - 1; lv >= 1; lv--) {
|
||||
for (let indexLv = lv; indexLv < ITID_STONE_LIMIT; indexLv++) {
|
||||
|
||||
let id = gameData.stoneItIdLv.get(`${itId}_${indexLv}`);
|
||||
// console.log("------- id", id);
|
||||
let tempItem1 = curItem.get(id) ? curItem.get(id) : 0;
|
||||
let tempItem2 = allAddItem.get(id) ? allAddItem.get(id) : 0
|
||||
let count = tempItem1 + tempItem2;
|
||||
if (count == 0) continue;//当前品没有,无法进行升下一品
|
||||
|
||||
let nextLvId = gameData.stoneItIdLv.get(`${itId}_${indexLv + 1}`); //stoneLvId.get(indexLv + 1);
|
||||
// console.log("------- nextLvId", nextLvId);
|
||||
|
||||
let nextLvId = gameData.stoneItIdLv.get(`${itId}_${indexLv + 1}`);
|
||||
if (!nextLvId) continue; //不存在下一品
|
||||
|
||||
// console.log("-x-x-x-x-x-x-x--x-x- nextLvId", nextLvId)
|
||||
//计算升到下一阶消耗
|
||||
let nextLvMaterial = await getComposeStoneNeedCost(nextLvId);
|
||||
// console.log("x-x-x-x-x--x-x-x-x-x-x-- nextLvMaterial", nextLvMaterial)
|
||||
if (!nextLvMaterial || nextLvMaterial.length == 0) {
|
||||
//升下一品不存在消耗
|
||||
//产出
|
||||
let addCount = allAddItem.get(nextLvId) ? allAddItem.get(nextLvId) : 0
|
||||
allAddItem.set(nextLvId, addCount + count);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算能升品的下一品新增数量
|
||||
let nextLvCount = nextLvMaterial[0].count ? nextLvMaterial[0].count : 0;
|
||||
//设置初始数量
|
||||
let initial = nextLvMaterial[0];
|
||||
if (!initial.count || initial.count == 0) {
|
||||
console.error("dic_zyz_stone配置错误, good_id=%s", nextLvId);
|
||||
continue;
|
||||
}
|
||||
let val1 = curItem.get(initial.id) ? curItem.get(initial.id) : 0;
|
||||
let val2 = allAddItem.get(initial.id) ? allAddItem.get(initial.id) : 0;
|
||||
let nextLvCount = Math.floor((val1 + val2) / initial.count);//设置初始值
|
||||
for (let material of nextLvMaterial) {
|
||||
if (!material.count || material.count == 0) {
|
||||
nextLvCount = 0;
|
||||
console.error("dic_zyz_stone配置错误, good_id=%s", nextLvId);
|
||||
continue;
|
||||
}
|
||||
let tempCount1 = curItem.get(material.id) ? curItem.get(material.id) : 0;
|
||||
let tempCount2 = allAddItem.get(material.id) ? allAddItem.get(material.id) : 0;
|
||||
nextLvCount = Math.min(nextLvCount, Math.floor((tempCount1 + tempCount2) / material.count));
|
||||
}
|
||||
console.log("x-x--x-x-x-x-x-x-x-x- nextLvCount", nextLvCount)
|
||||
|
||||
if (nextLvCount == 0) continue;// 不能升品
|
||||
|
||||
// 消耗
|
||||
for (let material of nextLvMaterial) {
|
||||
let costCount = nextLvCount * material.count;
|
||||
let tempCostCount = allCostItem.get(material.id) ? allCostItem.get(material.id) : 0;
|
||||
allCostItem.set(material.id, tempCostCount + costCount);
|
||||
let needCostCount = nextLvCount * material.count; //需要消耗数量
|
||||
let tempCount1 = curItem.get(material.id) ? curItem.get(material.id) : 0; // 当前item中已有的数量
|
||||
let tempCount2 = allAddItem.get(material.id) ? allAddItem.get(material.id) : 0; // 当前总产出中已有的数量
|
||||
let tempCostCount = allCostItem.get(material.id) ? allCostItem.get(material.id) : 0; // 当前总消耗中已有的数量
|
||||
|
||||
let tempCount1 = curItem.get(material.id);
|
||||
let tempCount2 = allAddItem.get(material.id);
|
||||
if (tempCount1) {
|
||||
if (tempCount1 > costCount) {
|
||||
curItem.set(material.id, tempCount1 - costCount);
|
||||
continue;
|
||||
}
|
||||
|
||||
curItem.delete(material.id);
|
||||
allAddItem.set(material.id, (tempCount2 - (costCount - tempCount1)));
|
||||
let diff = tempCount1 - needCostCount;
|
||||
if (diff > 0) {// 先消耗item中的
|
||||
curItem.set(material.id, diff);
|
||||
allCostItem.set(material.id, tempCostCount + needCostCount); //记录入总消耗(仅item中,allAddItem消耗会在其中减掉)
|
||||
continue;
|
||||
}
|
||||
allAddItem.set(material.id, tempCount2 - costCount);
|
||||
|
||||
curItem.delete(material.id);
|
||||
if (tempCount1 != 0) allCostItem.set(material.id, tempCount1);//记录入总消耗(0不记录)
|
||||
|
||||
|
||||
if (tempCount2 - Math.abs(diff) < 0) return;//异常
|
||||
|
||||
allAddItem.set(material.id, (tempCount2 - Math.abs(diff)));
|
||||
}
|
||||
|
||||
// 产出
|
||||
|
||||
Reference in New Issue
Block a user