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

108 lines (107 loc) 5.13 kB
import { HunterGuildMaster } from './HunterGuildMaster'; import { HUNTER_RUMOUR_REGISTRY } from './Rumours'; /** * Defines the Hunter Guild Masters and their properties, including the minimum Hunter level required to receive rumours from them, whether they require the completion of "At First Light" to assign rumours, and the tier of rumours they provide. The HunterGuild class provides methods to retrieve masters by name, get all masters, retrieve rumours by ID, determine eligible rumours for a player based on their level and completed quests, and assign a rumour to a player while ensuring all eligibility criteria are met. The Hunter Guild module serves as the central hub for all logic related to the Hunter Guild, its masters, and the assignment of rumours to players. * Note: The rumours are defined in a separate module to avoid circular dependencies, as HunterRumour references HunterGuildMaster and vice versa. */ const HUNTER_GUILD_MASTERS = [ new HunterGuildMaster('Gilman', 'Novice', 46), new HunterGuildMaster('Cervus', 'Adept', 57), new HunterGuildMaster('Ornus', 'Adept', 57), new HunterGuildMaster('Aco', 'Expert', 72), new HunterGuildMaster('Teco', 'Expert', 72), new HunterGuildMaster('Wolf', 'Master', 91, true), ]; /** * The Hunter Guild module encapsulates all data and logic related to the Hunter Guild, including its masters, rumours, and player progress. It provides methods to retrieve masters and rumours, determine eligibility, and assign rumours to players based on their level, completed quests, and current progress. * Note: The rumours are defined in a separate module to avoid circular dependencies, as HunterRumour references HunterGuildMaster and vice versa. */ export class HunterGuild { wikiUrl = 'https://runescape.wiki/w/Hunter_Guild'; gilman; cervus; ornus; aco; teco; wolf; completedQuests = []; constructor(completedQuests = []) { this.completedQuests = completedQuests ?? []; this.gilman = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Gilman'); this.cervus = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Cervus'); this.ornus = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Ornus'); this.aco = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Aco'); this.teco = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Teco'); this.wolf = HUNTER_GUILD_MASTERS.find((master) => master.name === 'Wolf'); } /* Getters Start */ get Gilman() { return this.gilman; } get Cervus() { return this.cervus; } get Ornus() { return this.ornus; } get Aco() { return this.aco; } get Teco() { return this.teco; } get Wolf() { return this.wolf; } /* Getters end */ getMasterByName(masterName) { return HUNTER_GUILD_MASTERS.find((master) => master.name === masterName); } getAllMasters() { return [...HUNTER_GUILD_MASTERS]; } getRumourById(rumourId) { return HUNTER_RUMOUR_REGISTRY.find((rumour) => rumour.id === rumourId); } doesAnyMasterHaveRumour(rumourId) { return HUNTER_GUILD_MASTERS.some((master) => master.currentRumourId === rumourId); } setMasterCurrentRumour(masterName, rumourId) { const master = this.getMasterByName(masterName); if (master) { master.currentRumourId = rumourId; } } assignRumourToMaster(masterName, rumourId) { const master = this.getMasterByName(masterName); if (master) { master.assignRumour(rumourId); } } getEligibleRumours(masterName, hunterLevel, completedQuests = []) { const master = this.getMasterByName(masterName); if (!master || !master.canAssignRumour(hunterLevel, completedQuests)) { return []; } return HUNTER_RUMOUR_REGISTRY.filter((rumour) => rumour.canBeAssignedByMaster(masterName) && rumour.isEligible(hunterLevel, completedQuests) && !this.doesAnyMasterHaveRumour(rumour.id)); } assignRumour(masterName, hunterLevel, completedQuests = [], randomizer = Math.random) { const eligibleRumours = this.getEligibleRumours(masterName, hunterLevel, completedQuests); if (eligibleRumours.length === 0) { // cannot assign a rumour if there are no eligible rumours available for the master, which can happen if the player does not meet the requirements for any of the rumours or if all eligible rumours are currently assigned to other masters. In this case, the method returns null to indicate that no assignment could be made. return null; } const index = Math.floor(randomizer() * eligibleRumours.length); const selectedRumour = eligibleRumours[index]; const assignment = { id: `${masterName}-${selectedRumour.id}-${Date.now()}`, masterName, rumourId: selectedRumour.id, assignedAt: new Date(), }; return assignment; } } ;