/** * Client LMB default against world entities (snapshot fields only). * Friendly humanoids prefer dialogue / shop / approach — never accidental Attack. * Attack is reserved for aggressives, active combat opponents, and town guards * that respond to a red-skull player. */ import { isHumanoidMob, isTownGuardMob } from "../definitions/mobs.js"; import { skullAttractsTownGuards } from "./skull.js"; /** * @param {{ * untargetable?: boolean, * characterId?: string|number|null, * canFight?: boolean, * mobTypeId?: string|number|null, * talkable?: boolean, * hasDialogue?: boolean, * hasShop?: boolean, * aggressive?: boolean, * hostile?: boolean, * entityId?: number|null * }} entity * @param {{ * localSkullValue?: number, * skullSettings?: { skullBlackMax?: number, skullRedMax?: number } | null, * inCombatWithLocal?: boolean * }} [context] * @returns {"inspect"|"attack"|"talk"|"approach"|null} */ export function defaultLeftClickEntityAction (entity, context = {}) { if (!entity || entity.untargetable) { return null; } if (entity.characterId) { return "inspect"; } const attackable = !!entity.canFight || (!!entity.mobTypeId && !entity.talkable); const aggressive = !!(entity.aggressive || entity.hostile); const inCombat = !!context.inCombatWithLocal; const guardHostile = isTownGuardMob(entity.mobTypeId) && skullAttractsTownGuards(context.localSkullValue ?? 0, context.skullSettings ?? null); if (attackable && (aggressive || inCombat || guardHostile)) { return "attack"; } if (entity.hasDialogue || entity.hasShop) { return "talk"; } // Peaceful body NPCs (vendors without shop UI yet, idle guards, CE staff, …): walk up. if (isHumanoidMob(entity.mobTypeId) || isTownGuardMob(entity.mobTypeId)) { return "approach"; } if (attackable) { return "attack"; } return null; } /** * Whether the context menu should list Attack before Talk/Shop (matches LMB default). */ export function preferAttackInContextMenu (entity, context = {}) { return defaultLeftClickEntityAction(entity, context) === "attack"; }