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) {
|
public async composeStoneByItId(msg: { itId: number }, session: BackendSession) {
|
||||||
let { itId } = msg;
|
let { itId } = msg;
|
||||||
let roleId: string = session.get('roleId');
|
let roleId: string = session.get('roleId');
|
||||||
@@ -753,7 +759,7 @@ export class EquipHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let { allCostItem, allAddItem } = await getComposeStoneCostAndAdd(curItem, itId)
|
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);
|
// console.log("---composeStoneByItId-- allCostItem=%s, allAddItem=%s", allCostItem, allAddItem);
|
||||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,17 +225,14 @@ export async function getComposeStoneNeedCost(id: number) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前类型6品以下玉石升级相关道具
|
* 获取当前类型6品以下玉石升级相关道具
|
||||||
* @param roleId
|
* @param {string} roleId
|
||||||
* @param itId
|
* @param {number} itId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function getCurItem(roleId: string, itId: number) {
|
export async function getCurItem(roleId: string, itId: number) {
|
||||||
//记录升品所需要的当前已有道具
|
|
||||||
let curItem = new Map<number, number>();
|
let curItem = new Map<number, number>();
|
||||||
let stoneLvId = new Map<number, number>();
|
|
||||||
let stoneItId = gameData.stoneItId.get(itId);
|
let stoneItId = gameData.stoneItId.get(itId);
|
||||||
for (const { good_id, lv } of stoneItId) {
|
for (const { good_id, lv } of stoneItId) {
|
||||||
// stoneLvId.set(lv, good_id);
|
|
||||||
if (lv >= ITID_STONE_LIMIT) continue;
|
if (lv >= ITID_STONE_LIMIT) continue;
|
||||||
let nextLvMaterial = await getComposeStoneNeedCost(good_id);
|
let nextLvMaterial = await getComposeStoneNeedCost(good_id);
|
||||||
if (!nextLvMaterial) continue;
|
if (!nextLvMaterial) continue;
|
||||||
@@ -246,10 +243,6 @@ export async function getCurItem(roleId: string, itId: number) {
|
|||||||
curItem.set(material.id, item.count);
|
curItem.set(material.id, item.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('---------------- curItem', curItem);
|
|
||||||
// console.log('---------------- stoneLvId', stoneLvId);
|
|
||||||
|
|
||||||
return curItem;
|
return curItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,67 +253,76 @@ export async function getCurItem(roleId: string, itId: number) {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function getComposeStoneCostAndAdd(curItem, itId) {
|
export async function getComposeStoneCostAndAdd(curItem, itId) {
|
||||||
let allAddItem = new Map<number, number>();//Array<ItemInter> = [];//总产出
|
let allAddItem = new Map<number, number>();
|
||||||
let allCostItem = new Map<number, number>();//Array<ItemInter> = [];//总消耗
|
let allCostItem = new Map<number, number>();
|
||||||
|
|
||||||
//计算升品所需消耗
|
//计算升品所需消耗
|
||||||
for (let lv = ITID_STONE_LIMIT - 1; lv >= 1; lv--) {
|
for (let lv = ITID_STONE_LIMIT - 1; lv >= 1; lv--) {
|
||||||
for (let indexLv = lv; indexLv < ITID_STONE_LIMIT; indexLv++) {
|
for (let indexLv = lv; indexLv < ITID_STONE_LIMIT; indexLv++) {
|
||||||
|
|
||||||
let id = gameData.stoneItIdLv.get(`${itId}_${indexLv}`);
|
let id = gameData.stoneItIdLv.get(`${itId}_${indexLv}`);
|
||||||
// console.log("------- id", id);
|
|
||||||
let tempItem1 = curItem.get(id) ? curItem.get(id) : 0;
|
let tempItem1 = curItem.get(id) ? curItem.get(id) : 0;
|
||||||
let tempItem2 = allAddItem.get(id) ? allAddItem.get(id) : 0
|
let tempItem2 = allAddItem.get(id) ? allAddItem.get(id) : 0
|
||||||
let count = tempItem1 + tempItem2;
|
let count = tempItem1 + tempItem2;
|
||||||
if (count == 0) continue;//当前品没有,无法进行升下一品
|
if (count == 0) continue;//当前品没有,无法进行升下一品
|
||||||
|
|
||||||
let nextLvId = gameData.stoneItIdLv.get(`${itId}_${indexLv + 1}`); //stoneLvId.get(indexLv + 1);
|
let nextLvId = gameData.stoneItIdLv.get(`${itId}_${indexLv + 1}`);
|
||||||
// console.log("------- nextLvId", nextLvId);
|
|
||||||
|
|
||||||
if (!nextLvId) continue; //不存在下一品
|
if (!nextLvId) continue; //不存在下一品
|
||||||
|
|
||||||
// console.log("-x-x-x-x-x-x-x--x-x- nextLvId", nextLvId)
|
|
||||||
//计算升到下一阶消耗
|
//计算升到下一阶消耗
|
||||||
let nextLvMaterial = await getComposeStoneNeedCost(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) {
|
if (!nextLvMaterial || nextLvMaterial.length == 0) {
|
||||||
//升下一品不存在消耗
|
//升下一品不存在消耗
|
||||||
//产出
|
//产出
|
||||||
let addCount = allAddItem.get(nextLvId) ? allAddItem.get(nextLvId) : 0
|
let addCount = allAddItem.get(nextLvId) ? allAddItem.get(nextLvId) : 0
|
||||||
allAddItem.set(nextLvId, addCount + count);
|
allAddItem.set(nextLvId, addCount + count);
|
||||||
|
|
||||||
continue;
|
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) {
|
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 tempCount1 = curItem.get(material.id) ? curItem.get(material.id) : 0;
|
||||||
let tempCount2 = allAddItem.get(material.id) ? allAddItem.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));
|
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;// 不能升品
|
if (nextLvCount == 0) continue;// 不能升品
|
||||||
|
|
||||||
// 消耗
|
// 消耗
|
||||||
for (let material of nextLvMaterial) {
|
for (let material of nextLvMaterial) {
|
||||||
let costCount = nextLvCount * material.count;
|
let needCostCount = nextLvCount * material.count; //需要消耗数量
|
||||||
let tempCostCount = allCostItem.get(material.id) ? allCostItem.get(material.id) : 0;
|
let tempCount1 = curItem.get(material.id) ? curItem.get(material.id) : 0; // 当前item中已有的数量
|
||||||
allCostItem.set(material.id, tempCostCount + costCount);
|
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 diff = tempCount1 - needCostCount;
|
||||||
let tempCount2 = allAddItem.get(material.id);
|
if (diff > 0) {// 先消耗item中的
|
||||||
if (tempCount1) {
|
curItem.set(material.id, diff);
|
||||||
if (tempCount1 > costCount) {
|
allCostItem.set(material.id, tempCostCount + needCostCount); //记录入总消耗(仅item中,allAddItem消耗会在其中减掉)
|
||||||
curItem.set(material.id, tempCount1 - costCount);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
curItem.delete(material.id);
|
|
||||||
allAddItem.set(material.id, (tempCount2 - (costCount - tempCount1)));
|
|
||||||
continue;
|
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