From 3838089790c8831c92fecc24337c1a611704c1dc Mon Sep 17 00:00:00 2001 From: 502milk Date: Tue, 11 Jan 2022 15:31:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=99=E4=B8=8B=E4=BA=86=E7=9C=9F=E6=AD=A3?= =?UTF-8?q?=E7=9A=84=E9=A9=AC=EF=BC=88=E4=B8=8D=E6=98=AF=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E9=83=A8=E5=88=86=E4=BA=8B=E4=BB=B6=E5=86=85?= =?UTF-8?q?=E5=AE=B9=20=E6=9B=B4=E6=94=B9=E4=BA=86=E8=B5=9B=E9=81=93?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=20=E6=9B=B4=E6=94=B9=E4=BA=86=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E5=A5=96=E5=8A=B1=EF=BC=88=E6=94=B9=E4=B8=BA=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/JHRCommand.kt | 7 ++++ src/main/kotlin/JHRPluginConfig.kt | 33 ++++++++++++++--- src/main/kotlin/JHorseRacing.kt | 59 +++++++++++------------------- 3 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/main/kotlin/JHRCommand.kt b/src/main/kotlin/JHRCommand.kt index 48ff60b..405fc03 100644 --- a/src/main/kotlin/JHRCommand.kt +++ b/src/main/kotlin/JHRCommand.kt @@ -2,6 +2,7 @@ package top.jie65535.jhr import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.CompositeCommand +import net.mamoe.mirai.console.plugin.jvm.reloadPluginConfig object JHRCommand : CompositeCommand( JHorseRacing, "jhr", @@ -21,4 +22,10 @@ object JHRCommand : CompositeCommand( JHRPluginConfig.enabledGroups.remove(group) sendMessage("OK") } + @SubCommand + @Deprecated("重载配置") + suspend fun CommandSender.reload() { + JHorseRacing.reloadPluginConfig(JHRPluginConfig) + sendMessage("OK") + } } \ No newline at end of file diff --git a/src/main/kotlin/JHRPluginConfig.kt b/src/main/kotlin/JHRPluginConfig.kt index 1f04cf3..34c46ae 100644 --- a/src/main/kotlin/JHRPluginConfig.kt +++ b/src/main/kotlin/JHRPluginConfig.kt @@ -1,14 +1,13 @@ package top.jie65535.jhr +import net.mamoe.mirai.console.command.CommandSender +import net.mamoe.mirai.console.command.CompositeCommand import net.mamoe.mirai.console.data.AutoSavePluginConfig import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value object JHRPluginConfig : AutoSavePluginConfig("HorseRacingPluginConfig") { - @ValueDescription("签到奖励") - val signReward by value(5000) - @ValueDescription("启用赛马的群") var enabledGroups: MutableList by value() @@ -19,6 +18,7 @@ object JHRPluginConfig : AutoSavePluginConfig("HorseRacingPluginConfig") { "我有多少钱", "我有多少钱老婆", "老子还有多少钱", + "查询", )) @ValueDescription("好事件 ?为占位符") @@ -27,6 +27,18 @@ object JHRPluginConfig : AutoSavePluginConfig("HorseRacingPluginConfig") { "?号马使用了私藏的超级棒棒糖,加速加速!", "?号马已经没什么所谓了!", "?号马发现,赛道岂是如此不便之物!", + "?号马使用了砸瓦鲁多!", + "?号马说:兄弟!买挂吗!", + "?号马旋转升天法力无边!", + "?号马那我走?", + "?号马勇敢牛牛不怕困难!", + "?号马三点了!饮茶先啊!", + "?号马使用了印尼宽带!", + "?号马正面上我啊!", + "?号马发现了前方有电脑配件!", + "?号马欧拉欧拉欧拉欧拉欧拉!", + "?号马就这就这?", + )) @ValueDescription("坏事件 ?为占位符") @@ -36,8 +48,17 @@ object JHRPluginConfig : AutoSavePluginConfig("HorseRacingPluginConfig") { "?号马踩到了sf!", "?号马突然想上天摘星星!", "?号马掉入了时辰的陷阱!", - )) + "?号马突然想吃饭!", + "?号马看到了后方的母马!", + "?号马前去买瓜", + "?号马~希望の花 繋いだ絆を~", + "?号马看到了招生'减'章!", + "?号马听君一席话如听君一席话", + "?号马网抑云了", + "?号马小丑竟是我自己!", + "?号马希望大家玩得愉快", + )) +} // @ValueDescription("赛马数量") -// val horseCount by value(5) -} \ No newline at end of file +// val horseCount by value(5) \ No newline at end of file diff --git a/src/main/kotlin/JHorseRacing.kt b/src/main/kotlin/JHorseRacing.kt index 775a9b4..2b35b96 100644 --- a/src/main/kotlin/JHorseRacing.kt +++ b/src/main/kotlin/JHorseRacing.kt @@ -13,7 +13,6 @@ import net.mamoe.mirai.message.data.* import net.mamoe.mirai.message.data.MessageSource.Key.quote import net.mamoe.mirai.utils.info import java.util.* -import java.util.regex.Pattern import kotlin.random.Random @@ -45,41 +44,24 @@ object JHorseRacing : KotlinPlugin( } // endregion + //随机签到奖励范围 + val signReward + get() = (100..1000).random() + // region 赛马 private data class Bet(val id: Long, val number: Int, val score: Int) private data class Horse(val type: Int, var position: Int = 0) private val pools = mutableMapOf>() - private const val horseCount = 5 - private const val lapLength = 10 + private const val horseCount = 5 //多少个马 + private const val lapLength = 20 //赛道长度 private val horseTypes = listOf( "\uD83E\uDD84", "\uD83D\uDC34", - "\uD83D\uDC3A", - "\uD83D\uDC02", - "\uD83D\uDC04", - "\uD83D\uDC0E", - "\uD83D\uDC07", - "\uD83D\uDC13", - "\uD83E\uDD8F", - "\uD83D\uDC29", - "\uD83D\uDC2E", - "\uD83D\uDC35", - "\uD83D\uDC19", - "\uD83D\uDC80", - "\uD83D\uDC24", - "\uD83D\uDC28", - "\uD83D\uDC2E", "\uD83D\uDC14", - "\uD83D\uDC38", - "\uD83D\uDC7B", - "\uD83D\uDC1B", - "\uD83D\uDC20", - "\uD83D\uDC36", - "\uD83D\uDC2F", - " ", - "\uD83D\uDEBD" + "\uD83D\uDEBD", + "\uD83D\uDC1C" ) private val ranks = mutableMapOf>() private fun newRank() = List(horseCount) { Horse(Random.nextInt(horseTypes.size)) } @@ -111,7 +93,7 @@ object JHorseRacing : KotlinPlugin( // 确认该群是否启用赛马 if (JHRPluginConfig.enabledGroups.indexOf(group.id) == -1) { - if (msg == "#开启赛马" && sender.permission.isOperator()) { + if (msg == "开启赛马" && sender.permission.isOperator()) { JHRPluginConfig.enabledGroups.add(group.id) subject.sendMessage("已开启赛马") } @@ -119,7 +101,7 @@ object JHorseRacing : KotlinPlugin( } when { - msg.startsWith("#赛马") -> { + msg.startsWith("赛马") -> { if (pools[subject.id] != null) { subject.sendMessage("已经有比赛在进行了") } else { @@ -127,7 +109,7 @@ object JHorseRacing : KotlinPlugin( subject.sendMessage("赛马比赛开盘,有钱交钱妹钱交人") } } - msg.startsWith("#开始赛马") -> { + msg.startsWith("开始赛马") -> { subject.sendMessage("赛马开始辣,走过路过不要错过") val rank = newRank() ranks[subject.id] = rank @@ -137,13 +119,14 @@ object JHorseRacing : KotlinPlugin( while (winner == -1) { delay(Random.nextLong(1000) + 2000) // 比赛事件触发 + val horserandom = (1..3).random() //事件触发前进或后退随机大小 val eventHorseIndex = Random.nextInt(rank.size) val eventHorse = rank[eventHorseIndex] val eventMsg = if (Random.nextInt(77) > 32) { - eventHorse.position += 1 + eventHorse.position += (horserandom) JHRPluginConfig.goodEvents[Random.nextInt(JHRPluginConfig.goodEvents.size)] } else { - eventHorse.position -= 1 + eventHorse.position -= (horserandom) JHRPluginConfig.badEvents[Random.nextInt(JHRPluginConfig.badEvents.size)] } subject.sendMessage(eventMsg.replace("?", (eventHorseIndex + 1).toString())) @@ -171,25 +154,25 @@ object JHorseRacing : KotlinPlugin( subject.sendMessage("${winner}最终赢得了胜利,让我们为它鼓掌") } } - msg == "#关闭赛马" -> { + msg == "关闭赛马" -> { if (sender.permission.isOperator()) { JHRPluginConfig.enabledGroups.remove(subject.id) subject.sendMessage("已关闭赛马") } } - msg == "#签到" -> { + msg == "签到" -> { if (checkSign(sender.id)) { subject.sendMessage("一天只能签到一次噢") } else { signUpSheet.add(sender.id) val score = JHRPluginData.Scores[sender.id] - val reward = JHRPluginConfig.signReward + val reward = signReward if (score != null) { JHRPluginData.Scores[sender.id] = score + reward - subject.sendMessage("马币+${reward},现在马币:${score + reward}") + subject.sendMessage("硬币+${reward},现有${score + reward}硬币") } else { JHRPluginData.Scores[sender.id] = reward - subject.sendMessage("马币+${reward}") + subject.sendMessage("硬币+${reward}") } } } @@ -201,7 +184,7 @@ object JHorseRacing : KotlinPlugin( } val m = msg.removePrefix("押马") - val p = m.split('#') + val p = m.split(' ') if (p.size != 2) { return@subscribeAlways } @@ -240,7 +223,7 @@ object JHorseRacing : KotlinPlugin( ret.add(",还没有签到哦") } } else { - ret.add("锅里没有一滴油") + ret.add("手里捧着窝窝头,菜里没有一滴油") } subject.sendMessage(ret.asMessageChain()) }