UNPKG

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

118 lines (117 loc) 5.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Task = void 0; /** * 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 { /** * 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.weight = weight; this.amountMin = amountMin; this.amountMax = amountMax; this.requirements = requirements; this.extendedAmountMin = extendedAmountMin !== null && extendedAmountMin !== void 0 ? extendedAmountMin : null; this.extendedAmountMax = extendedAmountMax !== null && extendedAmountMax !== void 0 ? extendedAmountMax : null; this.alternatives = alternatives !== null && alternatives !== void 0 ? alternatives : []; 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.extendedAmountMin, json.extendedAmountMax, json.requirements, 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 {any[]} 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 ? Array.isArray(this.alternatives) ? this.alternatives : Object.values(this.alternatives).flat() : []; } /** * * @returns */ toJSON() { return { alternatives: this.alternatives, amountMax: this.amountMax, amountMin: this.amountMin, name: this.name, unlockRequirements: this.requirements, weight: this.weight, }; } /** * 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} }`; } } exports.Task = Task;