Added ability to swap spellbooks by operating the Mage's Book

The spellbook needs to first be unlocked by completing the quest and using the book on the respoctive altar.
This commit is contained in:
randy 2025-03-08 14:50:09 -07:00
parent 9926b5c244
commit 18d30a3e1e

View file

@ -0,0 +1,91 @@
package content.global.handlers.item
import core.api.*
import core.game.node.Node
import core.game.node.entity.player.Player
import core.game.node.entity.player.link.SpellBookManager.SpellBook
//import core.game.node.item.Item
import core.game.interaction.InteractionListener
import core.game.interaction.IntType
import core.game.world.update.flag.context.Animation
import core.game.world.update.flag.context.Graphics
import core.game.dialogue.*
import core.tools.START_DIALOGUE
import org.rs09.consts.Items
import org.rs09.consts.Sounds
import org.rs09.consts.Scenery
import org.rs09.consts.Animations
import content.data.Quests
//import core.game.component.Component
/**
* Listener for the Mage's Book from Mage Training Arena. The other spellbooks can be inscribed into the book by using it on the respective altar.
* Operate the book to switch to spellbooks that have been added.
*
*/
class SnowscapeMagesBook : InteractionListener {
override fun defineListeners() {
on(Items.MAGES_BOOK_6889, IntType.ITEM, "operate") { player, node ->
if (player.inCombat()) {
player.sendMessage("You cannot concentrate on the book during combat.")
} else {
player.animate(Animation(6299))
player.graphics(Graphics(1062))
openDialogue(player, SnowscapeMagesBookDialogue())
}
return@on true
}
val altars = intArrayOf(Scenery.ALTAR_6552,Scenery.ALTAR_17010)
onUseWith(IntType.SCENERY, Items.MAGES_BOOK_6889, *altars) { player, used, with ->
val ancient = (with.getId() == Scenery.ALTAR_6552)
val quest = if (ancient) Quests.DESERT_TREASURE else Quests.LUNAR_DIPLOMACY
val attribute = if (ancient) "/save:snowscape:magesbook:2" else "/save:snowscape:magesbook:3"
if (hasRequirement(player, quest)){
setAttribute(player, attribute, true)
sendDialogue(player, "You carefully focus on the magic in the altar, and inscribe it into the book.")
playAudio(player, Sounds.LUNAR_STAT_SPY_3620)
playAudio(player, Sounds.LUNAR_STAT_SPY_IMPACT_3621)
animate(player, Animations.LUNAR_SPELLBOOK_STATSPY_6293)
}
return@onUseWith true
}
}
}
class SnowscapeMagesBookDialogue : DialogueFile() {
override fun handle(componentID: Int, buttonID: Int) {
when (stage) {
START_DIALOGUE -> options("Modern","Ancient","Lunar").also {stage++}
1 -> {
end()
if (player == null) return
// This is ordered a little strange, but checking the quest comes first so that access to the spellbook is lost when the quest is released, until it's completed.
if (buttonID == 2 && !hasRequirement(player!!, Quests.DESERT_TREASURE)) return
if (buttonID == 3 && !hasRequirement(player!!, Quests.LUNAR_DIPLOMACY)) return
if (buttonID > 1 && !getAttribute(player!!, "snowscape:magesbook:$buttonID", false)) {
val altarDescription = if (buttonID == 2) "altar in the Pyramid" else "Astral altar"
sendDialogue(player!!, "The book does not contain the knowledge of those spells. Use the book on the $altarDescription to inscribe it.")
return
}
player!!.spellBookManager.setSpellBook(SpellBook.values()[buttonID - 1])
player!!.spellBookManager.update(player!!)
playAudio(player!!, Sounds.PRAYER_RECHARGE_2674)
sendMessage(player!!, "You retrieve the inscribed knowledge and let it fill your mind.")
}
}
}
}