Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nwjgit/oldschooljs into m…
Browse files Browse the repository at this point in the history
…ossyKeyFixes
  • Loading branch information
nwjgit committed Jun 3, 2024
2 parents e69f14a + 5f7bbad commit 6ba071b
Show file tree
Hide file tree
Showing 36 changed files with 11,915 additions and 4,075 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oldschooljs",
"version": "2.4.0",
"version": "2.5.4",
"description": "Allows you to interact with the OSRS Hiscores, Wiki, Items, & more.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
40 changes: 33 additions & 7 deletions scripts/prepareItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readFileSync, writeFileSync } from 'fs';
import fetch from 'node-fetch';

import { EquipmentSlot, Item } from '../dist/meta/types';
import Items, { USELESS_ITEMS } from '../dist/structures/Items';
import Items, { CLUE_SCROLLS, CLUE_SCROLL_NAMES, USELESS_ITEMS } from '../dist/structures/Items';
import { itemID } from '../dist/util';
import { itemChanges } from './manualItemChanges';

Expand All @@ -30,15 +30,22 @@ interface RawItemCollection {
};
}

// This regex matches the nearly 600 individual clue-step items:
const clueStepRegex = /^Clue scroll \((beginner|easy|medium|hard|elite|master)\) - .*$/;

function itemShouldntBeAdded(item: any) {
if (CLUE_SCROLLS.includes(item.id)) return false;

return (
CLUE_SCROLL_NAMES.includes(item.name) && !CLUE_SCROLLS.includes(item.id) ||
USELESS_ITEMS.includes(item.id) ||
item.duplicate === true ||
item.noted ||
item.linked_id_item ||
item.placeholder ||
item.name === 'Null' ||
item.wiki_name?.includes(' (Worn)')
item.wiki_name?.includes(' (Worn)') ||
(item.wiki_name && clueStepRegex.exec(item.wiki_name))
);
}

Expand Down Expand Up @@ -311,7 +318,10 @@ export default async function prepareItems(): Promise<void> {

const price = allPrices[item.id];
if (price) {
item.price = Math.max(0, ((price.high as number) + (price.low as number)) / 2);
// Fix weird bug with prices: (high can be 1 and low 2.14b for example... blame Jamflex)
if (price.high < price.low) price.high = price.low;
// Calculate average of High + Low
item.price = Math.ceil(Math.max(0, ((price.high as number) + (price.low as number)) / 2));
} else {
item.price = 0;
}
Expand All @@ -322,9 +332,18 @@ export default async function prepareItems(): Promise<void> {
item.price = 0;
}

// If major price increase, just dont fucking change it.
if (previousItem && item.tradeable && previousItem.price < item.price / 20 && previousItem.price !== 0) {
majorPriceChanges.push([previousItem, item]);
let dontChange = false;
if (previousItem && item.tradeable) {
// If major price increase, just dont fucking change it.
if (previousItem.price < item.price / 20 && previousItem.price !== 0) dontChange = true;
// Prevent weird bug with expensive items: (An item with 2b val on GE had high = 1 & low = 100k)
if (item.price < previousItem.price / 10) dontChange = true;
// If price differs by 10000x just don't change it.
if (price && price.high / 10000 > price.low) dontChange = true;
}

if (dontChange) {
majorPriceChanges.push([previousItem, {...item}]);
item.price = previousItem.price;
}

Expand Down Expand Up @@ -426,7 +445,14 @@ export default async function prepareItems(): Promise<void> {

messages.push(`New Items: ${moidLink(newItems)}.`);
messages.push(`Deleted Items: ${moidLink(deletedItems)}.`);
const sql = `SELECT

const totalQtySql = `SELECT id, SUM(kv.value::int) AS total_quantity
FROM users, jsonb_each_text(bank::jsonb) AS kv(itemID, value)
WHERE itemID::int = ANY(ARRAY[${deletedItems.map(i => i.id).join(',')}]::int[])
GROUP BY id`;
messages.push(`------------------- Get Total Qty of Deleted Items----------------\n${totalQtySql}\n`);

const sql = `SELECT
${deletedItems
.map(
item => `COUNT(*) FILTER (WHERE bank->>'${item.id}' IS NOT NULL) AS people_with_item_${item.id},
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const MINIGAMES = [
"pvpArena",
"soulWars",
"riftsClosed",
"colosseumGlory",
] as const;

export const CLUES = ["all", "beginner", "easy", "medium", "hard", "elite", "master"] as const;
Expand Down Expand Up @@ -72,6 +73,7 @@ export const mappedBossNames: [keyof BossRecords, string][] = [
["kraken", "Kraken"],
["kreeArra", "Kree'Arra"],
["krilTsutsaroth", "K'ril Tsutsaroth"],
["lunarChests", "Lunar Chests"],
["mimic", "Mimic"],
["nex", "Nex"],
["nightmare", "The Nightmare"],
Expand All @@ -82,6 +84,7 @@ export const mappedBossNames: [keyof BossRecords, string][] = [
["scorpia", "Scorpia"],
["scurrius", "Scurrius"],
["skotizo", "Skotizo"],
["solHeredit", "Sol Heredit"],
["spindel", "Spindel"],
["tempoross", "Tempoross"],
["theGauntlet", "The Gauntlet"],
Expand Down
Loading

0 comments on commit 6ba071b

Please sign in to comment.