osrs-tools
Version:
A comprehensive TypeScript library for Old School RuneScape (OSRS) data and utilities, including quest data, skill requirements, and game item information
66 lines (65 loc) • 3.01 kB
JavaScript
import { HunterGuildMaster } from './HunterGuildMaster';
import { HunterGuildProgress } from './HunterGuildProgress';
import { HUNTER_RUMOUR_REGISTRY } from './Rumours';
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 const HUNTER_GUILD = {
wikiUrl: 'https://runescape.wiki/w/Hunter_Guild',
masters: [...HUNTER_GUILD_MASTERS],
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);
},
getEligibleRumours(masterName, hunterLevel, completedQuests = [], progress = new HunterGuildProgress()) {
const master = HUNTER_GUILD_MASTERS.find((entry) => entry.name === masterName);
if (!master || !master.canAssignAnswers(hunterLevel, completedQuests)) {
return [];
}
return HUNTER_RUMOUR_REGISTRY.filter((rumour) => {
if (!rumour.canBeAssignedByMaster(masterName)) {
return false;
}
if (!rumour.isEligible(hunterLevel, completedQuests)) {
return false;
}
if (progress.isAssigned(rumour.id)) {
return false;
}
if (!progress.backToBackEnabled && progress.lastCompletedRumourId === rumour.id) {
return false;
}
return true;
});
},
assignRumour(masterName, hunterLevel, completedQuests = [], progress = new HunterGuildProgress(), randomizer = Math.random) {
const eligibleRumours = this.getEligibleRumours(masterName, hunterLevel, completedQuests, progress);
if (eligibleRumours.length === 0) {
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(),
};
progress.addAssignment(assignment);
return assignment;
},
};