Created
August 11, 2017 16:20
-
-
Save Jire/99815ede296e08f21b8f9b1bc576b3cf to your computer and use it in GitHub Desktop.
Eden's dialogue extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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