Skip to content

Commit

Permalink
Performance improvements (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
gc authored Sep 10, 2024
1 parent 872a163 commit 350c7c5
Show file tree
Hide file tree
Showing 30 changed files with 350 additions and 351 deletions.
15 changes: 10 additions & 5 deletions scripts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { Items, Monsters } from "../src";
import { USELESS_ITEMS } from "../src/structures/Items";
import { moidLink } from "./prepareItems";

export function safeItemName(itemName: string) {
let key = itemName;
key = key.replace("3rd", "third");
key = key.replace(/[^\w\s]|_/g, "");
key = key.replace(/\s+/g, "_");
key = key.toUpperCase();
return key;
}
const exitingKeys = new Set<string>();
const duplicates = new Set<number>();
let str = "export enum EItem {";
Expand Down Expand Up @@ -32,11 +40,8 @@ outer: for (const item of Items.values()) {
if (USELESS_ITEMS.includes(item.id)) {
continue;
}
let key = item.wiki_name ?? item.name;
key = key.replace("3rd", "third");
key = key.replace(/[^\w\s]|_/g, "");
key = key.replace(/\s+/g, "_");
key = key.toUpperCase();
const key = safeItemName(item.wiki_name ?? item.name);

if (exitingKeys.has(key)) {
duplicates.add(item.id);
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/meta/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ export interface WikiPage {
}[];
}

export interface IntKeyBank {
[key: number]: number;
}
export interface ItemBank {
[key: string]: number;
}
Expand Down
18 changes: 7 additions & 11 deletions src/simulation/clues/Beginner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randInt } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
Expand Down Expand Up @@ -88,16 +86,14 @@ export const StandardTable = new LootTable()

export const BeginnerClueTable = new LootTable().add(StandardTable, 1, 11).add(UniqueTable, 1, 1);

export class BeginnerCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();
for (let i = 0; i < quantity; i++) {
const numberOfRolls = randInt(1, 3);
const MainTable = new LootTable().add(BeginnerClueTable, [1, 3]);

for (let i = 0; i < numberOfRolls; i++) {
loot.add(BeginnerClueTable.roll());
}
}
export class BeginnerCasket extends Clue {
open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/simulation/clues/Easy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randInt, roll } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
Expand Down Expand Up @@ -189,20 +187,13 @@ export const EasyStandardTable = new LootTable()

export const EasyClueTable = new LootTable().add(EasyStandardTable, 1, 11).add(EasyRareTable, 1, 1);

const MainTable = new LootTable().add(EasyClueTable, [2, 4]).tertiary(50, "Clue scroll (master)");
export class EasyCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();

for (let i = 0; i < quantity; i++) {
const numberOfRolls = randInt(2, 4);

if (roll(50)) loot.add("Clue scroll (master)");

for (let i = 0; i < numberOfRolls; i++) {
loot.add(EasyClueTable.roll());
}
}

open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/simulation/clues/Elite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randInt, roll } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
Expand Down Expand Up @@ -152,21 +150,14 @@ export const EliteStandardTable = new LootTable()
.add(BlessingTable);

export const EliteClueTable = new LootTable().add(EliteStandardTable, 1, 24).add(EliteRareTable, 1, 1);
const MainTable = new LootTable().add(EliteClueTable, [4, 6]).tertiary(5, "Clue scroll (master)");

export class EliteCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();

for (let i = 0; i < quantity; i++) {
const numberOfRolls = randInt(4, 6);

if (roll(5)) loot.add("Clue scroll (master)");

for (let i = 0; i < numberOfRolls; i++) {
loot.add(EliteClueTable.roll());
}
}

open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
35 changes: 14 additions & 21 deletions src/simulation/clues/Hard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { randInt, roll } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
import { itemID } from "../../util";
import { itemID, itemTupleToTable } from "../../util";
import { BlessingTable, FirelighterTable, GildedTable, PrayerPageTable, TeleportScrollTable } from "./General";

export const Hard3rdageTable = new LootTable()
Expand All @@ -25,11 +23,13 @@ export const HardMegaRareTable = new LootTable()
.add("Super energy(4)", 15)
.add("Super restore(4)", 15)
.add("Antifire potion(4)", 15)
.add([
["Super attack(4)", 5],
["Super strength(4)", 5],
["Super defence(4)", 5],
])
.add(
itemTupleToTable([
["Super attack(4)", 5],
["Super strength(4)", 5],
["Super defence(4)", 5],
]),
)
.add(Hard3rdageTable)
.add(GildedTable, 1, 5);

Expand Down Expand Up @@ -206,21 +206,14 @@ export const HardStandardTable = new LootTable()
.add(HardBowTable);

export const HardClueTable = new LootTable().add(HardStandardTable, 1, 12).add(HardRareTable, 1, 1);
const MainTable = new LootTable().add(HardClueTable, [4, 6]).tertiary(15, "Clue scroll (master)");

export class HardCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();

for (let i = 0; i < quantity; i++) {
const numberOfRolls = randInt(4, 6);

if (roll(15)) loot.add("Clue scroll (master)");

for (let i = 0; i < numberOfRolls; i++) {
loot.add(HardClueTable.roll());
}
}

open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
22 changes: 7 additions & 15 deletions src/simulation/clues/Master.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randInt, roll } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
Expand Down Expand Up @@ -161,20 +159,14 @@ export const MasterStandardTable = new LootTable()

export const MasterClueTable = new LootTable().add(MasterStandardTable, 1, 22).add(MasterRareTable, 1, 1);

export class MasterCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();

