import { mobDefinition } from "./mobs.js"; import { SkillId, UNARMED_ATTACK } from "./skills.js"; export const DEFAULT_AGGRO_RANGE_TILES = 5; /** Living mobs with health can fight unless explicitly non-combat (pigeon, etc.). */ export function mobCanFight (def) { if (!def || def.untargetable || def.freeFlight) { return false; } if (def.canFight === false) { return false; } return Number(def.health ?? def.maxHealth ?? 0) > 0; } export function mobCanFightType (mobTypeId) { return mobCanFight(mobDefinition(mobTypeId)); } /** Aggressive mobs auto-engage players in range with line of sight. */ export function mobIsAggressive (def) { return !!(def?.aggressive && mobCanFight(def)); } export function mobAggroRangeTiles (def) { const range = def?.aggroRangeTiles | 0; return range > 0 ? range : DEFAULT_AGGRO_RANGE_TILES; } /** Melee profile for a mob: one attackSkill drives hit chance and damage. */ export function mobMeleeAttackProfile (def) { const attackSkill = Math.max(1, def?.attackSkill | 0 || 1); return { mode: "melee", hitSkillId: SkillId.unarmed, damageSkillId: SkillId.unarmed, cooldownMs: def?.attackCooldownMs ?? 900, baseDamage: def?.baseDamage ?? 1, mobAttackSkill: attackSkill }; } /** @deprecated Use shared/combat/rolls.js — kept for reference tests only. */ export function mobHitChance (attackSkill) { const skill = Math.max(1, attackSkill | 0 || 1); return Math.min(0.95, 0.45 + skill * 0.03); } /** @deprecated Use shared/combat/rolls.js */ export function mobDamage (attackSkill, baseDamage = 1) { const skill = Math.max(1, attackSkill | 0 || 1); return Math.max(1, (baseDamage | 0) + Math.floor(skill / 5)); } export function mobSkillLevels (def) { const attackSkill = Math.max(1, def?.attackSkill | 0 || 1); const agilitySkill = Math.max(1, def?.agilitySkill ?? attackSkill); const defenceSkill = Math.max(1, def?.defenceSkill ?? attackSkill); return { [SkillId.unarmed]: attackSkill, [SkillId.dexterity]: agilitySkill, [SkillId.defence]: defenceSkill }; } export function fallbackMobAttackProfile () { return { ...UNARMED_ATTACK, mobAttackSkill: 1 }; }