Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
xyz.cssxsh.arknights.penguin.Data.kt Maven / Gradle / Ivy
package xyz.cssxsh.arknights.penguin
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import xyz.cssxsh.arknights.*
import java.time.*
/**
* 根据名字查找
* @see Id.id
*/
fun Iterable.id(id: String) = first { it.id in id }
/**
* 根据类型分类
* @see Item.type
*/
fun > Iterable.types() = groupBy { it.type }
/**
* 根据类型过滤
* @see Item.type
*/
fun > Iterable.types(vararg types: T) = filter { it.type in types }.groupBy { it.type }
/**
* 根据名称过滤
*/
fun Iterable.name(name: String) = first { name in it.i18n.values }
/**
* 根据名字查找掉落
* @see Item.i18n
* @see Item.alias
*/
fun Iterable- .name(name: String) = first { name in it.i18n.values || it.alias.any { (_, names) -> name in names } }
/**
* 根据稀有度分类掉落 rarity in 0..4
* @see Item.rarity
*/
fun Iterable
- .rarities() = groupBy { it.rarity }
/**
* 根据稀有度过滤掉落 rarity in 0..4
* @see Item.rarity
*/
fun Iterable
- .rarities(vararg rarities: Int) = filter { it.rarity in rarities }.groupBy { it.rarity }
/**
* 根据COST消耗分类关卡
* @see Stage.cost
*/
fun Iterable
.cost() = groupBy { it.cost }
/**
* 根据COST消耗过滤关卡
* @see Stage.cost
*/
fun Iterable.cost(costs: IntRange) = filter { it.cost in costs }.groupBy { it.cost }
/**
* 根据掉落物过滤
* @see Drop.drops
*/
fun Iterable.drop(item: Item) = filter { it.drops.any { info -> info.itemId == item.id } }
/**
* 根据掉落物过滤
* @see drop
* @see name
*/
fun Pair, Iterable- >.drop(name: String) = first.drop(second.name(name))
/**
* 根据区域过滤
* @see ZoneId.zoneId
*/
fun
Iterable.zone(zone: Zone) = filter { it.zoneId == zone.id }
/**
* 根据 isGacha 过滤关卡
* @see Stage.isGacha
*/
fun Iterable.gacha(value: Boolean) = filter { it.isGacha == value }
/**
* 根据名字过滤区域
* @see Zone.i18n
*/
fun Pair, Iterable>.name(name: String) = first.name(name).let { it to second.zone(it) }
/**
* 根据名字过滤区域
* @see Zone.i18n
*/
fun Iterable.with(zones: Iterable) = map { it to zones.id(it.zoneId) }
/**
* 根据物品ID过滤掉落记录
* @see Matrix.itemId
*/
fun Iterable.item(item: Item) = filter { it.itemId == item.id }
/**
* 根据物品名过滤掉落记录
* @see item
* @see name
*/
fun Pair, Iterable>.item(name: String) = first.name(name).let { it to second.item(it) }
/**
* XXX
*/
@JvmName("withItem")
infix fun Iterable.with(items: Iterable- ) = map { it to items.id(it.itemId) }
/**
* XXX
*/
val Pair
.rarity get() = first.probability * second.rarity
/**
* 根据关卡过滤掉落记录
* @see Matrix.stageId
*/
fun Iterable.stage(stage: Stage) = filter { it.stageId == stage.id }
/**
* 根据物品名过滤掉落记录
* @see stage
* @see code
*/
fun Pair, Iterable>.stage(code: String) =
first.name(code).let { it to second.stage(it) }
/**
* XXX
*/
@JvmName("withStage")
infix fun Iterable.with(stages: Iterable) = map { it to stages.id(it.stageId) }
/**
* XXX
*/
val Pair<*, Stage>.stage get() = second
/**
* XXX
*/
val Pair.frequency get() = first
/**
* XXX
*/
val Pair.single get() = stage.cost / frequency.probability
/**
* XXX
*/
val Pair.short get() = (stage.minClearTime / frequency.probability).toLong()
/**
* 根据时间戳过滤
* @see TimePeriod
*/
fun Iterable.time(time: OffsetDateTime) = filter { time in it.start..it.end }
/**
* 根据当前时间戳过滤
* @see TimePeriod
*/
fun Iterable.now() = time(OffsetDateTime.now())
typealias I18n = Map
object OffsetDataTimeSerializer : KSerializer {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor(OffsetDateTime::class.qualifiedName!!, PrimitiveKind.LONG)
override fun deserialize(decoder: Decoder): OffsetDateTime {
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(decoder.decodeLong()), SERVER_ZONE)
}
override fun serialize(encoder: Encoder, value: OffsetDateTime) {
encoder.encodeLong(value.toEpochSecond() * 1_000)
}
}
interface Existences {
val existence: Server
}
interface NameI18n {
val i18n: I18n
}
infix fun I18n.get(server: ServerType) = get(server.locale.language)
fun I18n.get() = get(SERVER.locale.language)
interface Id {
val id: String
}
interface Type> {
val type: T
}
interface Quantity {
val quantity: Long
}
interface Times {
val times: Long
}
interface Frequency : Quantity, Times {
val probability get() = (quantity.toDouble() / times)
}
interface TimePeriod {
val start: OffsetDateTime
val end: OffsetDateTime
}
interface ItemId {
val itemId: String
}
interface StageId {
val stageId: String
}
interface ZoneId {
val zoneId: String
}
interface Drop {
val drops: List
}
@Serializable
data class Existence(
@SerialName("exist")
val exist: Boolean,
@SerialName("openTime")
@Serializable(OffsetDataTimeSerializer::class)
override val start: OffsetDateTime = OffsetDateTime.MIN,
@SerialName("closeTime")
@Serializable(OffsetDataTimeSerializer::class)
override val end: OffsetDateTime = OffsetDateTime.MAX
) : TimePeriod
@Serializable
data class Item(
@SerialName("addTimePoint")
val addTimePoint: Int? = null,
@SerialName("alias")
val alias: I18n>,
@SerialName("existence")
override val existence: Server,
@SerialName("groupID")
val groupId: String? = null,
@SerialName("itemId")
override val id: String,
@SerialName("itemType")
override val type: ItemType,
@SerialName("name")
val name: String,
@SerialName("name_i18n")
override val i18n: I18n,
@SerialName("pron")
val pron: I18n>,
@SerialName("rarity")
val rarity: Int,
@SerialName("sortId")
val sortId: Int,
@SerialName("spriteCoord")
val sprites: List = emptyList()
) : Existences, NameI18n, Id, Type
enum class ItemType {
CARD_EXP,
MATERIAL,
FURN,
ACTIVITY_ITEM,
TEMP,
LGG_SHD,
ARKPLANNER,
CHIP
}
@Serializable
data class Stage(
@SerialName("apCost")
val cost: Int,
@SerialName("code")
val code: String,
@SerialName("code_i18n")
override val i18n: I18n,
@SerialName("dropInfos")
override val drops: List = emptyList(),
@SerialName("existence")
override val existence: Server,
/**
* 单位毫秒
*/
@SerialName("minClearTime")
val minClearTime: Long = 0,
@SerialName("stageId")
override val id: String,
@SerialName("stageType")
override val type: StageType,
@SerialName("zoneId")
override val zoneId: String,
@SerialName("isGacha")
val isGacha: Boolean = false,
@SerialName("recognitionOnly")
val recognitionOnly: List = emptyList()
) : Existences, NameI18n, Id, Type, Drop, ZoneId
enum class StageType {
MAIN,
SUB,
ACTIVITY,
DAILY
}
@Serializable
data class DropInfo(
@SerialName("bounds")
val bounds: Bounds,
@SerialName("dropType")
val type: DropType,
@SerialName("itemId")
override val itemId: String = ""
) : ItemId
enum class DropType {
NORMAL_DROP,
EXTRA_DROP,
FURNITURE,
SPECIAL_DROP
}
@Serializable
data class Bounds(
@SerialName("lower")
val lower: Int,
@SerialName("upper")
val upper: Int,
@SerialName("exceptions")
val exceptions: List = emptyList()
)
@Serializable
data class Zone(
@SerialName("background")
val background: String? = null,
@SerialName("existence")
override val existence: Server,
@SerialName("stages")
val stages: List,
@SerialName("type")
override val type: ZoneType,
@SerialName("zoneId")
override val id: String,
@SerialName("zoneIndex")
val index: Int,
@SerialName("zoneName")
val name: String,
@SerialName("zoneName_i18n")
override val i18n: I18n
) : Existences, NameI18n, Id, Type
enum class ZoneType {
MAINLINE,
ACTIVITY,
WEEKLY
}
@Serializable
data class Period(
@SerialName("existence")
override val existence: Server,
@SerialName("label_i18n")
override val i18n: I18n,
@SerialName("start")
@Serializable(OffsetDataTimeSerializer::class)
override val start: OffsetDateTime,
@SerialName("end")
@Serializable(OffsetDataTimeSerializer::class)
override val end: OffsetDateTime = OffsetDateTime.now()
) : Existences, NameI18n, TimePeriod
@Serializable
data class ServerStats(
@SerialName("totalApCost")
val totalCost: Long,
@SerialName("totalItemQuantities")
val totalItemQuantities: List,
@SerialName("totalStageTimes")
val totalStageTimes: List,
@SerialName("totalStageTimes_24h")
val totalStageTimes24h: List
)
@Serializable
data class ItemQuantity(
@SerialName("itemId")
override val itemId: String,
@SerialName("quantity")
override val quantity: Long
) : Quantity, ItemId
@Serializable
data class StageTimes(
@SerialName("stageId")
override val stageId: String,
@SerialName("times")
override val times: Long
) : Times, StageId
@Serializable
data class MatrixData(
@SerialName("matrix")
val matrices: List
)
@Serializable
data class Matrix(
@SerialName("end")
@Serializable(OffsetDataTimeSerializer::class)
override val end: OffsetDateTime = OffsetDateTime.MAX,
@SerialName("itemId")
override val itemId: String,
@SerialName("quantity")
override val quantity: Long,
@SerialName("stageId")
override val stageId: String,
@SerialName("start")
@Serializable(OffsetDataTimeSerializer::class)
override val start: OffsetDateTime,
@SerialName("times")
override val times: Long
) : Frequency, TimePeriod, ItemId, StageId
@Serializable
data class PatternData(
@SerialName("pattern_matrix")
val patterns: List
)
@Serializable
data class PatternMatrix(
@SerialName("end")
@Serializable(OffsetDataTimeSerializer::class)
override val end: OffsetDateTime = OffsetDateTime.now(),
@SerialName("pattern")
val pattern: Pattern,
@SerialName("quantity")
override val quantity: Long,
@SerialName("stageId")
override val stageId: String,
@SerialName("start")
@Serializable(OffsetDataTimeSerializer::class)
override val start: OffsetDateTime,
@SerialName("times")
override val times: Long
) : Frequency, TimePeriod, StageId
@Serializable
data class Pattern(
@SerialName("drops")
override val drops: List
) : Drop