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

169 lines (168 loc) 5.46 kB
/** * Represents an NPC in the game with comprehensive combat and attribute data. * All data is verified against the OSRS wiki. * * Wiki references: * - https://oldschool.runescape.wiki/w/Abyssal_demon (Example NPC with full stats) * - https://oldschool.runescape.wiki/w/Non-player_character (General NPC info) * - https://oldschool.runescape.wiki/w/Character (Character mechanics) */ export class Npc { // Basic Identification id; name; examine; members; officialWikiUrl; // Combat Metrics combatLevel; slayerLevel; // Required slayer level to damage (if applicable) slayerXp; // Slayer XP awarded // Combat Stats (6 core stats from https://oldschool.runescape.wiki/w/Abyssal_demon) stats; // Offensive bonuses (Aggressive stats section) aggressiveStats; // Defensive bonuses organized by damage type defences; // Combat Mechanics combat; // Immunities immunities; // Game World locations; // Where the NPC can be found drops; // Items dropped on death // Additional Information products; // Services/items the NPC offers dialogue; // Notable dialogue changes; // Update history trivia; // Interesting facts constructor(data) { this.id = data.id; this.name = data.name; this.examine = data.examine; this.members = data.members; this.officialWikiUrl = data.officialWikiUrl; this.combatLevel = data.combatLevel; this.slayerLevel = data.slayerLevel; this.slayerXp = data.slayerXp; this.stats = data.stats; this.aggressiveStats = data.aggressiveStats; this.defences = data.defences; this.combat = data.combat; this.immunities = data.immunities; this.locations = data.locations; this.drops = data.drops; this.products = data.products; this.dialogue = data.dialogue; this.changes = data.changes; this.trivia = data.trivia; } /** * Get the NPC's defense roll against a specific attack type. * Used in hit chance calculations. * Wiki reference: https://oldschool.runescape.wiki/w/Abyssal_demon (Defence sections) * @param attackType - Type of attack ("stab", "slash", "crush", "magic", "ranged-light", "ranged-standard", "ranged-heavy") */ getDefenseAgainst(attackType) { switch (attackType) { case "stab": return this.defences.melee.stab; case "slash": return this.defences.melee.slash; case "crush": return this.defences.melee.crush; case "magic": return this.defences.magic.bonus; case "ranged-light": return this.defences.ranged.light; case "ranged-standard": return this.defences.ranged.standard; case "ranged-heavy": return this.defences.ranged.heavy; default: return 0; } } /** * Check if this NPC can be harmed by a specific type of damage or effect. * @param damageType - Type of damage/effect to check */ canBeDamagedBy(damageType) { switch (damageType) { case "poison": return this.immunities.canBePoison; case "venom": return this.immunities.canBeVenom; case "cannon": return this.immunities.canBeCannoned; case "thrall": return this.immunities.canBeThralled; default: return false; } } /** * Create a minimal NPC with default values for quick testing. * Not intended for actual game use - always verify with wiki. */ static createBasicNpc(id, name) { return new Npc({ id, name, examine: "", members: false, officialWikiUrl: "", combatLevel: 1, locations: [], drops: [], stats: { hitpoints: 10, attack: 1, strength: 1, defence: 1, magic: 1, ranged: 1, }, aggressiveStats: { attackBonus: 0, strengthBonus: 0, magicStrengthBonus: 0, rangedStrengthBonus: 0, }, defences: { melee: { stab: 0, slash: 0, crush: 0, }, magic: { bonus: 0, elementalWeakness: undefined, }, ranged: { light: 0, standard: 0, heavy: 0, }, }, combat: { maxHit: 0, attackSpeed: 4, respawnTime: 60, isAggressive: false, isAttackable: true, attackStyles: [], isPoisonous: false, hasWeaponVenom: false, weaknesses: [], }, immunities: { canBePoison: true, isPoisonous: false, canBeVenom: true, canBeCannoned: true, canBeThralled: true, }, }); } }