feat(玉石一键合成): 新增玉石一键合成

This commit is contained in:
zhangxk
2023-07-14 13:41:27 +08:00
committed by luying
parent 9c10f33401
commit fc440afe83
7 changed files with 237 additions and 9 deletions
+5
View File
@@ -1689,6 +1689,11 @@ export function checkRouteParam(route: string, msg: any) {
if (!checkNaturalNumbers(msg.id, msg.count)) return false;
break;
}
case "role.equipHandler.composeStoneByItId":
{
if (!checkNaturalNumbers(msg.itId)) return false;
break;
}
case "role.equipHandler.inheritJewel":
{
if (!checkNaturalNumbers(msg.originJewel, msg.targetJewel)) return false;
+128 -2
View File
@@ -1,4 +1,4 @@
import { CURRENCY_TYPE, HANDLE_REWARD_TYPE, CURRENCY_BY_TYPE } from '../../consts';
import { CURRENCY_TYPE, HANDLE_REWARD_TYPE, CURRENCY_BY_TYPE, CONSUME_TYPE, ITID_STONE_LIMIT } from '../../consts';
import { RoleModel, RoleType } from '../../db/Role';
import { ItemModel, ItemType } from '../../db/Item';
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
@@ -210,4 +210,130 @@ export class CheckMeterial {
public getConsume() {
return this.consumes;
}
}
};
/**
* 获取升品所需消耗
* @param id
* @returns
*/
export async function getComposeStoneNeedCost(id: number) {
let dicStone = gameData.stone.get(id);
if (!dicStone || dicStone.composeMaterial.length <= 0) return false;
return dicStone.composeMaterial;
}
/**
* 获取当前类型6品以下玉石升级相关道具
* @param roleId
* @param 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;
for (let material of nextLvMaterial) {
if (curItem.get(material.id)) continue;
const item = await ItemModel.findbyRoleAndGid(roleId, material.id)
if (!item || item.count == 0) continue;
curItem.set(material.id, item.count);
}
}
// console.log('---------------- curItem', curItem);
// console.log('---------------- stoneLvId', stoneLvId);
return curItem;
}
/**
* 计算玉石一键升品总产出与消耗
* @param initialJewel
* @param curItem
* @returns
*/
export async function getComposeStoneCostAndAdd(curItem, itId) {
let allAddItem = new Map<number, number>();//Array<ItemInter> = [];//总产出
let allCostItem = new Map<number, number>();//Array<ItemInter> = [];//总消耗
//计算升品所需消耗
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);
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;
for (let material of nextLvMaterial) {
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 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)));
continue;
}
allAddItem.set(material.id, tempCount2 - costCount);
}
// 产出
let addCount = allAddItem.get(nextLvId) ? allAddItem.get(nextLvId) : 0
allAddItem.set(nextLvId, addCount + nextLvCount);
}
}
// console.log('---------------- allCostItem', allCostItem);
// console.log('---------------- allAddItem', allAddItem);
return { allCostItem, allAddItem };
}