From bd4c768a4886752759cca4833cf162ff9c9a9e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Mon, 28 Nov 2022 20:24:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8B=E4=BB=B6=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E5=A4=9A=E5=8C=B9=E9=A9=AC=E5=90=8C=E6=97=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index be14598..fdafb1f 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -139,21 +139,26 @@ object JHorseRacing : KotlinPlugin( ++horse.position } + // 是否好事件 + val isGoodEvent = Random.nextInt(77) > 32 // 比赛事件触发 - val steps = (1..3).random() //事件触发前进或后退随机大小 - // 事件赛马下标 - val eventHorseIndex = Random.nextInt(rank.horses.size) - // 事件赛马 - val eventHorse = rank.horses[eventHorseIndex] + val steps = (1..3).random() * if (isGoodEvent) 1 else -1 //事件触发前进或后退随机大小 // 触发事件 - val eventMsg = if (Random.nextInt(77) > 32) { - eventHorse.position += steps + val eventMsg = StringBuilder(if (isGoodEvent) { JHRPluginConfig.goodEvents[Random.nextInt(JHRPluginConfig.goodEvents.size)] } else { - eventHorse.position -= steps JHRPluginConfig.badEvents[Random.nextInt(JHRPluginConfig.badEvents.size)] - } + }) + for (eventHorseIndex in rank.horses.indices.shuffled()) { + // 找到事件中的问号 + val qIndex = eventMsg.indexOf('?') + if (qIndex == -1) break + // 移动 + rank.horses[eventHorseIndex].position += steps + val number = (eventHorseIndex + 1).toString() + eventMsg.replace(qIndex, qIndex+1, number) + } // 计算获胜者 for ((i, horse) in rank.horses.withIndex()) { @@ -162,9 +167,7 @@ object JHorseRacing : KotlinPlugin( } } - // 发送事件消息 - val number = (eventHorseIndex + 1).toString() - subject.sendMessage(eventMsg.replace("?", number)) + subject.sendMessage(eventMsg.toString()) delay(Random.nextLong(100, 200)) // 渲染赛马 subject.sendMessage(drawHorse(rank.horses))