Skip to content

Commit

Permalink
feat: uty packs
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster committed May 24, 2024
1 parent 4be4d77 commit d7f9d46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/base/store/buyPacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ wrap(() => {
type, count, gold,
}) {
if (gold) { // Gold error checking
const goldCost = type === 'UTY' ? 200 : 100;
const g = parseInt($('#golds').text(), 10);
if (g < 100 * count) {
if (g < goldCost * count) {
throw new Error('Not enough Gold');
}
} else { // UCP error checking
const ucpCost = type === 'UTY' ? 20 : 10;
const ucp = parseInt($('#ucp').text(), 10);
if (ucp < 10 * count) {
if (ucp < ucpCost * count) {
throw new Error('Not enough UCP');
}
}
Expand All @@ -34,21 +36,22 @@ wrap(() => {
});
}

function getCount(e, cost) {
if (e.ctrlKey) return Math.floor(parseInt($(cost ? '#ucp' : '#golds').text(), 10) / (cost ? 10 : 100));
function getCount(e, cost, baseCost) {
if (e.ctrlKey) return Math.floor(parseInt($(cost ? '#ucp' : '#golds').text(), 10) / (cost ? baseCost / 10 : baseCost));
if (e.altKey) return 10;
return 1;
}

eventManager.on(':loaded:Packs', () => {
const types = ['', 'DR'];
const types = ['', 'DR', 'UTY'];

types.forEach((type) => {
['', 'Ucp'].forEach((cost) => {
const el = document.querySelector(`#btn${cost}${type}Add`);
el.onclick = null;
el.addEventListener('click', (e) => {
const count = getCount(e, cost);
const price = type === 'UTY' ? 200 : 100;
const count = getCount(e, cost, price);
if (!count) return;
const data = {
count,
Expand All @@ -58,7 +61,7 @@ wrap(() => {
if (cost && !e.shiftKey) {
global('BootstrapDialog').show({
title: 'Buy packs with UCP?',
message: $.i18n(`Buy ${count} pack${count > 1 ? 's' : ''} for {{UCP:${count * 10}}} UCP?`),
message: $.i18n(`Buy ${count} pack${count > 1 ? 's' : ''} for {{UCP:${count * (price / 10)}}} UCP?`),
buttons: [{
label: $.i18n('dialog-continue'),
cssClass: 'btn-success',
Expand All @@ -84,7 +87,7 @@ wrap(() => {

api.register('buyPacks', (count, { type = '', gold = true } = {}) => {
if (!types.includes(type)) throw new Error(`Unsupported Pack: ${type}`);
if (Number.isNaN(count)) throw new Error(`Count(${count}) must be a number`);
if (!Number.isInteger(count) || count < 1) throw new Error(`Count(${count}) must be a number`);
buyPacks({
type,
count,
Expand Down
2 changes: 1 addition & 1 deletion src/base/store/quickPacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ onPage('Packs', async function quickOpenPack() {
});
}

const types = ['', 'DR', 'Shiny', 'Super', 'Final'];
const types = ['', 'DR', 'UTY', 'Shiny', 'Super', 'Final'];
api.register('openPacks', (count, type = '') => {
if (openingPacks()) throw new Error('Currently opening packs');
if (!types.includes(type)) throw new Error(`Unsupported Pack: ${type}`);
Expand Down

0 comments on commit d7f9d46

Please sign in to comment.