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

131 lines (130 loc) 5.75 kB
/** * Represents a Slayer task in the game. This class encapsulates all the properties and methods related to a Slayer task. * A Slayer task defines the monsters that players can be assigned to kill, the amount of those monsters, and various other attributes. * A Task is not an assignment, but rather a template for an assignment. * The assignment is the actual task given to a player, which is based on the Task. */ class Task { name; // Name of the task weight; // Weight of the task, used to determine the likelihood of being assigned this task amountMin; // Minimum amount of monsters to kill for this task amountMax; // Maximum amount of monsters to kill for this task requirements; // Array of requirements for this task extendedAmountMin; // Minimum amount for extended tasks (optional) extendedAmountMax; // Maximum amount for extended tasks (optional) alternatives; // Array of alternatives for this task (optional) combatLevels; // Array of combat levels for this task slayerExp; // Slayer experience gained from this task locations; // Array of locations where this task can be found wildernessLevels; // Array of wilderness levels for this task bosses; // Array of bosses for this task /** * Constructor for the Task class. * @param name - Name of the task * @param amountMin - Minimum amount of monsters to kill for this task * @param amountMax - Maximum amount of monsters to kill for this task * @param requirements - Array of requirements for this task * @param extendedAmountMin - Minimum amount for extended tasks (optional) * @param extendedAmountMax - Maximum amount for extended tasks (optional) * @param weight - Weight of the task (default is 1) * @param alternatives - Array of alternatives for this task (optional) * @param combatLevels - Array of combat levels for this task * @param SlayerExp - Slayer experience gained from this task * @param locations - Array of locations where this task can be found * @param wildernessLevels - Array of wilderness levels for this task * @param bosses - Array of bosses for this task */ constructor(name, amountMin, amountMax, requirements, extendedAmountMin, extendedAmountMax, alternatives = [], weight = 1, combatLevels = [], SlayerExp = 0, locations = [], wildernessLevels = [], bosses = []) { this.name = name; this.amountMin = amountMin; this.amountMax = amountMax; this.requirements = requirements; this.extendedAmountMin = extendedAmountMin ?? null; this.extendedAmountMax = extendedAmountMax ?? null; this.alternatives = alternatives ?? []; this.weight = weight; this.combatLevels = combatLevels; this.slayerExp = SlayerExp; this.locations = locations; this.wildernessLevels = wildernessLevels; this.bosses = bosses; } static fromJSON(json) { return new Task(json.name, json.amountMin, json.amountMax, json.requirements, json.extendedAmountMin, json.extendedAmountMax, json.alternatives, json.weight, json.combatLevels, json.slayerExp, json.locations, json.wildernessLevels, json.bosses); } /** * Get the name of the task. * @example * const task = new Task("Goblin", 10, 20, [], 0, null, [], 1); * console.log(task.getName()); // "Goblin" * @returns */ getName() { return this.name; } /** * Get the weight of the task. The weight is used to determine the likelihood of being assigned this task compared to others. * @returns {number} The weight of the task, which can be used to determine the likelihood of being assigned this task compared to others. */ getWeight() { return this.weight; } /** * Get the minimum and maximum amount of monsters to kill for this task. * The amountMin and amountMax properties define the range of monsters that can be assigned for this task. * @returns {number} The minimum amount of monsters to kill for this task. */ getAmountMin() { return this.amountMin; } /** * Get the maximum amount of monsters to kill for this task. * @returns {number} The maximum amount of monsters to kill for this task. */ getAmountMax() { return this.amountMax; } /** * */ getRequirements() { return this.requirements; } /** * * @returns {string[]} An array of alternatives for this task. If alternatives are defined as an object, it flattens the values into a single array. */ getAlternatives() { return this.alternatives || []; } /** * * @returns */ toJSON() { return { alternatives: this.alternatives, amountMax: this.amountMax, amountMin: this.amountMin, bosses: this.bosses, combatLevels: this.combatLevels, extendedAmountMax: this.extendedAmountMax, extendedAmountMin: this.extendedAmountMin, locations: this.locations, name: this.name, requirements: this.requirements, slayerExp: this.slayerExp, weight: this.weight, wildernessLevels: this.wildernessLevels, }; } /** * Returns a string representation of the Task object. * This method is useful for debugging and logging purposes, providing a quick overview of the task's name and other properties. * @returns {string} A string representation of the Task object, useful for debugging and logging purposes. */ toString() { return `Task{ name: ${this.name} }`; } } export { Task };