商店:修改商店价格
This commit is contained in:
@@ -89,9 +89,10 @@ export function getShopPrice(goodId: number, count: number, buyCount: number, st
|
|||||||
let result = 0;
|
let result = 0;
|
||||||
for(let i = 0; i < count; i++) {
|
for(let i = 0; i < count; i++) {
|
||||||
let curPrice = 0;
|
let curPrice = 0;
|
||||||
for(let { times, price } of arr) {
|
for(let { times, price, maxTimes } of arr) {
|
||||||
curPrice = price;
|
if(buyCount + i + 1 >= times && (buyCount + i + 1 <= maxTimes||maxTimes == -1)) {
|
||||||
if(buyCount + i <= times) break;
|
curPrice = price; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result += curPrice;
|
result += curPrice;
|
||||||
}
|
}
|
||||||
@@ -102,14 +103,16 @@ export function getShopPrice(goodId: number, count: number, buyCount: number, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseShopPrice(str: string) {
|
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;
|
if (!str) return result;
|
||||||
let decodeArr = decodeArrayListStr(str);
|
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))) {
|
if (isNaN(parseInt(times)) || isNaN(parseInt(price))) {
|
||||||
throw new Error('data table format wrong');
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user