-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from rune-js/equipment-screen
Item action plugins + player equipment stats screen
- Loading branch information
Showing
13 changed files
with
350 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,13 @@ | ||
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 { equipItemAction } from '../../world/actor/player/action/equip-item-action'; | ||
import { itemAction } from '@server/world/actor/player/action/item-action'; | ||
|
||
export const itemEquipPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { | ||
const containerId = packet.readShortLE(); | ||
const widgetId = packet.readShortLE(); | ||
const slot = packet.readNegativeOffsetShortLE(); | ||
const itemId = packet.readShortBE(); | ||
|
||
if(widgetId !== widgetIds.inventory.widgetId || containerId !== widgetIds.inventory.containerId) { | ||
logger.warn(`${player.username} attempted to equip item from incorrect widget ${widgetId}:${containerId}.`); | ||
return; | ||
} | ||
|
||
if(slot < 0 || slot > 27) { | ||
logger.warn(`${player.username} attempted to equip item ${itemId} in invalid slot ${slot}.`); | ||
return; | ||
} | ||
|
||
const itemInSlot = player.inventory.items[slot]; | ||
|
||
if(!itemInSlot) { | ||
logger.warn(`${player.username} attempted to equip item ${itemId} in slot ${slot}, but they do not have that item.`); | ||
return; | ||
} | ||
|
||
if(itemInSlot.itemId !== itemId) { | ||
logger.warn(`${player.username} attempted to equip item ${itemId} in slot ${slot}, but ${itemInSlot.itemId} was found there instead.`); | ||
return; | ||
} | ||
|
||
equipItemAction(player, itemId, slot); | ||
itemAction(player, itemId, slot, widgetId, containerId, 'equip'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 { Player } from '@server/world/actor/player/player'; | ||
|
||
export function updateBonusStrings(player: Player) { | ||
[ | ||
{ id: 108, text: 'Stab', value: player.bonuses.offencive.stab }, | ||
{ id: 109, text: 'Slash', value: player.bonuses.offencive.slash }, | ||
{ id: 110, text: 'Crush', value: player.bonuses.offencive.crush }, | ||
{ id: 111, text: 'Magic', value: player.bonuses.offencive.magic }, | ||
{ id: 112, text: 'Range', value: player.bonuses.offencive.ranged }, | ||
{ id: 113, text: 'Stab', value: player.bonuses.defencive.stab }, | ||
{ id: 114, text: 'Slash', value: player.bonuses.defencive.slash }, | ||
{ id: 115, text: 'Crush', value: player.bonuses.defencive.crush }, | ||
{ id: 116, text: 'Magic', value: player.bonuses.defencive.magic }, | ||
{ 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, | ||
`${bonus.text}: ${bonus.value > 0 ? `+${bonus.value}` : bonus.value}`)); | ||
} | ||
|
||
export const action: buttonAction = (details) => { | ||
const { player } = details; | ||
|
||
player.updateBonuses(); | ||
|
||
updateBonusStrings(player); | ||
|
||
player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.equipmentStats, player.equipment); | ||
player.outgoingPackets.sendUpdateAllWidgetItems(widgetIds.inventory, player.inventory); | ||
|
||
player.activeWidget = { | ||
widgetId: widgetIds.equipmentStats.widgetId, | ||
secondaryWidgetId: widgetIds.inventory.widgetId, | ||
type: 'SCREEN_AND_TAB', | ||
closeOnWalk: true | ||
}; | ||
}; | ||
|
||
export default new RunePlugin({ type: ActionType.BUTTON, widgetId: widgetIds.equipment.widgetId, buttonIds: 24, action }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ActionType, RunePlugin } from '@server/plugins/plugin'; | ||
import { widgetIds } 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'; | ||
|
||
export const action: itemAction = (details) => { | ||
const { player, itemId, itemSlot, widgetId } = details; | ||
|
||
const equipment = player.equipment; | ||
const item = getItemFromContainer(itemId, itemSlot, equipment); | ||
|
||
if(!item) { | ||
// The specified item was not found in the specified slot. | ||
return; | ||
} | ||
|
||
const inventory = player.inventory; | ||
const inventorySlot = inventory.getFirstOpenSlot(); | ||
|
||
if(inventorySlot === -1) { | ||
player.outgoingPackets.chatboxMessage(`You don't have enough free space to do that.`); | ||
return; | ||
} | ||
|
||
equipment.remove(itemSlot); | ||
inventory.set(inventorySlot, item); | ||
|
||
player.updateBonuses(); | ||
|
||
player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.inventory, inventorySlot, item); | ||
player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.equipment, itemSlot, null); | ||
|
||
if(widgetId === widgetIds.equipmentStats.widgetId) { | ||
player.outgoingPackets.sendUpdateSingleWidgetItem(widgetIds.equipmentStats, itemSlot, null); | ||
updateBonusStrings(player); | ||
} | ||
|
||
player.updateFlags.appearanceUpdateRequired = true; | ||
}; | ||
|
||
export default new RunePlugin({ | ||
type: ActionType.ITEM_ACTION, | ||
widgets: [ | ||
widgetIds.equipment, | ||
widgetIds.equipmentStats | ||
], | ||
options: 'option-1', | ||
action, | ||
cancelOtherActions: false | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.