Created
June 13, 2018 01:40
-
-
Save Jire/b6fbf0058908b8fbe27e2bc2acf2cc9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ps.eden.server.game.content.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