import { mobDefinition, mobMaxHealthForLevel } from "./mobs.js"; import { SkillId, UNARMED_ATTACK, ALL_SKILL_IDS } 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 || def.usePlayerBody === true; } 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, level = null) { const attackSkill = Math.max( 1, level != null ? (level | 0) : (def?.attackSkill | 0 || 1) ); return { mode: "melee", hitSkillId: SkillId.unarmed, damageSkillId: SkillId.unarmed, cooldownMs: def?.attackCooldownMs ?? 900, 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)); } /** * Flat skill map for a mob at the given level (all combat-relevant skills equal the level). * Falls back to def.attackSkill when level is omitted (legacy wildlife). */ export function mobSkillLevels (def, level = null) { const attackSkill = Math.max( 1, level != null ? (Math.floor(Number(level) || 1)) : (def?.attackSkill | 0 || 1) ); const levels = {}; for (const skillId of ALL_SKILL_IDS) { levels[skillId] = attackSkill; } return levels; } export function mobHealthForLevel (def, level) { return mobMaxHealthForLevel(def, level); } /** * Mob spell cast chance % derived from spawner/creature level (1–100). * Editor shows this as a label; it is not authorable per spell. */ export function mobSpellCastChancePercent (level) { const lv = Math.max(1, Math.min(99, Math.floor(Number(level) || 1))); return Math.max(1, Math.min(100, lv)); } export function fallbackMobAttackProfile () { return { ...UNARMED_ATTACK, mobAttackSkill: 1 }; }