for (let i = 0; i < quantity; i++) {
if (roll(1000)) loot.add("Bloodhound");

const numberOfRolls = randInt(5, 7);

for (let i = 0; i < numberOfRolls; i++) {
loot.add(MasterClueTable.roll());
}
}
const MainTable = new LootTable().add(MasterClueTable, [5, 7]).tertiary(1000, "Bloodhound");

export class MasterCasket extends Clue {
open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
22 changes: 7 additions & 15 deletions src/simulation/clues/Medium.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { randInt, roll } from "e";

import Bank from "../../structures/Bank";
import Clue from "../../structures/Clue";
import LootTable from "../../structures/LootTable";
Expand Down Expand Up @@ -173,20 +171,14 @@ export const MediumStandardTable = new LootTable()

export const MediumClueTable = new LootTable().add(MediumStandardTable, 1, 10).add(MediumRareTable, 1, 1);

export class MediumCasket extends Clue {
public open(quantity = 1): Bank {
const loot = new Bank();

for (let i = 0; i < quantity; i++) {
const numberOfRolls = randInt(3, 5);

if (roll(30)) loot.add("Clue scroll (master)");

for (let i = 0; i < numberOfRolls; i++) {
loot.add(MediumClueTable.roll());
}
}
const MainTable = new LootTable().add(MediumClueTable, [3, 5]).tertiary(30, "Clue scroll (master)");

export class MediumCasket extends Clue {
open(quantity: number, targetBank?: undefined): Bank;
open(quantity: number, targetBank: Bank): null;
public open(quantity: number, targetBank?: Bank): Bank | null {
const loot = targetBank ?? new Bank();
MainTable.roll(quantity, { targetBank: loot });
return loot;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/simulation/monsters/bosses/Bryophyta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LootTable from "../../../structures/LootTable";
import SimpleMonster from "../../../structures/SimpleMonster";
import { itemTupleToTable } from "../../../util";
import HerbDropTable from "../../subtables/HerbDropTable";
import UncommonSeedDropTable from "../../subtables/UncommonSeedDropTable";

Expand Down Expand Up @@ -39,10 +40,10 @@ const BryophytaTable = new LootTable()
/* Materials */
.add("Runite bar", 2, 6)
.add(
[
itemTupleToTable([
["Uncut ruby", 5],
["Uncut diamond", 5],
],
]),
1,
4,
)
Expand Down
9 changes: 5 additions & 4 deletions src/simulation/monsters/bosses/CommanderZilyana.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LootTable from "../../../structures/LootTable";
import SimpleMonster from "../../../structures/SimpleMonster";
import { itemTupleToTable } from "../../../util";
import GWRareDropTable, { GWGemTable, ShardTable } from "../../subtables/GWRareDropTable";

const MinionUniqueTable = new LootTable().add("Coins", [1400, 1500], 124).add("Saradomin sword", 1, 3);
Expand Down Expand Up @@ -45,18 +46,18 @@ const CommanderZilyanaTable = new LootTable()
/* Potions */
.add("Prayer potion(4)", 3, 8)
.add(
[
itemTupleToTable([
["Super defence(3)", 3],
["Magic potion(3)", 3],
],
]),
1,
8,
)
.add(
[
itemTupleToTable([
["Saradomin brew(3)", 3],
["Super restore(4)", 3],
],
]),
1,
6,
)
Expand Down
5 changes: 3 additions & 2 deletions src/simulation/monsters/bosses/Kreearra.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LootTable from "../../../structures/LootTable";
import SimpleMonster from "../../../structures/SimpleMonster";
import { itemTupleToTable } from "../../../util";
import GWRareDropTable, { GWGemTable, ShardTable } from "../../subtables/GWRareDropTable";

const KreearraArmorTable = new LootTable().add("Armadyl helmet").add("Armadyl chestplate").add("Armadyl chainskirt");
Expand Down Expand Up @@ -52,10 +53,10 @@ const KreearraTable = new LootTable()
/* Other */
.add("Coins", [19_500, 20_000], 40)
.add(
[
itemTupleToTable([
["Ranging potion(3)", 3],
["Super defence(3)", 3],
],
]),
1,
8,
)
Expand Down
9 changes: 5 additions & 4 deletions src/simulation/monsters/bosses/KrilTsutsaroth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LootTable from "../../../structures/LootTable";
import SimpleMonster from "../../../structures/SimpleMonster";
import { itemTupleToTable } from "../../../util";
import GWRareDropTable, { GWGemTable, ShardTable } from "../../subtables/GWRareDropTable";

const MinionUniqueTable = new LootTable().add("Coins", [1300, 1400], 124).add("Zamorakian spear", 1, 3);
Expand Down Expand Up @@ -50,18 +51,18 @@ const KrilTsutsarothTable = new LootTable()

/* Potions */
.add(
[
itemTupleToTable([
["Super attack(3)", 3],
["Super strength(3)", 3],
],
]),
1,
8,
)
.add(
[
itemTupleToTable([
["Super restore(3)", 3],
["Zamorak brew(3)", 3],
],
]),
1,
8,
)
Expand Down
5 changes: 3 additions & 2 deletions src/simulation/monsters/bosses/Obor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LootTable from "../../../structures/LootTable";
import SimpleMonster from "../../../structures/SimpleMonster";
import { itemTupleToTable } from "../../../util";

const OborTable = new LootTable({ limit: 118 })
.every("Big Bones")
Expand Down Expand Up @@ -34,10 +35,10 @@ const OborTable = new LootTable({ limit: 118 })
.add("Limpwurt root", 20, 8)
.add("Big bones", 50, 8)
.add(
[
itemTupleToTable([
["Uncut diamond", 5],
["Uncut ruby", 5],
],
]),
1,
5,
);
Expand Down
Loading

0 comments on commit 350c7c5

Please sign in to comment.