UNPKG

osrs-tools

Version:

A comprehensive TypeScript library for Old School RuneScape (OSRS) data and utilities, including quest data, skill requirements, and game item information

72 lines (71 loc) 3.49 kB
import { HUNTER_RUMOUR_REGISTRY } from './Rumours'; export const HunterGuildMasterName = { GILMAN: { name: 'Gilman' }, CERVUS: { name: 'Cervus' }, ORNUS: { name: 'Ornus' }, ACO: { name: 'Aco' }, TECO: { name: 'Teco' } }; /** * Represents a Hunter Guild Master, who can assign rumours to players based on their * Hunter level, * completed quests, and the tier of the rumour. * Each master has specific requirements for assigning rumours, * and some may require the completion of certain quests (e.g., "At First Light") * to unlock higher-tier rumours. * The HunterGuildMaster class encapsulates the properties and logic related to each master, * allowing for easy retrieval and eligibility checks when assigning rumours to players. */ export class HunterGuildMaster { name; //name of the master tier; // the tier of rumour they give minimumLevel; // required level for it to be assigned by this master requiresAtFirstLight; // whether the master requires completion of "At First Light" to assign their rumours currentRumourId; // the ID of the currently assigned rumour, if any constructor(name, tier, minimumLevel, requiresAtFirstLight = false) { this.name = name; this.tier = tier; this.minimumLevel = minimumLevel; this.requiresAtFirstLight = requiresAtFirstLight; this.currentRumourId = ''; } canAssignRumour(hunterLevel, completedQuests = []) { if (hunterLevel < this.minimumLevel) { return false; } if (this.requiresAtFirstLight && !completedQuests.includes('At First Light')) { return false; } return true; } get wikiUrl() { return `https://runescape.wiki/w/${this.name}`; } get isAssigned() { return this.currentRumourId !== ''; } // Assigns a rumour to this master by setting the currentRumourId. This method can be called when a new rumour is assigned to the master, allowing us to track which rumour is currently active for that master. When a rumour is completed, the currentRumourId can be cleared to indicate that the master is ready for a new assignment. assignRumour(rumourId) { this.currentRumourId = rumourId; } get rumoursThatCanBeAssigned() { return HUNTER_RUMOUR_REGISTRY.filter((rumour) => rumour.canBeAssignedByMaster(this.name)); } /** * When having a master assign a Hunter Rumour, it needs to check all the current assigned rumours from the other masters; * It cannot give a rumour that is already assigned from another master, even if it is eligible for assignment. * This method takes in the list of eligible rumours for this master and the list of currently assigned rumours from the other masters, * and returns a random rumour ID that can be assigned to this master without conflicts. * @param eligibleRumours * @param otherMasterRumours */ getRandomRumour(eligibleRumours, otherMasterRumours) { const otherAssignedRumourIds = new Set(otherMasterRumours.map((rumour) => rumour.id)); const assignableRumours = eligibleRumours.filter((rumour) => !otherAssignedRumourIds.has(rumour.id)); if (assignableRumours.length === 0) { throw new Error(`No assignable rumours available for master ${this.name}`); } const randomIndex = Math.floor(Math.random() * assignableRumours.length); return assignableRumours[randomIndex]; } }