-
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 #22 from rune-js/item-swapping
Adding the ability to swap inventory items.
- Loading branch information
Showing
6 changed files
with
54 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Player } from '../player'; | ||
import { interfaceIds } from '../game-interface'; | ||
|
||
export const swapItemAction = (player: Player, fromSlot: number, toSlot: number, interfaceId: number) => { | ||
if(interfaceId === interfaceIds.inventory) { | ||
const inventory = player.inventory; | ||
|
||
if(toSlot > inventory.size - 1 || fromSlot > inventory.size - 1) { | ||
return; | ||
} | ||
|
||
inventory.swap(fromSlot, toSlot); | ||
} | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/world/entity/mob/player/packet/impl/item-swap-packet.ts
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,22 @@ | ||
import { incomingPacket } from '../incoming-packet'; | ||
import { Player } from '../../player'; | ||
import { RsBuffer } from '../../../../../../net/rs-buffer'; | ||
import { swapItemAction } from '../../action/swap-item-action'; | ||
|
||
export const itemSwapPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { | ||
const toSlot = packet.readNegativeOffsetShortLE(); | ||
const swapType = packet.readPostNegativeOffsetByte(); | ||
const interfaceId = packet.readNegativeOffsetShortBE(); | ||
const fromSlot = packet.readShortLE(); | ||
|
||
if(toSlot < 0 || fromSlot < 0) { | ||
return; | ||
} | ||
|
||
if(swapType === 0) { | ||
// Swap | ||
swapItemAction(player, fromSlot, toSlot, interfaceId); | ||
} else if(swapType === 1) { | ||
// @TODO insert | ||
} | ||
}; |
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