All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xyz.cssxsh.arknights.penguin.Dsl.kt Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package xyz.cssxsh.arknights.penguin

import xyz.cssxsh.arknights.*
import java.time.*

/**
 * 根据名字查找
 * @see Id.id
 */
public fun  Iterable.id(id: String): V = first { it.id in id }

/**
 * 根据类型分类
 * @see Item.type
 */
public fun > Iterable.types(): Map> = groupBy { it.type }

/**
 * 根据类型过滤
 * @see Item.type
 */
public fun > Iterable.types(vararg types: T): Map> =
    filter { it.type in types }.groupBy { it.type }

/**
 * 根据名称过滤
 */
public fun  Iterable.name(name: String): V = first { name in it.i18n.values }

/**
 * 根据名字查找掉落
 * @see Item.i18n
 * @see Item.alias
 */
public fun Iterable.name(name: String): Item =
    first { name in it.i18n.values || it.alias.any { (_, names) -> name in names } }

/**
 * 根据稀有度分类掉落
 * @see Item.rarity
 */
public fun Iterable.rarities(): Map> = groupBy { it.rarity }

/**
 * 根据稀有度过滤掉落 rarity in 0..4
 * @see Item.rarity
 */
public fun Iterable.rarities(vararg rarities: Int): Map> =
    filter { it.rarity in rarities }.groupBy { it.rarity }

/**
 * 根据COST消耗分类关卡
 * @see Stage.cost
 */
public fun Iterable.cost(): Map> = groupBy { it.cost }

/**
 * 根据COST消耗过滤关卡
 * @see Stage.cost
 */
public fun Iterable.cost(costs: IntRange): Map> =
    filter { it.cost in costs }.groupBy { it.cost }

/**
 * 根据掉落物过滤
 * @see Drop.drops
 */
public fun  Iterable.drop(item: Item): List = filter { it.drops.any { info -> info.itemId == item.id } }

/**
 * 根据掉落物过滤
 * @see drop
 * @see name
 */
public fun  Pair, Iterable>.drop(name: String): List = first.drop(second.name(name))

/**
 * 根据区域过滤
 * @see ZoneId.zoneId
 */
public fun  Iterable.zone(zone: Zone): List = filter { it.zoneId == zone.id }

/**
 * 根据 isGacha 过滤关卡
 * @see Stage.isGacha
 */
public fun Iterable.gacha(value: Boolean): List = filter { it.isGacha == value }

/**
 * 根据名字过滤区域
 * @see Zone.i18n
 */
public fun  Iterable.with(zones: Iterable): List> = map { it to zones.id(it.zoneId) }

/**
 * 根据物品ID过滤掉落记录
 * @see Matrix.itemId
 */
public fun  Iterable.item(item: Item): List = filter { it.itemId == item.id }

/**
 * 连接物品
 */
@JvmName("withItem")
public infix fun  Iterable.with(items: Iterable): List> =
    map { it to items.id(it.itemId) }

/**
 * 平均品质
 */
public val Pair.rarity: Double get() = first.probability * second.rarity

/**
 * 根据关卡过滤掉落记录
 * @see Matrix.stageId
 */
public fun  Iterable.stage(stage: Stage): List = filter { it.stageId == stage.id }

/**
 * 连接关卡
 */
@JvmName("withStage")
public infix fun  Iterable.with(stages: Iterable): List> =
    map { it to stages.id(it.stageId) }

/**
 * 计算单个用时
 */
public val Pair.single: Double get() = second.cost / first.probability


/**
 * 计算最短用时
 */
public val Pair.short: Long get() = (second.minClearTime / first.probability).toLong()

/**
 * 根据时间戳过滤
 * @see TimePeriod
 */
public fun  Iterable.time(time: OffsetDateTime): List = filter { time in it.start..it.end }

/**
 * 根据当前时间戳过滤
 * @see TimePeriod
 */
public fun  Iterable.now(): List = time(OffsetDateTime.now())

public typealias I18n = Map

public interface Existences {
    public val existence: Server
}

public interface NameI18n {
    public val i18n: I18n
}

public fun  I18n.locale(): T? = get(SERVER.locale.language)

public interface Id {
    public val id: String
}

public interface Type> {
    public val type: T
}

public interface Quantity {
    public val quantity: Long
}

public interface Times {
    public val times: Long
}

public interface Frequency : Quantity, Times {
    public val probability: Double get() = (quantity.toDouble() / times)
}

public interface TimePeriod {
    public val start: OffsetDateTime
    public val end: OffsetDateTime
}

public interface ItemId {
    public val itemId: String
}

public interface StageId {
    public val stageId: String
}

public interface ZoneId {
    public val zoneId: String
}

public interface Drop {
    public val drops: List
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy