diff --git a/Server/src/main/content/global/handlers/iface/BookInterface.kt b/Server/src/main/content/global/handlers/iface/BookInterface.kt index ccb9d228d..0146e2bdb 100644 --- a/Server/src/main/content/global/handlers/iface/BookInterface.kt +++ b/Server/src/main/content/global/handlers/iface/BookInterface.kt @@ -14,10 +14,9 @@ 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 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. + * Instead, simply call BookInterface.openBook(...) in the listener and set the following attributes: + * bookInterfaceCallback - callback function for the page to display(player: Player, pageNum: Int, buttonID: Int) : Boolean + * You must create that display() function so that can be passed in the callback and display contents of each page. * * You may at any time after pageSetup, * - call any functions below @@ -32,6 +31,9 @@ import core.game.node.entity.player.Player class BookInterface : InterfaceListener { companion object { + const val CALLBACK_ATTRIBUTE = "bookInterfaceCallback"; + const val CURRENT_PAGE_ATTRIBUTE = "bookInterfaceCurrentPage"; + /* These should be in org.rs09.consts.Components but currently are not. */ const val FANCY_BOOK_26 = 26 // This is a 15-Lines per page book. const val FANCY_BOOK_2_27 = 27 // This is a 15-Lines per page book with index and row clickable listeners. @@ -47,30 +49,51 @@ class BookInterface : InterfaceListener { val FANCY_BOOK_2_27_BUTTON_IDS = arrayOf(1, 3, 159, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158) val FANCY_BOOK_3_49_BUTTON_IDS = arrayOf(51, 53); - /** 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) { - val currentPage = getAttribute(player, "bookInterfaceCurrentPage", 0) - closeInterface(player) // Important: Close previous interfaces. + /* Image IDs. [...lines 1 to X] */ + val FANCY_BOOK_2_27_IMAGE_ENABLE_DRAW_IDS = arrayOf(9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97); + val FANCY_BOOK_2_27_IMAGE_DRAW_IDS = arrayOf(10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98); + + /** Opens the book interface. Call this only once in the defineListeners() at the start of opening a book. */ + fun openBook(player: Player, bookComponent: Int, displayCallback: (player: Player, pageNum: Int, buttonId: Int) -> Boolean) { + closeInterface(player) // Important: Closes the previous interface. + setAttribute(player, CURRENT_PAGE_ATTRIBUTE, 0) // Resets the book to the first page. + setAttribute(player, CALLBACK_ATTRIBUTE, displayCallback) // Sets the display callback if (bookComponent == FANCY_BOOK_26) { openInterface(player, FANCY_BOOK_26) // Important: Opens the current interface. + } else if (bookComponent == FANCY_BOOK_2_27) { + openInterface(player, FANCY_BOOK_2_27) // Important: Opens the current interface. + } else if (bookComponent == FANCY_BOOK_3_49) { + openInterface(player, FANCY_BOOK_3_49) // Important: Opens the current interface. + } + displayCallback.invoke(player, 0, 0) + } + + /** Sets up title, pagination and content. Call this in the display callback every time the page changes. */ + fun pageSetup(player: Player, bookComponent: Int, title: String, contents: Array, hasPagination: Boolean = true) { + val currentPage = getAttribute(player, CURRENT_PAGE_ATTRIBUTE, 0) + if (bookComponent == FANCY_BOOK_26) { clearBookLines(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS); clearButtons(player, FANCY_BOOK_26, FANCY_BOOK_26_BUTTON_IDS); setTitle(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS, title); - setPagination(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS, FANCY_BOOK_26_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + if (hasPagination) { + setPagination(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS, FANCY_BOOK_26_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + } setPageContent(player, FANCY_BOOK_26, FANCY_BOOK_26_LINE_IDS, FANCY_BOOK_26_BUTTON_IDS, currentPage, contents); } else if (bookComponent == FANCY_BOOK_2_27) { - openInterface(player, FANCY_BOOK_2_27) // Important: Opens the current interface. clearBookLines(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_LINE_IDS); clearButtons(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_BUTTON_IDS); setTitle(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_LINE_IDS, title); - setPagination(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_LINE_IDS, FANCY_BOOK_2_27_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + if (hasPagination) { + setPagination(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_LINE_IDS, FANCY_BOOK_2_27_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + } setPageContent(player, FANCY_BOOK_2_27, FANCY_BOOK_2_27_LINE_IDS, FANCY_BOOK_2_27_BUTTON_IDS, currentPage, contents); } else if (bookComponent == FANCY_BOOK_3_49) { - openInterface(player, FANCY_BOOK_3_49) // Important: Opens the current interface. clearBookLines(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_LINE_IDS); clearButtons(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_BUTTON_IDS); setTitle(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_LINE_IDS, title); - setPagination(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_LINE_IDS, FANCY_BOOK_3_49_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + if (hasPagination) { + setPagination(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_LINE_IDS, FANCY_BOOK_3_49_BUTTON_IDS, currentPage, contents.size, contents[currentPage].pages.size == 1) + } setPageContent(player, FANCY_BOOK_3_49, FANCY_BOOK_3_49_LINE_IDS, FANCY_BOOK_3_49_BUTTON_IDS, currentPage, contents); } } @@ -102,8 +125,14 @@ class BookInterface : InterfaceListener { player.packetDispatch.sendString("" + (currentPage * 2 + 1), componentId, bookLineIds[1]) player.packetDispatch.sendString("" + (currentPage * 2 + 2), componentId, bookLineIds[2]) if (hasRightPage) { - // If there's no right side page, remove the page number. Usually for odd page books. - player.packetDispatch.sendString("", componentId, BookInterface.FANCY_BOOK_26_LINE_IDS[2]) + // If there's no right side page, remove the page number. Usually for odd paged books. + if (componentId == FANCY_BOOK_26) { + player.packetDispatch.sendString("", componentId, FANCY_BOOK_26_LINE_IDS[2]) + } else if (componentId == FANCY_BOOK_2_27) { + player.packetDispatch.sendString("", componentId, FANCY_BOOK_2_27_LINE_IDS[2]) + } else if (componentId == FANCY_BOOK_3_49) { + player.packetDispatch.sendString("", componentId, FANCY_BOOK_3_49_LINE_IDS[2]) + } } } @@ -124,6 +153,17 @@ class BookInterface : InterfaceListener { } } + /** Sets models(pictures) on lineId of pageSet (0 index). Call this in the display function after pageSetup. */ + fun setModelOnPage(player: Player, pageSet: Int, modelId: Int, componentId: Int, enableLineId: Int, drawLineId: Int, zoom: Int, pitch: Int, yaw: Int) { + if (pageSet == getAttribute(player, CURRENT_PAGE_ATTRIBUTE, 0)) { + player.packetDispatch.sendInterfaceConfig(componentId, enableLineId, false) + player.packetDispatch.sendModelOnInterface(modelId, componentId, drawLineId, 0) + player.packetDispatch.sendAngleOnInterface(componentId, drawLineId, zoom, pitch, yaw) + } else { + player.packetDispatch.sendInterfaceConfig(componentId, enableLineId, true) + } + } + /** Function to check if player read to the last page. For quest triggers. */ fun isLastPage(pageNum: Int, totalPages: Int): Boolean { return pageNum == totalPages - 1; @@ -132,9 +172,9 @@ class BookInterface : InterfaceListener { /** 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 currentPage = getAttribute(player, "bookInterfaceCurrentPage", 0) - setAttribute(player, "bookInterfaceCurrentPage", currentPage + increment) + getAttribute(player, CALLBACK_ATTRIBUTE, null) + val currentPage = getAttribute(player, CURRENT_PAGE_ATTRIBUTE, 0) + setAttribute(player, CURRENT_PAGE_ATTRIBUTE, currentPage + increment) callback?.invoke(player, currentPage + increment, buttonId) } diff --git a/Server/src/main/content/global/handlers/item/book/GeneralRuleBook.kt b/Server/src/main/content/global/handlers/item/book/GeneralRuleBook.kt index 9e1bbf267..12a6be03f 100644 --- a/Server/src/main/content/global/handlers/item/book/GeneralRuleBook.kt +++ b/Server/src/main/content/global/handlers/item/book/GeneralRuleBook.kt @@ -4,8 +4,7 @@ import content.global.handlers.iface.BookInterface import content.global.handlers.iface.BookLine import content.global.handlers.iface.Page import content.global.handlers.iface.PageSet -import core.api.getAttribute -import core.api.setAttribute +import core.api.* import core.game.interaction.IntType import core.game.interaction.InteractionListener import core.game.node.entity.player.Player @@ -204,9 +203,7 @@ class GeneralRuleBook { /** Since the Town Crier shows you the book, there is no item here. */ fun openBook(player: Player) { - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_2_27, ::display) } } } \ No newline at end of file diff --git a/Server/src/main/content/global/handlers/item/book/GrimDiary.kt b/Server/src/main/content/global/handlers/item/book/GrimDiary.kt index 3c627d58d..1567391c3 100644 --- a/Server/src/main/content/global/handlers/item/book/GrimDiary.kt +++ b/Server/src/main/content/global/handlers/item/book/GrimDiary.kt @@ -132,9 +132,7 @@ class GrimDiary : InteractionListener { override fun defineListeners() { on(Items.THE_GRIM_REAPERS_DIARY_11780, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_26, ::display) return@on true } } diff --git a/Server/src/main/content/global/handlers/item/book/SecurityBookPlugin.kt b/Server/src/main/content/global/handlers/item/book/SecurityBookPlugin.kt index 803c861b1..4813fed18 100644 --- a/Server/src/main/content/global/handlers/item/book/SecurityBookPlugin.kt +++ b/Server/src/main/content/global/handlers/item/book/SecurityBookPlugin.kt @@ -127,9 +127,7 @@ class SecurityBookPlugin : InteractionListener { override fun defineListeners() { on(Items.SECURITY_BOOK_9003, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_2_27, ::display) return@on true } } diff --git a/Server/src/main/content/global/handlers/item/book/StrongholdNotes.kt b/Server/src/main/content/global/handlers/item/book/StrongholdNotes.kt index fb29dd00f..4a67ee93f 100644 --- a/Server/src/main/content/global/handlers/item/book/StrongholdNotes.kt +++ b/Server/src/main/content/global/handlers/item/book/StrongholdNotes.kt @@ -129,9 +129,7 @@ class StrongholdNotes : InteractionListener { override fun defineListeners() { on(Items.STRONGHOLD_NOTES_9004, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_2_27, ::display) return@on true } } diff --git a/Server/src/main/content/region/asgarnia/taverley/quest/witchshouse/WitchesDiaryBook.kt b/Server/src/main/content/region/asgarnia/taverley/quest/witchshouse/WitchesDiaryBook.kt index cf3a9ae91..457f44a5f 100644 --- a/Server/src/main/content/region/asgarnia/taverley/quest/witchshouse/WitchesDiaryBook.kt +++ b/Server/src/main/content/region/asgarnia/taverley/quest/witchshouse/WitchesDiaryBook.kt @@ -130,9 +130,7 @@ class WitchesDiaryBook : InteractionListener { override fun defineListeners() { on(Items.DIARY_2408, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/desert/quest/thegolem/VarmensNotes.kt b/Server/src/main/content/region/desert/quest/thegolem/VarmensNotes.kt index f4ee117f8..75cafd258 100644 --- a/Server/src/main/content/region/desert/quest/thegolem/VarmensNotes.kt +++ b/Server/src/main/content/region/desert/quest/thegolem/VarmensNotes.kt @@ -289,9 +289,7 @@ class VarmensNotes : InteractionListener { override fun defineListeners() { on(Items.VARMENS_NOTES_4616, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/dialogue/AstronomyBook.kt b/Server/src/main/content/region/kandarin/dialogue/AstronomyBook.kt index 4c1a353e0..db9971ffe 100644 --- a/Server/src/main/content/region/kandarin/dialogue/AstronomyBook.kt +++ b/Server/src/main/content/region/kandarin/dialogue/AstronomyBook.kt @@ -122,9 +122,7 @@ class AstronomyBook : InteractionListener { override fun defineListeners() { on(Items.ASTRONOMY_BOOK_600, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/dialogue/BindingBook.kt b/Server/src/main/content/region/kandarin/dialogue/BindingBook.kt index a7af347ca..3318d9077 100644 --- a/Server/src/main/content/region/kandarin/dialogue/BindingBook.kt +++ b/Server/src/main/content/region/kandarin/dialogue/BindingBook.kt @@ -142,9 +142,7 @@ class BindingBook : InteractionListener { override fun defineListeners() { on(Items.BINDING_BOOK_730, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/dialogue/GiannesCookBook.kt b/Server/src/main/content/region/kandarin/dialogue/GiannesCookBook.kt index 32e6ce64d..e663c99ba 100644 --- a/Server/src/main/content/region/kandarin/dialogue/GiannesCookBook.kt +++ b/Server/src/main/content/region/kandarin/dialogue/GiannesCookBook.kt @@ -331,9 +331,7 @@ class GiannesCookBook : InteractionListener { override fun defineListeners() { on(Items.GIANNES_COOK_BOOK_2167, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/dialogue/ShamansTomeBook.kt b/Server/src/main/content/region/kandarin/dialogue/ShamansTomeBook.kt index a42792953..9559fa9fa 100644 --- a/Server/src/main/content/region/kandarin/dialogue/ShamansTomeBook.kt +++ b/Server/src/main/content/region/kandarin/dialogue/ShamansTomeBook.kt @@ -48,9 +48,7 @@ class ShamansTomeBook : InteractionListener { override fun defineListeners() { on(Items.SHAMANS_TOME_729, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/quest/dwarfcannon/NulodionsNotes.kt b/Server/src/main/content/region/kandarin/quest/dwarfcannon/NulodionsNotes.kt index 6a4107846..9d9aea830 100644 --- a/Server/src/main/content/region/kandarin/quest/dwarfcannon/NulodionsNotes.kt +++ b/Server/src/main/content/region/kandarin/quest/dwarfcannon/NulodionsNotes.kt @@ -35,9 +35,7 @@ class NulodionsNotes : InteractionListener { override fun defineListeners() { on(Items.NULODIONS_NOTES_3, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/quest/dwarfcannon/dmc/DMCManual.kt b/Server/src/main/content/region/kandarin/quest/dwarfcannon/dmc/DMCManual.kt index b14e62c89..fa22f2bed 100644 --- a/Server/src/main/content/region/kandarin/quest/dwarfcannon/dmc/DMCManual.kt +++ b/Server/src/main/content/region/kandarin/quest/dwarfcannon/dmc/DMCManual.kt @@ -88,9 +88,7 @@ class DMCManual : InteractionListener { override fun defineListeners() { on(Items.INSTRUCTION_MANUAL_5, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/quest/grandtree/GloughsJournal.kt b/Server/src/main/content/region/kandarin/quest/grandtree/GloughsJournal.kt index 90983d7ef..e6c57f0cc 100644 --- a/Server/src/main/content/region/kandarin/quest/grandtree/GloughsJournal.kt +++ b/Server/src/main/content/region/kandarin/quest/grandtree/GloughsJournal.kt @@ -126,9 +126,7 @@ class GloughsJournal : InteractionListener { override fun defineListeners() { on(Items.GLOUGHS_JOURNAL_785, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/quest/grandtree/TranslationBook.kt b/Server/src/main/content/region/kandarin/quest/grandtree/TranslationBook.kt index 3ec08a676..a4c5c7bd9 100644 --- a/Server/src/main/content/region/kandarin/quest/grandtree/TranslationBook.kt +++ b/Server/src/main/content/region/kandarin/quest/grandtree/TranslationBook.kt @@ -132,9 +132,7 @@ class TranslationBook : InteractionListener { override fun defineListeners() { on(Items.TRANSLATION_BOOK_784, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/quest/waterfall/BaxtorianBook.kt b/Server/src/main/content/region/kandarin/quest/waterfall/BaxtorianBook.kt index 2b3353547..c3f1bf63f 100644 --- a/Server/src/main/content/region/kandarin/quest/waterfall/BaxtorianBook.kt +++ b/Server/src/main/content/region/kandarin/quest/waterfall/BaxtorianBook.kt @@ -152,9 +152,7 @@ class BaxtorianBook : InteractionListener { override fun defineListeners() { on(Items.BOOK_ON_BAXTORIAN_292, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/BatteredBookHandler.kt b/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/BatteredBookHandler.kt index 36efe94c5..ec157b031 100644 --- a/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/BatteredBookHandler.kt +++ b/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/BatteredBookHandler.kt @@ -32,9 +32,7 @@ class BatteredBookHandler : InteractionListener { override fun defineListeners() { on(Items.BATTERED_BOOK_2886, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/SlashedBookHandler.kt b/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/SlashedBookHandler.kt index c720fcbfc..9c10a3cb1 100644 --- a/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/SlashedBookHandler.kt +++ b/Server/src/main/content/region/kandarin/seers/quest/elementalworkshop/SlashedBookHandler.kt @@ -25,9 +25,7 @@ class SlashedBookHandler : InteractionListener { override fun defineListeners() { on(Items.SLASHED_BOOK_9715, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/karamja/quest/tribaltotem/ArdougneGuideBook.kt b/Server/src/main/content/region/karamja/quest/tribaltotem/ArdougneGuideBook.kt index 2f58869aa..74ce79ed9 100644 --- a/Server/src/main/content/region/karamja/quest/tribaltotem/ArdougneGuideBook.kt +++ b/Server/src/main/content/region/karamja/quest/tribaltotem/ArdougneGuideBook.kt @@ -117,9 +117,7 @@ class ArdougneGuideBook : InteractionListener { override fun defineListeners() { on(Items.GUIDE_BOOK_1856, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/digsite/dialogue/ChemicalsBook.kt b/Server/src/main/content/region/misthalin/digsite/dialogue/ChemicalsBook.kt index 09ed93db8..b0e51fa1a 100644 --- a/Server/src/main/content/region/misthalin/digsite/dialogue/ChemicalsBook.kt +++ b/Server/src/main/content/region/misthalin/digsite/dialogue/ChemicalsBook.kt @@ -76,9 +76,7 @@ class ChemicalsBook : InteractionListener { override fun defineListeners() { on(Items.BOOK_ON_CHEMICALS_711, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/draynor/dialogue/ChickenBook.kt b/Server/src/main/content/region/misthalin/draynor/dialogue/ChickenBook.kt index 67ed41a85..f8e06d5ee 100644 --- a/Server/src/main/content/region/misthalin/draynor/dialogue/ChickenBook.kt +++ b/Server/src/main/content/region/misthalin/draynor/dialogue/ChickenBook.kt @@ -104,9 +104,7 @@ class ChickenBook : InteractionListener { override fun defineListeners() { on(Items.BOOK_ON_CHICKENS_7464, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/draynor/dialogue/FolkloreBook.kt b/Server/src/main/content/region/misthalin/draynor/dialogue/FolkloreBook.kt index f64063ff6..1ad19ee1a 100644 --- a/Server/src/main/content/region/misthalin/draynor/dialogue/FolkloreBook.kt +++ b/Server/src/main/content/region/misthalin/draynor/dialogue/FolkloreBook.kt @@ -53,9 +53,7 @@ class FolkloreBook : InteractionListener { override fun defineListeners() { on(Items.BOOK_OF_FOLKLORE_5508, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/draynor/dialogue/StrangeBook.kt b/Server/src/main/content/region/misthalin/draynor/dialogue/StrangeBook.kt index 35fe868e0..3def67ce9 100644 --- a/Server/src/main/content/region/misthalin/draynor/dialogue/StrangeBook.kt +++ b/Server/src/main/content/region/misthalin/draynor/dialogue/StrangeBook.kt @@ -240,9 +240,7 @@ class StrangeBook : InteractionListener { override fun defineListeners() { on(Items.STRANGE_BOOK_5507, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/varrock/dialogue/surok/AbyssalBook.kt b/Server/src/main/content/region/misthalin/varrock/dialogue/surok/AbyssalBook.kt index 230c37660..76d8eefb3 100644 --- a/Server/src/main/content/region/misthalin/varrock/dialogue/surok/AbyssalBook.kt +++ b/Server/src/main/content/region/misthalin/varrock/dialogue/surok/AbyssalBook.kt @@ -372,9 +372,7 @@ class AbyssalBook : InteractionListener { override fun defineListeners() { on(Items.ABYSSAL_BOOK_5520, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/content/region/misthalin/varrock/quest/shieldofarrav/ShieldofArravBook.kt b/Server/src/main/content/region/misthalin/varrock/quest/shieldofarrav/ShieldofArravBook.kt index 3aed0d317..faebb66c3 100644 --- a/Server/src/main/content/region/misthalin/varrock/quest/shieldofarrav/ShieldofArravBook.kt +++ b/Server/src/main/content/region/misthalin/varrock/quest/shieldofarrav/ShieldofArravBook.kt @@ -96,9 +96,7 @@ class ShieldofArravBook : InteractionListener { override fun defineListeners() { on(Items.BOOK_757, IntType.ITEM, "read") { player, _ -> - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_3_49, ::display) return@on true } } diff --git a/Server/src/main/core/game/node/entity/player/link/PacketDispatch.java b/Server/src/main/core/game/node/entity/player/link/PacketDispatch.java index 3a315c307..08adc715b 100644 --- a/Server/src/main/core/game/node/entity/player/link/PacketDispatch.java +++ b/Server/src/main/core/game/node/entity/player/link/PacketDispatch.java @@ -219,6 +219,10 @@ public final class PacketDispatch { PacketRepository.send(DisplayModel.class, new DisplayModelContext(player, ModelType.MODEL, modelID,zoom,interfaceId,childId,new Object())); } + public void sendAngleOnInterface(int interfaceId, int childId, int zoom, int pitch, int yaw){ + PacketRepository.send(InterfaceSetAngle.class, new DefaultContext(player, pitch, zoom, yaw, interfaceId, childId)); + } + /** * Send the item on interface packet. * @param itemId The item id. diff --git a/Server/src/main/core/game/system/command/sets/ModelViewerCommandSet.kt b/Server/src/main/core/game/system/command/sets/ModelViewerCommandSet.kt new file mode 100644 index 000000000..bdef8ed1f --- /dev/null +++ b/Server/src/main/core/game/system/command/sets/ModelViewerCommandSet.kt @@ -0,0 +1,99 @@ +package core.game.system.command.sets + +import content.global.handlers.iface.BookInterface +import core.api.* +import core.game.node.entity.player.Player +import core.game.system.command.Privilege +import core.plugin.Initializable + +/** To view models in game. */ +@Initializable +class ModelViewerCommandSet : CommandSet(Privilege.ADMIN) { + companion object { + + const val DEF_BOOK = 10216 + const val TITLE = "Model Viewer" + const val ATTRIBUTE_MODEL_NUMBER = "modelNumber" + const val ATTRIBUTE_ZOOM = "modelZoom" + const val ATTRIBUTE_PITCH = "modelPitch" + const val ATTRIBUTE_YAW = "modelYaw" + + private fun display(player: Player, pageNum: Int, buttonID: Int) : Boolean { + BookInterface.clearBookLines(player, BookInterface.FANCY_BOOK_2_27, BookInterface.FANCY_BOOK_2_27_LINE_IDS); + BookInterface.clearButtons(player, BookInterface.FANCY_BOOK_2_27, BookInterface.FANCY_BOOK_2_27_BUTTON_IDS); + BookInterface.setTitle(player, BookInterface.FANCY_BOOK_2_27, BookInterface.FANCY_BOOK_2_27_LINE_IDS, TITLE); + + // Custom button interfaces for model book + // These are non-standard. No pages are "turned" here. + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 114, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 116, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 118, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 122, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 124, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 126, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 128, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 144, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 146, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 148, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 152, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 154, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 156, false) + player.packetDispatch.sendInterfaceConfig(BookInterface.FANCY_BOOK_2_27, 158, false) + player.packetDispatch.sendString("-1 zoom" ,BookInterface.FANCY_BOOK_2_27, 114) + player.packetDispatch.sendString("-1 pitch" ,BookInterface.FANCY_BOOK_2_27, 116) + player.packetDispatch.sendString("-1 yaw" ,BookInterface.FANCY_BOOK_2_27, 118) + player.packetDispatch.sendString("-1" ,BookInterface.FANCY_BOOK_2_27, 122) + player.packetDispatch.sendString("-10" ,BookInterface.FANCY_BOOK_2_27, 124) + player.packetDispatch.sendString("-100" ,BookInterface.FANCY_BOOK_2_27, 126) + player.packetDispatch.sendString("-1000" ,BookInterface.FANCY_BOOK_2_27, 128) + player.packetDispatch.sendString("+1 zoom" ,BookInterface.FANCY_BOOK_2_27, 144) + player.packetDispatch.sendString("+1 pitch" ,BookInterface.FANCY_BOOK_2_27, 146) + player.packetDispatch.sendString("+1 yaw" ,BookInterface.FANCY_BOOK_2_27, 148) + player.packetDispatch.sendString("+1" ,BookInterface.FANCY_BOOK_2_27, 152) + player.packetDispatch.sendString("+10" ,BookInterface.FANCY_BOOK_2_27, 154) + player.packetDispatch.sendString("+100" ,BookInterface.FANCY_BOOK_2_27, 156) + player.packetDispatch.sendString("+1000" ,BookInterface.FANCY_BOOK_2_27, 158) + + // Attach buttons to setAttributes + when (buttonID) { + 114 -> setAttribute(player, ATTRIBUTE_ZOOM, getAttribute(player, ATTRIBUTE_ZOOM, 700) - 100) + 116 -> setAttribute(player, ATTRIBUTE_PITCH, getAttribute(player, ATTRIBUTE_PITCH, 0) - 100) + 118 -> setAttribute(player, ATTRIBUTE_YAW, getAttribute(player, ATTRIBUTE_YAW, 0) - 100) + 122 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) - 1) + 124 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) - 10) + 126 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) - 100) + 128 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) - 1000) + 144 -> setAttribute(player, ATTRIBUTE_ZOOM, getAttribute(player, ATTRIBUTE_ZOOM, 700) + 100) + 146 -> setAttribute(player, ATTRIBUTE_PITCH, getAttribute(player, ATTRIBUTE_PITCH, 0) + 100) + 148 -> setAttribute(player, ATTRIBUTE_YAW, getAttribute(player, ATTRIBUTE_YAW, 0) + 100) + 152 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 1) + 154 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 10) + 156 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 100) + 158 -> setAttribute(player, ATTRIBUTE_MODEL_NUMBER, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 1000) + } + + // Display model number + player.packetDispatch.sendString("No: " + getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + " " + getAttribute(player, ATTRIBUTE_ZOOM, 700) + " " + getAttribute(player, ATTRIBUTE_PITCH, 0) + " " + getAttribute(player, ATTRIBUTE_YAW, 0),BookInterface.FANCY_BOOK_2_27, 38) + player.packetDispatch.sendString("No: " + (getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 1),BookInterface.FANCY_BOOK_2_27, 53) + + // Display the models in the middle + BookInterface.setModelOnPage(player,0, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK), BookInterface.FANCY_BOOK_2_27, BookInterface.FANCY_BOOK_2_27_IMAGE_ENABLE_DRAW_IDS[7], BookInterface.FANCY_BOOK_2_27_IMAGE_DRAW_IDS[7], getAttribute(player, ATTRIBUTE_ZOOM, 700), getAttribute(player, ATTRIBUTE_PITCH, 0), getAttribute(player, ATTRIBUTE_YAW, 0)) + BookInterface.setModelOnPage(player,0, getAttribute(player, ATTRIBUTE_MODEL_NUMBER, DEF_BOOK) + 1, BookInterface.FANCY_BOOK_2_27, BookInterface.FANCY_BOOK_2_27_IMAGE_ENABLE_DRAW_IDS[22], BookInterface.FANCY_BOOK_2_27_IMAGE_DRAW_IDS[22], getAttribute(player, ATTRIBUTE_ZOOM, 700), getAttribute(player, ATTRIBUTE_PITCH, 0), getAttribute(player, ATTRIBUTE_YAW, 0)) + + return true + } + } + override fun defineCommands() { + define("models"){ player, args -> + + // Bad number of args + if(args.size > 2){ + reject(player,"Usage: ::models") + return@define + } + + BookInterface.openBook(player, BookInterface.FANCY_BOOK_2_27, ::display) + return@define + } + } +} \ No newline at end of file diff --git a/Server/src/main/core/game/system/command/sets/StatsCommandSet.kt b/Server/src/main/core/game/system/command/sets/StatsCommandSet.kt index 01370d6ae..33ff9a4bc 100644 --- a/Server/src/main/core/game/system/command/sets/StatsCommandSet.kt +++ b/Server/src/main/core/game/system/command/sets/StatsCommandSet.kt @@ -188,10 +188,8 @@ class StatsCommandSet : CommandSet(Privilege.STANDARD) { return@define } - setAttribute(player, "bookInterfaceCallback", ::display) - setAttribute(player, "bookInterfaceCurrentPage", 0) setAttribute(player, "stats-command-query-player", queryPlayer) - display(player, 0, 0) + BookInterface.openBook(player, BookInterface.FANCY_BOOK_26, ::display) return@define } } diff --git a/Server/src/main/core/net/packet/PacketRepository.java b/Server/src/main/core/net/packet/PacketRepository.java index 87e28cf7e..3fcfabcfd 100644 --- a/Server/src/main/core/net/packet/PacketRepository.java +++ b/Server/src/main/core/net/packet/PacketRepository.java @@ -77,6 +77,7 @@ public final class PacketRepository { OUTGOING_PACKETS.put(Varbit.class, new Varbit()); OUTGOING_PACKETS.put(ResetInterface.class, new ResetInterface()); OUTGOING_PACKETS.put(VarcUpdate.class, new VarcUpdate()); + OUTGOING_PACKETS.put(InterfaceSetAngle.class, new InterfaceSetAngle()); } /** diff --git a/Server/src/main/core/net/packet/out/InterfaceSetAngle.java b/Server/src/main/core/net/packet/out/InterfaceSetAngle.java new file mode 100644 index 000000000..835419cf4 --- /dev/null +++ b/Server/src/main/core/net/packet/out/InterfaceSetAngle.java @@ -0,0 +1,26 @@ +package core.net.packet.out; + +import core.game.node.entity.player.Player; +import core.net.packet.context.DefaultContext; +import core.net.packet.IoBuffer; +import core.net.packet.OutgoingPacket; + +public final class InterfaceSetAngle implements OutgoingPacket { + @Override + public void send(DefaultContext context) { + Player player = context.getPlayer(); + Object[] objects = context.getObjects(); + int pitch = (Integer)objects[0]; + int scale = (Integer)objects[1]; + int yaw = (Integer)objects[2]; + int interfaceId = (Integer)objects[3]; + int childId = (Integer)objects[4]; + IoBuffer buffer = new IoBuffer(132); + buffer.putShort(pitch); + buffer.putShortA(player.getInterfaceManager().getPacketCount(1)); + buffer.putLEShortA(scale); + buffer.putLEShortA(yaw); + buffer.putInt(interfaceId << 16 | childId); + buffer.cypherOpcode(context.getPlayer().getSession().getIsaacPair().getOutput());context.getPlayer().getSession().write(buffer); + } +} \ No newline at end of file