Fixed a bug with leprechaun interface

This commit is contained in:
Ceikry 2021-03-08 22:14:40 -06:00
parent 95eb5747e1
commit f68b626739
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package core.game.node.entity.skill.farming
import core.cache.def.impl.NPCDefinition
import core.game.component.Component
import core.game.content.dialogue.FacialExpression
import core.game.interaction.OptionHandler
import core.game.node.Node
import core.game.node.entity.player.Player
import core.plugin.Initializable
import core.plugin.Plugin
import core.tools.Components
val TL_IDS = arrayOf(3021,8000,4965)
@Initializable
class ToolLeprechaunHandler : OptionHandler() {
override fun newInstance(arg: Any?): Plugin<Any> {
for(id in TL_IDS){
val def = NPCDefinition.forId(id)
def.handlers["option:exchange"] = this
def.handlers["option:teleport"] = this
}
return this
}
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
node ?: return false
when(option){
"exchange" -> player?.interfaceManager?.open(Component(Components.farming_tools_125))
"teleport" -> player?.dialogueInterpreter?.sendDialogues(node.id,if(node.id == 4965) FacialExpression.FRIENDLY else FacialExpression.OLD_NORMAL, "I forgot how to do that it seems.")
}
return true
}
}

View file

@ -136,6 +136,10 @@ class ToolLeprechaunInterface : ComponentPlugin() {
if(!checkMethod.invoke(player)){
player.dialogueInterpreter.sendDialogue("You don't have any of those stored.")
} else {
if(!player.inventory.hasSpaceFor(Item(item))){
player.dialogueInterpreter.sendDialogue("You don't have enough space for that.")
return
}
withdrawMethod.invoke(player,false)
player.inventory.add(Item(item))
}
@ -239,6 +243,10 @@ class ToolLeprechaunInterface : ComponentPlugin() {
if(finalAmount > hasAmount){
finalAmount = hasAmount
}
if(!player.inventory.hasSpaceFor(Item(item,finalAmount)) || finalAmount == 0){
player.dialogueInterpreter.sendDialogue("You don't have enough inventory space for that.")
return
}
player.inventory.add(Item(item,finalAmount))
updateQuantityMethod.invoke(player,-finalAmount)
}