| 1 | /** |
| 2 | * Client LMB default against world entities (snapshot fields only). |
| 3 | * Aggressive hostiles prefer Attack even when they are also talkable. |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * @param {{ |
| 8 | * untargetable?: boolean, |
| 9 | * characterId?: string|number|null, |
| 10 | * canFight?: boolean, |
| 11 | * mobTypeId?: string|number|null, |
| 12 | * talkable?: boolean, |
| 13 | * hasDialogue?: boolean, |
| 14 | * hasShop?: boolean, |
| 15 | * aggressive?: boolean, |
| 16 | * hostile?: boolean |
| 17 | * }} entity |
| 18 | * @returns {"inspect"|"attack"|"talk"|null} |
| 19 | */ |
| 20 | export function defaultLeftClickEntityAction (entity) |
| 21 | { |
| 22 | if (!entity || entity.untargetable) |
| 23 | { return null; } |
| 24 | if (entity.characterId) |
| 25 | { return "inspect"; } |
| 26 | const attackable = !!entity.canFight |
| 27 | || (!!entity.mobTypeId && !entity.talkable); |
| 28 | const aggressive = !!(entity.aggressive || entity.hostile); |
| 29 | if (attackable && aggressive) |
| 30 | { return "attack"; } |
| 31 | if (entity.hasDialogue || entity.talkable || entity.hasShop) |
| 32 | { return "talk"; } |
| 33 | if (attackable) |
| 34 | { return "attack"; } |
| 35 | return null; |
| 36 | } |