Skip to content

Commit

Permalink
time function fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 25, 2023
1 parent d610625 commit dca097a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
108 changes: 54 additions & 54 deletions plugin/src/main/java/kor/toxicity/questadder/mechanic/dialog/Dialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 <reified T, reified R : Any> addOperation(name: String, priority: Int, noinline operate: (T, T) -> R) {
addOperation(name,priority,T::class.java,R::class.java,operate)
Expand Down

0 comments on commit dca097a

Please sign in to comment.