Skip to content

Commit

Permalink
Bso wildy slayer (#5877)
Browse files Browse the repository at this point in the history
  • Loading branch information
TastyPumPum authored Jun 14, 2024
1 parent de2117f commit b932c05
Show file tree
Hide file tree
Showing 69 changed files with 1,895 additions and 487 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/jest-image-snapshot": "^6.1.0",
"@types/lodash": "^4.14.195",
"@types/madge": "^5.0.0",
"@types/mitm": "^1.3.8",
"@types/node": "^14.18.12",
"@types/node-cron": "^3.0.7",
"@types/node-fetch": "^2.6.1",
Expand All @@ -85,6 +86,7 @@
"eslint-plugin-unicorn": "^44.0.2",
"fast-check": "^3.18.0",
"jest-image-snapshot": "^6.2.0",
"mitm": "^1.7.2",
"madge": "^7.0.0",
"prettier": "^2.7.1",
"prisma": "^5.13.0",
Expand Down
9 changes: 5 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,11 @@ model UserStats {
high_gambles Int @default(0)
honour_points Int @default(0)
slayer_task_streak Int @default(0)
slayer_superior_count Int @default(0)
slayer_unsired_offered Int @default(0)
slayer_chewed_offered Int @default(0)
slayer_task_streak Int @default(0)
slayer_wildy_task_streak Int @default(0)
slayer_superior_count Int @default(0)
slayer_unsired_offered Int @default(0)
slayer_chewed_offered Int @default(0)
tob_cost Json @default("{}")
tob_loot Json @default("{}")
Expand Down
30 changes: 19 additions & 11 deletions src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,20 +901,28 @@ Charge your items using ${mentionCommand(globalClient, 'minion', 'charge')}.`
return this.caPoints() >= CombatAchievements[tier].rewardThreshold;
}

buildCATertiaryItemChanges() {
buildTertiaryItemChanges(hasRingOfWealthI: boolean = false, inWildy: boolean = false, onTask: boolean = false) {
const changes = new Map();
if (this.hasCompletedCATier('easy')) {
changes.set('Clue scroll (easy)', 5);
}
if (this.hasCompletedCATier('medium')) {
changes.set('Clue scroll (medium)', 5);
}
if (this.hasCompletedCATier('hard')) {
changes.set('Clue scroll (hard)', 5);

const tiers = Object.keys(CombatAchievements) as Array<keyof typeof CombatAchievements>;
for (const tier of tiers) {
let change = hasRingOfWealthI ? 50 : 0;
if (this.hasCompletedCATier(tier)) {
change += 5;
}
changes.set(`Clue scroll (${tier})`, change);
}
if (this.hasCompletedCATier('elite')) {
changes.set('Clue scroll (elite)', 5);

if (inWildy) changes.set('Giant key', 50);

if (inWildy && !onTask) {
changes.set('Mossy key', 60);
} else if (!inWildy && onTask) {
changes.set('Mossy key', 66.67);
} else if (inWildy && onTask) {
changes.set('Mossy key', 77.6);
}

return changes;
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/bankImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export const bankFlags = [
] as const;
export type BankFlag = (typeof bankFlags)[number];

class BankImageTask {
export class BankImageTask {
public itemIconsList: Set<number>;
public itemIconImagesCache: Map<number, Image>;
public backgroundImages: BankBackground[] = [];
Expand Down Expand Up @@ -855,6 +855,7 @@ class BankImageTask {
if (!isTransparent && noBorder !== 1) {
this.drawBorder(ctx, bgSprite, bgImage.name === 'Default');
}

await this.drawItems(
ctx,
compact,
Expand Down Expand Up @@ -1045,5 +1046,6 @@ declare global {
}
}
}
global.bankImageGenerator = new BankImageTask();
export const bankImageTask = new BankImageTask();
global.bankImageGenerator = bankImageTask;
bankImageGenerator.init();
41 changes: 40 additions & 1 deletion src/lib/bossEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { Bank, LootTable } from 'oldschooljs';

import { OWNER_IDS, production } from '../config';
import { scaryEatables } from './constants';
import { prisma } from './settings/prisma';
import {
getPHeadDescriptor,
Expand All @@ -26,6 +25,7 @@ import { BossInstance, BossOptions, BossUser } from './structures/Boss';
import { Gear } from './structures/Gear';
import { NewBossOptions } from './types/minions';
import { formatDuration, roll } from './util';
import getOSItem from './util/getOSItem';
import { logError } from './util/logError';
import { sendToChannelID } from './util/webhook';
import { LampTable } from './xpLamps';
Expand All @@ -39,6 +39,45 @@ interface BossEvent {

export const bossEventChannelID = production ? '897170239333220432' : '1023760501957722163';

export const scaryEatables = [
{
item: getOSItem('Candy teeth'),
healAmount: 3
},
{
item: getOSItem('Toffeet'),
healAmount: 5
},
{
item: getOSItem('Chocolified skull'),
healAmount: 8
},
{
item: getOSItem('Rotten sweets'),
healAmount: 9
},
{
item: getOSItem('Hairyfloss'),
healAmount: 12
},
{
item: getOSItem('Eyescream'),
healAmount: 13
},
{
item: getOSItem('Goblinfinger soup'),
healAmount: 20
},
{
item: getOSItem("Benny's brain brew"),
healAmount: 50
},
{
item: getOSItem('Roasted newt'),
healAmount: 120
}
];

function getScaryFoodFromBank(user: MUser, totalHealingNeeded: number, _userBank?: Bank): false | Bank {
if (OWNER_IDS.includes(user.id)) return new Bank();
let totalHealingCalc = totalHealingNeeded;
Expand Down
41 changes: 1 addition & 40 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,45 +668,6 @@ export const mahojiInformationalButtons: APIButtonComponent[] = buttonSource.map
export const PATRON_ONLY_GEAR_SETUP =
'Sorry - but the `other` gear setup is only available for Tier 3 Patrons (and higher) to use.';

export const scaryEatables = [
{
item: getOSItem('Candy teeth'),
healAmount: 3
},
{
item: getOSItem('Toffeet'),
healAmount: 5
},
{
item: getOSItem('Chocolified skull'),
healAmount: 8
},
{
item: getOSItem('Rotten sweets'),
healAmount: 9
},
{
item: getOSItem('Hairyfloss'),
healAmount: 12
},
{
item: getOSItem('Eyescream'),
healAmount: 13
},
{
item: getOSItem('Goblinfinger soup'),
healAmount: 20
},
{
item: getOSItem("Benny's brain brew"),
healAmount: 50
},
{
item: getOSItem('Roasted newt'),
healAmount: 120
}
];

export const projectiles = {
arrow: {
items: resolveItems(['Adamant arrow', 'Rune arrow', 'Amethyst arrow', 'Dragon arrow', 'Hellfire arrow']),
Expand Down Expand Up @@ -878,7 +839,7 @@ const globalConfigSchema = z.object({
patreonCampaignID: z.coerce.number().int().default(1),
patreonWebhookSecret: z.coerce.string().default(''),
httpPort: z.coerce.number().int().default(8080),
clientID: z.string().min(15).max(25),
clientID: z.string().min(10).max(25),
geAdminChannelID: z.string().default('')
});
dotenv.config({ path: path.resolve(process.cwd(), process.env.TEST ? '.env.test' : '.env') });
Expand Down
6 changes: 3 additions & 3 deletions src/lib/data/CollectionsExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2020,9 +2020,9 @@ export const slayerCL = resolveItems([
'Mystic gloves (dusk)',
'Mystic boots (dusk)',
'Basilisk jaw',
// "Dagon'hai hat",
// "Dagon'hai robe top",
// "Dagon'hai robe bottom",
"Dagon'hai hat",
"Dagon'hai robe top",
"Dagon'hai robe bottom",
'Blood shard',
...stoneSpirits.map(i => i.spirit.id),
'Brackish blade',
Expand Down
9 changes: 9 additions & 0 deletions src/lib/data/buyables/buyables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,15 @@ const Buyables: Buyable[] = [
return toaKCs.expertKC >= 25 ? [true] : [false, 'You need a 25 Expert KC in Tombs of Amascut to buy this.'];
}
},
{
name: 'Lockpick',
gpCost: 5000,
ironmanPrice: 500,
skillsNeeded: {
agility: 50,
thieving: 50
}
},
...sepulchreBuyables,
...constructionBuyables,
...hunterBuyables,
Expand Down
1 change: 1 addition & 0 deletions src/lib/data/creatablesTable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
| Kodai wand | 1x Master wand, 1x Kodai insignia | 1x Kodai wand | 0 |
| Salve amulet (e) | 1x Salve amulet | 1x Salve amulet (e) | 0 |
| Salve amulet(ei) | 1x Salve amulet(i) | 1x Salve amulet(ei) | 0 |
| Ring of wealth (i) | 1x Ring of wealth, 1x Ring of wealth scroll | 1x Ring of wealth (i) | 50000 |
| Strange hallowed tome | 1x Mysterious page 1, 1x Mysterious page 2, 1x Mysterious page 3, 1x Mysterious page 4, 1x Mysterious page 5 | 1x Strange hallowed tome | 0 |
| Frozen key | 1x Frozen key piece (armadyl), 1x Frozen key piece (bandos), 1x Frozen key piece (zamorak), 1x Frozen key piece (saradomin) | 1x Frozen key | 0 |
| Ecumenical key | 50x Ecumenical key shard | 1x Ecumenical key | 0 |
Expand Down
6 changes: 6 additions & 0 deletions src/lib/data/createables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,12 @@ const Createables: Createable[] = [
},
customReq: salveECustomReq
},
{
name: 'Ring of wealth (i)',
inputItems: new Bank().add('Ring of wealth').add('Ring of wealth scroll'),
GPCost: 50_000,
outputItems: new Bank().add('Ring of wealth (i)')
},
{
name: 'Strange hallowed tome',
inputItems: new Bank({
Expand Down
69 changes: 1 addition & 68 deletions src/lib/geImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ import { formatItemStackQuantity, generateHexColorForCashStack, toTitleCase } fr
import { GEListing, GETransaction } from '@prisma/client';
import * as fs from 'fs/promises';
import { floor } from 'lodash';
import fetch from 'node-fetch';
import * as path from 'path';

import { GEListingWithTransactions } from './../mahoji/commands/ge';
import { GrandExchange } from './grandExchange';
import { fillTextXTimesInCtx } from './util/canvasUtil';
import getOSItem from './util/getOSItem';
import { logError } from './util/logError';

const CACHE_DIR = './icon_cache';

function drawTitle(ctx: SKRSContext2D, title: string, canvas: Canvas) {
// Draw Page Title
Expand All @@ -34,20 +29,9 @@ class GeImageTask {
public geProgressShadow: Image | null = null;
public geIconBuy: Image | null = null;
public geIconSell: Image | null = null;
public itemIconsList: Set<number>;
public itemIconImagesCache: Map<number, Image>;

public constructor() {
// This tells us simply whether the file exists or not on disk.
this.itemIconsList = new Set();

// If this file does exist, it might be cached in this, or need to be read from fs.
this.itemIconImagesCache = new Map();
}

async init() {
await this.prepare();
await this.run();
}

async prepare() {
Expand All @@ -74,23 +58,6 @@ class GeImageTask {
);
}

async run() {
await this.cacheFiles();
}

async cacheFiles() {
// Ensure that the icon_cache dir exists.
await fs.mkdir(CACHE_DIR).catch(() => null);
CACHE_DIR;
// Get a list of all files (images) in the dir.
const filesInDir = await fs.readdir(CACHE_DIR);

// For each one, set a cache value that it exists.
for (const fileName of filesInDir) {
this.itemIconsList.add(parseInt(path.parse(fileName).name));
}
}

drawText(
ctx: SKRSContext2D,
text: string,
Expand Down Expand Up @@ -148,7 +115,7 @@ class GeImageTask {

if (listing) {
// Get item
const itemImage = await this.getItemImage(listing.item_id);
const itemImage = await bankImageGenerator.getItemImage(listing.item_id);

// Draw item
ctx.textAlign = 'left';
Expand Down Expand Up @@ -221,40 +188,6 @@ class GeImageTask {
}
}

async getItemImage(itemID: number): Promise<Image> {
const cachedImage = this.itemIconImagesCache.get(itemID);
if (cachedImage) return cachedImage;

const isOnDisk = this.itemIconsList.has(itemID);
if (!isOnDisk) {
await this.fetchAndCacheImage(itemID);
return this.getItemImage(itemID);
}

const imageBuffer = await fs.readFile(path.join(CACHE_DIR, `${itemID}.png`));
try {
const image = await loadImage(imageBuffer);
this.itemIconImagesCache.set(itemID, image);
return image;
} catch (err) {
logError(`Failed to load item icon with id: ${itemID}`);
return this.getItemImage(1);
}
}

async fetchAndCacheImage(itemID: number) {
const imageBuffer = await fetch(`https://chisel.weirdgloop.org/static/img/osrs-sprite/${itemID}.png`).then(
result => result.buffer()
);

await fs.writeFile(path.join(CACHE_DIR, `${itemID}.png`), imageBuffer);

const image = await loadImage(imageBuffer);

this.itemIconsList.add(itemID);
this.itemIconImagesCache.set(itemID, image);
}

async createInterface(opts: {
user: MUser;
page: number;
Expand Down
Loading

0 comments on commit b932c05

Please sign in to comment.