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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Item } from '@engine/world/items/item';
import { widgets } from '@engine/config';
import { itemIds } from '@engine/world/config/item-ids';

interface TanableHide {
export interface TanableHide {
hideId: number;
requiredLevel: number;
ingredients: Item;
Expand Down Expand Up @@ -101,33 +101,33 @@ export const widgetButtonIds: Map<number, TanButton> = new Map<number, TanButton
[148, { shouldTakeInput: false, count: 1, hide: COWHIDE_LEATHER }],
[140, { shouldTakeInput: false, count: 5, hide: COWHIDE_LEATHER }],
[132, { shouldTakeInput: true, count: 0, hide: COWHIDE_LEATHER }],
[124, { shouldTakeInput: false, count: 0, hide: COWHIDE_LEATHER }],
[124, { shouldTakeInput: false, count: -1, hide: COWHIDE_LEATHER }],
[149, { shouldTakeInput: false, count: 1, hide: COWHIDE_HARDLEATHER }],
[141, { shouldTakeInput: false, count: 5, hide: COWHIDE_HARDLEATHER }],
[133, { shouldTakeInput: true, count: 0, hide: COWHIDE_HARDLEATHER }],
[125, { shouldTakeInput: false, count: 0, hide: COWHIDE_HARDLEATHER }],
[125, { shouldTakeInput: false, count: -1, hide: COWHIDE_HARDLEATHER }],
[150, { shouldTakeInput: false, count: 1, hide: SNAKEHIDE }],
[142, { shouldTakeInput: false, count: 5, hide: SNAKEHIDE }],
[134, { shouldTakeInput: true, count: 0, hide: SNAKEHIDE }],
[126, { shouldTakeInput: false, count: 0, hide: SNAKEHIDE }],
[126, { shouldTakeInput: false, count: -1, hide: SNAKEHIDE }],
[151, { shouldTakeInput: false, count: 1, hide: SNAKEHIDE_TEMPLE_TREKKING }],
[143, { shouldTakeInput: false, count: 5, hide: SNAKEHIDE_TEMPLE_TREKKING }],
[135, { shouldTakeInput: true, count: 0, hide: SNAKEHIDE_TEMPLE_TREKKING }],
[127, { shouldTakeInput: false, count: 0, hide: SNAKEHIDE_TEMPLE_TREKKING }],
[127, { shouldTakeInput: false, count: -1, hide: SNAKEHIDE_TEMPLE_TREKKING }],
[152, { shouldTakeInput: false, count: 1, hide: GREEN_D_HIDE }],
[144, { shouldTakeInput: false, count: 5, hide: GREEN_D_HIDE }],
[136, { shouldTakeInput: true, count: 0, hide: GREEN_D_HIDE }],
[128, { shouldTakeInput: false, count: 0, hide: GREEN_D_HIDE }],
[128, { shouldTakeInput: false, count: -1, hide: GREEN_D_HIDE }],
[153, { shouldTakeInput: false, count: 1, hide: BLUE_D_HIDE }],
[145, { shouldTakeInput: false, count: 5, hide: BLUE_D_HIDE }],
[137, { shouldTakeInput: true, count: 0, hide: BLUE_D_HIDE }],
[129, { shouldTakeInput: false, count: 0, hide: BLUE_D_HIDE }],
[129, { shouldTakeInput: false, count: -1, hide: BLUE_D_HIDE }],
[154, { shouldTakeInput: false, count: 1, hide: RED_D_HIDE }],
[146, { shouldTakeInput: false, count: 5, hide: RED_D_HIDE }],
[138, { shouldTakeInput: true, count: 0, hide: RED_D_HIDE }],
[130, { shouldTakeInput: false, count: 0, hide: RED_D_HIDE }],
[130, { shouldTakeInput: false, count: -1, hide: RED_D_HIDE }],
[155, { shouldTakeInput: false, count: 1, hide: BLACK_D_HIDE }],
[147, { shouldTakeInput: false, count: 5, hide: BLACK_D_HIDE }],
[139, { shouldTakeInput: true, count: 0, hide: BLACK_D_HIDE }],
[131, { shouldTakeInput: false, count: 0, hide: BLACK_D_HIDE }],
[131, { shouldTakeInput: false, count: -1, hide: BLACK_D_HIDE }],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { colors } from '@engine/util/colors';
import { findItem } from '@engine/config';
import { Player } from '@engine/world/actor/player/player';

import { widgetButtonIds, widgetModelSlots } from './tanning-hides-constants';
import { widgetButtonIds, widgetModelSlots, TanableHide } from './tanning-hides-constants';

/**
* Opens the "Tan Hides" interface
Expand Down Expand Up @@ -78,17 +78,36 @@ const activate = (task: TaskExecutor<ButtonAction>): void => {
const hideToTan = widgetButtonIds.get(buttonId);

if (!hideToTan.shouldTakeInput) {
for (let i = 0; i < hideToTan.count; i++) {
if (!player.hasItemInInventory(hideToTan.hide.hideId)) break;
player.removeFirstItem(hideToTan.hide.hideId);
player.removeCoins(hideToTan.hide.cost);
player.giveItem(hideToTan.hide.output.itemId);
}
tanHide(player, hideToTan.hide, hideToTan.count);
} else {
const numericInput = player.numericInputEvent.subscribe((amount) => {
numericInput?.unsubscribe();
tanHide(player, hideToTan.hide, amount);
});

player.outgoingPackets.showNumberInputDialogue();
}

player.sendMessage(`The tanner tans your ${findItem(hideToTan.hide.hideId).name.toLowerCase()}.`);
}

const tanHide = (player: Player, hide: TanableHide, amount: number): void => {
let trueAmount = 0;

if (amount === -1) {
trueAmount = player.inventory.findAll(hide.hideId).length;
} else {
trueAmount = amount;
}

for (let i = 0; i < trueAmount; i++) {
if (!player.hasItemInInventory(hide.hideId)) break;
player.removeFirstItem(hide.hideId);
player.removeCoins(hide.cost);
player.giveItem(hide.output.itemId);
}
};

export default {
pluginId: 'rs:tanning-hides-interface',
hooks: [
Expand Down