From e8bf1d407a395ed111ff8617994c9e6ba1bdc814 Mon Sep 17 00:00:00 2001 From: TheBlackParade Date: Fri, 28 Feb 2020 13:28:29 -0600 Subject: [PATCH] Converting drop item action into a plugin and changing widget id naming to just widget. --- src/net/incoming-packet-sizes.ts | 4 +-- .../character-design-packet.ts | 4 +-- src/net/incoming-packets/drop-item-packet.ts | 28 ++------------- .../incoming-packets/item-on-item-packet.ts | 6 ++-- src/plugins/buttons/logout-button-plugin.ts | 4 +-- .../buttons/player-setting-button-plugin.ts | 4 +-- src/plugins/equipment/equip-item-plugin.ts | 12 +++---- .../equipment/equipment-stats-plugin.ts | 14 ++++---- src/plugins/equipment/unequip-item-plugin.ts | 14 ++++---- src/plugins/items/drop-item-plugin.ts | 30 ++++++++++++++++ src/plugins/skills/skill-guide-plugin.ts | 28 +++++++-------- .../actor/player/action/buy-item-action.ts | 12 +++---- .../actor/player/action/drop-item-action.ts | 12 ------- src/world/actor/player/action/shop-action.ts | 22 ++++++------ .../actor/player/action/swap-item-action.ts | 4 +-- src/world/actor/player/player.ts | 36 +++++++++---------- src/world/config/sound-ids.ts | 1 + src/world/config/widget.ts | 2 +- 18 files changed, 116 insertions(+), 121 deletions(-) create mode 100644 src/plugins/items/drop-item-plugin.ts delete mode 100644 src/world/actor/player/action/drop-item-action.ts diff --git a/src/net/incoming-packet-sizes.ts b/src/net/incoming-packet-sizes.ts index ec65e6b7e..be21753fe 100644 --- a/src/net/incoming-packet-sizes.ts +++ b/src/net/incoming-packet-sizes.ts @@ -5,9 +5,9 @@ export const incomingPacketSizes: number[] = [ 6, -3, -3, -3, -3, -3, -3, -3, 8, -3, //30 16, -3, -3, -3, -3, -3, -3, -3, -3, -3, //40 -3, -3, -3, -3, -3, -3, -3, -3, 4, -3, //50 - -3, -3, -3, 2, 4, -3, -3, -3, -3, -3, //60 + -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, -3, -3, -3, -3, -1, //80 + -3, -3, -3, 9, -3, 6, -3, -3, -3, -1, //80 -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, //90 -3, -3, 8, -3, -3, -3, -3, -3, -3, -3, //100 -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, //110 diff --git a/src/net/incoming-packets/character-design-packet.ts b/src/net/incoming-packets/character-design-packet.ts index 73f38d194..51c5810e1 100644 --- a/src/net/incoming-packets/character-design-packet.ts +++ b/src/net/incoming-packets/character-design-packet.ts @@ -1,10 +1,10 @@ import { incomingPacket } from '../incoming-packet'; import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; -import { widgetIds } from '../../world/config/widget'; +import { widgets } from '../../world/config/widget'; export const characterDesignPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { - if(!player.activeWidget || player.activeWidget.widgetId !== widgetIds.characterDesign) { + if(!player.activeWidget || player.activeWidget.widgetId !== widgets.characterDesign) { return; } diff --git a/src/net/incoming-packets/drop-item-packet.ts b/src/net/incoming-packets/drop-item-packet.ts index e7dacde23..2c849ad84 100644 --- a/src/net/incoming-packets/drop-item-packet.ts +++ b/src/net/incoming-packets/drop-item-packet.ts @@ -1,9 +1,7 @@ import { incomingPacket } from '../incoming-packet'; import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; -import { logger } from '@runejs/logger/dist/logger'; -import { widgetIds } from '../../world/config/widget'; -import { dropItemAction } from '@server/world/actor/player/action/drop-item-action'; +import { itemAction } from '@server/world/actor/player/action/item-action'; export const dropItemPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { const widgetId = packet.readUnsignedShortLE(); @@ -11,27 +9,5 @@ export const dropItemPacket: incomingPacket = (player: Player, packetId: number, const slot = packet.readNegativeOffsetShortBE(); const itemId = packet.readUnsignedShortLE(); - if(widgetId !== widgetIds.inventory.widgetId || containerId !== widgetIds.inventory.containerId) { - logger.warn(`${player.username} attempted to drop item from incorrect widget id ${widgetId}.`); - return; - } - - if(slot < 0 || slot > 27) { - logger.warn(`${player.username} attempted to drop item ${itemId} in invalid slot ${slot}.`); - return; - } - - const itemInSlot = player.inventory.items[slot]; - - if(!itemInSlot) { - logger.warn(`${player.username} attempted to drop item ${itemId} in slot ${slot}, but they do not have that item.`); - return; - } - - if(itemInSlot.itemId !== itemId) { - logger.warn(`${player.username} attempted to drop item ${itemId} in slot ${slot}, but ${itemInSlot.itemId} was found there instead.`); - return; - } - - dropItemAction(player, itemInSlot, slot); + itemAction(player, itemId, slot, widgetId, containerId, 'drop'); }; diff --git a/src/net/incoming-packets/item-on-item-packet.ts b/src/net/incoming-packets/item-on-item-packet.ts index fb8e49a4a..29729c4a6 100644 --- a/src/net/incoming-packets/item-on-item-packet.ts +++ b/src/net/incoming-packets/item-on-item-packet.ts @@ -1,7 +1,7 @@ import { incomingPacket } from '../incoming-packet'; import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; import { logger } from '@runejs/logger/dist/logger'; import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item-action'; @@ -15,8 +15,8 @@ export const itemOnItemPacket: incomingPacket = (player: Player, packetId: numbe const usedItemId = packet.readUnsignedShortLE(); const usedSlot = packet.readNegativeOffsetShortBE(); - if(usedWidgetId === widgetIds.inventory.widgetId && usedContainerId === widgetIds.inventory.containerId && - usedWithWidgetId === widgetIds.inventory.widgetId && usedWithContainerId === widgetIds.inventory.containerId) { + if(usedWidgetId === widgets.inventory.widgetId && usedContainerId === widgets.inventory.containerId && + usedWithWidgetId === widgets.inventory.widgetId && usedWithContainerId === widgets.inventory.containerId) { if(usedSlot < 0 || usedSlot > 27 || usedWithSlot < 0 || usedWithSlot > 27) { return; } diff --git a/src/plugins/buttons/logout-button-plugin.ts b/src/plugins/buttons/logout-button-plugin.ts index 2d424d087..e3d985587 100644 --- a/src/plugins/buttons/logout-button-plugin.ts +++ b/src/plugins/buttons/logout-button-plugin.ts @@ -1,10 +1,10 @@ import { buttonAction } from '@server/world/actor/player/action/button-action'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; export const action: buttonAction = (details) => { const { player } = details; player.logout(); }; -export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgetIds.logoutTab, buttonIds: 6, action }); +export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgets.logoutTab, buttonIds: 6, action }); diff --git a/src/plugins/buttons/player-setting-button-plugin.ts b/src/plugins/buttons/player-setting-button-plugin.ts index d6ee50caf..e131ebe03 100644 --- a/src/plugins/buttons/player-setting-button-plugin.ts +++ b/src/plugins/buttons/player-setting-button-plugin.ts @@ -1,6 +1,6 @@ import { buttonAction } from '@server/world/actor/player/action/button-action'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; const buttonIds: number[] = [ 0, // walk/run @@ -20,4 +20,4 @@ export const action: buttonAction = (details) => { player.settingChanged(buttonId); }; -export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgetIds.settingsTab, buttonIds: buttonIds, action }); +export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgets.settingsTab, buttonIds: buttonIds, action }); diff --git a/src/plugins/equipment/equip-item-plugin.ts b/src/plugins/equipment/equip-item-plugin.ts index 3edca0647..bc1d678d7 100644 --- a/src/plugins/equipment/equip-item-plugin.ts +++ b/src/plugins/equipment/equip-item-plugin.ts @@ -1,5 +1,5 @@ import { ActionType, RunePlugin } from '@server/plugins/plugin'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; import { getItemFromContainer, itemAction } from '@server/world/actor/player/action/item-action'; import { updateBonusStrings } from '@server/plugins/equipment/equipment-stats-plugin'; import { EquipmentSlot, equipmentSlotIndex, ItemDetails, WeaponType } from '@server/world/config/item-data'; @@ -94,11 +94,11 @@ export const action: itemAction = (details) => { player.updateBonuses(); // @TODO change packets to only update modified container slots - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, inventory); - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.equipment, equipment); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, inventory); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.equipment, equipment); - if(player.hasWidgetOpen(widgetIds.equipmentStats.widgetId)) { - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.equipmentStats, equipment); + if(player.hasWidgetOpen(widgets.equipmentStats.widgetId)) { + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.equipmentStats, equipment); updateBonusStrings(player); } @@ -107,7 +107,7 @@ export const action: itemAction = (details) => { export default new RunePlugin({ type: ActionType.ITEM_ACTION, - widgets: widgetIds.inventory, + widgets: widgets.inventory, options: 'equip', action, cancelOtherActions: false diff --git a/src/plugins/equipment/equipment-stats-plugin.ts b/src/plugins/equipment/equipment-stats-plugin.ts index 30eb0f4a6..b4e6318fa 100644 --- a/src/plugins/equipment/equipment-stats-plugin.ts +++ b/src/plugins/equipment/equipment-stats-plugin.ts @@ -1,6 +1,6 @@ import { buttonAction } from '@server/world/actor/player/action/button-action'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; import { Player } from '@server/world/actor/player/player'; export function updateBonusStrings(player: Player) { @@ -17,7 +17,7 @@ export function updateBonusStrings(player: Player) { { id: 117, text: 'Range', value: player.bonuses.defencive.ranged }, { id: 119, text: 'Strength', value: player.bonuses.skill.strength }, { id: 120, text: 'Prayer', value: player.bonuses.skill.prayer }, - ].forEach(bonus => player.outgoingPackets.updateWidgetString(widgetIds.equipmentStats.widgetId, bonus.id, + ].forEach(bonus => player.outgoingPackets.updateWidgetString(widgets.equipmentStats.widgetId, bonus.id, `${bonus.text}: ${bonus.value > 0 ? `+${bonus.value}` : bonus.value}`)); } @@ -28,15 +28,15 @@ export const action: buttonAction = (details) => { updateBonusStrings(player); - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.equipmentStats, player.equipment); - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, player.inventory); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.equipmentStats, player.equipment); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, player.inventory); player.activeWidget = { - widgetId: widgetIds.equipmentStats.widgetId, - secondaryWidgetId: widgetIds.inventory.widgetId, + widgetId: widgets.equipmentStats.widgetId, + secondaryWidgetId: widgets.inventory.widgetId, type: 'SCREEN_AND_TAB', closeOnWalk: true }; }; -export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgetIds.equipment.widgetId, buttonIds: 24, action }); +export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgets.equipment.widgetId, buttonIds: 24, action }); diff --git a/src/plugins/equipment/unequip-item-plugin.ts b/src/plugins/equipment/unequip-item-plugin.ts index 4ace9b713..a4eb16ec1 100644 --- a/src/plugins/equipment/unequip-item-plugin.ts +++ b/src/plugins/equipment/unequip-item-plugin.ts @@ -1,5 +1,5 @@ import { ActionType, RunePlugin } from '@server/plugins/plugin'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; import { getItemFromContainer, itemAction } from '@server/world/actor/player/action/item-action'; import { updateBonusStrings } from '@server/plugins/equipment/equipment-stats-plugin'; @@ -27,11 +27,11 @@ export const action: itemAction = (details) => { player.updateBonuses(); - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.inventory, inventorySlot, item); - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.equipment, itemSlot, null); + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.inventory, inventorySlot, item); + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.equipment, itemSlot, null); - if(widgetId === widgetIds.equipmentStats.widgetId) { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.equipmentStats, itemSlot, null); + if(widgetId === widgets.equipmentStats.widgetId) { + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.equipmentStats, itemSlot, null); updateBonusStrings(player); } @@ -41,8 +41,8 @@ export const action: itemAction = (details) => { export default new RunePlugin({ type: ActionType.ITEM_ACTION, widgets: [ - widgetIds.equipment, - widgetIds.equipmentStats + widgets.equipment, + widgets.equipmentStats ], options: 'option-1', action, diff --git a/src/plugins/items/drop-item-plugin.ts b/src/plugins/items/drop-item-plugin.ts new file mode 100644 index 000000000..775ee42a6 --- /dev/null +++ b/src/plugins/items/drop-item-plugin.ts @@ -0,0 +1,30 @@ +import { ActionType, RunePlugin } from '@server/plugins/plugin'; +import { widgets } from '@server/world/config/widget'; +import { getItemFromContainer, itemAction } from '@server/world/actor/player/action/item-action'; +import { world } from '@server/game-server'; +import { soundIds } from '@server/world/config/sound-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.sendUpdateSingleWidgetItem(widgets.inventory, itemSlot, null); + player.outgoingPackets.playSound(soundIds.dropItem, 5); + world.chunkManager.spawnWorldItem(item, player.position, player, 300); +}; + +export default new RunePlugin({ + type: ActionType.ITEM_ACTION, + widgets: widgets.inventory, + options: 'drop', + action, + cancelOtherActions: false +}); diff --git a/src/plugins/skills/skill-guide-plugin.ts b/src/plugins/skills/skill-guide-plugin.ts index 07cae6a4d..b93f87661 100644 --- a/src/plugins/skills/skill-guide-plugin.ts +++ b/src/plugins/skills/skill-guide-plugin.ts @@ -5,7 +5,7 @@ import { readFileSync } from 'fs'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { Player } from '@server/world/actor/player/player'; import { widgetAction } from '@server/world/actor/player/action/widget-action'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; // @TODO fix me! @@ -54,17 +54,17 @@ function loadGuide(player: Player, guideId: number, subGuideId: number = 0, refr let guide: SkillGuide = guides.find(g => g.id === guideId); if(refreshSidebar) { - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 133, guide.members ? 'Members only skill' : ''); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 133, guide.members ? 'Members only skill' : ''); for(let i = 0; i < sidebarTextIds.length; i++) { const sidebarId = sidebarIds[i]; let hide: boolean = true; if(i >= guide.subGuides.length) { - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, sidebarTextIds[i], ''); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, sidebarTextIds[i], ''); hide = true; } else { - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, sidebarTextIds[i], guide.subGuides[i].name); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, sidebarTextIds[i], guide.subGuides[i].name); hide = false; } @@ -72,30 +72,30 @@ function loadGuide(player: Player, guideId: number, subGuideId: number = 0, refr // Apparently you can never have only TWO subguides... // Because childId 98 deletes both options 2 AND 3. So, good thing there are no guides with only 2 sections, I guess?... // Verified this in an interface editor, and they are indeed grouped in a single layer for some reason... - player.outgoingPackets.toggleWidgetVisibility(widgetIds.skillGuide, sidebarIds[i], hide); + player.outgoingPackets.toggleWidgetVisibility(widgets.skillGuide, sidebarIds[i], hide); } } } const subGuide: SkillSubGuide = guide.subGuides[subGuideId]; - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 1, guide.name + ' - ' + subGuide.name); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 1, guide.name + ' - ' + subGuide.name); const itemIds: number[] = subGuide.lines.map(g => g.itemId).concat(new Array(30 - subGuide.lines.length).fill(null)); - player.outgoingPackets.sendUpdateAllWidgetItemsById({ widgetId: widgetIds.skillGuide, containerId: 132 }, itemIds); + player.outgoingPackets.sendUpdateAllWidgetItemsById({ widgetId: widgets.skillGuide, containerId: 132 }, itemIds); for(let i = 0; i < 30; i++) { if(subGuide.lines.length <= i) { - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 5 + i, ''); - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 45 + i, ''); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 5 + i, ''); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 45 + i, ''); } else { - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 5 + i, subGuide.lines[i].level.toString()); - player.outgoingPackets.updateWidgetString(widgetIds.skillGuide, 45 + i, subGuide.lines[i].text); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 5 + i, subGuide.lines[i].level.toString()); + player.outgoingPackets.updateWidgetString(widgets.skillGuide, 45 + i, subGuide.lines[i].text); } } player.activeWidget = { - widgetId: widgetIds.skillGuide, + widgetId: widgets.skillGuide, type: 'SCREEN', closeOnWalk: false }; @@ -127,6 +127,6 @@ export const openSubGuideAction: widgetAction = (details) => { }; export default new RunePlugin([ - { type: ActionType.BUTTON, widgetId: widgetIds.skillsTab, buttonIds, action: openGuideAction }, - { type: ActionType.WIDGET_ACTION, widgetIds: widgetIds.skillGuide, childIds: sidebarTextIds, optionId: 0, action: openSubGuideAction } + { type: ActionType.BUTTON, widgetId: widgets.skillsTab, buttonIds, action: openGuideAction }, + { type: ActionType.WIDGET_ACTION, widgetIds: widgets.skillGuide, childIds: sidebarTextIds, optionId: 0, action: openSubGuideAction } ]); diff --git a/src/world/actor/player/action/buy-item-action.ts b/src/world/actor/player/action/buy-item-action.ts index 0cf9100a2..278f49b18 100644 --- a/src/world/actor/player/action/buy-item-action.ts +++ b/src/world/actor/player/action/buy-item-action.ts @@ -1,6 +1,6 @@ import { Player } from '@server/world/actor/player/player'; import { gameCache } from '@server/game-server'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; export const buyItemAction = (player: Player, itemId: number, amount: number, slot: number, interfaceId: number) => { const purchasedItem = gameCache.itemDefinitions.get(itemId); @@ -11,7 +11,7 @@ export const buyItemAction = (player: Player, itemId: number, amount: number, sl return; } - if(interfaceId !== widgetIds.shop.shopInventory) { + if(interfaceId !== widgets.shop.shopInventory) { return; } @@ -38,12 +38,12 @@ export const buyItemAction = (player: Player, itemId: number, amount: number, sl player.inventory.add(itemId); } - if(interfaceId === widgetIds.shop.shopInventory) { - console.log(interfaceId, widgetIds.shop.shopInventory); - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.shop.playerInventory, player.inventory); + if(interfaceId === widgets.shop.shopInventory) { + console.log(interfaceId, widgets.shop.shopInventory); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.shop.playerInventory, player.inventory); } // Update the inventory items. - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, player.inventory); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, player.inventory); }; diff --git a/src/world/actor/player/action/drop-item-action.ts b/src/world/actor/player/action/drop-item-action.ts deleted file mode 100644 index 6eb412e3f..000000000 --- a/src/world/actor/player/action/drop-item-action.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Player } from '../player'; -import { world } from '@server/game-server'; -import { Item } from '@server/world/items/item'; -import { widgetIds } from '@server/world/config/widget'; - -export const dropItemAction = (player: Player, item: Item, inventorySlot: number) => { - player.inventory.remove(inventorySlot); - // @TODO change packets to only update modified container slots - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, player.inventory); - player.outgoingPackets.playSound(2739, 7); - world.chunkManager.spawnWorldItem(item, player.position, player, 300); -}; diff --git a/src/world/actor/player/action/shop-action.ts b/src/world/actor/player/action/shop-action.ts index 628da8bc4..9626ce57b 100644 --- a/src/world/actor/player/action/shop-action.ts +++ b/src/world/actor/player/action/shop-action.ts @@ -2,7 +2,7 @@ import { world } from '@server/game-server'; import { Player } from '@server/world/actor/player/player'; import { logger } from '@runejs/logger/dist/logger'; import { Shop } from '@server/world/config/shops'; -import { widgetIds } from '@server/world/config/widget'; +import { widgets } from '@server/world/config/widget'; function findShop(identification: string): Shop { for(let i = 0; i <= world.shops.length; i++) { @@ -20,37 +20,37 @@ export function openShop(player: Player, identification: string, closeOnWalk: bo // player.packetSender.updateWidgetString(widgetIds.shop.shopTitle, openedShop.name); for(let i = 0; i < 30; i++) { if(openedShop.items.length <= i) { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.shop.shopInventory, i, null); + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.shop.shopInventory, i, null); } else { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.shop.shopInventory, i, { + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.shop.shopInventory, i, { itemId: openedShop.items[i].id, amount: openedShop.items[i].amountInStock }); } } for(let i = 0; i < openedShop.items.length; i++) { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.shop.shopInventory, i, { + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.shop.shopInventory, i, { itemId: openedShop.items[i].id, amount: openedShop.items[i].amountInStock }); } - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.shop.playerInventory, player.inventory); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.shop.playerInventory, player.inventory); player.activeWidget = { - widgetId: widgetIds.shop.shopScreen, - secondaryWidgetId: widgetIds.shop.playerTab, + widgetId: widgets.shop.shopScreen, + secondaryWidgetId: widgets.shop.playerTab, type: 'SCREEN_AND_TAB', closeOnWalk: closeOnWalk }; - player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, player.inventory); - player.outgoingPackets.showScreenAndTabWidgets(widgetIds.shop.shopScreen, widgetIds.shop.playerTab); + player.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, player.inventory); + player.outgoingPackets.showScreenAndTabWidgets(widgets.shop.shopScreen, widgets.shop.playerTab); for(let i = 0; i < player.inventory.items.length; i++) { if(player.inventory.items[i] !== null) { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.shop.playerInventory, i, { + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.shop.playerInventory, i, { itemId: player.inventory.items[i].itemId, amount: player.inventory.items[i].amount }); } else { - player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.shop.playerInventory, i, null); + player.outgoingPackets.sendUpdateSingleWidgetItem(widgets.shop.playerInventory, i, null); } } diff --git a/src/world/actor/player/action/swap-item-action.ts b/src/world/actor/player/action/swap-item-action.ts index a2e1cb37b..95c93bd98 100644 --- a/src/world/actor/player/action/swap-item-action.ts +++ b/src/world/actor/player/action/swap-item-action.ts @@ -1,8 +1,8 @@ import { Player } from '../player'; -import { widgetIds } from '../../../config/widget'; +import { widgets } from '../../../config/widget'; export const swapItemAction = (player: Player, fromSlot: number, toSlot: number, widget: { widgetId: number, containerId: number }) => { - if(widget.widgetId === widgetIds.inventory.widgetId && widget.containerId === widgetIds.inventory.containerId) { + if(widget.widgetId === widgets.inventory.widgetId && widget.containerId === widgets.inventory.containerId) { const inventory = player.inventory; if(toSlot > inventory.size - 1 || fromSlot > inventory.size - 1) { diff --git a/src/world/actor/player/player.ts b/src/world/actor/player/player.ts index 28ca7d693..3025da2bf 100644 --- a/src/world/actor/player/player.ts +++ b/src/world/actor/player/player.ts @@ -13,7 +13,7 @@ import { PlayerSave, PlayerSettings, savePlayerData, validateSettings } from './player-data'; -import { ActiveWidget, widgetIds, widgetSettings } from '../../config/widget'; +import { ActiveWidget, widgets, widgetSettings } from '../../config/widget'; import { ContainerUpdateEvent, ItemContainer } from '../../items/item-container'; import { EquipmentBonuses, ItemDetails } from '../../config/item-data'; import { Item } from '../../items/item'; @@ -25,7 +25,7 @@ import { QuadtreeKey } from '@server/world/world'; import { daysSinceLastLogin } from '@server/util/time'; const DEFAULT_TAB_WIDGET_IDS = [ - 92, widgetIds.skillsTab, 274, widgetIds.inventory.widgetId, widgetIds.equipment.widgetId, 271, 192, -1, 131, 148, widgetIds.logoutTab, widgetIds.settingsTab, 464, 239 + 92, widgets.skillsTab, 274, widgets.inventory.widgetId, widgets.equipment.widgetId, 271, 192, -1, 131, 148, widgets.logoutTab, widgets.settingsTab, 464, 239 ]; export enum Rights { @@ -162,12 +162,12 @@ export class Player extends Actor { this.skills.values.forEach((skill, index) => this.outgoingPackets.updateSkill(index, skill.level, skill.exp)); - this.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, this.inventory); - this.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.equipment, this.equipment); + this.outgoingPackets.sendUpdateAllWidgetItems(widgets.inventory, this.inventory); + this.outgoingPackets.sendUpdateAllWidgetItems(widgets.equipment, this.equipment); if(this.firstTimePlayer) { this.activeWidget = { - widgetId: widgetIds.characterDesign, + widgetId: widgets.characterDesign, type: 'SCREEN', disablePlayerMovement: true }; @@ -182,18 +182,18 @@ export class Player extends Actor { } else { loginDaysStr = daysSinceLogin + ' days ago'; } - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreenChildren.question, 1, `Want to help RuneJS improve?\\nSend us a pull request over on Github!`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 13, `You last logged in @red@${loginDaysStr}@bla@ from: @red@${this.lastAddress}`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 16, `You have @yel@0 unread messages\\nin your message centre.`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 14, `\\nYou have not yet set any recovery questions.\\nIt is @lre@strongly@yel@ recommended that you do so.\\n\\nIf you don't you will be @lre@unable to recover your\\n@lre@password@yel@ if you forget it, or it is stolen.`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 22, `To change your recovery questions:\\n1) Logout and return to the frontpage of this website.\\n2) Choose 'Set new recovery questions'.`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 17, `\\nYou do not have a Bank PIN.\\nPlease visit a bank if you would like one.`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 21, `To start a subscripton:\\n1) Logout and return to the frontpage of this website.\\n2) Choose 'Start a new subscription'`); - this.outgoingPackets.updateWidgetString(widgetIds.welcomeScreen, 19, `You are not a member.\\n\\nChoose to subscribe and\\nyou'll get loads of extra\\nbenefits and features.`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreenChildren.question, 1, `Want to help RuneJS improve?\\nSend us a pull request over on Github!`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 13, `You last logged in @red@${loginDaysStr}@bla@ from: @red@${this.lastAddress}`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 16, `You have @yel@0 unread messages\\nin your message centre.`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 14, `\\nYou have not yet set any recovery questions.\\nIt is @lre@strongly@yel@ recommended that you do so.\\n\\nIf you don't you will be @lre@unable to recover your\\n@lre@password@yel@ if you forget it, or it is stolen.`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 22, `To change your recovery questions:\\n1) Logout and return to the frontpage of this website.\\n2) Choose 'Set new recovery questions'.`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 17, `\\nYou do not have a Bank PIN.\\nPlease visit a bank if you would like one.`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 21, `To start a subscripton:\\n1) Logout and return to the frontpage of this website.\\n2) Choose 'Start a new subscription'`); + this.outgoingPackets.updateWidgetString(widgets.welcomeScreen, 19, `You are not a member.\\n\\nChoose to subscribe and\\nyou'll get loads of extra\\nbenefits and features.`); this.activeWidget = { - widgetId: widgetIds.welcomeScreen, - secondaryWidgetId: widgetIds.welcomeScreenChildren.question, + widgetId: widgets.welcomeScreen, + secondaryWidgetId: widgets.welcomeScreenChildren.question, type: 'FULLSCREEN' }; } @@ -354,14 +354,14 @@ export class Player extends Actor { return -1; } - this.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.inventory, slot, null); + this.outgoingPackets.sendUpdateSingleWidgetItem(widgets.inventory, slot, null); return slot; } public removeItem(slot: number): void { this.inventory.remove(slot); - this.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.inventory, slot, null); + this.outgoingPackets.sendUpdateSingleWidgetItem(widgets.inventory, slot, null); } public giveItem(item: number | Item): boolean { @@ -370,7 +370,7 @@ export class Player extends Actor { return false; } - this.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.inventory, addedItem.slot, addedItem.item); + this.outgoingPackets.sendUpdateSingleWidgetItem(widgets.inventory, addedItem.slot, addedItem.item); return true; } diff --git a/src/world/config/sound-ids.ts b/src/world/config/sound-ids.ts index 14f74abc6..2d41ed959 100644 --- a/src/world/config/sound-ids.ts +++ b/src/world/config/sound-ids.ts @@ -1,4 +1,5 @@ export const soundIds = { + dropItem: 2739, milkCow: 372, lightingFire: 2599, fireLit: 2594, diff --git a/src/world/config/widget.ts b/src/world/config/widget.ts index 3fb863587..739e8ead0 100644 --- a/src/world/config/widget.ts +++ b/src/world/config/widget.ts @@ -1,4 +1,4 @@ -export const widgetIds: any = { +export const widgets: any = { characterDesign: 269, inventory: { widgetId: 149,