mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
More work on the shelf listener
This commit is contained in:
parent
a0cd34a1af
commit
655d5f0e06
1 changed files with 66 additions and 26 deletions
|
|
@ -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 {
|
||||||
|
|
||||||
|
override fun defineListeners() {
|
||||||
|
on(ShelfDialogue.shelves.keys.toIntArray(), IntType.SCENERY, "Search") {player, node ->
|
||||||
|
searchShelf(player, node.id)
|
||||||
|
return@on true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun searchShelf(player : Player, shelfId: Int){
|
||||||
|
openDialogue(player, ShelfDialogue(shelfId, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShelfDialogue(val shelfId: Int, val offset: Int) : DialogueFile() {
|
||||||
|
|
||||||
companion object{
|
companion object{
|
||||||
|
|
||||||
const val NEXT = 5
|
const val NEXT = 5
|
||||||
const val PREV = -5
|
const val PREV = -5
|
||||||
|
|
||||||
val woodshelf_1_items = listOf(
|
private val woodshelf_1_items = listOf(
|
||||||
"Kettle" to Items.KETTLE_7688,
|
"Kettle" to Items.KETTLE_7688,
|
||||||
"Teapot" to Items.TEAPOT_7702,
|
"Teapot" to Items.TEAPOT_7702,
|
||||||
"Clay Cup" to Items.EMPTY_CUP_7728
|
"Clay Cup" to Items.EMPTY_CUP_7728
|
||||||
)
|
)
|
||||||
|
|
||||||
val woodshelf_2_items = woodshelf_1_items + mapOf(
|
private val woodshelf_2_items = woodshelf_1_items + listOf(
|
||||||
"Empty beer glass" to Items.BEER_GLASS_1919
|
"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(
|
val shelves = mapOf(
|
||||||
Scenery.SHELVES_13545 to woodshelf_1_items
|
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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
override fun defineListeners() {
|
|
||||||
on(shelves.keys.toIntArray(), IntType.SCENERY, "Search") {player, node ->
|
|
||||||
searchShelf(player, node.id)
|
|
||||||
return@on true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun searchShelf(player : Player, shelf_id: Int, offset : Int = 0){
|
val end = min(shelves[shelfId]!!.size, 5)
|
||||||
val shelfItems = shelves[shelf_id]!!.slice(offset..offset+4)
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue