mirror of
https://github.com/jie65535/mirai-console-jhr-plugin.git
synced 2025-06-02 17:39:16 +08:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/kotlin/game/PlayerStatistics.kt
This commit is contained in:
commit
549e0b669e
@ -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
|
||||
@ -19,6 +20,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.min
|
||||
import java.util.*
|
||||
import kotlin.random.Random
|
||||
|
||||
@ -97,7 +99,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 min(lapLength, horse.position))
|
||||
sb.append("Ξ")
|
||||
sb.appendLine()
|
||||
}
|
||||
@ -132,7 +134,13 @@ object JHorseRacing : KotlinPlugin(
|
||||
launch(rank.job) {
|
||||
val winners = mutableListOf<Int>()
|
||||
while (winners.size == 0) {
|
||||
delay(Random.nextLong(1000) + 2000)
|
||||
delay(Random.nextLong(5000, 7000))
|
||||
|
||||
// 所有马前进
|
||||
for (horse in rank.horses) {
|
||||
++horse.position
|
||||
}
|
||||
|
||||
// 比赛事件触发
|
||||
val steps = (1..3).random() //事件触发前进或后退随机大小
|
||||
val eventHorseIndex = Random.nextInt(rank.horses.size)
|
||||
@ -144,19 +152,21 @@ 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) {
|
||||
if (horse.position >= lapLength) {
|
||||
winners.add(i + 1)
|
||||
}
|
||||
}
|
||||
subject.sendMessage(drawHorse(rank.horses))
|
||||
|
||||
delay(Random.nextLong(1000) + 3000)
|
||||
val number = (eventHorseIndex + 1).toString()
|
||||
subject.sendMessage(eventMsg.replace("?", number))
|
||||
delay(Random.nextLong(100, 200))
|
||||
subject.sendMessage(drawHorse(rank.horses))
|
||||
}
|
||||
delay(Random.nextLong(100, 200))
|
||||
val mb = MessageChainBuilder()
|
||||
for (winner in winners) {
|
||||
// 增加该赛马胜场
|
||||
@ -171,8 +181,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
|
||||
@ -435,21 +447,21 @@ 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.filter { subject.contains(it.key) }
|
||||
.sortedByDescending { it.value }
|
||||
.take(10)
|
||||
.onEach {
|
||||
msgB.append("| ${it.value} | ${subject[it.key]!!.nameCardOrNick}\n")
|
||||
}
|
||||
subject.sendMessage(msgB.asMessageChain())
|
||||
}
|
||||
msg == "统计" -> {
|
||||
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())
|
||||
}
|
||||
msg == "胜率" -> {
|
||||
|
@ -1,8 +1,10 @@
|
||||
package top.jie65535.jhr.game
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* 玩家数据统计
|
||||
*/
|
||||
@Serializable
|
||||
class PlayerStatistics {
|
||||
/**
|
||||
* 下注次数
|
||||
@ -23,4 +25,17 @@ class PlayerStatistics {
|
||||
* 签到次数
|
||||
*/
|
||||
var signCount = 0
|
||||
|
||||
/**
|
||||
* 下注积分累计
|
||||
*/
|
||||
var totalBetScore = 0
|
||||
|
||||
override fun toString(): String {
|
||||
return "下注次数:${betCount}\n" +
|
||||
"获胜次数:${winCount}\n" +
|
||||
"贡献次数:${contribution}\n" +
|
||||
"签到次数:${signCount}\n" +
|
||||
"下注积分:${totalBetScore}"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user