forked from runejs/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bank command uses object interaction, support for fake widgets, suppo…
…rt for item-on-player and basic potato
- Loading branch information
Showing
19 changed files
with
489 additions
and
12 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
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
64 changes: 64 additions & 0 deletions
64
src/game-engine/net/inbound-packets/item-on-player-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,64 @@ | ||
import { logger } from '@runejs/core'; | ||
import { world } from '../../game-server'; | ||
import { World } from '../../world'; | ||
import { widgets } from '../../config'; | ||
import { Player } from "@engine/world/actor/player/player"; | ||
import { PacketData } from "@engine/net/inbound-packets"; | ||
|
||
const itemOnPlayerPacket = (player: Player, packet: PacketData) => { | ||
const { buffer } = packet; | ||
const playerIndex = buffer.get('SHORT', 'UNSIGNED', 'LITTLE_ENDIAN') - 1; | ||
const itemWidgetId = buffer.get('SHORT', 'SIGNED', 'LITTLE_ENDIAN'); | ||
const itemContainerId = buffer.get('SHORT'); | ||
const itemId = buffer.get('SHORT', 'UNSIGNED', 'BIG_ENDIAN'); | ||
const itemSlot = buffer.get('SHORT', 'UNSIGNED', 'BIG_ENDIAN'); | ||
|
||
|
||
let usedItem; | ||
if(itemWidgetId === widgets.inventory.widgetId && itemContainerId === widgets.inventory.containerId) { | ||
if(itemSlot < 0 || itemSlot > 27) { | ||
return; | ||
} | ||
|
||
usedItem = player.inventory.items[itemSlot]; | ||
if(!usedItem) { | ||
return; | ||
} | ||
|
||
if(usedItem.itemId !== itemId) { | ||
return; | ||
} | ||
} else { | ||
logger.warn(`Unhandled item on object case using widget ${ itemWidgetId }:${ itemContainerId }`); | ||
} | ||
|
||
|
||
if(playerIndex < 0 || playerIndex > World.MAX_PLAYERS - 1) { | ||
return; | ||
} | ||
|
||
const otherPlayer = world.playerList[playerIndex]; | ||
if(!otherPlayer) { | ||
return; | ||
} | ||
|
||
|
||
const position = otherPlayer.position; | ||
const distance = Math.floor(position.distanceBetween(player.position)); | ||
|
||
|
||
|
||
// Too far away | ||
if(distance > 16) { | ||
return; | ||
} | ||
|
||
|
||
player.actionPipeline.call('item_on_player', player, otherPlayer, position, usedItem, itemWidgetId, itemContainerId) | ||
}; | ||
|
||
export default { | ||
opcode: 110, | ||
size: 10, | ||
handler: itemOnPlayerPacket | ||
}; |
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,120 @@ | ||
import { Player } from '@engine/world/actor/player/player'; | ||
import { Position } from '@engine/world/position'; | ||
import { ActionHook, getActionHooks } from '@engine/world/action/hooks'; | ||
import { logger } from '@runejs/core'; | ||
import { Item } from '@engine/world/items/item'; | ||
import { Npc } from '@engine/world/actor/npc/npc'; | ||
import { playerWalkTo } from '@engine/game-server'; | ||
import { advancedNumberHookFilter, questHookFilter, stringHookFilter } from '@engine/world/action/hooks/hook-filters'; | ||
import { ActionPipe } from '@engine/world/action/index'; | ||
|
||
|
||
/** | ||
* Defines an item-on-player action hook. | ||
*/ | ||
export interface ItemOnPlayerActionHook extends ActionHook<itemOnPlayerActionHandler> { | ||
// A single game item ID or a list of item IDs that this action applies to. | ||
itemIds: number | number[]; | ||
// Whether or not the player needs to walk to this Player before performing the action. | ||
walkTo: boolean; | ||
} | ||
|
||
|
||
/** | ||
* The item-on-player action hook handler function to be called when the hook's conditions are met. | ||
*/ | ||
export type itemOnPlayerActionHandler = (itemOnPlayerAction: ItemOnPlayerAction) => void; | ||
|
||
|
||
/** | ||
* Details about an item-on-player action being performed. | ||
*/ | ||
export interface ItemOnPlayerAction { | ||
// The player performing the action. | ||
player: Player; | ||
// The player the action is being performed on. | ||
otherPlayer: Player; | ||
// The position that the Player was at when the action was initiated. | ||
position: Position; | ||
// The item being used. | ||
item: Item; | ||
// The ID of the UI widget that the item being used is in. | ||
itemWidgetId: number; | ||
// The ID of the UI container that the item being used is in. | ||
itemContainerId: number; | ||
} | ||
|
||
|
||
/** | ||
* The pipe that the game engine hands item-on-player actions off to. | ||
* @param player | ||
* @param otherPlayer | ||
* @param position | ||
* @param item | ||
* @param itemWidgetId | ||
* @param itemContainerId | ||
*/ | ||
const itemOnPlayerActionPipe = (player: Player, otherPlayer: Player, position: Position, item: Item, | ||
itemWidgetId: number, itemContainerId: number): void => { | ||
if(player.busy) { | ||
return; | ||
} | ||
|
||
// Find all item on player action plugins that reference this item | ||
let interactionActions = getActionHooks<ItemOnPlayerActionHook>('item_on_player').filter(plugin => | ||
questHookFilter(player, plugin) && advancedNumberHookFilter(plugin.itemIds, item.itemId)); | ||
const questActions = interactionActions.filter(plugin => plugin.questRequirement !== undefined); | ||
|
||
if(questActions.length !== 0) { | ||
interactionActions = questActions; | ||
} | ||
|
||
if(interactionActions.length === 0) { | ||
player.outgoingPackets.chatboxMessage(`Unhandled item on player interaction: ${ item.itemId } ` + | ||
`@ ${ position.x },${ position.y },${ position.level }`); | ||
return; | ||
} | ||
|
||
player.actionsCancelled.next(null); | ||
|
||
// Separate out walk-to actions from immediate actions | ||
const walkToPlugins = interactionActions.filter(plugin => plugin.walkTo); | ||
const immediateHooks = interactionActions.filter(plugin => !plugin.walkTo); | ||
|
||
// Make sure we walk to the player before running any of the walk-to plugins | ||
if(walkToPlugins.length !== 0) { | ||
playerWalkTo(player, position) | ||
.then(() => { | ||
player.face(position); | ||
|
||
walkToPlugins.forEach(plugin => | ||
plugin.handler({ | ||
player, | ||
otherPlayer, | ||
position, | ||
item, | ||
itemWidgetId, | ||
itemContainerId | ||
})); | ||
}) | ||
.catch(() => logger.warn(`Unable to complete walk-to action.`)); | ||
} | ||
|
||
// Immediately run any non-walk-to plugins | ||
for(const actionHook of immediateHooks) { | ||
actionHook.handler({ | ||
player, | ||
otherPlayer, | ||
position, | ||
item, | ||
itemWidgetId, | ||
itemContainerId | ||
}); | ||
} | ||
}; | ||
|
||
|
||
/** | ||
* Item-on-player action pipe definition. | ||
*/ | ||
export default [ 'item_on_player', itemOnPlayerActionPipe ] as ActionPipe; |
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
Oops, something went wrong.