| 1 | import { mobDefinition } from "./mobs.js"; |
| 2 | import { SkillId, UNARMED_ATTACK } from "./skills.js"; |
| 3 | |
| 4 | export const DEFAULT_AGGRO_RANGE_TILES = 5; |
| 5 | |
| 6 | /** Living mobs with health can fight unless explicitly non-combat (pigeon, etc.). */ |
| 7 | export function mobCanFight (def) |
| 8 | { |
| 9 | if (!def || def.untargetable || def.freeFlight) |
| 10 | { return false; } |
| 11 | if (def.canFight === false) |
| 12 | { return false; } |
| 13 | return Number(def.health ?? def.maxHealth ?? 0) > 0; |
| 14 | } |
| 15 | |
| 16 | export function mobCanFightType (mobTypeId) |
| 17 | { |
| 18 | return mobCanFight(mobDefinition(mobTypeId)); |
| 19 | } |
| 20 | |
| 21 | /** Aggressive mobs auto-engage players in range with line of sight. */ |
| 22 | export function mobIsAggressive (def) |
| 23 | { |
| 24 | return !!(def?.aggressive && mobCanFight(def)); |
| 25 | } |
| 26 | |
| 27 | export function mobAggroRangeTiles (def) |
| 28 | { |
| 29 | const range = def?.aggroRangeTiles | 0; |
| 30 | return range > 0 ? range : DEFAULT_AGGRO_RANGE_TILES; |
| 31 | } |
| 32 | |
| 33 | /** Melee profile for a mob: one attackSkill drives hit chance and damage. */ |
| 34 | export function mobMeleeAttackProfile (def) |
| 35 | { |
| 36 | const attackSkill = Math.max(1, def?.attackSkill | 0 || 1); |
| 37 | return { |
| 38 | mode: "melee", |
| 39 | hitSkillId: SkillId.unarmed, |
| 40 | damageSkillId: SkillId.unarmed, |
| 41 | cooldownMs: def?.attackCooldownMs ?? 900, |
| 42 | baseDamage: def?.baseDamage ?? 1, |
| 43 | mobAttackSkill: attackSkill |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | /** @deprecated Use shared/combat/rolls.js — kept for reference tests only. */ |
| 48 | export function mobHitChance (attackSkill) |
| 49 | { |
| 50 | const skill = Math.max(1, attackSkill | 0 || 1); |
| 51 | return Math.min(0.95, 0.45 + skill * 0.03); |
| 52 | } |
| 53 | |
| 54 | /** @deprecated Use shared/combat/rolls.js */ |
| 55 | export function mobDamage (attackSkill, baseDamage = 1) |
| 56 | { |
| 57 | const skill = Math.max(1, attackSkill | 0 || 1); |
| 58 | return Math.max(1, (baseDamage | 0) + Math.floor(skill / 5)); |
| 59 | } |
| 60 | |
| 61 | export function mobSkillLevels (def) |
| 62 | { |
| 63 | const attackSkill = Math.max(1, def?.attackSkill | 0 || 1); |
| 64 | const agilitySkill = Math.max(1, def?.agilitySkill ?? attackSkill); |
| 65 | const defenceSkill = Math.max(1, def?.defenceSkill ?? attackSkill); |
| 66 | return { |
| 67 | [SkillId.unarmed]: attackSkill, |
| 68 | [SkillId.dexterity]: agilitySkill, |
| 69 | [SkillId.defence]: defenceSkill |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | export function fallbackMobAttackProfile () |
| 74 | { |
| 75 | return { ...UNARMED_ATTACK, mobAttackSkill: 1 }; |
| 76 | } |