-
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.
Converting drop item action into a plugin and changing widget id nami…
…ng to just widget.
- Loading branch information
1 parent
04a5cf9
commit e8bf1d4
Showing
18 changed files
with
116 additions
and
121 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
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 { 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(); | ||
const containerId = packet.readUnsignedShortLE(); | ||
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'); | ||
}; |
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,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 }); |
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
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,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 | ||
}); |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.