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
113 lines (112 loc) • 4.52 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlayerMaster = void 0;
/**
* SlayerMaster class represents a Slayer Master in the game.
* It encapsulates the properties and methods related to a Slayer Master,
* including the tasks they assign, their location, level requirements,
* and the ability to generate random assignments.
* Reference: https://oldschool.runescape.wiki/w/Duradel
*
*/
class SlayerMaster {
// Constructor for the SlayerMaster class
constructor(name, tasks, location, levelRequirement, url, taskPoints, // Pass the task points mapping in the constructor
eliteDiaryTaskPoints) {
this.location = ""; // Location of the Slayer Master (optional, can be set later if needed)
this.minimumCombatLevel = 0; // Level requirement to access this Slayer Master (optional, can be set later if needed)
this.wikiUrl = ""; // URL for the Slayer Master (optional, can be set later if needed)
this.name = name;
this.tasks = tasks; // Array of tasks assigned to this Slayer Master
this.tasks.forEach((task) => {
task.weight = task.weight || 0; // Default weight to 0 if not provided
}); // Initialize the tasks array
this.totalWeight = this.calculateTotalWeight(); // Calculate the total weight of the tasks
this.location = location; // Default to an empty string if not provided
this.minimumCombatLevel = levelRequirement; // Default to 0 if not provided
this.wikiUrl = url; // Default to an empty string if not provided
this.taskPoints = taskPoints; // Initialize the task points mapping
this.eliteDiaryTaskPoints = eliteDiaryTaskPoints; // Optional mapping for elite diary task points
}
/**
* Calculate the total weight of all tasks assigned to this Slayer Master.
* @returns {number} The total weight of all tasks assigned to this Slayer Master.
*/
calculateTotalWeight() {
if (this.tasks.length === 0)
return 0; // Return 0 if there are no tasks
return this.tasks.reduce((total, task) => {
return total + (task.weight || 0); // Sum up the weights of all tasks
}, 0);
throw new Error("Method not implemented.");
}
/**
* Get the points awarded for completing a task based on the interval.
* @param {number} taskInterval - The interval of the task (e.g., 1 for every task, 10 for every 10th task, etc.).
* @returns {number} The points awarded for the given task interval.
*/
getPointsForTaskInterval(taskInterval) {
return this.taskPoints[taskInterval] || 0; // Return the points for the interval or 0 if not defined
}
/**
* Get the location of the Slayer Master
*/
getLocation() {
return this.location;
}
/**
* Get the minimum combat level of the Slayer Master
*/
getMinimumCombatLevel() {
return this.minimumCombatLevel;
}
/**
* Get the wiki URL of the Slayer Master
*/
getWikiUrl() {
return this.wikiUrl;
}
/**
* Get a random task based on the weighting system of the tasks.
* Tasks with higher weights have a higher chance of being selected.
* @returns {Task | null} A randomly selected task or null if no tasks are available.
*/
getRandomTask() {
if (this.tasks.length === 0)
return null; // Return null if there are no tasks
const randomWeight = Math.random() * this.totalWeight; // Generate a random number between 0 and totalWeight
let cumulativeWeight = 0;
for (const task of this.tasks) {
cumulativeWeight += task.weight || 0; // Add the task's weight to the cumulative weight
if (randomWeight <= cumulativeWeight) {
return task; // Return the task if the random weight falls within its range
}
}
return null; // Fallback in case no task is selected (shouldn't happen if weights are correct)
}
/**
* Get the total weight of tasks
*/
getTotalWeight() {
return this.totalWeight;
}
/**
* Get Name of Slayer Master
*/
getName() {
return this.name;
}
/**
* Get Tasks
*/
getTasks() {
return this.tasks;
}
/**
* toString function
*/
toString() {
return `SlayerMaster :) WIP SlayerMaster:{\nname: ${this.name}\n}`;
}
}
exports.SlayerMaster = SlayerMaster;