Skip to content

Commit

Permalink
fix(core): 添加国服攻略配置和指令, 修复与mirai-skia-plugin冲突的问题?
Browse files Browse the repository at this point in the history
  • Loading branch information
diyigemt committed Aug 6, 2023
1 parent 4132c03 commit cc1c41f
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 62 deletions.
3 changes: 2 additions & 1 deletion arona-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ dependencies {
// https://mvnrepository.com/artifact/com.github.taptap/pinyin-plus
implementation("com.github.taptap:pinyin-plus:1.0")
implementation("net.mamoe.yamlkt:yamlkt-jvm:0.10.2")
val skikoVersion = "0.7.68"
val skikoVersion = "0.7.72"
implementation("org.jetbrains.skiko:skiko-awt-runtime-windows-x64:$skikoVersion")
implementation("org.jetbrains.skiko:skiko-awt-runtime-linux-x64:$skikoVersion")
implementation("org.jetbrains.skiko:skiko-awt-runtime-linux-arm64:$skikoVersion")
// implementation("org.jetbrains.skiko:skiko-awt-runtime-x64:$skikoVersion")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,41 @@ object ActivityNotify: AronaQuartzService {
private const val ActivityNotifyDataInitKey = "init"
private const val ActivityNotifyOneHour = "ActivityNotifyOneHour"
private const val ActivityKey = "activity"
private const val NotifyStringKey = "notifyString"
private const val MaintenanceKey = "maintenance"
private const val DropActivityTime = 22
private const val DropEndTime = 24 + 3 - DropActivityTime
override var jobKey: JobKey? = null

class ActivityNotifyJob: Job {
override fun execute(context: JobExecutionContext?) {
val jp: Pair<List<Activity>, List<Activity>> = ActivityUtil.fetchJPActivity()
val jp = ActivityUtil.fetchJPActivity()
val en = ActivityUtil.fetchENActivity()
val cn = ActivityUtil.fetchCNActivity()
val alertListJP = mutableListOf<Activity>()
val alertListEN = mutableListOf<Activity>()
val alertListCN = mutableListOf<Activity>()
val filterJP = jp.first
.filter {
filterActive(it, alertListJP)
} to jp.second
.filter {
filterPending(it)
}
}.also { insertAlert(alertListJP, ServerLocale.JP) }
val filterEN = en.first
.filter {
filterActive(it, alertListEN)
} to en.second
.filter {
filterPending(it)
}
insertAlert(alertListJP)
insertAlert(alertListEN)
}.also { insertAlert(alertListEN, ServerLocale.GLOBAL) }
val filterCN = cn.first
.filter {
filterActive(it, alertListCN)
} to cn.second
.filter {
filterPending(it)
}.also { insertAlert(alertListCN, ServerLocale.CN) }
// 初始化不显示信息
val init = context?.mergedJobDataMap?.getBoolean(ActivityNotifyDataInitKey) ?: false
if (init) return
Expand All @@ -64,6 +72,10 @@ object ActivityNotify: AronaQuartzService {
val enMessage = ActivityUtil.createActivityImage(filterEN, ServerLocale.GLOBAL)
sendMessage(enMessage, AronaNotifyConfig.notifyStringEN)
}
if (AronaNotifyConfig.enableCN) {
val enMessage = ActivityUtil.createActivityImage(filterCN, ServerLocale.CN)
sendMessage(enMessage, AronaNotifyConfig.notifyStringCN)
}
}
}

Expand All @@ -78,21 +90,24 @@ object ActivityNotify: AronaQuartzService {
}
}

private fun doInsert(activity: List<Activity>, h: Int, extraKey: String = "") {
private fun doInsert(activity: List<Activity>, h: Int, locale: ServerLocale, extraKey: String = "") {
val now = Calendar.getInstance()
now.set(Calendar.HOUR_OF_DAY, h)
now.set(Calendar.MINUTE, 0)
now.set(Calendar.MILLISECOND, 0)
val serverJp = isJPServer(activity)
QuartzProvider.createSingleTask(
ActivityNotifyOneHourJob::class.java,
now.time,
"${ActivityNotifyOneHour}-${if (serverJp) "jp" else "en"}-${h}-${extraKey}",
"${ActivityNotifyOneHour}-${locale.commandName}-${h}-${extraKey}",
ActivityNotifyOneHour,
mapOf(ActivityKey to activity)
mapOf(ActivityKey to activity, NotifyStringKey to when(locale) {
ServerLocale.JP -> AronaNotifyConfig.notifyStringJP
ServerLocale.GLOBAL -> AronaNotifyConfig.notifyStringEN
ServerLocale.CN -> AronaNotifyConfig.notifyStringCN
})
)
}
private fun insertAlert(activity: MutableList<Activity>) {
private fun insertAlert(activity: MutableList<Activity>, locale: ServerLocale) {
if (activity.isEmpty()) return
val instance = Calendar.getInstance()
val dropActivities = activity.filter { isMidnightEndActivity(it) }
Expand All @@ -101,26 +116,19 @@ object ActivityNotify: AronaQuartzService {
val nowH = instance.get(Calendar.HOUR_OF_DAY)
if (activity.isNotEmpty()) {
activity.groupBy { calcDiffDayAndHour(it.time).first }.forEach { (h, u) ->
doInsert(u, nowH + h - 1, h.toString())
doInsert(u, nowH + h - 1, locale, h.toString())
}
}
// 双倍掉落提醒
if (dropActivities.isNotEmpty()) {
doInsert(dropActivities, DropActivityTime)
doInsert(dropActivities, DropActivityTime, locale)
}
}

private fun insertMaintenanceAlert(activity: Activity, h: Int) {
doInsert(listOf(activity), Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + h - 1, extraKey = MaintenanceKey)
}

private fun filterPending(activity: Activity): Boolean {
val extra = calcDiffDayAndHour(activity.time)
val h = extra.first
val d = extra.second
if ((d == 0) && isMaintenanceActivity(activity)) {
insertMaintenanceAlert(activity, h)
}
return doFilter(d, h)
}

Expand All @@ -147,7 +155,6 @@ object ActivityNotify: AronaQuartzService {
val ac = context?.mergedJobDataMap?.get(ActivityKey) ?: return
ac as List<Activity>
if (ac.isEmpty()) return
val server = isJPServer(ac)
val activity = ac.toMutableList()
val maintenance: Activity? = activity
.filter { isMaintenanceActivity(it) }
Expand All @@ -163,12 +170,15 @@ object ActivityNotify: AronaQuartzService {
if (maintenance != null) {
Arona.sendMessage("距离${serverName}维护还有1小时")
}
val notifyPrefix = context.mergedJobDataMap?.get(NotifyStringKey) ?: "${serverName}防侠提醒"
// 只有维护信息时
if (activity.isEmpty()) return
val activityString = activity
.map { at -> "${at.content}\n" }
.reduceOrNull { prv, cur -> prv + cur }
val serverString = MiraiCode.deserializeMiraiCode(if (server) AronaNotifyConfig.notifyStringJP else AronaNotifyConfig.notifyStringEN)
val serverString = if (context.mergedJobDataMap?.get(NotifyStringKey) != null) {
MiraiCode.deserializeMiraiCode(notifyPrefix as String)
} else notifyPrefix
val endTime = if (isMidnightEndActivity(activity[0])) {
DropEndTime
} else {
Expand All @@ -190,10 +200,6 @@ object ActivityNotify: AronaQuartzService {

private fun isMaintenanceActivity(activity: Activity): Boolean = activity.type == ActivityType.MAINTENANCE

private fun isJPServer(activity: List<Activity>) = isJPServer(activity[0])

private fun isJPServer(activity: Activity) = activity.serverLocale == ServerLocale.JP

override fun init() {
registerService()
}
Expand All @@ -219,4 +225,4 @@ object ActivityNotify: AronaQuartzService {
// 每日防侠提醒类型
enum class NotifyType {
ALL, ONLY_24H, ONLY_48H
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object ActivityCommand : SimpleCommand(
when(locale) {
ServerLocale.JP -> sendJP(subject)
ServerLocale.GLOBAL -> sendEN(subject)
ServerLocale.CN -> sendCN(subject)
}
}
when {
Expand Down Expand Up @@ -49,7 +50,8 @@ object ActivityCommand : SimpleCommand(
}

private suspend fun sendCN(subject: Contact) {
subject.sendMessage("国服还没开呢,别急")
val cnActivity = ActivityUtil.fetchCNActivity()
send(subject, cnActivity, ServerLocale.CN)
}

private suspend fun send(subject: Contact, activities: Pair<List<Activity>, List<Activity>>, serverLocale: ServerLocale = ServerLocale.JP) {
Expand All @@ -65,4 +67,4 @@ object ActivityCommand : SimpleCommand(
registerService()
register()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ object AronaNotifyConfig: AutoSavePluginConfig("arona-notify") {
@ValueDescription("国际服防侠提醒开头文字")
val notifyStringEN: String by value("arona的防侠预警(国际服)")

@ValueDescription("\"/活动\"指令的默认目标服务器,可选值为 \"JP\"\"GLOBAL\"")
@ValueDescription("启用国服防侠提醒")
val enableCN: Boolean by value(true)

@ValueDescription("国服防侠提醒开头文字")
val notifyStringCN: String by value("arona的防侠预警(国服)")

@ValueDescription("\"/活动\"指令的默认目标服务器,可选值为 \"JP\"\"GLOBAL\"\"CN\"")
val defaultActivityCommandServer: ServerLocale by value(ServerLocale.JP)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class Activity(
enum class ServerLocale(val serverName: String, val dbName: String, val commandName: String) {
JP("日服", "JPN", "jp"),
GLOBAL("国际服", "GLB", "en"),
// CN("国服", "CN", "cn"),
CN("国服", "CN", "cn"),
}

enum class ActivityType(val level: Int) {
Expand All @@ -28,4 +28,4 @@ enum class ActivityType(val level: Int) {
MAINTENANCE(4), // 维护
ACTIVITY(2), // 普通活动
BIRTHDAY(5) //生日
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ data class CommonDAO(
val terrain = when(type){
ServerLocale.GLOBAL -> item.getOrNull(Raid.CurrentGLB)!!
ServerLocale.JP -> item.getOrNull(Raid.CurrentJPN)!!
ServerLocale.CN -> item.getOrNull(Raid.CurrentGLB)!!
}
dao.regions[serverType].current_raid = dao.regions[serverType].current_raid.plus(CurrentRaid(value, terrain, start, end))
}
Expand Down Expand Up @@ -231,4 +232,4 @@ data class CurrentRaid(
data class ChangeLog(
val date : String,
val contents : List<String>
)
)
64 changes: 54 additions & 10 deletions arona-core/src/main/kotlin/net/diyigemt/arona/util/ActivityUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object ActivityUtil {
private const val WikiruPage = "イベント一覧"
const val DEFAULT_CALENDAR_FONT_SIZE = 144
const val DEFAULT_CALENDAR_LINE_MARGIN = 30
const val DEFAULT_IMAGE_SCALE = 0.2F
const val DEFAULT_IMAGE_SCALE = 0.15F
const val ServerMaintenanceStartTimeEN = "11:00"
const val ServerMaintenanceStartTimeJP = "10:00"
const val ServerMaintenanceEndTimeEN = "15:00"
Expand Down Expand Up @@ -73,8 +73,9 @@ object ActivityUtil {

private fun fetchENActivityFromSchaleDB(): Pair<List<Activity>, List<Activity>> = SchaleDBUtil.getGlobalEventData()

private fun fetchENActivityFromGameKee(): Pair<List<Activity>, List<Activity>> =
GameKeeUtil.getEventData(ServerLocale.GLOBAL)
private fun fetchENActivityFromGameKee() = GameKeeUtil.getEventData(ServerLocale.GLOBAL)

private fun fetchCNActivityFromGameKee() = GameKeeUtil.getEventData(ServerLocale.CN)

fun fetchENActivity(): Pair<List<Activity>, List<Activity>> {
return fetchENActivityFromGameKee().let {
Expand All @@ -83,6 +84,13 @@ object ActivityUtil {
}
}

fun fetchCNActivity(): Pair<List<Activity>, List<Activity>> {
return fetchCNActivityFromGameKee().let {
// 加入生日信息
it.first to it.second.toMutableList().also { a -> a.addAll(SchaleDBUtil.getENBirthdayData()) }
}
}

fun fetchJPActivity(): Pair<List<Activity>, List<Activity>> {
return fetchJPActivityFromGameKee().let { it.first to it.second.toMutableList().also { a -> a.addAll(SchaleDBUtil.getJPBirthdayData()) } }
}
Expand Down Expand Up @@ -533,7 +541,7 @@ object ActivityUtil {
}

private fun extraActivityJPTypeFromCN(activity: Activity): Activity {
return activity
return extraActivityTypeFromGameKee(activity, ServerLocale.JP)
}

private fun extraActivityTypeFromGameKee(activity: Activity, server: ServerLocale): Activity {
Expand Down Expand Up @@ -630,6 +638,39 @@ object ActivityUtil {
doInsert0(now, parseStart, parseEnd, active, pending, activity)
}

/**
* 插入国服活动并对活动进行分类
* @param now 当前时间
* @param parseStart 活动开始时间
* @param parseEnd 活动结束时间
* @param active 正在进行的活动列表
* @param pending 即将开始的活动列表
* @param contentSource 活动内容
* @param type0 已知的活动类型(如果已经得知可以直接填,未知请在本方法里注册方法解析出来)
*/
fun insertCnActivity(
now: Date,
parseStart: Date,
parseEnd: Date,
active: MutableList<Activity>,
pending: MutableList<Activity>,
contentSource: String,
from: ActivityCNSource = ActivityCNSource.GAME_KEE,
type0: ActivityType = ActivityType.NULL
) {
var activity = Activity(
contentSource,
TimeUtil.calcTime(parseStart, true),
serverLocale = ServerLocale.CN,
)
if (type0 == ActivityType.NULL) {
activity = extraActivityTypeFromGameKee(activity, ServerLocale.CN)
} else {
activity.type = type0
}
doInsert0(now, parseStart, parseEnd, active, pending, activity)
}


/**
* 插入活动并对活动进行分类
Expand All @@ -655,8 +696,6 @@ object ActivityUtil {
}
}

private fun locale(type: ActivityType?): ServerLocale = if (type == null) ServerLocale.JP else ServerLocale.GLOBAL

private fun sortActive(active: Activity): Int {
val diff = calcDiffDayAndHour(active.time)
return diff.first * 24 + diff.second
Expand Down Expand Up @@ -716,8 +755,8 @@ object ActivityUtil {
drawActivity(pending, true)
ImageUtil.drawText(image, "数据来源: https://ba.gamekee.com/", calcY())
val imageFile = File(Arona.dataFolder.absolutePath + "/activity-${server.serverName}.png")
image.first.scale(DEFAULT_IMAGE_SCALE, DEFAULT_IMAGE_SCALE).makeImageSnapshot().also {
ImageIO.write(ImageIO.read(ByteArrayInputStream(it.encodeToData()?.bytes)), "png", imageFile)
image.first.scale(DEFAULT_IMAGE_SCALE, DEFAULT_IMAGE_SCALE).also {
ImageIO.write(it, "png", imageFile)
}
return imageFile
}
Expand All @@ -726,12 +765,17 @@ object ActivityUtil {
B_WIKI("https://wiki.biligame.com/bluearchive/"),
WIKI_RU("https://bluearchive.wikiru.jp/"),
GAME_KEE("https://ba.gamekee.com/"),
SCHALE_DB("https://lonqie.github.io/SchaleDB/")
SCHALE_DB("https://schale.gg/")
}

enum class ActivityENSource(val source: String) {
SCHALE_DB("https://lonqie.github.io/SchaleDB/"),
SCHALE_DB("https://schale.gg/"),
BILIBILI("https://space.bilibili.com/1585224247"),
GAME_KEE("https://ba.gamekee.com/")
}

enum class ActivityCNSource(val source: String) {
GAME_KEE("https://ba.gamekee.com/"),
SCHALE_DB("https://schale.gg/"),
}
}
Loading

0 comments on commit cc1c41f

Please sign in to comment.