From b3da1ba954b35b98583b627ee02a54760d67d6bf Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 09:34:19 +0800 Subject: [PATCH 1/8] =?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())) From 6e386d0c830fe08815fa37fd389a7d0a489df372 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 09:47:41 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/game/PlayerStatistics.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/game/PlayerStatistics.kt b/src/main/kotlin/game/PlayerStatistics.kt index 64c2223..f1d19ba 100644 --- a/src/main/kotlin/game/PlayerStatistics.kt +++ b/src/main/kotlin/game/PlayerStatistics.kt @@ -1,5 +1,7 @@ package top.jie65535.jhr.game +import kotlinx.serialization.Serializable +@Serializable class PlayerStatistics { var betCount = 0 var winCount = 0 From 1e9b96a43b02cfedab7cd414f6a1838844a84963 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 09:53:39 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98=E4=B8=8E=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index ded5d6c..ef0f6cf 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -434,10 +434,12 @@ object JHorseRacing : KotlinPlugin( } msg == "排名" || msg == "积分榜" -> { val msgB = MessageChainBuilder(11) - msgB.append("积分榜") - JHRPluginData.Scores.entries.sortedBy { it.value }.take(10).onEach { - msgB.append(At(it.key)).append(" ${it.value}") - } + msgB.append("积分榜\n") + JHRPluginData.Scores.entries.sortedByDescending { it.value } + .take(10) + .onEach { + msgB.append(At(it.key)).append(" ${it.value}\n") + } subject.sendMessage(msgB.asMessageChain()) } msg == "统计" -> { From 8c448602e13a13ecfe7f1b913de8ba3171c42e26 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 13:39:19 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=20=E6=A6=9C=E5=8D=95?= =?UTF-8?q?=E4=B8=8D=E5=86=8Dat=20=E4=B8=94=E4=BB=85=E5=88=97=E5=87=BA?= =?UTF-8?q?=E6=9C=AC=E7=BE=A4=E6=8E=92=E5=90=8D=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E6=8F=90=E4=BA=A4=E6=94=B9=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index ef0f6cf..355508c 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -19,7 +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.lang.Integer.min import java.util.* import kotlin.random.Random @@ -98,7 +98,7 @@ object JHorseRacing : KotlinPlugin( for (j in horse.position until lapLength) sb.append("Ξ") sb.append(horseTypes[horse.type]) - for (j in 0 until max(lapLength, horse.position)) + for (j in 0 until min(lapLength, horse.position)) sb.append("Ξ") sb.appendLine() } @@ -435,10 +435,11 @@ object JHorseRacing : KotlinPlugin( msg == "排名" || msg == "积分榜" -> { val msgB = MessageChainBuilder(11) msgB.append("积分榜\n") - JHRPluginData.Scores.entries.sortedByDescending { it.value } + JHRPluginData.Scores.entries.filter { subject.contains(it.key) } + .sortedByDescending { it.value } .take(10) .onEach { - msgB.append(At(it.key)).append(" ${it.value}\n") + msgB.append("${subject[it.key]!!.nameCard} | ${it.value} |\n") } subject.sendMessage(msgB.asMessageChain()) } From 462fb4d3ba4b26051c74da2963f11246e7a5e0ef Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 13:51:55 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E8=8E=B7=E8=83=9C?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=A1=BA=E5=BA=8F=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 355508c..99650bb 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -136,10 +136,8 @@ object JHorseRacing : KotlinPlugin( delay(Random.nextLong(5000, 7000)) // 所有马前进 - for ((i, horse) in rank.horses.withIndex()) { - if (++horse.position >= lapLength) { - winners.add(i + 1) - } + for (horse in rank.horses) { + ++horse.position } // 比赛事件触发 @@ -154,6 +152,14 @@ object JHorseRacing : KotlinPlugin( JHRPluginConfig.badEvents[Random.nextInt(JHRPluginConfig.badEvents.size)] } + + // 计算获胜者 + for ((i, horse) in rank.horses.withIndex()) { + if (horse.position >= lapLength) { + winners.add(i + 1) + } + } + val number = (eventHorseIndex + 1).toString() subject.sendMessage(eventMsg.replace("?", number)) delay(Random.nextLong(100, 200)) From 0e52bdeb7a89649e5ad4e462fdddbd5c5515b4cb Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 14:21:36 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=20=E6=8E=92=E5=90=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=BE=A4=E5=90=8D=E7=89=87=E6=88=96=E6=98=B5?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 99650bb..53d398e 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -9,6 +9,7 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.isOperator +import net.mamoe.mirai.contact.nameCardOrNick import net.mamoe.mirai.event.GlobalEventChannel import net.mamoe.mirai.event.events.GroupMessageEvent import net.mamoe.mirai.event.events.MessageEvent @@ -445,7 +446,7 @@ object JHorseRacing : KotlinPlugin( .sortedByDescending { it.value } .take(10) .onEach { - msgB.append("${subject[it.key]!!.nameCard} | ${it.value} |\n") + msgB.append("${subject[it.key]!!.nameCardOrNick} | ${it.value} |\n") } subject.sendMessage(msgB.asMessageChain()) } From e854fa4be5fcf6455c66d3138406668c7c2cbb33 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 14:22:41 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=20=E6=8E=92=E5=90=8D?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=A0=B7=E5=BC=8F=20=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E5=9C=A8=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 53d398e..9a7c198 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -446,7 +446,7 @@ object JHorseRacing : KotlinPlugin( .sortedByDescending { it.value } .take(10) .onEach { - msgB.append("${subject[it.key]!!.nameCardOrNick} | ${it.value} |\n") + msgB.append("| ${it.value} | ${subject[it.key]!!.nameCardOrNick}\n") } subject.sendMessage(msgB.asMessageChain()) } From 0fedded7d1bded387f8d958d5e51a95be912df85 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Mon, 17 Jan 2022 16:25:01 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E4=B8=8B=E6=B3=A8?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHorseRacing.kt | 11 +++++------ src/main/kotlin/game/PlayerStatistics.kt | 9 +++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 9a7c198..e0750a3 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -182,8 +182,10 @@ object JHorseRacing : KotlinPlugin( if (pool != null && pool.size > 0) { for (bet in pool) { val score = JHRPluginData.Scores[bet.id]!! + val stat = getPlayerStat(bet.id) + stat.totalBetScore += bet.score val income = if (winners.indexOf(bet.number) != -1) { - getPlayerStat(bet.id).winCount += 1 + stat.winCount += 1 (bet.score * 1.5).toInt() } else { -bet.score @@ -454,11 +456,8 @@ object JHorseRacing : KotlinPlugin( val stat = getPlayerStat(sender.id) val ret = MessageChainBuilder() ret.append(message.quote()) - .append("下注次数:${stat.betCount}\n") - .append("获胜次数:${stat.winCount}\n") - .append("贡献次数:${stat.contribution}\n") - .append("签到次数:${stat.signCount}\n") - .append("ヾ(◍°∇°◍)ノ゙继续加油吧!") + .append(getPlayerStat(sender.id).toString()) + .append("\nヾ(◍°∇°◍)ノ゙继续加油吧!") subject.sendMessage(ret.asMessageChain()) } } diff --git a/src/main/kotlin/game/PlayerStatistics.kt b/src/main/kotlin/game/PlayerStatistics.kt index f1d19ba..a828a37 100644 --- a/src/main/kotlin/game/PlayerStatistics.kt +++ b/src/main/kotlin/game/PlayerStatistics.kt @@ -7,4 +7,13 @@ class PlayerStatistics { var winCount = 0 var contribution = 0 var signCount = 0 + var totalBetScore = 0 + + override fun toString(): String { + return "下注次数:${betCount}\n" + + "获胜次数:${winCount}\n" + + "贡献次数:${contribution}\n" + + "签到次数:${signCount}\n" + + "下注积分:${totalBetScore}" + } }