mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
Created a new ScrollInterface similar to BookInterface
Implemented KnightsNotes in the new scroll interface
This commit is contained in:
parent
cb4c94f3ab
commit
0c54348f69
4 changed files with 122 additions and 8 deletions
|
|
@ -99712,7 +99712,7 @@
|
|||
},
|
||||
{
|
||||
"destroy_message": "You can reclaim this item from the place you found it.",
|
||||
"examine": "A scroll for Sir Tiffy. The wax seal is broken. / Before reading the scroll: A scroll for Sir Tiffy. It is sealed with a wax insignia.",
|
||||
"examine": "A scroll for Sir Tiffy. It is sealed with a wax insignia.",
|
||||
"durability": null,
|
||||
"name": "Knight's notes",
|
||||
"tradeable": "false",
|
||||
|
|
@ -99722,7 +99722,7 @@
|
|||
},
|
||||
{
|
||||
"destroy_message": "You can reclaim this item from the place you found it.",
|
||||
"examine": "A scroll for Sir Tiffy. The wax seal is broken. / Before reading the scroll: A scroll for Sir Tiffy. It is sealed with a wax insignia.",
|
||||
"examine": "A scroll for Sir Tiffy. The wax seal is broken.",
|
||||
"durability": null,
|
||||
"name": "Knight's notes",
|
||||
"tradeable": "false",
|
||||
|
|
|
|||
|
|
@ -14,9 +14,18 @@ import core.game.node.entity.player.Player
|
|||
* This will handle component(26), component(27) and component(49) globally.
|
||||
* DO NOT extend this class or override on(26), on(27), on(49) for defineInterfaceListeners.
|
||||
*
|
||||
* Instead, simply call BookInterface.pageSetup(...) and pass two attributes.
|
||||
* Instead, simply call BookInterface.pageSetup(...) and pass two attributes to open a book.
|
||||
* bookInterfaceCallback - function to callback (player: Player, pageNum: Int, buttonID: Int) : Boolean
|
||||
* bookInterfaceCurrentPage - 0 for first page.
|
||||
* Recommend creating a display() function both to be called when opening an item and passing it to the callback.
|
||||
*
|
||||
* You may at any time after pageSetup,
|
||||
* - call any functions below
|
||||
* - call player.packetDispatch.sendInterfaceConfig
|
||||
* - call player.packetDispatch.sendString
|
||||
*
|
||||
* @see content.region.desert.quest.thegolem.VarmensNotes for a quest-like example.
|
||||
* @see content.global.handlers.item.book.GeneralRuleBook for an interactive page-jumping book.
|
||||
*
|
||||
* @author ovenbreado
|
||||
*/
|
||||
|
|
@ -41,7 +50,7 @@ class BookInterface : InterfaceListener {
|
|||
/** Sets up standard pagination and page numbering. Call this for default setup of book components. */
|
||||
fun pageSetup(player: Player, bookComponent: Int, title: String, contents: Array<PageSet>) {
|
||||
val currentPage = getAttribute(player, "bookInterfaceCurrentPage", 0)
|
||||
closeInterface(player) // Important: Close previous book interfaces.
|
||||
closeInterface(player) // Important: Close previous interfaces.
|
||||
if (bookComponent == FANCY_BOOK_26) {
|
||||
openInterface(player, FANCY_BOOK_26) // Important: Opens the current interface.
|
||||
clearBookLines(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS);
|
||||
|
|
@ -115,14 +124,15 @@ class BookInterface : InterfaceListener {
|
|||
}
|
||||
}
|
||||
|
||||
/** Check book is read. Trigger off */
|
||||
/** Function to check if player read to the last page. For quest triggers. */
|
||||
fun isLastPage(pageNum: Int, totalPages: Int): Boolean {
|
||||
return pageNum == totalPages - 1;
|
||||
}
|
||||
|
||||
/** PRIVATE: Increments the current page and invokes the callback function. */
|
||||
private fun changePageAndCallback(player: Player, increment: Int, buttonId: Int) {
|
||||
val callback :((player: Player, pageNum: Int, buttonId: Int) -> Boolean)? = getAttribute(player, "bookInterfaceCallback", null)
|
||||
val callback: ((player: Player, pageNum: Int, buttonId: Int) -> Boolean)? =
|
||||
getAttribute(player, "bookInterfaceCallback", null)
|
||||
val currentPage = getAttribute(player, "bookInterfaceCurrentPage", 0)
|
||||
setAttribute(player, "bookInterfaceCurrentPage", currentPage + increment)
|
||||
|
||||
|
|
@ -166,6 +176,7 @@ class PageSet(vararg pages: Page) {
|
|||
this.pages = pages as Array<Page>
|
||||
}
|
||||
}
|
||||
|
||||
/** Constructs a new Page object. */
|
||||
class Page(vararg lines: BookLine) {
|
||||
val lines: Array<BookLine>
|
||||
|
|
@ -174,8 +185,9 @@ class Page(vararg lines: BookLine) {
|
|||
this.lines = lines as Array<BookLine>
|
||||
}
|
||||
}
|
||||
/** Constructs a new Page object. */
|
||||
class BookLine (
|
||||
|
||||
/** Constructs a new BookLine object. */
|
||||
class BookLine(
|
||||
val message: String,
|
||||
val child: Int
|
||||
)
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package content.global.handlers.iface
|
||||
|
||||
import core.api.closeInterface
|
||||
import core.api.openInterface
|
||||
import core.game.node.entity.player.Player
|
||||
import org.rs09.consts.Components
|
||||
|
||||
/**
|
||||
* Interface listener for Scrolls
|
||||
* Use this to set up a simple scroll display.
|
||||
*
|
||||
* Currently, scrolls do not happen to have any button interactions, so no listeners are here yet.
|
||||
* This is generally a helper class until certain scrolls require interactions.
|
||||
*
|
||||
* @author ovenbreado
|
||||
*/
|
||||
class ScrollInterface {
|
||||
|
||||
companion object {
|
||||
/** This is a 15-Lines scroll */
|
||||
private val MESSAGESCROLL_220_LINE_IDS = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
|
||||
|
||||
fun scrollSetup(player: Player, scrollComponent: Int, contents: Array<ScrollLine>) {
|
||||
closeInterface(player) // Important: Close previous interfaces.
|
||||
if (scrollComponent == Components.MESSAGESCROLL_220) {
|
||||
openInterface(player, Components.MESSAGESCROLL_220)
|
||||
setPageContent(player, Components.MESSAGESCROLL_220, MESSAGESCROLL_220_LINE_IDS, contents);
|
||||
}
|
||||
}
|
||||
|
||||
/** Set text contents of scroll */
|
||||
fun setPageContent(player: Player, componentId: Int, scrollLineIds: Array<Int>, contents: Array<ScrollLine>) {
|
||||
for (line in contents) {
|
||||
// This is to prevent error child lines being set and crashing the client.
|
||||
if (scrollLineIds.contains(line.child)) {
|
||||
player.packetDispatch.sendString(line.message, componentId, line.child)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Constructs a new ScrollLine object. */
|
||||
class ScrollLine(
|
||||
val message: String,
|
||||
val child: Int
|
||||
)
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package content.region.asgarnia.trollheim.dialogue
|
||||
|
||||
import content.global.handlers.iface.ScrollInterface
|
||||
import content.global.handlers.iface.ScrollLine
|
||||
import core.api.*
|
||||
import core.game.interaction.IntType
|
||||
import core.game.interaction.InteractionListener
|
||||
import org.rs09.consts.Items
|
||||
import org.rs09.consts.Components
|
||||
|
||||
/**
|
||||
* @author szu
|
||||
*/
|
||||
class KnightsNotes : InteractionListener {
|
||||
companion object {
|
||||
val CONTENTS = arrayOf(
|
||||
ScrollLine("My friend, you were right to send me to investigate the",3),
|
||||
ScrollLine("dwarf's drunken claims, for I have discovered a treasure",4),
|
||||
ScrollLine("beyond our wildest dreams. The aviantese are alive, and I",5),
|
||||
ScrollLine("suspect they still guard the godsword! Beneath the remnants",6),
|
||||
ScrollLine("of the temple a great battle is being fought between followers",7),
|
||||
ScrollLine("of Bandos, Armadyl, Saradomin and Zamorak. My command was",8),
|
||||
ScrollLine("slaughtered and I am grieviously wounded. YOU MUST PREVENT",9),
|
||||
ScrollLine("THE GODSWORD FROM FALLING INTO THE WRONG HANDS! I do not",10),
|
||||
ScrollLine("know how I am going to get this message to you, why is that",11),
|
||||
ScrollLine("talking skull never around when he's needed? Your comrade,",12),
|
||||
ScrollLine("Sir Gerry.",13),
|
||||
);
|
||||
}
|
||||
|
||||
override fun defineListeners() {
|
||||
// The scroll has not been opened. This will lead to a different dialogue with Sir Tiffy Cashien.
|
||||
on(Items.KNIGHTS_NOTES_11734, IntType.ITEM, "read") { player, _ ->
|
||||
sendDialogueOptions(player, "The scroll is sealed. Do you still want to open it?", "Yes", "No")
|
||||
player!!.packetDispatch.sendInterfaceConfig(228, 6, true)
|
||||
player!!.packetDispatch.sendInterfaceConfig(228, 9, false) // childId 7 is left 8 is right
|
||||
addDialogueAction(player) { player, button ->
|
||||
if (button == 2) {
|
||||
sendMessage(player, "You break the wax seal and open the scroll.");
|
||||
if (removeItem(player, Items.KNIGHTS_NOTES_11734)) {
|
||||
addItem(player, Items.KNIGHTS_NOTES_11735)
|
||||
ScrollInterface.scrollSetup(player, Components.MESSAGESCROLL_220, CONTENTS)
|
||||
}
|
||||
}
|
||||
return@addDialogueAction
|
||||
}
|
||||
return@on true
|
||||
}
|
||||
// The scroll has been read. This will lead to a different dialogue with Sir Tiffy Cashien.
|
||||
on(Items.KNIGHTS_NOTES_11735, IntType.ITEM, "read") { player, _ ->
|
||||
ScrollInterface.scrollSetup(player, Components.MESSAGESCROLL_220, CONTENTS)
|
||||
return@on true
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue