Implemented the proper interaction for low-alchemy option on the Explorer's Ring
Implemented a generic item selection ContentAPI method Added ContentAPI method for running CS2 scripts Added development command for running CS2 scripts
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package content.global.handlers.iface
|
||||
|
||||
import core.api.*
|
||||
import core.tools.*
|
||||
import core.game.interaction.*
|
||||
import core.game.system.task.Pulse
|
||||
import core.game.node.entity.player.Player
|
||||
|
||||
class GenericItemSelect : InterfaceListener {
|
||||
val GENERIC_ITEM_SELECT_IFACE = 12
|
||||
|
||||
override fun defineInterfaceListeners() {
|
||||
onOpen(GENERIC_ITEM_SELECT_IFACE) {player, _ ->
|
||||
player.pulseManager.run(object : Pulse() {
|
||||
override fun pulse() : Boolean {
|
||||
return false
|
||||
}
|
||||
override fun stop() {
|
||||
super.stop()
|
||||
player.interfaceManager.closeSingleTab()
|
||||
}
|
||||
})
|
||||
return@onOpen true
|
||||
}
|
||||
|
||||
on(GENERIC_ITEM_SELECT_IFACE){player, _, opcode, buttonID, slot, _ ->
|
||||
processResponse(player, opcode, slot)
|
||||
return@on true
|
||||
}
|
||||
|
||||
onClose(GENERIC_ITEM_SELECT_IFACE) {player, _ ->
|
||||
removeAttribute(player, "itemselect-callback")
|
||||
return@onClose true
|
||||
}
|
||||
}
|
||||
|
||||
private fun processResponse (player: Player, opcode: Int, slot: Int) {
|
||||
val callback = getAttribute<((Int, Int) -> Unit)?>(player, "itemselect-callback", null)
|
||||
if (callback == null) {
|
||||
log (this::class.java, Log.WARN, "${player.name} is trying to use an item select prompt with no callback!")
|
||||
return
|
||||
}
|
||||
|
||||
val optionIndex = when (opcode) {
|
||||
155 -> 0
|
||||
196 -> 1
|
||||
124 -> 2
|
||||
199 -> 3
|
||||
234 -> 4
|
||||
9 -> 10
|
||||
else -> -1
|
||||
}
|
||||
if (optionIndex == -1) {
|
||||
log (this::class.java, Log.WARN, "${player.name} is clicking a right-click index that we don't know the opcode for yet, lol. Here's the opcode: $opcode")
|
||||
return
|
||||
}
|
||||
|
||||
callback.invoke(slot, optionIndex)
|
||||
removeAttribute (player, "itemselect-callback")
|
||||
player.interfaceManager.closeSingleTab()
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
package content.global.handlers.item
|
||||
|
||||
import core.api.hasLevelStat
|
||||
import core.api.sendMessage
|
||||
import core.api.teleport
|
||||
import core.api.visualize
|
||||
import core.api.*
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.link.TeleportManager.TeleportType
|
||||
import core.game.node.entity.skill.Skills
|
||||
@@ -15,12 +12,8 @@ import core.ServerStore.Companion.getBoolean
|
||||
import core.ServerStore.Companion.getInt
|
||||
import core.game.interaction.IntType
|
||||
import core.game.interaction.InteractionListener
|
||||
import content.global.skill.magic.modern.ModernListeners
|
||||
|
||||
/**
|
||||
* Handles the explorers ring.
|
||||
*
|
||||
* @author Vexia
|
||||
*/
|
||||
class ExplorersRingPlugin : InteractionListener {
|
||||
|
||||
val RINGS = intArrayOf(Items.EXPLORERS_RING_1_13560, Items.EXPLORERS_RING_2_13561, Items.EXPLORERS_RING_3_13562)
|
||||
@@ -44,19 +37,30 @@ class ExplorersRingPlugin : InteractionListener {
|
||||
return@on true
|
||||
}
|
||||
|
||||
//Sources Used
|
||||
// - https://www.youtube.com/watch?v=PEA0fkRK0-A&t=64s&pp=ygUcMjAwOSBydW5lc2NhcGUgZXhwbG9yZXIgcmluZw%3D%3D
|
||||
// - https://runescape.wiki/w/Explorer%27s_ring?oldid=899927
|
||||
on(RINGS, IntType.ITEM, "low-alchemy"){ player, _ ->
|
||||
if (!hasLevelStat(player, Skills.MAGIC, 21)) {
|
||||
sendMessage(player,"You need a Magic level of 21 in order to do that.")
|
||||
return@on true
|
||||
}
|
||||
if(getStoreFile().getBoolean(player.username.toLowerCase() + ":alchs")){
|
||||
sendMessage(player, "You have claimed all the charges you can for one day.")
|
||||
val remaining = getStoreFile().getInt(player.username.lowercase() + ":alchs", 30)
|
||||
if (remaining <= 0) {
|
||||
sendMessage(player, "You have used up all of your charges for the day.")
|
||||
return@on true
|
||||
}
|
||||
sendMessage(player,"You grant yourself with 30 free low alchemy charges.") // todo this implementation is not correct, see https://www.youtube.com/watch?v=UbUIF2Kw_Dw
|
||||
|
||||
getStoreFile()[player.username.toLowerCase() + ":alchs"] = true
|
||||
|
||||
sendDialogue(player, "Choose the item you wish to convert to coins.")
|
||||
addDialogueAction (player) {_,_ ->
|
||||
sendItemSelect (player, "Choose") { slot, optionIndex ->
|
||||
val item = player.inventory[slot]
|
||||
if (item == null)
|
||||
return@sendItemSelect
|
||||
if (!ModernListeners().alchemize(player, item, false))
|
||||
return@sendItemSelect
|
||||
getStoreFile()[player.username.lowercase() + ":alchs"] = remaining - 1
|
||||
}
|
||||
}
|
||||
return@on true
|
||||
}
|
||||
|
||||
|
||||
@@ -221,19 +221,19 @@ class ModernListeners : SpellListener("modern"){
|
||||
setDelay(player,false)
|
||||
}
|
||||
|
||||
private fun alchemize(player: Player,item: Item,high:Boolean){
|
||||
if(item.name == "Coins") player.sendMessage("You can't alchemize something that's already gold!").also { return }
|
||||
if(!item.definition.isTradeable) player.sendMessage("You can't cast this spell on something like that.").also { return }
|
||||
public fun alchemize(player: Player, item: Item, high: Boolean) : Boolean {
|
||||
if(item.name == "Coins") player.sendMessage("You can't alchemize something that's already gold!").also { return false }
|
||||
if(!item.definition.isTradeable) player.sendMessage("You can't cast this spell on something like that.").also { return false }
|
||||
|
||||
if(player.zoneMonitor.isInZone("Alchemists' Playground")){
|
||||
player.sendMessage("You can only alch items from the cupboards!")
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
val coins = Item(995, item.definition.getAlchemyValue(high))
|
||||
if (coins.amount > 0 && !player.inventory.hasSpaceFor(coins)) {
|
||||
player.sendMessage("Not enough space in your inventory!")
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
if (player.pulseManager.current !is MovementPulse) {
|
||||
@@ -259,6 +259,7 @@ class ModernListeners : SpellListener("modern"){
|
||||
addXP(player, if (high) 65.0 else 31.0)
|
||||
showMagicTab(player)
|
||||
setDelay(player, 5)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun sendTeleport(player: Player, xp: Double, location: Location){
|
||||
|
||||
@@ -118,7 +118,7 @@ public final class SlayerMasterDialogue extends DialoguePlugin {
|
||||
|
||||
@Override
|
||||
public boolean handle(int interfaceId, int buttonId) {
|
||||
rerolls = ServerStore.getInt(getStoreFile(), player.getUsername().toLowerCase());
|
||||
rerolls = ServerStore.getInt(getStoreFile(), player.getUsername().toLowerCase(), 0);
|
||||
if (isDiary) {
|
||||
switch (stage) {
|
||||
case 999:
|
||||
|
||||
Reference in New Issue
Block a user