Skip to content

Commit b1fafee

Browse files
committed
match osrs queue, and delay system
1 parent 16a1472 commit b1fafee

File tree

13 files changed

+693
-329
lines changed

13 files changed

+693
-329
lines changed

src/engine/action/pipe/task/walk-to-object-plugin-task.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,18 @@ export class WalkToObjectPluginTask<TAction extends ObjectAction> extends ActorL
4848
this.data = data;
4949
}
5050

51-
/**
52-
* Executed every tick to check if the player has arrived yet and calls the plugins if so.
53-
*/
54-
public execute(): void {
55-
// call super to manage waiting for the movement to complete
56-
super.execute();
5751

58-
// check if the player has arrived yet
52+
protected onObjectReached(): void {
5953
const landscapeObject = this.landscapeObject;
6054
const landscapeObjectPosition = this.landscapeObjectPosition;
55+
6156
if (!landscapeObject || !landscapeObjectPosition) {
57+
this.stop();
6258
return;
6359
}
6460

65-
// call the relevant plugins
6661
this.plugins.forEach(plugin => {
67-
if (!plugin || !plugin.handler) {
68-
return;
69-
}
62+
if (!plugin?.handler) return;
7063

7164
const action = {
7265
player: this.actor,
@@ -78,7 +71,6 @@ export class WalkToObjectPluginTask<TAction extends ObjectAction> extends ActorL
7871
plugin.handler(action);
7972
});
8073

81-
// this task only executes once, on arrival
8274
this.stop();
8375
}
8476
}

src/engine/net/inbound-packets/walk.packet.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ const walkPacket = (player: Player, packet: PacketData) => {
99
size -= 14;
1010
}
1111

12-
if (!player.canMove()) {
12+
// Check if player can move and isn't delayed
13+
if (!player.canMove() || player.delayManager.isDelayed()) {
1314
return;
1415
}
1516

1617
const totalSteps = Math.floor((size - 5) / 2);
17-
1818
const firstY = buffer.get('short', 'u', 'le');
19-
const runSteps = buffer.get('byte') === 1; // @TODO forced running
19+
const runSteps = buffer.get('byte') === 1;
2020
const firstX = buffer.get('short', 'u', 'le');
2121

2222
const walkingQueue = player.walkingQueue;
2323

24+
// Cancel any weak tasks since movement interrupts them
2425
player.actionsCancelled.next('manual-movement');
2526

2627
walkingQueue.clear();
@@ -34,6 +35,7 @@ const walkPacket = (player: Player, packet: PacketData) => {
3435
}
3536
};
3637

38+
3739
export default [{
3840
opcode: 73,
3941
size: -1,

src/engine/plugins/content-plugin.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import { logger } from '@runejs/common';
22
import { getFiles } from '@runejs/common/fs';
33
import { join } from 'path';
4+
import { ContentPlugin } from '@engine/plugins/plugin.types';
45

5-
import { ActionHook } from '@engine/action/hook';
6-
import { Quest } from '@engine/world/actor/player/quest';
7-
8-
9-
/**
10-
* The definition of a single content plugin.
11-
*/
12-
export class ContentPlugin {
13-
public pluginId: string;
14-
public hooks?: ActionHook[];
15-
public quests?: Quest[];
16-
}
176

187

198
/**

src/engine/plugins/plugin.types.ts

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import { ActionHook, ActionType } from '@engine/action';
2+
import { Quest } from '@engine/world/actor/player/quest';
3+
4+
// Base hook type that all hook types must extend
5+
export interface BaseHook {
6+
type: ActionType;
7+
handler: (...args: any[]) => any;
8+
}
9+
10+
// Object interaction hook type
11+
export interface ObjectInteractionHook extends BaseHook {
12+
type: 'object_interaction';
13+
objectIds: number[];
14+
options?: string[];
15+
walkTo?: boolean;
16+
}
17+
18+
// Button interaction hook type
19+
export interface ButtonHook extends BaseHook {
20+
type: 'button';
21+
widgetId: number;
22+
buttonIds: number[];
23+
}
24+
25+
// Widget interaction hook type
26+
export interface WidgetInteractionHook extends BaseHook {
27+
type: 'widget_interaction';
28+
widgetIds: number | number[];
29+
childIds?: number | number[];
30+
optionId?: number;
31+
}
32+
33+
// NPC interaction hook type
34+
export interface NpcInteractionHook extends BaseHook {
35+
type: 'npc_interaction';
36+
npcs?: string | string[];
37+
options?: string | string[];
38+
walkTo: boolean;
39+
}
40+
41+
// Item interaction hook type
42+
export interface ItemInteractionHook extends BaseHook {
43+
type: 'item_interaction';
44+
itemIds?: number | number[];
45+
widgets?: { widgetId: number, containerId: number } | { widgetId: number, containerId: number }[];
46+
options?: string | string[];
47+
}
48+
49+
// Item-on-object hook type
50+
export interface ItemOnObjectHook extends BaseHook {
51+
type: 'item_on_object';
52+
objectIds: number | number[];
53+
itemIds: number | number[];
54+
walkTo: boolean;
55+
}
56+
57+
// Item-on-NPC hook type
58+
export interface ItemOnNpcHook extends BaseHook {
59+
type: 'item_on_npc';
60+
npcs: string | string[];
61+
itemIds: number | number[];
62+
walkTo: boolean;
63+
}
64+
65+
// Item-on-player hook type
66+
export interface ItemOnPlayerHook extends BaseHook {
67+
type: 'item_on_player';
68+
itemIds: number | number[];
69+
walkTo: boolean;
70+
}
71+
72+
// Item-on-item hook type
73+
export interface ItemOnItemHook extends BaseHook {
74+
type: 'item_on_item';
75+
items: { item1: number, item2?: number }[];
76+
}
77+
78+
// Player/NPC init hook type
79+
export interface InitHook extends BaseHook {
80+
type: 'player_init' | 'npc_init';
81+
}
82+
83+
// Player command hook type
84+
export interface PlayerCommandHook extends BaseHook {
85+
type: 'player_command';
86+
commands: string | string[];
87+
args?: {
88+
name: string;
89+
type: 'number' | 'string' | 'either';
90+
defaultValue?: number | string;
91+
}[];
92+
}
93+
94+
// Player interaction hook type
95+
export interface PlayerInteractionHook extends BaseHook {
96+
type: 'player_interaction';
97+
options: string | string[];
98+
walkTo: boolean;
99+
}
100+
101+
// Region change hook type
102+
export interface RegionChangeHook extends BaseHook {
103+
type: 'region_change';
104+
regionType?: string;
105+
regionTypes?: string[];
106+
teleporting?: boolean;
107+
}
108+
109+
// Equipment change hook type
110+
export interface EquipmentChangeHook extends BaseHook {
111+
type: 'equipment_change';
112+
itemIds?: number | number[];
113+
eventType?: 'equip' | 'unequip';
114+
}
115+
116+
// Item swap hook type
117+
export interface ItemSwapHook extends BaseHook {
118+
type: 'item_swap';
119+
widgetId?: number;
120+
widgetIds?: number[];
121+
}
122+
123+
// Move item hook type
124+
export interface MoveItemHook extends BaseHook {
125+
type: 'move_item';
126+
widgetId?: number;
127+
widgetIds?: number[];
128+
}
129+
130+
// Item on world item hook type
131+
export interface ItemOnWorldItemHook extends BaseHook {
132+
type: 'item_on_world_item';
133+
items: { item?: number, worldItem?: number }[];
134+
}
135+
136+
// Spawned item interaction hook type
137+
export interface SpawnedItemInteractionHook extends BaseHook {
138+
type: 'spawned_item_interaction';
139+
itemIds?: number | number[];
140+
options: string | string[];
141+
walkTo: boolean;
142+
}
143+
144+
// Magic on item hook type
145+
export interface MagicOnItemHook extends BaseHook {
146+
type: 'magic_on_item';
147+
itemIds?: number | number[];
148+
spellIds?: number | number[];
149+
}
150+
151+
// Magic on player hook type
152+
export interface MagicOnPlayerHook extends BaseHook {
153+
type: 'magic_on_player';
154+
spellIds?: number | number[];
155+
}
156+
157+
// Magic on NPC hook type
158+
export interface MagicOnNpcHook extends BaseHook {
159+
type: 'magic_on_npc';
160+
npcs?: string | string[];
161+
spellIds?: number | number[];
162+
}
163+
164+
// Prayer hook type
165+
export interface PrayerHook extends BaseHook {
166+
type: 'prayer';
167+
prayers?: number | number[];
168+
}
169+
170+
171+
// Union of all possible hook types
172+
export type PluginHook =
173+
| ObjectInteractionHook
174+
| ButtonHook
175+
| WidgetInteractionHook
176+
| NpcInteractionHook
177+
| ItemInteractionHook
178+
| ItemOnObjectHook
179+
| ItemOnNpcHook
180+
| ItemOnPlayerHook
181+
| ItemOnItemHook
182+
| ItemOnWorldItemHook
183+
| ItemSwapHook
184+
| MoveItemHook
185+
| SpawnedItemInteractionHook
186+
| MagicOnItemHook
187+
| MagicOnPlayerHook
188+
| MagicOnNpcHook
189+
| InitHook
190+
| PlayerCommandHook
191+
| PlayerInteractionHook
192+
| RegionChangeHook
193+
| EquipmentChangeHook
194+
| PrayerHook;
195+
196+
// Main plugin type
197+
export interface ContentPlugin {
198+
// Unique identifier for the plugin
199+
pluginId: string;
200+
201+
// Array of hooks this plugin provides
202+
hooks?: PluginHook[];
203+
204+
// Optional quests defined by this plugin
205+
quests?: Quest[];
206+
207+
// Optional plugin configuration
208+
config?: {
209+
// Whether the plugin can be hot-reloaded
210+
reloadable?: boolean;
211+
212+
// Plugin dependencies
213+
dependencies?: string[];
214+
215+
// Plugin load priority (higher numbers load first)
216+
priority?: number;
217+
};
218+
}

0 commit comments

Comments
 (0)