Skip to content

Commit

Permalink
Add price abuse check to packaged buyables.
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert committed Mar 3, 2024
1 parent 6078da7 commit c2d22b8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/data/buyables/buyables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ const Buyables: Buyable[] = [
})),
{
name: 'Menaphite purple outfit',
gpCost: 5000,
ironmanPrice: 600,
gpCost: 25_000,
ironmanPrice: 10_000,
outputItems: new Bank({
'Menaphite purple hat': 1,
'Menaphite purple top': 1,
Expand All @@ -1005,8 +1005,8 @@ const Buyables: Buyable[] = [
},
{
name: 'Menaphite red outfit',
gpCost: 5000,
ironmanPrice: 600,
gpCost: 25_000,
ironmanPrice: 10_000,
outputItems: new Bank({
'Menaphite red hat': 1,
'Menaphite red top': 1,
Expand Down
59 changes: 58 additions & 1 deletion tests/unit/priceAbuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,63 @@ import { sacrificePriceOfItem } from '../../src/mahoji/commands/sacrifice';
import { sellPriceOfItem, sellStorePriceOfItem } from '../../src/mahoji/commands/sell';

describe('Price Abusing', () => {
const gpPackageBuyables = Buyables.filter(
i =>
i.gpCost !== undefined &&
i.itemCost === undefined &&
i.outputItems !== undefined &&
!isFunction(i.outputItems) &&
i.outputItems.length > 1
);

test('Package buyables', () => {
for (const b of gpPackageBuyables) {
// Check for packaged items
if (b.outputItems) {
if (isFunction(b.outputItems)) continue;
const outputItems = b.outputItems.items();

let totalPriceSoldFor = 0;
for (const [item, qty] of outputItems) {
totalPriceSoldFor += sellPriceOfItem(item, 0).price * qty;
}
const priceBoughtFor = b.gpCost;

if (totalPriceSoldFor > priceBoughtFor!) {
throw new Error(
`(Package) ${b.name} has an abusable price: buys for ${priceBoughtFor}, sells for ${totalPriceSoldFor}.`
);
}
if (b.ironmanPrice) {
let storePrice = 0;
for (const [item, qty] of outputItems) {
storePrice += sellStorePriceOfItem(item, qty).price;
}
if (storePrice > b.ironmanPrice) {
throw new Error(
`(Package) ${b.name} has an abusable price: buys for ${b.ironmanPrice}, sells for ${storePrice}.`
);
}
}

let sacPrice = 0;
for (const [item, qty] of outputItems) {
sacPrice += sacrificePriceOfItem(item, qty);
}
if (sacPrice > priceBoughtFor!) {
throw new Error(
`${b.name} has an abusable sacrifice price: buys for ${priceBoughtFor}, sacrifices for ${sacPrice}.`
);
}
if (b.ironmanPrice && sacPrice > b.ironmanPrice) {
throw new Error(
`${b.name} has an abusable ironman sacrifice price: buys for ${b.ironmanPrice}, sacrifices for ${sacPrice}.`
);
}
}
}
});

const gpBuyables = Buyables.filter(
i =>
i.gpCost !== undefined &&
Expand All @@ -31,7 +88,7 @@ describe('Price Abusing', () => {
const storePrice = sellStorePriceOfItem(item, 1);
if (storePrice.price > b.ironmanPrice) {
throw new Error(
`${item.name} has an abusable price: buys for ${storePrice.price}, sells for ${b.ironmanPrice}.`
`${item.name} has an abusable price: buys for ${b.ironmanPrice}, sells for ${storePrice.price}.`
);
}
}
Expand Down

0 comments on commit c2d22b8

Please sign in to comment.