-
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 #111 from Promises/master
item on npc, and abusing sheep
- Loading branch information
Showing
15 changed files
with
351 additions
and
55 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
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,60 @@ | ||
import { incomingPacket } from '../incoming-packet'; | ||
import { Player } from '../../world/actor/player/player'; | ||
import { RsBuffer } from '@server/net/rs-buffer'; | ||
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'; | ||
import { Position } from '@server/world/position'; | ||
import { gameCache, world } from '@server/game-server'; | ||
import { objectAction } from '@server/world/actor/player/action/object-action'; | ||
import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; | ||
import { World } from '@server/world/world'; | ||
import { npcAction } from '@server/world/actor/player/action/npc-action'; | ||
import { itemOnNpcAction } from '@server/world/actor/player/action/item-on-npc-action'; | ||
|
||
export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { | ||
const npcIndex = packet.readNegativeOffsetShortBE(); | ||
const itemId = packet.readNegativeOffsetShortBE(); | ||
const itemSlot = packet.readNegativeOffsetShortLE(); | ||
const itemWidgetId = packet.readShortBE(); | ||
const itemContainerId = packet.readShortBE(); | ||
|
||
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 (npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) { | ||
return; | ||
} | ||
|
||
const npc = world.npcList[npcIndex]; | ||
if (!npc) { | ||
return; | ||
} | ||
|
||
const position = npc.position; | ||
const distance = Math.floor(position.distanceBetween(player.position)); | ||
|
||
// Too far away | ||
if (distance > 16) { | ||
return; | ||
} | ||
|
||
itemOnNpcAction(player, npc, position, usedItem, itemWidgetId, itemContainerId); | ||
|
||
}; |
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,54 @@ | ||
import { ActionType, RunePlugin } from '@server/plugins/plugin'; | ||
import { npcIds } from '@server/world/config/npc-ids'; | ||
import { npcInitAction } from '@server/world/actor/npc/npc'; | ||
import { World } from '@server/world/world'; | ||
import { itemOnNpcAction } from '@server/world/actor/player/action/item-on-npc-action'; | ||
import { itemIds } from '@server/world/config/item-ids'; | ||
import { soundIds } from '@server/world/config/sound-ids'; | ||
import { animationIds } from '@server/world/config/animation-ids'; | ||
|
||
const initAction: npcInitAction = (details) => { | ||
setInterval(() => { | ||
if (Math.random() >= 0.66) { | ||
details.npc.updateFlags.addChatMessage({message: `Baa!`}); | ||
details.npc.sendSound(soundIds.sheepBaa, 4); | ||
} | ||
}, (Math.floor(Math.random() * 20) + 10) * World.TICK_LENGTH); | ||
}; | ||
|
||
export const shearAction: itemOnNpcAction = (details) => { | ||
details.player.busy = true; | ||
details.player.playAnimation(animationIds.shearSheep); | ||
details.player.outgoingPackets.playSound(soundIds.shearSheep, 5); | ||
|
||
setTimeout(() => { | ||
if (Math.random() >= 0.66) { | ||
details.player.outgoingPackets.chatboxMessage('The sheep manages to get away from you!'); | ||
// TODO: move sheep backwards about 5 tiles, moonwalk, not turn around | ||
} else { | ||
details.player.outgoingPackets.chatboxMessage('You get some wool.'); | ||
details.player.giveItem(itemIds.wool); | ||
details.npc.updateFlags.addChatMessage({message: 'Baa!'}); | ||
details.npc.sendSound(soundIds.sheepBaa, 4); | ||
//TODO: Replace with naked sheep | ||
|
||
} | ||
details.player.busy = false; | ||
}, World.TICK_LENGTH); | ||
|
||
}; | ||
export default new RunePlugin([ | ||
{ | ||
type: ActionType.NPC_INIT, | ||
npcIds: npcIds.sheep, | ||
action: initAction | ||
}, | ||
{ | ||
type: ActionType.ITEM_ON_NPC_ACTION, | ||
npcsIds: [npcIds.sheep], | ||
itemIds: [itemIds.shears, itemIds.recruitmentDrive.shears], | ||
walkTo: true, | ||
action: shearAction | ||
} | ||
] | ||
); |
Oops, something went wrong.