From ff5b28af7a97626738554c29559ec8f111424568 Mon Sep 17 00:00:00 2001 From: luying Date: Tue, 9 Aug 2022 15:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=BA=97=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=95=86=E5=BA=97=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game-server/app/services/shopService.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/game-server/app/services/shopService.ts b/game-server/app/services/shopService.ts index c24b8d10c..511ad4b68 100644 --- a/game-server/app/services/shopService.ts +++ b/game-server/app/services/shopService.ts @@ -89,9 +89,10 @@ export function getShopPrice(goodId: number, count: number, buyCount: number, st let result = 0; for(let i = 0; i < count; i++) { let curPrice = 0; - for(let { times, price } of arr) { - curPrice = price; - if(buyCount + i <= times) break; + for(let { times, price, maxTimes } of arr) { + if(buyCount + i + 1 >= times && (buyCount + i + 1 <= maxTimes||maxTimes == -1)) { + curPrice = price; break; + } } result += curPrice; } @@ -102,14 +103,16 @@ export function getShopPrice(goodId: number, count: number, buyCount: number, st } function parseShopPrice(str: string) { - let result = new Array<{ times: number, price: number }>(); + let result = new Array<{ times: number, price: number, maxTimes: number }>(); if (!str) return result; let decodeArr = decodeArrayListStr(str); - for (let [times, price] of decodeArr) { + for (let i = 0; i < decodeArr.length; i++) { + let [times, price] = decodeArr[i]; if (isNaN(parseInt(times)) || isNaN(parseInt(price))) { throw new Error('data table format wrong'); } - result.push({ times: parseInt(times), price: parseInt(price) }); + result.push({ times: parseInt(times), price: parseInt(price), maxTimes: -1 }); + if(result[i - 1]) result[i - 1].maxTimes = parseInt(times); } return result }