Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ChilledJelly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lajnux committed Nov 3, 2024
2 parents 0de4cf5 + 2d13d47 commit 179f194
Show file tree
Hide file tree
Showing 21 changed files with 1,068 additions and 595 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ coverage
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/versions
wiki.xml
4 changes: 2 additions & 2 deletions dist/cjs/index.cjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/cjs/index.cjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/esm/index.mjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/esm/index.mjs.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/types/EItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4159,6 +4159,7 @@ export declare enum EItem {
DIVINE_MAGIC_POTION2 = 23751,
DIVINE_MAGIC_POTION1 = 23754,
YOUNGLLEF = 23757,
CORRUPTED_YOUNGLLEF = 23759,
SMOLCANO = 23760,
CRYSTAL_HARPOON = 23762,
CRYSTAL_IMPLING_JAR = 23768,
Expand Down
2 changes: 1 addition & 1 deletion dist/types/EItem.d.ts.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/types/meta/monsterData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export declare enum MonsterAttackType {
export interface MonsterData {
members: boolean;
combatLevel: number;
hitpoints: number | null;
hitpoints?: number | null;
maxHit?: number | null;
attackType: MonsterAttackType[];
attackSpeed: number | null;
aggressive: boolean;
poisonous: boolean;
poisonous?: boolean;
immuneToPoison: boolean;
immuneToVenom: boolean;
attributes: MonsterAttribute[];
Expand Down
2 changes: 1 addition & 1 deletion dist/types/meta/monsterData.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/types/simulation/openables/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import OgreCoffin from "./OgreCoffin";
import { GiantsFoundryOrePack, VolcanicMineOrePack } from "./OrePack";
import SeedPack from "./SeedPack";
import SinisterChest from "./SinisterChest";
export { MysteryBox, NestBoxEmpty, NestBoxRing, NestBoxSeeds, GiantEggSacFull, BronzeHAMChest, IronHAMChest, SilverHAMChest, SteelHAMChest, Casket, CrystalChest, ElvenCrystalChest, GrubbyChest, MuddyChest, OgreCoffin, SinisterChest, BrimstoneChest, LarransChest, SeedPack, BabyImpling, YoungImpling, GourmetImpling, EarthImpling, EssenceImpling, EclecticImpling, NatureImpling, MagpieImpling, NinjaImpling, CrystalImpling, DragonImpling, LuckyImpling, VolcanicMineOrePack, GiantsFoundryOrePack, IntricatePouch, BasicSack, AdeptSack, ExpertSack, MasterSack, };
import ZombiePiratesLocker from "./ZombiePiratesLocker";
export { MysteryBox, NestBoxEmpty, NestBoxRing, NestBoxSeeds, GiantEggSacFull, BronzeHAMChest, IronHAMChest, SilverHAMChest, SteelHAMChest, Casket, CrystalChest, ElvenCrystalChest, GrubbyChest, MuddyChest, OgreCoffin, SinisterChest, BrimstoneChest, LarransChest, SeedPack, BabyImpling, YoungImpling, GourmetImpling, EarthImpling, EssenceImpling, EclecticImpling, NatureImpling, MagpieImpling, NinjaImpling, CrystalImpling, DragonImpling, LuckyImpling, VolcanicMineOrePack, GiantsFoundryOrePack, IntricatePouch, BasicSack, AdeptSack, ExpertSack, MasterSack, ZombiePiratesLocker, };
declare const Openables: Collection<number, Openable> & {
MysteryBox: import("../..").SimpleOpenable;
NestBoxEmpty: import("../..").SimpleOpenable;
Expand Down
2 changes: 1 addition & 1 deletion dist/types/simulation/openables/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@
"concurrently": "^9.0.1",
"deep-object-diff": "^1.1.9",
"deepmerge": "^4.3.1",
"remeda": "^2.16.0",
"tsx": "^4.19.1",
"typescript": "^5.6.2",
"vitest": "^2.1.1"
"vitest": "^2.1.1",
"wtf_wikipedia": "^10.3.2"
},
"keywords": ["runescape"],
"files": ["dist"],
Expand Down
4 changes: 2 additions & 2 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prepareItems from "./prepareItems";
import "./enum";
import { prepareMonsters } from "./prepareMonsters";
import { monstersWikiUpdate } from "./wiki";

prepareItems();
prepareMonsters();
monstersWikiUpdate();
126 changes: 0 additions & 126 deletions scripts/prepareMonsters.ts

This file was deleted.

169 changes: 169 additions & 0 deletions scripts/wiki.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { mergeDeep, omitBy } from "remeda";
import wtf from "wtf_wikipedia";

import { Monsters } from "../src";

const transformData = (data: any): any => {
let {
id,
members,
combat,
hitpoints,
"attack style": attackStyle,
aggressive,
poisonous,
immunepoison,
immunevenom,
cat,
examine,
smwname,
name,
slaylvl,
slayxp,
assignedby,
att,
str,
def,
mage,
range,
amagic,
arange,
dstab,
dslash,
dcrush,
dmagic,
drange,
attributes,
} = data;
attributes ??= [];
if (!Array.isArray(attributes)) {
attributes = [attributes];
}

const attackSpeed = data["attack speed"] ?? data["attack speed1"] ?? data["attack speed2"] ?? null;

let combatLevel = Boolean(combat) ? Number(combat) : 0;
if (!combatLevel) combatLevel = 0;

return {
id: Number(data.id ?? data.id1?.number),
members: members?.toLowerCase() === "yes",
combatLevel,
hitpoints,
attackType: attackStyle?.toLowerCase().split(", "),
attackSpeed: attackSpeed === "No" ? null : Number(attackSpeed),
aggressive: aggressive?.toLowerCase() === "yes",
poisonous: poisonous?.toLowerCase().includes("yes"),
immuneToPoison: immunepoison?.toLowerCase() === "yes",
immuneToVenom: immunevenom?.toLowerCase() === "yes",
attributes: attributes ?? [],
category: cat?.toLowerCase().split(", "),
examineText: examine,
wikiName: name,
wikiURL: `https://oldschool.runescape.wiki/w/${name}`,
attackLevel: Number(att ?? 0),
strengthLevel: Number(str ?? 0),
defenceLevel: Number(def ?? 0),
magicLevel: Number(mage ?? 0),
rangedLevel: Number(range ?? 0),
attackStab: 0,
attackSlash: 0,
attackCrush: 0,
attackMagic: Number(amagic ?? 0),
attackRanged: Number(arange ?? 0),
defenceStab: Number(dstab ?? 0),
defenceSlash: Number(dslash ?? 0),
defenceCrush: Number(dcrush ?? 0),
defenceMagic: Number(dmagic ?? 0),
defenceRanged: Number(drange ?? 0),
attackAccuracy: 0,
meleeStrength: 0,
rangedStrength: 0,
magicDamage: 0,
isSlayerMonster: !!slaylvl,
slayerLevelRequired: slaylvl,
slayerXP: slayxp,
assignableSlayerMasters: assignedby?.split(",").map(master => master.trim().toLowerCase()),
};
};

export async function monstersWikiUpdate() {
if (!existsSync("wiki.xml")) {
writeFileSync(
"wiki.xml",
`https://oldschool.runescape.wiki/w/Special:Export"
${Monsters.map(m => m.data?.wikiName)
.flat(222)
.join("\n")}`,
);
}
const json = wtf(readFileSync("wiki.xml", "utf-8")).json();
const sections = json.sections
.map(s => s.infoboxes)
.flat(100)
.filter(s => s && Boolean(s.name) && Boolean(s.examine))
.map(s =>
omitBy(s, (value, key) =>
["version", "image", "release", "examine", "update"].some(str => key.startsWith(str)),
),
);
for (let i = 0; i < sections.length; i++) {
const section = sections[i];
const allIDs: any[] = [];
for (const [key, val] of Object.entries(section) as any[]) {
if (key.startsWith("id") && key.length !== 2) {
allIDs.push(val.text);
continue;
}
section[key] = val.number ?? val.text ?? val;
}
section.allIDs = allIDs
.map(idOrIdArr => (idOrIdArr.includes(",") ? idOrIdArr.split(",") : idOrIdArr))
.flat(100)
.map(id => Number(id.trim()))
.sort((a, b) => a - b);
}

const obj: any = JSON.parse(readFileSync("./src/data/monsters_data.json", "utf-8"));
const parsed = sections.map(transformData);

for (const monData of parsed) {
const existingMonster = Monsters.find(m => m.id === monData.id);
if (!existingMonster && !["Chilled jelly", "Wealthy citizen"].some(s => monData.wikiName.includes(s))) {
console.log(`No monster found for ${monData.wikiName}`);
continue;
}

const id = existingMonster?.id ?? monData.id;
if (typeof id === "undefined" || !Number.isInteger(id)) {
throw new Error(`No ID found for monster ${monData.wikiName} ${existingMonster?.id} ${monData.id}`);
}
obj[id] = mergeDeep(existingMonster?.data ?? {}, monData);
if (existingMonster) {
obj[id].examineText = existingMonster.data.examineText;
obj[id].wikiURL = existingMonster.data.wikiURL;
obj[id].category = existingMonster.data.category;
obj[id].attributes = existingMonster.data.attributes;
obj[id].wikiName = existingMonster.data.wikiName;
obj[id].slayerLevelRequired = existingMonster.data.slayerLevelRequired;
obj[id].isSlayerMonster = existingMonster.data.isSlayerMonster;
obj[id].slayerXP = existingMonster.data.slayerXP;
obj[id].attackType = existingMonster.data.attackType;
obj[id].aggressive = existingMonster.data.aggressive;
obj[id].assignableSlayerMasters = existingMonster.data.assignableSlayerMasters;
}
if (!("attackType" in obj[id])) {
obj[id].attackType = [];
}
if (!("category" in obj[id])) {
obj[id].category = [];
}
if (!("slayerLevelRequired" in obj[id])) {
obj[id].slayerLevelRequired = 0;
}
delete obj[id].id;
}
writeFileSync("src/data/monsters_data.json", JSON.stringify(obj, null, 4));
}
1 change: 1 addition & 0 deletions src/EItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4159,6 +4159,7 @@ export enum EItem {
DIVINE_MAGIC_POTION2 = 23751,
DIVINE_MAGIC_POTION1 = 23754,
YOUNGLLEF = 23757,
CORRUPTED_YOUNGLLEF = 23759,
SMOLCANO = 23760,
CRYSTAL_HARPOON = 23762,
CRYSTAL_IMPLING_JAR = 23768,
Expand Down
4 changes: 2 additions & 2 deletions src/meta/monsterData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export enum MonsterAttackType {
export interface MonsterData {
members: boolean;
combatLevel: number;
hitpoints: number | null;
hitpoints?: number | null;
maxHit?: number | null;
attackType: MonsterAttackType[];
attackSpeed: number | null;
aggressive: boolean;
poisonous: boolean;
poisonous?: boolean;
immuneToPoison: boolean;
immuneToVenom: boolean;
attributes: MonsterAttribute[];
Expand Down
Loading

0 comments on commit 179f194

Please sign in to comment.