|
1 |
| -import { Player } from '@engine/world/actor/player/player'; |
2 |
| -import { ActionHook, getActionHooks } from '@engine/world/action/hooks'; |
3 |
| -import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters'; |
4 |
| -import { ActionPipe, RunnableHooks } from '@engine/world/action/index'; |
| 1 | +import { Player } from '@engine/world/actor/player/player'; |
| 2 | +import { ActionHook, getActionHooks } from '@engine/world/action/hooks'; |
| 3 | +import { advancedNumberHookFilter, questHookFilter } from '@engine/world/action/hooks/hook-filters'; |
| 4 | +import { ActionPipe, RunnableHooks } from '@engine/world/action/index'; |
5 | 5 | import { Npc } from '../actor/npc/npc';
|
6 |
| - |
7 |
| - |
8 |
| -/** |
9 |
| - * Defines a button action hook. |
10 |
| - */ |
| 6 | + |
| 7 | + |
| 8 | +/** |
| 9 | + * Defines a button action hook. |
| 10 | + */ |
11 | 11 | export interface MagicOnNPCActionHook extends ActionHook<MagicOnNPCAction, magiconnpcActionHandler> {
|
12 |
| - // The npc world id that was clicked on after choosing the spell |
13 |
| - npcworldId?: number; |
14 |
| - // The IDs of the UI widgets that the buttons are on. |
15 |
| - widgetIds?: number[]; |
16 |
| - // The child ID or list of child IDs of the button(s) within the UI widget. |
17 |
| - buttonIds?: number | number[]; |
18 |
| - // Whether or not this item action should cancel other running or queued actions. |
19 |
| - cancelActions?: boolean; |
20 |
| -} |
21 |
| - |
22 |
| - |
23 |
| -/** |
24 |
| - * The button action hook handler function to be called when the hook's conditions are met. |
25 |
| - */ |
| 12 | + // The npc world id that was clicked on after choosing the spell |
| 13 | + npcworldId?: number; |
| 14 | + // The IDs of the UI widgets that the buttons are on. |
| 15 | + widgetIds?: number[]; |
| 16 | + // The child ID or list of child IDs of the button(s) within the UI widget. |
| 17 | + buttonIds?: number | number[]; |
| 18 | + // Whether or not this item action should cancel other running or queued actions. |
| 19 | + cancelActions?: boolean; |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +/** |
| 24 | + * The button action hook handler function to be called when the hook's conditions are met. |
| 25 | + */ |
26 | 26 | export type magiconnpcActionHandler = (buttonAction: MagicOnNPCAction) => void | Promise<void>;
|
27 |
| - |
28 |
| - |
29 |
| -/** |
30 |
| - * Details about a button action being performed. |
31 |
| - */ |
| 27 | + |
| 28 | + |
| 29 | +/** |
| 30 | + * Details about a button action being performed. |
| 31 | + */ |
32 | 32 | export interface MagicOnNPCAction {
|
33 |
| - // The npc world id that was clicked on after choosing the spell |
| 33 | + // The npc world id that was clicked on after choosing the spell |
34 | 34 | npc: Npc;
|
35 |
| - // The player performing the action. |
36 |
| - player: Player; |
37 |
| - // The ID of the UI widget that the button is on. |
38 |
| - widgetId: number; |
39 |
| - // The child ID of the button within the UI widget. |
40 |
| - buttonId: number; |
41 |
| -} |
42 |
| - |
43 |
| - |
44 |
| -/** |
45 |
| - * The pipe that the game engine hands button actions off to. |
46 |
| - * @param npc |
47 |
| - * @param player |
48 |
| - * @param widgetId |
49 |
| - * @param buttonId |
50 |
| - */ |
51 |
| -const buttonActionPipe = (npc:Npc, player: Player, widgetId: number, buttonId: number): RunnableHooks<MagicOnNPCAction> => { |
52 |
| - //console.info(`pew pew you use magic on ${npc.name}!`); |
53 |
| - |
54 |
| - // Find all object action plugins that reference this location object |
| 35 | + // The player performing the action. |
| 36 | + player: Player; |
| 37 | + // The ID of the UI widget that the button is on. |
| 38 | + widgetId: number; |
| 39 | + // The child ID of the button within the UI widget. |
| 40 | + buttonId: number; |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +/** |
| 45 | + * The pipe that the game engine hands button actions off to. |
| 46 | + * @param npc |
| 47 | + * @param player |
| 48 | + * @param widgetId |
| 49 | + * @param buttonId |
| 50 | + */ |
| 51 | +const magicOnNpcActionPipe = (npc:Npc, player: Player, widgetId: number, buttonId: number): RunnableHooks<MagicOnNPCAction> => { |
| 52 | + //console.info(`pew pew you use magic on ${npc.name}!`); |
| 53 | + |
| 54 | + // Find all object action plugins that reference this location object |
55 | 55 | const matchingHooks = getActionHooks<MagicOnNPCActionHook>('magic_on_npc');
|
56 |
| - |
57 |
| - |
58 |
| - return { |
59 |
| - hooks: matchingHooks, |
60 |
| - actionPosition: player.position, |
61 |
| - action: { |
62 |
| - npc, |
63 |
| - player, |
64 |
| - widgetId, |
65 |
| - buttonId |
66 |
| - } |
67 |
| - } |
68 |
| - |
69 |
| - |
70 |
| -}; |
71 |
| - |
72 |
| - |
73 |
| -/** |
74 |
| - * Button action pipe definition. |
75 |
| - */ |
76 |
| -export default [ 'magic_on_npc', buttonActionPipe ] as ActionPipe; |
| 56 | + |
| 57 | + |
| 58 | + return { |
| 59 | + hooks: matchingHooks, |
| 60 | + actionPosition: player.position, |
| 61 | + action: { |
| 62 | + npc, |
| 63 | + player, |
| 64 | + widgetId, |
| 65 | + buttonId |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | +}; |
| 71 | + |
| 72 | + |
| 73 | +/** |
| 74 | + * Button action pipe definition. |
| 75 | + */ |
| 76 | +export default [ 'magic_on_npc', magicOnNpcActionPipe ] as ActionPipe; |
0 commit comments