| 1 | import { SkillId, skillLevel } from "../definitions/skills.js"; |
| 2 | |
| 3 | /** Minutes in one chunk before aggressive (non-boss) mobs stop auto-aggroing the player. */ |
| 4 | export const CHUNK_AGGRO_PEACE_MS = 15 * 60 * 1000; |
| 5 | |
| 6 | const MELEE_STYLE_SKILL_IDS = Object.freeze([ |
| 7 | SkillId.swordfighting, |
| 8 | SkillId.axefighting, |
| 9 | SkillId.unarmed, |
| 10 | SkillId.clubfighting |
| 11 | ]); |
| 12 | |
| 13 | function skillLvl (skills, skillId) |
| 14 | { |
| 15 | return skillLevel(skills, skillId); |
| 16 | } |
| 17 | |
| 18 | /** Display combat level from a player's skill component. */ |
| 19 | export function combatLevelFromSkills (skillsComponent) |
| 20 | { |
| 21 | const D = 0.25 * ( |
| 22 | skillLvl(skillsComponent, SkillId.health) |
| 23 | + skillLvl(skillsComponent, SkillId.defence) |
| 24 | + skillLvl(skillsComponent, SkillId.agility) |
| 25 | ); |
| 26 | const meleeMax = Math.max( |
| 27 | ...MELEE_STYLE_SKILL_IDS.map((skillId) => skillLvl(skillsComponent, skillId)) |
| 28 | ); |
| 29 | const M = 0.3 * (meleeMax + skillLvl(skillsComponent, SkillId.strength)); |
| 30 | const R = 0.3 * ( |
| 31 | skillLvl(skillsComponent, SkillId.archery) |
| 32 | + skillLvl(skillsComponent, SkillId.dexterity) |
| 33 | ); |
| 34 | const S = 0.3 * ( |
| 35 | skillLvl(skillsComponent, SkillId.magic) |
| 36 | + skillLvl(skillsComponent, SkillId.mind) |
| 37 | ); |
| 38 | return Math.floor(Math.max(M, R, S) + D); |
| 39 | } |
| 40 | |
| 41 | /** Mob level used for aggression immunity (creature.level, spawn origin, or def.attackSkill). */ |
| 42 | export function mobAggressionLevel (creature, spawnOrigin, mobDef) |
| 43 | { |
| 44 | if (creature?.level != null) |
| 45 | { return Math.max(1, creature.level | 0 || 1); } |
| 46 | if (spawnOrigin?.level != null) |
| 47 | { return Math.max(1, spawnOrigin.level | 0 || 1); } |
| 48 | return Math.max(1, mobDef?.attackSkill | 0 || 1); |
| 49 | } |
| 50 | |
| 51 | /** True when the player's combat level is high enough to ignore this mob's auto-aggro. */ |
| 52 | export function playerOutlevelsMobAggression (playerCombatLevel, mobLevel) |
| 53 | { |
| 54 | return (playerCombatLevel | 0) > 2 * (mobLevel | 0) + 1; |
| 55 | } |