mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Improved how books are handled
Implemented admin model viewer ::models
This commit is contained in:
parent
3cf73ba09a
commit
d76b99c77a
30 changed files with 214 additions and 95 deletions
|
|
@ -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<PageSet>) {
|
||||
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<PageSet>, 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);
|
||||
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);
|
||||
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);
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
26
Server/src/main/core/net/packet/out/InterfaceSetAngle.java
Normal file
26
Server/src/main/core/net/packet/out/InterfaceSetAngle.java
Normal file
|
|
@ -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<DefaultContext> {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue