From dca097aa7efd0e92dfe6aac87dbc6894d6a7a40d Mon Sep 17 00:00:00 2001 From: toxicity188 Date: Sat, 25 Nov 2023 09:17:50 +0900 Subject: [PATCH] time function fix. --- .../questadder/mechanic/dialog/Dialog.kt | 108 +++++++++--------- .../util/builder/FunctionBuilder.kt | 16 ++- 2 files changed, 64 insertions(+), 60 deletions(-) diff --git a/plugin/src/main/java/kor/toxicity/questadder/mechanic/dialog/Dialog.kt b/plugin/src/main/java/kor/toxicity/questadder/mechanic/dialog/Dialog.kt index 16dccc7..8937a35 100644 --- a/plugin/src/main/java/kor/toxicity/questadder/mechanic/dialog/Dialog.kt +++ b/plugin/src/main/java/kor/toxicity/questadder/mechanic/dialog/Dialog.kt @@ -810,6 +810,60 @@ class Dialog(adder: QuestAdder, val file: File, private val dialogKey: String, s } } } + bluePrint.checkQuest?.forEach { + val split = it.split(' ') + if (split.size > 1) { + adder.addLazyTask { + val quest = DialogManager.getQuest(split[0]) ?: run { + error("not found error: the quest named \"${split[0]}\" doesn't exist.") + return@addLazyTask + } + when (split[1].lowercase()) { + "has" -> { current: DialogCurrent -> + quest.has(current.player) + } + "complete" -> { current: DialogCurrent -> + quest.isCompleted(current.player) + } + "ready" -> { current: DialogCurrent -> + quest.isReady(current.player) + } + "clear" -> { current: DialogCurrent -> + quest.isCleared(current.player) + } + "!has" -> { current: DialogCurrent -> + !quest.has(current.player) + } + "!complete" -> { current: DialogCurrent -> + !quest.isCompleted(current.player) + } + "!ready" -> { current: DialogCurrent -> + !quest.isReady(current.player) + } + "!clear" -> { current: DialogCurrent -> + !quest.isCleared(current.player) + } + else -> { + error("not found error: the quest predicate \"${split[1]}\" doesn't exist.") + null + } + }?.let { pre -> + if (split.size > 2) { + val dialog = DialogManager.getDialog(split[2]) + if (dialog == null) error("not found error: the dialog named ${split[2]} doesn't exist.") + else addPredicate { current -> + if (pre(current)) { + dialog.start(current) + false + } else true + } + } else { + addPredicate(pre) + } + } + } + } + } bluePrint.condition?.let { cond -> adder.addLazyTask { fun throwRuntimeError(result: Any?) { @@ -891,60 +945,6 @@ class Dialog(adder: QuestAdder, val file: File, private val dialogKey: String, s } } } - bluePrint.checkQuest?.forEach { - val split = it.split(' ') - if (split.size > 1) { - adder.addLazyTask { - val quest = DialogManager.getQuest(split[0]) ?: run { - error("not found error: the quest named \"${split[0]}\" doesn't exist.") - return@addLazyTask - } - when (split[1].lowercase()) { - "has" -> { current: DialogCurrent -> - quest.has(current.player) - } - "complete" -> { current: DialogCurrent -> - quest.isCompleted(current.player) - } - "ready" -> { current: DialogCurrent -> - quest.isReady(current.player) - } - "clear" -> { current: DialogCurrent -> - quest.isCleared(current.player) - } - "!has" -> { current: DialogCurrent -> - !quest.has(current.player) - } - "!complete" -> { current: DialogCurrent -> - !quest.isCompleted(current.player) - } - "!ready" -> { current: DialogCurrent -> - !quest.isReady(current.player) - } - "!clear" -> { current: DialogCurrent -> - !quest.isCleared(current.player) - } - else -> { - error("not found error: the quest predicate \"${split[1]}\" doesn't exist.") - null - } - }?.let { pre -> - if (split.size > 2) { - val dialog = DialogManager.getDialog(split[2]) - if (dialog == null) error("not found error: the dialog named ${split[2]} doesn't exist.") - else addPredicate { current -> - if (pre(current)) { - dialog.start(current) - false - } else true - } - } else { - addPredicate(pre) - } - } - } - } - } bluePrint.qna?.forEach { adder.addLazyTask { DialogManager.getQnA(it)?.let { q -> diff --git a/plugin/src/main/java/kor/toxicity/questadder/util/builder/FunctionBuilder.kt b/plugin/src/main/java/kor/toxicity/questadder/util/builder/FunctionBuilder.kt index fae7795..06de1f4 100644 --- a/plugin/src/main/java/kor/toxicity/questadder/util/builder/FunctionBuilder.kt +++ b/plugin/src/main/java/kor/toxicity/questadder/util/builder/FunctionBuilder.kt @@ -345,42 +345,42 @@ object FunctionBuilder { false } } - addFunction("day", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("day", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.DAYS.between(t.time, LocalDateTime.now()) } } ?: -1L } - addFunction("second", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("second", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.SECONDS.between(t.time, LocalDateTime.now()) } } ?: -1L } - addFunction("minute", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("minute", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.MINUTES.between(t.time, LocalDateTime.now()) } } ?: -1L } - addFunction("month", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("month", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.MONTHS.between(t.time, LocalDateTime.now()) } } ?: -1L } - addFunction("year", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("year", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.YEARS.between(t.time, LocalDateTime.now()) } } ?: -1L } - addFunction("hour", listOf(Player::class.java, Quest::class.java)) { _: Null, args -> + addFunction("hour", listOf(Player::class.java, String::class.java)) { _: Null, args -> QuestAdderBukkit.getPlayerData(args[0] as Player)?.let { it.questVariables[args[1] as String]?.let { t -> ChronoUnit.HOURS.between(t.time, LocalDateTime.now()) @@ -390,6 +390,10 @@ object FunctionBuilder { addFunction("timeformat", listOf(Number::class.java)) { _: Null, args -> QuestAdderBukkit.Config.timeFormat.format((args[0] as Number).toLong()) } + addFunction("between", listOf(Number::class.java, Number::class.java, Number::class.java)) { _: Null, args -> + val num = (args[0] as Number).toDouble() + num >= (args[1] as Number).toDouble() && num <= (args[2] as Number).toDouble() + } } inline fun addOperation(name: String, priority: Int, noinline operate: (T, T) -> R) { addOperation(name,priority,T::class.java,R::class.java,operate)