From b3da1ba954b35b98583b627ee02a54760d67d6bf Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 09:34:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=A1=BA=E5=BA=8F=20=E5=85=88=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E5=90=8E=E5=86=8D=E8=A7=A6=E5=8F=91=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E8=B7=91=E9=81=93=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 60dbfd1..ded5d6c 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -19,6 +19,7 @@ import net.mamoe.mirai.utils.info import top.jie65535.jhr.game.Bet import top.jie65535.jhr.game.Horse import top.jie65535.jhr.game.PlayerStatistics +import java.lang.Integer.max import java.util.* import kotlin.random.Random @@ -97,7 +98,7 @@ object JHorseRacing : KotlinPlugin( for (j in horse.position until lapLength) sb.append("Ξ") sb.append(horseTypes[horse.type]) - for (j in 1 until horse.position) + for (j in 0 until max(lapLength, horse.position)) sb.append("Ξ") sb.appendLine() } @@ -132,7 +133,15 @@ object JHorseRacing : KotlinPlugin( launch(rank.job) { val winners = mutableListOf() while (winners.size == 0) { - delay(Random.nextLong(1000) + 2000) + delay(Random.nextLong(5000, 7000)) + + // 所有马前进 + for ((i, horse) in rank.horses.withIndex()) { + if (++horse.position >= lapLength) { + winners.add(i + 1) + } + } + // 比赛事件触发 val steps = (1..3).random() //事件触发前进或后退随机大小 val eventHorseIndex = Random.nextInt(rank.horses.size) @@ -144,19 +153,13 @@ object JHorseRacing : KotlinPlugin( eventHorse.position -= steps JHRPluginConfig.badEvents[Random.nextInt(JHRPluginConfig.badEvents.size)] } + val number = (eventHorseIndex + 1).toString() subject.sendMessage(eventMsg.replace("?", number)) - - // 所有马前进 - for ((i, horse) in rank.horses.withIndex()) { - if (++horse.position >= lapLength) { - winners.add(i + 1) - } - } + delay(Random.nextLong(100, 200)) subject.sendMessage(drawHorse(rank.horses)) - - delay(Random.nextLong(1000) + 3000) } + delay(Random.nextLong(100, 200)) val mb = MessageChainBuilder() for (winner in winners) { mb.add(JHRPluginConfig.winnerMessage[Random.nextInt(JHRPluginConfig.winnerMessage.size)].replace("?", winner.toString()))