BlueGit

timfa questward

Files

questward / shared / definitions / mobCombat.js

mobCombat.js

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