| 1 | /** |
| 2 | * Client LMB default against world entities (snapshot fields only). |
| 3 | * Friendly humanoids prefer dialogue / shop / approach — never accidental Attack. |
| 4 | * Attack is reserved for aggressives, active combat opponents, and town guards |
| 5 | * that respond to a red-skull player. |
| 6 | */ |
| 7 | |
| 8 | import { isHumanoidMob, isTownGuardMob } from "../definitions/mobs.js"; |
| 9 | import { skullAttractsTownGuards } from "./skull.js"; |
| 10 | |
| 11 | /** |
| 12 | * @param {{ |
| 13 | * untargetable?: boolean, |
| 14 | * characterId?: string|number|null, |
| 15 | * canFight?: boolean, |
| 16 | * mobTypeId?: string|number|null, |
| 17 | * talkable?: boolean, |
| 18 | * hasDialogue?: boolean, |
| 19 | * hasShop?: boolean, |
| 20 | * aggressive?: boolean, |
| 21 | * hostile?: boolean, |
| 22 | * entityId?: number|null |
| 23 | * }} entity |
| 24 | * @param {{ |
| 25 | * localSkullValue?: number, |
| 26 | * skullSettings?: { skullBlackMax?: number, skullRedMax?: number } | null, |
| 27 | * inCombatWithLocal?: boolean |
| 28 | * }} [context] |
| 29 | * @returns {"inspect"|"attack"|"talk"|"approach"|null} |
| 30 | */ |
| 31 | export function defaultLeftClickEntityAction (entity, context = {}) |
| 32 | { |
| 33 | if (!entity || entity.untargetable) |
| 34 | { return null; } |
| 35 | if (entity.characterId) |
| 36 | { return "inspect"; } |
| 37 | |
| 38 | const attackable = !!entity.canFight |
| 39 | || (!!entity.mobTypeId && !entity.talkable); |
| 40 | const aggressive = !!(entity.aggressive || entity.hostile); |
| 41 | const inCombat = !!context.inCombatWithLocal; |
| 42 | const guardHostile = isTownGuardMob(entity.mobTypeId) |
| 43 | && skullAttractsTownGuards(context.localSkullValue ?? 0, context.skullSettings ?? null); |
| 44 | |
| 45 | if (attackable && (aggressive || inCombat || guardHostile)) |
| 46 | { return "attack"; } |
| 47 | if (entity.hasDialogue || entity.talkable || entity.hasShop) |
| 48 | { return "talk"; } |
| 49 | // Peaceful body NPCs (vendors without shop UI yet, idle guards, CE staff, …): walk up. |
| 50 | if (isHumanoidMob(entity.mobTypeId) || isTownGuardMob(entity.mobTypeId)) |
| 51 | { return "approach"; } |
| 52 | if (attackable) |
| 53 | { return "attack"; } |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Whether the context menu should list Attack before Talk/Shop (matches LMB default). |
| 59 | */ |
| 60 | export function preferAttackInContextMenu (entity, context = {}) |
| 61 | { |
| 62 | return defaultLeftClickEntityAction(entity, context) === "attack"; |
| 63 | } |