Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/net/incoming-packet-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { widgetsClosedPacket } from '@server/net/incoming-packets/widgets-closed
import { pickupItemPacket } from '@server/net/incoming-packets/pickup-item-packet';
import { itemInteractionPacket } from '@server/net/incoming-packets/item-interaction-packet';
import { itemOnObjectPacket } from '@server/net/incoming-packets/item-on-object-packet';
import { numberInputPacket } from '@server/net/incoming-packets/number-input-packet';

const ignore = [ 234, 160, 58 /* camera move */ ];

Expand All @@ -34,6 +35,8 @@ const packets: { [key: number]: incomingPacket } = {
132: widgetInteractionPacket,
176: widgetsClosedPacket,
231: characterDesignPacket,
238: numberInputPacket,
//86: stringInputPacket, @TODO

83: itemSwapPacket,
40: itemOnItemPacket,
Expand All @@ -48,7 +51,7 @@ const packets: { [key: number]: incomingPacket } = {

63: npcInteractionPacket,
116: npcInteractionPacket,
24: itemOnObjectPacket,
24: itemOnObjectPacket,

30: objectInteractionPacket,
164: objectInteractionPacket,
Expand Down
4 changes: 2 additions & 2 deletions src/net/incoming-packet-sizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const incomingPacketSizes: number[] = [
-3, -3, -3, -3, -3, -3, -3, -3, 4, -3, //50
-3, -3, -3, 2, 4, 6, -3, -3, -3, -3, //60
-3, -3, -3, -1, -3, -3, -3, -3, -3, -3, //70
-3, -3, -3, 9, -3, 6, -3, -3, -3, -1, //80
-3, -3, -3, 9, -3, 6, 8, -3, -3, -1, //80
-3, -3, -3, -3, -3, -3, -3, -3, 8, -3, //90
-3, -3, 8, -3, -3, -3, -3, -3, -3, -3, //100
-3, -3, -3, -3, -3, -3, 2, -3, -3, -3, //110
Expand All @@ -22,7 +22,7 @@ export const incomingPacketSizes: number[] = [
-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, //200
-3, -3, -3, -3, -3, -3, 0, -3, -3, -3, //210
-3, -3, -3, -3, -3, -3, -3, -3, 8, -3, //220
-3, 13, -3, -3, 4, -3, -1, -3, -3, -3, //230
-3, 13, -3, -3, 4, -3, -1, -3, 4, -3, //230
-3, -3, -3, -3, -3, -3, -3, -3, -1, -3, //240
-3, -3, -3, -3, -3, -3, -3 //250
];
8 changes: 8 additions & 0 deletions src/net/incoming-packets/number-input-packet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { incomingPacket } from '../incoming-packet';
import { Player } from '../../world/actor/player/player';
import { RsBuffer } from '@server/net/rs-buffer';

export const numberInputPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => {
const input = packet.readUnsignedIntBE();
player.numericInputEvent.next(input);
};
10 changes: 10 additions & 0 deletions src/net/outgoing-packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ export class OutgoingPackets {
this.queue(packet);
}

public showNumberInputDialogue(): void {
const packet = new Packet(132);
this.queue(packet);
}

public showTextInputDialogue(): void {
const packet = new Packet(124);
this.queue(packet);
}

public updateCarryWeight(weight: number): void {
const packet = new Packet(171);
packet.writeShortBE(weight);
Expand Down
6 changes: 6 additions & 0 deletions src/net/rs-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ export class RsBuffer {
return value;
}

public readUnsignedIntBE(): number {
const value = this.buffer.readUInt32BE(this.readerIndex);
this.readerIndex += 4;
return value;
}

public readIntBE(): number {
const value = this.buffer.readInt32BE(this.readerIndex);
this.readerIndex += 4;
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/commands/input-widget-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { commandAction } from '@server/world/actor/player/action/input-command-action';

const action: commandAction = (details) => {
const { player, args } = details;

const type: number = args.type as number;

if(type === 1) {
player.outgoingPackets.showNumberInputDialogue();
} else if(type === 2) {
player.outgoingPackets.showTextInputDialogue();
}
};

export default new RunePlugin({
type: ActionType.COMMAND,
commands: [ 'input' ],
args: [
{
name: 'type',
type: 'number'
}
],
action
});
6 changes: 4 additions & 2 deletions src/plugins/commands/item-selection-test-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const action: commandAction = (details) => {
}

player.outgoingPackets.chatboxMessage(`Player selected itemId ${choice.itemId} with amount ${choice.amount}`);
}).catch(); // <- CATCH IS REQUIRED FOR ALL ITEM SELECTION ACTIONS!
}).catch(error => { console.log('action cancelled'); }); // <- CATCH IS REQUIRED FOR ALL ITEM SELECTION ACTIONS!
// Always catch these, as the promise returned by `itemSelectionAction` will reject if actions have been cancelled!
// The console.log is not required, it's only here for testing purposes.
};

export default new RunePlugin({
type: ActionType.COMMAND,
commands: 'itemselection',
action
action,
cancelOtherActions: false
});
1 change: 0 additions & 1 deletion src/plugins/dialogue/item-selection-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { widgetAction } from '@server/world/actor/player/action/widget-action';
export const action: widgetAction = (details) => {
const { player, childId } = details;
player.dialogueInteractionEvent.next(childId);
player.activeWidget = null;
};

export default new RunePlugin({ type: ActionType.WIDGET_ACTION, widgetIds: [ 303, 304, 305, 306, 307, 309 ], action, cancelActions: false });
84 changes: 59 additions & 25 deletions src/world/actor/player/action/item-selection-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ItemSelection {
}

// @TODO Make-X
export const itemSelectionAction = (player: Player, type: 'COOKING' | 'MAKING', items: SelectableItem[]): Promise<ItemSelection> => {
export function itemSelectionAction(player: Player, type: 'COOKING' | 'MAKING', items: SelectableItem[]): Promise<ItemSelection> {
let widgetId = 307;

if(type === 'MAKING') {
Expand All @@ -66,61 +66,95 @@ export const itemSelectionAction = (player: Player, type: 'COOKING' | 'MAKING',
}
}

return new Promise((resolve, reject) => {
const childIds = widgets[widgetId].items;
childIds.forEach((childId, index) => {
const itemInfo = items[index];
const childIds = widgets[widgetId].items;
childIds.forEach((childId, index) => {
const itemInfo = items[index];

if(itemInfo.offset === undefined) {
itemInfo.offset = -12;
}
if(itemInfo.offset === undefined) {
itemInfo.offset = -12;
}

if(itemInfo.zoom === undefined) {
itemInfo.zoom = 180;
}
if(itemInfo.zoom === undefined) {
itemInfo.zoom = 180;
}

player.outgoingPackets.setItemOnWidget(widgetId, childId, itemInfo.itemId, itemInfo.zoom);
player.outgoingPackets.moveWidgetChild(widgetId, childId, 0, itemInfo.offset);
player.outgoingPackets.updateWidgetString(widgetId, widgets[widgetId].text[index], '\\n\\n\\n\\n' + itemInfo.itemName);
});
player.outgoingPackets.setItemOnWidget(widgetId, childId, itemInfo.itemId, itemInfo.zoom);
player.outgoingPackets.moveWidgetChild(widgetId, childId, 0, itemInfo.offset);
player.outgoingPackets.updateWidgetString(widgetId, widgets[widgetId].text[index], '\\n\\n\\n\\n' + itemInfo.itemName);
});

return new Promise((resolve, reject) => {
player.activeWidget = {
widgetId,
type: 'CHAT',
closeOnWalk: false
closeOnWalk: true
};

const actionsSub = player.actionsCancelled.subscribe(() => {
let actionsSub = player.actionsCancelled.subscribe(() => {
actionsSub.unsubscribe();
reject();
reject('Pending Actions Cancelled');
});

const interactionSub = player.dialogueInteractionEvent.subscribe(childId => {
const options = widgets[widgetId].options;
if(!player.activeWidget || player.activeWidget.widgetId !== widgetId) {
interactionSub.unsubscribe();
actionsSub.unsubscribe();
reject('Active Widget Mismatch');
return;
}

console.log(childId);
const options = widgets[widgetId].options;

const choiceIndex = options.findIndex(arr => arr.indexOf(childId) !== -1);

if(choiceIndex === -1) {
interactionSub.unsubscribe();
reject();
actionsSub.unsubscribe();
reject('Choice Index Not Found');
return;
}

const optionIndex = options[choiceIndex].indexOf(childId);

if(optionIndex === -1) {
interactionSub.unsubscribe();
reject();
actionsSub.unsubscribe();
reject('Option Index Not Found');
return;
}

const itemId = items[choiceIndex].itemId;
const amount = amounts[optionIndex];

interactionSub.unsubscribe();
resolve({ itemId, amount } as ItemSelection);
if(amount === 0) {
actionsSub.unsubscribe();

player.outgoingPackets.showNumberInputDialogue();

actionsSub = player.actionsCancelled.subscribe(() => {
actionsSub.unsubscribe();
reject('Pending Actions Cancelled');
});

const inputSub = player.numericInputEvent.subscribe(input => {
inputSub.unsubscribe();
actionsSub.unsubscribe();
interactionSub.unsubscribe();

if(input < 1 || input > 2147483647) {
player.closeActiveWidget();
reject('Invalid User Amount Input');
} else {
player.closeActiveWidget();
resolve({itemId, amount: input} as ItemSelection);
}
});
} else {
actionsSub.unsubscribe();
interactionSub.unsubscribe();
player.closeActiveWidget();
resolve({itemId, amount} as ItemSelection);
}
});
});
};
}
2 changes: 2 additions & 0 deletions src/world/actor/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class Player extends Actor {
private _carryWeight: number;
private _settings: PlayerSettings;
public readonly dialogueInteractionEvent: Subject<number>;
public readonly numericInputEvent: Subject<number>;
private _walkingTo: Position;
private _nearbyChunks: Chunk[];
public readonly actionsCancelled: Subject<boolean>;
Expand All @@ -88,6 +89,7 @@ export class Player extends Actor {
this._carryWeight = 0;
this._equipment = new ItemContainer(14);
this.dialogueInteractionEvent = new Subject<number>();
this.numericInputEvent = new Subject<number>();
this._nearbyChunks = [];
this.actionsCancelled = new Subject<boolean>();

Expand Down