More work on the shelf listener

This commit is contained in:
gregf36665 2024-12-22 18:40:54 +00:00 committed by Syndromeramo
parent a0cd34a1af
commit 655d5f0e06

View file

@ -1,58 +1,98 @@
package content.global.skill.construction.decoration.kitchen package content.global.skill.construction.decoration.kitchen
import core.api.* import core.api.*
import core.game.dialogue.*
import core.game.interaction.IntType import core.game.interaction.IntType
import core.game.interaction.InteractionListener import core.game.interaction.InteractionListener
import core.game.node.entity.player.Player import core.game.node.entity.player.Player
import core.tools.END_DIALOGUE
import org.rs09.consts.Items import org.rs09.consts.Items
import org.rs09.consts.Scenery import org.rs09.consts.Scenery
import kotlin.math.min
class ShelfListener : InteractionListener { class ShelfListener : InteractionListener {
companion object{
const val NEXT = 5
const val PREV = -5
val woodshelf_1_items = listOf(
"Kettle" to Items.KETTLE_7688,
"Teapot" to Items.TEAPOT_7702,
"Clay Cup" to Items.EMPTY_CUP_7728
)
val woodshelf_2_items = woodshelf_1_items + mapOf(
"Empty beer glass" to Items.BEER_GLASS_1919
)
val shelves = mapOf(
Scenery.SHELVES_13545 to woodshelf_1_items
)
}
override fun defineListeners() { override fun defineListeners() {
on(shelves.keys.toIntArray(), IntType.SCENERY, "Search") {player, node -> on(ShelfDialogue.shelves.keys.toIntArray(), IntType.SCENERY, "Search") {player, node ->
searchShelf(player, node.id) searchShelf(player, node.id)
return@on true return@on true
} }
} }
fun searchShelf(player : Player, shelf_id: Int, offset : Int = 0){ private fun searchShelf(player : Player, shelfId: Int){
val shelfItems = shelves[shelf_id]!!.slice(offset..offset+4) openDialogue(player, ShelfDialogue(shelfId, 0))
}
class ShelfDialogue(val shelfId: Int, val offset: Int) : DialogueFile() {
companion object{
const val NEXT = 5
const val PREV = -5
private val woodshelf_1_items = listOf(
"Kettle" to Items.KETTLE_7688,
"Teapot" to Items.TEAPOT_7702,
"Clay Cup" to Items.EMPTY_CUP_7728
)
private val woodshelf_2_items = woodshelf_1_items + listOf(
"Empty beer glass" to Items.BEER_GLASS_1919
)
private val woodshelf_3_items = woodshelf_2_items + listOf(
"Cake tin" to Items.CAKE_TIN_1887
)
private val oakshelf_1_items = woodshelf_2_items + listOf(
"More Options" to NEXT,
"Cake tin" to Items.CAKE_TIN_1887,
"Bowl" to Items.BOWL_1923,
"More Options" to PREV
)
val shelves = mapOf(
Scenery.SHELVES_13545 to woodshelf_1_items,
Scenery.SHELVES_13546 to woodshelf_2_items,
Scenery.SHELVES_13547 to woodshelf_3_items,
Scenery.SHELVES_13548 to oakshelf_1_items,
)
}
val end = min(shelves[shelfId]!!.size, 5)
val shelfItems = shelves[shelfId]!!.slice(offset until end)
val shelfItemsNames = shelfItems.map { it.first } val shelfItemsNames = shelfItems.map { it.first }
val shelfItemsIds = shelfItems.map { it.second } val shelfItemsIds = shelfItems.map { it.second }
sendDialogueOptions(player, "Select an Option", *shelfItemsNames.toTypedArray())
addDialogueAction(player) { p, button -> fun checkItem(player: Player, shelfId: Int, offset: Int, button : Int){
val item = shelfItemsIds[button] val item = shelfItemsIds[button]
if (item < 1000){ if (item < 1000){
searchShelf(player, shelf_id, offset+item) openDialogue(player, ShelfDialogue(shelfId, offset+item))
} }
else{ else{
if (hasSpaceFor(player, item, 1)){ if (hasSpaceFor(player, item, 1)){
addItem(player, item) addItem(player, item)
end()
} }
else{ else{
sendMessage(player, "You need at least one free inventory space to take from the shelves.") sendDialogue(player, "You need at least one free inventory space to take from the shelves.").also { stage = END_DIALOGUE }
} }
} }
} }
override fun handle(componentID: Int, buttonID: Int) {
println("Stage: $stage")
when(stage){
0 -> showTopics(
*shelfItemsNames.toTypedArray().mapIndexed { index, item -> Topic(item, index+1, skipPlayer = true) }.toTypedArray()
)
in 1 .. 5 -> checkItem(player!!, shelfId, offset, stage - 1).also { stage = 6 }
else -> end()
}
}
} }
} }