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
2 changes: 2 additions & 0 deletions src/net/incoming-packet-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { dropItemPacket } from '@server/net/incoming-packets/drop-item-packet';
import { itemOnItemPacket } from '@server/net/incoming-packets/item-on-item-packet';
import { widgetsClosedPacket } from '@server/net/incoming-packets/widgets-closed-packet';
import { pickupItemPacket } from '@server/net/incoming-packets/pickup-item-packet';
import { itemOption2Packet } from '@server/net/incoming-packets/item-option-2-packet';

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

Expand All @@ -38,6 +39,7 @@ const packets: { [key: number]: incomingPacket } = {
40: itemOnItemPacket,
102: itemEquipPacket,
38: itemOption1Packet,
98: itemOption2Packet,
29: dropItemPacket,
85: pickupItemPacket,

Expand Down
2 changes: 1 addition & 1 deletion src/net/incoming-packet-sizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const incomingPacketSizes: number[] = [
-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, -3, -3, -3, -3, -3, -3, -3, //90
-3, -3, -3, -3, -3, -3, -3, -3, 8, -3, //90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

-3, -3, 8, -3, -3, -3, -3, -3, -3, -3, //100
-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, //110
-3, 4, -3, -3, -3, -3, -3, -3, -3, -3, //120
Expand Down
71 changes: 71 additions & 0 deletions src/net/incoming-packets/item-option-2-packet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { incomingPacket } from '../incoming-packet';
import { RsBuffer } from '@server/net/rs-buffer';
import { Player } from '../../world/actor/player/player';
import { itemAction } from '@server/world/actor/player/action/item-action';

export const itemOption2Packet: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => {
const slot = packet.readShortBE();
const widgetId = packet.readShortLE();
const containerId = packet.readShortLE();
const itemId = packet.readShortBE();
// packet.readNegativeOffsetShortBE();
// packet.readUnsignedShortLE();
// packet.readShortLE(); // either widget id or container id
// packet.readShortLE(); // either widget id or container id
//
// Class32.packetBuffer.putShortBE(i);
// Class32.packetBuffer.putIntME1(i_10_);
// Class32.packetBuffer.putShortBE(i_12_);
//
// Class32.packetBuffer.putCustomNegativeOffsetShortBE(i_12_, -128);
// Class32.packetBuffer.putShortLE(i);
// Class32.packetBuffer.putIntME1(i_10_);

// @TODO parse widgets and find actual item option NAME to pass to this
itemAction(player, itemId, slot, widgetId, containerId, 'option-2');

/*
// Handles the value option in shops.
if(widgetId === widgetIds.shop.shopInventory) {
buyItemValueAction(player, itemId, slot);
return;
}

// Handles the value option in the shop inventory interface.
if(widgetId === widgetIds.shop.playerInventory) {
sellItemValueAction(player, itemId, slot);
return;
}

let container: ItemContainer = null;

if(widgetId === widgetIds.equipment.widgetId && containerId === widgetIds.equipment.containerId) {
container = player.equipment;
}

if(!container) {
logger.info(`Unhandled item option 1: ${widgetId}, ${slot}, ${itemId}`);
return;
}

if(slot < 0 || slot > container.size - 1) {
logger.warn(`${player.username} attempted item option 1 on ${itemId} in invalid slot ${slot}.`);
return;
}

const itemInSlot = container.items[slot];

if(!itemInSlot) {
logger.warn(`${player.username} attempted item option 1 on ${itemId} in slot ${slot}, but they do not have that item.`);
return;
}

if(itemInSlot.itemId !== itemId) {
logger.warn(`${player.username} attempted item option 1 on ${itemId} in slot ${slot}, but ${itemInSlot.itemId} was found there instead.`);
return;
}

if(widgetId === widgetIds.equipment.widgetId && containerId === widgetIds.equipment.containerId) {
unequipItemAction(player, itemId, slot);
}*/
};
31 changes: 31 additions & 0 deletions src/plugins/items/buckets/empty-bucket-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getItemFromContainer, itemAction } from '@server/world/actor/player/action/item-action';
import { widgets } from '@server/world/config/widget';
import { soundIds } from '@server/world/config/sound-ids';
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { itemIds } from '@server/world/config/item-ids';

export const action: itemAction = (details) => {
const { player, itemId, itemSlot } = details;

const inventory = player.inventory;
const item = getItemFromContainer(itemId, itemSlot, inventory);

if(!item) {
// The specified item was not found in the specified slot.
return;
}

inventory.remove(itemSlot);
player.outgoingPackets.playSound(soundIds.emptyBucket, 5);
player.giveItem(itemIds.bucket);
player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, inventory);
};

export default new RunePlugin({
type: ActionType.ITEM_ACTION,
widgets: widgets.inventory,
options: 'option-2',
itemIds: [itemIds.bucketOfMilk, itemIds.bucketOfWater],
action,
cancelOtherActions: false
});
2 changes: 1 addition & 1 deletion src/plugins/objects/cows/cow-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const action: objectAction = (details) => {
const {player, option, objectDefinition, object} = details;
const emptyBucketItem = gameCache.itemDefinitions.get(itemIds.bucket);

if(player.hasItemInInventory(itemIds.bucket)) {
if (player.hasItemInInventory(itemIds.bucket)) {
player.playAnimation(animationIds.milkCow);
player.outgoingPackets.playSound(soundIds.milkCow, 7);
player.removeFirstItem(itemIds.bucket);
Expand Down
1 change: 1 addition & 0 deletions src/world/config/item-ids.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const itemIds = {
bucket: 1925,
bucketOfMilk: 1927,
bucketOfWater: 1929,
ashes: 592,
tinderbox: 590,
logs: 1511,
Expand Down
1 change: 1 addition & 0 deletions src/world/config/sound-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const soundIds = {
homeTeleportSit: 196,
homeTeleportPullOutBook: 194,
homeTeleportCircleGlowAndTeleport: 195,
emptyBucket: 2401,
};