Merge branch 'bury-command' into 'master'

Add kermit-friendly bury command

See merge request 2009scape/2009scape!132
This commit is contained in:
Ceikry
2021-07-10 19:04:37 +00:00
2 changed files with 44 additions and 23 deletions
@@ -1,13 +1,20 @@
package rs09.game.system.command.sets package rs09.game.system.command.sets
import api.ContentAPI
import core.game.content.quest.tutorials.tutorialisland.CharacterDesign import core.game.content.quest.tutorials.tutorialisland.CharacterDesign
import core.game.node.entity.npc.NPC import core.game.node.entity.npc.NPC
import core.game.node.entity.player.Player
import core.game.system.task.Pulse import core.game.system.task.Pulse
import core.game.world.map.Location
import core.game.world.map.RegionManager import core.game.world.map.RegionManager
import core.game.world.update.flag.context.Animation import core.game.world.update.flag.context.Animation
import core.plugin.Initializable import core.plugin.Initializable
import rs09.game.content.dialogue.DialogueFile
import rs09.game.interaction.InteractionListeners
import rs09.game.interaction.SpadeDigListener
import rs09.game.system.command.Command import rs09.game.system.command.Command
import rs09.game.world.GameWorld import rs09.game.world.GameWorld
import rs09.tools.END_DIALOGUE
import java.util.* import java.util.*
@Initializable @Initializable
@@ -116,5 +123,42 @@ class FunCommandSet : CommandSet(Command.Privilege.ADMIN) {
define("makeover", Command.Privilege.MODERATOR){ player, _ -> define("makeover", Command.Privilege.MODERATOR){ player, _ ->
CharacterDesign.open(player) CharacterDesign.open(player)
} }
/**
* Bury inventory at current location
*/
define("bury"){player, _ ->
if(player.inventory.isEmpty){
reject(player, "You have no items to bury.")
}
player.dialogueInterpreter.open(object : DialogueFile(){
override fun handle(componentID: Int, buttonID: Int) {
when(stage){
0 -> dialogue("This will bury your whole inventory in this spot.","Are you sure?").also { stage++ }
1 -> options("Yes","No").also { stage++ }
2 -> when(buttonID){
1 -> bury(player).also { end() }
2 -> stage = END_DIALOGUE
}
}
}
})
}
}
fun bury(player: Player){
val loc = Location.create(player.location)
val inv = player.inventory.toArray().filterNotNull()
SpadeDigListener.registerListener(player.location){p ->
for(item in inv){
ContentAPI.addItemOrDrop(p, item.id, item.amount)
ContentAPI.sendMessage(p, "You dig and find ${if(item.amount > 1) "some" else "a"} ${item.name}")
}
SpadeDigListener.listeners.remove(loc)
}
player.inventory.clear()
notify(player, "You have buried your loot at ${loc.toString()}")
} }
} }
@@ -479,28 +479,5 @@ class MiscCommandSet : CommandSet(Command.Privilege.ADMIN){
notify(player,"No parent NPC found.") notify(player,"No parent NPC found.")
} }
} }
define("bury"){player,args ->
if(args.size < 2){
reject(player,"Usage: ::bury itemid")
}
val itemId = args[1].toInt()
val def = ItemDefinition.forId(itemId)
SpadeDigListener.registerListener(player.location){pl ->
if(player.getAttribute("${player.location.toString()}:$itemId",false)){
pl.sendMessage("You dig and find nothing.")
return@registerListener
}
pl.dialogueInterpreter.sendDialogue("You dig and find a ${def.name}!")
player.inventory.add(Item(itemId))
player.setExpirableAttribute("/save:${player.location.toString()}:$itemId",true,TimeUnit.SECONDS.toMillis(10))
}
notify(player,"You buried a ${def.name} at ${player.location}")
}
} }
} }