UNPKG

osrs-tools

Version:

A JavaScript package to provide JSON data for all current Old School RuneScape quests. This package aims to help junior software developers create tools related to Old School RuneScape. It's a work in progress, and issues should be reported to jamescer@ha

138 lines (137 loc) 5.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuestTool = void 0; const Requirement_1 = require("../Requirement"); class QuestTool { constructor(account) { this.osrsAccount = account; } /** * Set the account to be used in this quest tool * @param {OsrsAccount} acc1 The osrs Account to be associated with this class object. */ setOsrsAccount(acc1) { if (acc1) { this.osrsAccount = acc1; return true; } return false; } /** * Get the osrs account associated with this quest tool * @return {OsrsAccount | undefined} The osrs Account associated with this class object. */ getOsrsAccount() { return this.osrsAccount; } /** * Determine if the account can complete a quest, including recursively checking quest requirements. * @param quest The quest to check (must be a Quest instance) * @param visited (internal) Set of quest names already checked to prevent infinite recursion */ canCompleteQuest(quest, visited = new Set()) { if (!this.osrsAccount) return false; if (!quest) return false; if (visited.has(quest.name)) return true; // Prevent infinite loops visited.add(quest.name); // check requirements if (!quest.requirements || quest.requirements.length === 0) return true; for (const req of quest.requirements) { if (req.type === Requirement_1.RequirementType.Quest) { // Recursively check quest requirements const questReq = req; if (!questReq || !this.canCompleteQuest(QuestTool.getQuestByName(questReq.questName), visited)) { return false; } } else if (req.type === Requirement_1.RequirementType.Level) { // Check if the account meets the level requirement const levelReq = req; const skill = this.osrsAccount.getSkill(levelReq.skillName); if (!skill) { return false; // Skill not found in account } // If the skill is boostable, we can check if the current level + max boost is enough if (levelReq.boostable) { if (skill.level + QuestTool.getMaxSkillBoost(levelReq.skillName) < levelReq.level) { return false; } } else if (skill.level < levelReq.level) { return false; } } } return true; } /** * Static utility to get a Quest instance by its name. * This assumes all quests are exported as default from their respective files in quest/all/. * @param questName The name of the quest to retrieve * @returns Quest instance or undefined if not found */ static getQuestByName(questName) { // Normalize quest name to match file naming convention const normalized = questName .replace(/[^a-zA-Z0-9]/g, '') // Remove non-alphanumeric .replace(/\s+/g, '') // Remove spaces .replace(/^./, (c) => c.toUpperCase()); try { // Dynamically require the quest file // Note: This only works in Node.js, not in browser environments // and assumes all quest files are named as <QuestName>.ts/js and exported as default // Example: 'Dragon Slayer' => './all/DragonSlayer' // You may want to maintain a map for production use // eslint-disable-next-line @typescript-eslint/no-var-requires const questModule = require(`./all/${normalized}`); return questModule.default || questModule; } catch (e) { return undefined; } } /** * Get the maximum boost for a given skill, based on OSRS Wiki data. * @param skillName The name of the skill (case-insensitive, e.g. 'Attack', 'Herblore') * @returns The maximum boost amount for the skill (positive integer, or 0 if unboostable) */ static getMaxSkillBoost(skillName) { var _a; // Data from https://oldschool.runescape.wiki/w/Temporary_skill_boost const boosts = { Attack: 5, // Super combat potion, Overload(+) Strength: 5, // Super combat potion, Overload(+) Defence: 5, // Super combat potion, Overload(+) Magic: 4, // Overload(+), Imbued heart Ranged: 4, // Ranging potion, Overload(+) Prayer: 2, // Preserve, Prayer-boosting items Hitpoints: 0, // No boost Agility: 5, // Summer pie Herblore: 5, // Botanical pie Thieving: 5, // Volcanic ash, Summer pie Crafting: 3, // Mushroom pie Fletching: 3, // Fletching potion Slayer: 2, // Wild pie Hunter: 5, // Hunter potion Mining: 3, // Dwarven stout(m) Smithing: 4, // Spicy stew (orange) Fishing: 5, // Admiral pie Cooking: 5, // Chef's delight(m) Firemaking: 4, // Spicy stew (red) Woodcutting: 3, // Spicy stew (yellow) Farming: 5, // Garden pie Runecraft: 5, // Spicy stew (orange) Construction: 5, // Spicy stew (orange) // Add more as needed }; const normalized = skillName.charAt(0).toUpperCase() + skillName.slice(1).toLowerCase(); return (_a = boosts[normalized]) !== null && _a !== void 0 ? _a : 0; } } exports.QuestTool = QuestTool;