Skip to content

Commit ca0e768

Browse files
committed
Merge github.com:runejs/server
2 parents 2914ae4 + 5cfeecc commit ca0e768

File tree

8 files changed

+74
-19
lines changed

8 files changed

+74
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ yarn-error.log*
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
/.vs

src/game-engine/net/inbound-packets/widget-interaction-packet.js renamed to src/game-engine/net/inbound-packets/widget-interaction-packet.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const widgetInteractionPacket = (player, packet) => {
1+
import { Player } from '@engine/world/actor/player/player';
2+
import { PacketData } from '@engine/net/inbound-packets';
3+
4+
5+
const widgetInteractionPacket = (player: Player, packet: PacketData) => {
26
const { buffer } = packet;
37
const childId = buffer.get('short');
48
const widgetId = buffer.get('short');

src/game-engine/world/action/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ export type ActionCancelType =
6161
| 'widget';
6262

6363

64+
/**
65+
* The definition for the actual action pipe handler function.
66+
*/
67+
export type ActionPipeHandler = (...args: any[]) => RunnableHooks | void;
68+
6469
/**
6570
* Basic definition of a game engine action file (.action.ts exports).
6671
*/
67-
export type ActionPipe = [ ActionType, (...args: any[]) => void ];
72+
export type ActionPipe = [ ActionType, ActionPipeHandler ];
6873

6974

7075
/**
@@ -86,7 +91,7 @@ export interface RunnableHooks<T = any> {
8691
*/
8792
export class ActionPipeline {
8893

89-
private static pipes = new Map<string, any>();
94+
private static pipes = new Map<string, ActionPipeHandler>();
9095

9196
private runningTasks: TaskExecutor<any>[] = [];
9297
private canceling: boolean = false;
@@ -97,12 +102,12 @@ export class ActionPipeline {
97102
.subscribe(async () => this.cancelRunningTasks());
98103
}
99104

100-
public static getPipe(action: ActionType): Map<string, any> {
105+
public static getPipe(action: ActionType): ActionPipeHandler {
101106
return ActionPipeline.pipes.get(action);
102107
}
103108

104-
public static register(action: ActionType, actionPipe: (...args: any[]) => void): void {
105-
ActionPipeline.pipes.set(action.toString(), actionPipe);
109+
public static register(action: ActionType, actionPipeHandlerFn: ActionPipeHandler): void {
110+
ActionPipeline.pipes.set(action.toString(), actionPipeHandlerFn);
106111
}
107112

108113
public shutdown(): void {
@@ -113,7 +118,7 @@ export class ActionPipeline {
113118
const actionHandler = ActionPipeline.pipes.get(action.toString());
114119
if(actionHandler) {
115120
try {
116-
await this.runActionHandler(actionHandler, ...args);
121+
await this.runActionHandler(actionHandler, args);
117122
} catch(error) {
118123
if(error) {
119124
logger.error(`Error handling action ${action.toString()}`);
@@ -141,7 +146,7 @@ export class ActionPipeline {
141146
this.canceling = false;
142147
}
143148

144-
private async runActionHandler(actionHandler: any, ...args: any[]): Promise<void> {
149+
private async runActionHandler(actionHandler: any, args: any[]): Promise<void> {
145150
const runnableHooks: RunnableHooks | null | undefined = await actionHandler(...args);
146151

147152
if(!runnableHooks?.hooks || runnableHooks.hooks.length === 0) {
@@ -150,7 +155,6 @@ export class ActionPipeline {
150155

151156
for(let i = 0; i < runnableHooks.hooks.length; i++) {
152157
const hook = runnableHooks.hooks[i];
153-
154158
if(!hook) {
155159
continue;
156160
}

src/game-engine/world/action/widget-interaction.action.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ export interface WidgetInteractionAction {
4848
* @param optionId The widget context option chosen by the player.
4949
*/
5050
const widgetActionPipe = (player: Player, widgetId: number, childId: number, optionId: number): RunnableHooks<WidgetInteractionAction> => {
51-
const playerWidget = Object.values(player.interfaceState.widgetSlots).find((widget) => widget && widget.widgetId === widgetId);
51+
const playerWidget = Object.values(player.interfaceState.widgetSlots)
52+
.find((widget) => widget && widget.widgetId === widgetId);
5253

53-
if(playerWidget && playerWidget.fakeWidget != undefined) {
54+
if(playerWidget?.fakeWidget) {
5455
widgetId = playerWidget.fakeWidget;
5556
}
5657

@@ -86,9 +87,11 @@ const widgetActionPipe = (player: Player, widgetId: number, childId: number, opt
8687
return null;
8788
}
8889

90+
const action: WidgetInteractionAction = { player, widgetId, childId, optionId };
91+
8992
return {
9093
hooks: matchingHooks,
91-
action: { player, widgetId, childId, optionId }
94+
action
9295
};
9396
};
9497

src/plugins/items/rotten-potato/helpers/rotten-potato-helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { findItem, widgets } from '@engine/config';
22
import { ItemDetails } from '@engine/config/item-config';
33
import { Rights } from '@engine/world/actor/player/player';
44
import { ItemOnItemAction } from '@engine/world/action/item-on-item.action';
5+
import { WidgetInteractionAction } from '@engine/world/action/widget-interaction.action';
56

67
export const RottenPotatoItem: ItemDetails = findItem('rs:rotten_potato');
78

89

9-
export const ExecuteIfAdmin = (details: ItemOnItemAction, callback) => {
10+
export const ExecuteIfAdmin = (details: ItemOnItemAction | WidgetInteractionAction, callback) => {
1011
if(details.player.rights === Rights.ADMIN) {
1112
callback(details);
1213
return;

src/plugins/items/rotten-potato/rotten-potato.plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import peelPotato from '@plugins/items/rotten-potato/hooks/rotten-potato-peel';
66
import { potatoOnPlayer, potatoManipulatePlayerInventory } from '@plugins/items/rotten-potato/hooks/rotten-potato-item-on-player';
77
import eatPotato from '@plugins/items/rotten-potato/hooks/rotten-potato-eat';
88
import { travelMenuInteract } from '@plugins/items/rotten-potato/helpers/rotten-potato-travel';
9+
import { WidgetInteractionActionHook } from '@engine/world/action/widget-interaction.action';
910

1011
export default {
1112
pluginId: 'promises:rotten-potato',
@@ -52,8 +53,9 @@ export default {
5253
},
5354
{
5455
type: 'widget_interaction',
55-
widgetId: 3100002,
56+
widgetIds: 3100002,
5657
handler: (details) => ExecuteIfAdmin(details, travelMenuInteract),
57-
}
58+
multi: true
59+
} as WidgetInteractionActionHook
5860
]
5961
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { findItem, widgets } from '@engine/config';
2+
import { objectInteractionActionHandler } from '@engine/world/action/object-interaction.action';
3+
import { World } from '@engine/world';
4+
import { itemIds } from '@engine/world/config/item-ids';
5+
import { LandscapeObject } from '@runejs/filestore';
6+
7+
export const action: objectInteractionActionHandler = (details) => {
8+
const veggies = [itemIds.onion, itemIds.grain, itemIds.cabbage];
9+
details.player.busy = true;
10+
details.player.playAnimation(827);
11+
12+
const random = Math.floor(Math.random() * 3);
13+
const pickedItem = findItem(veggies[random]);
14+
15+
details.player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, details.player.inventory);
16+
17+
setTimeout(() => {
18+
details.player.sendMessage(`You found a ${pickedItem.name.toLowerCase()} chest!.`);
19+
details.player.playSound(2581, 7);
20+
details.player.instance.hideGameObjectTemporarily(details.object, 60);
21+
details.player.giveItem(pickedItem.gameId);
22+
details.player.busy = false;
23+
}, World.TICK_LENGTH);
24+
};
25+
26+
export default {
27+
pluginId: 'rs:crates',
28+
hooks: [
29+
{
30+
type: 'object_interaction',
31+
objectIds: [ 366, 357, 355 ],
32+
options: ['loot', 'search', 'examine' ],
33+
walkTo: true,
34+
handler: action
35+
}
36+
]
37+
};

src/plugins/skills/skill-guide.plugin.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { buttonActionHandler } from '@engine/world/action/button.action';
1+
import { buttonActionHandler, ButtonActionHook } from '@engine/world/action/button.action';
22
import { Player } from '@engine/world/actor/player/player';
3-
import { widgetInteractionActionHandler } from '@engine/world/action/widget-interaction.action';
3+
import {
4+
widgetInteractionActionHandler,
5+
WidgetInteractionActionHook
6+
} from '@engine/world/action/widget-interaction.action';
47
import { skillGuides, widgets } from '@engine/config';
58
import { SkillGuide, SkillSubGuide } from '@engine/config/skill-guide-config';
69

@@ -94,13 +97,13 @@ export default {
9497
widgetId: widgets.skillsTab,
9598
buttonIds,
9699
handler: guideHandler
97-
},
100+
} as ButtonActionHook,
98101
{
99102
type: 'widget_interaction',
100103
widgetIds: widgets.skillGuide,
101104
childIds: sidebarTextIds,
102105
optionId: 0,
103106
handler: subGuideHandler
104-
}
107+
} as WidgetInteractionActionHook
105108
]
106109
};

0 commit comments

Comments
 (0)