Skip to content

Commit 43af104

Browse files
authored
chore: dynamically detect pack cost
1 parent d3cc056 commit 43af104

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/base/store/buyPacks.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ wrap(() => {
1010
function buyPacks({
1111
type, count, gold,
1212
}) {
13+
const rawCost = document.querySelector(`#btn${gold ? '' : 'Ucp'}${type}Add`).nextElementSibling.textContent;
14+
const cost = Number(rawCost);
1315
if (gold) { // Gold error checking
14-
const goldCost = type === 'UTY' ? 200 : 100;
1516
const g = parseInt($('#golds').text(), 10);
16-
if (g < goldCost * count) {
17+
if (g < cost * count) {
1718
throw new Error('Not enough Gold');
1819
}
1920
} else { // UCP error checking
20-
const ucpCost = type === 'UTY' ? 20 : 10;
2121
const ucp = parseInt($('#ucp').text(), 10);
22-
if (ucp < ucpCost * count) {
22+
if (ucp < cost * count) {
2323
throw new Error('Not enough UCP');
2424
}
2525
}
@@ -37,7 +37,7 @@ wrap(() => {
3737
}
3838

3939
function getCount(e, cost, baseCost) {
40-
if (e.ctrlKey) return Math.floor(parseInt($(cost ? '#ucp' : '#golds').text(), 10) / (cost ? baseCost / 10 : baseCost));
40+
if (e.ctrlKey) return Math.floor(parseInt($(cost ? '#ucp' : '#golds').text(), 10) / baseCost);
4141
if (e.altKey) return 10;
4242
return 1;
4343
}
@@ -51,7 +51,7 @@ wrap(() => {
5151
if (!el) return;
5252
el.onclick = null;
5353
el.addEventListener('click', (e) => {
54-
const price = type === 'UTY' ? 200 : 100;
54+
const price = Number(el.nextElementSibling.textContent);
5555
const count = getCount(e, cost, price);
5656
if (!count) return;
5757
const data = {
@@ -62,7 +62,7 @@ wrap(() => {
6262
if (cost && !e.shiftKey) {
6363
global('BootstrapDialog').show({
6464
title: 'Buy packs with UCP?',
65-
message: $.i18n(`Buy ${count} pack${count > 1 ? 's' : ''} for {{UCP:${count * (price / 10)}}} UCP?`),
65+
message: $.i18n(`Buy ${count} pack${count > 1 ? 's' : ''} for {{UCP:${count * price}}} UCP?`),
6666
buttons: [{
6767
label: $.i18n('dialog-continue'),
6868
cssClass: 'btn-success',

0 commit comments

Comments
 (0)