Skip to content

Instantly share code, notes, and snippets.

@Jire
Created August 11, 2017 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jire/99815ede296e08f21b8f9b1bc576b3cf to your computer and use it in GitHub Desktop.
Save Jire/99815ede296e08f21b8f9b1bc576b3cf to your computer and use it in GitHub Desktop.
Eden's dialogue extension
package modules.dialogue
import ps.eden.server.game.content.dialogue.DialoguePlugin
import ps.eden.server.game.node.entity.player.Player
import kotlin.reflect.KVisibility
/**
* @author Jire
*/
abstract class Dialogue(vararg val applicableIDs: Int) : DialoguePlugin() {
val stages = Stages(this)
override fun newInstance(player: Player?) = this::class.constructors.firstOrNull {
it.visibility == KVisibility.PUBLIC && it.parameters.isEmpty()
}?.run {
call().apply {
this.player = player
if (player != null) interpreter = player.dialogueInterpreter
stages.define()
}
}
override fun open(vararg args: Any?): Boolean {
stage = Stages.START_STAGE
return handle(-1, -1)
}
override fun handle(interfaceId: Int, buttonId: Int): Boolean {
val stage = stages.stageFor(this.stage)
if (stage == null || this.stage == Stages.END_STAGE) end()
else {
stage.interfaceID = interfaceId
stage.buttonID = buttonId
this.stage = stage.next()
}
return true
}
abstract fun Stages.define()
override fun getIds() = applicableIDs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment