YuRaNnNzZZ — Сегодня, в 0:22
время проводить дестримификацию
This commit is contained in:
parent
296476e1d8
commit
6b5b1f938a
@ -5,6 +5,12 @@ import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
|||||||
import ru.dbotthepony.mc.otm.capability.UpgradeType
|
import ru.dbotthepony.mc.otm.capability.UpgradeType
|
||||||
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
import ru.dbotthepony.mc.otm.config.ConciseBalanceValues
|
||||||
import ru.dbotthepony.mc.otm.config.VerboseBalanceValues
|
import ru.dbotthepony.mc.otm.config.VerboseBalanceValues
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.filter
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.map
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.mapToDouble
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.mapToInt
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.reduce
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.sum
|
||||||
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
import ru.dbotthepony.mc.otm.core.isNotEmpty
|
||||||
import ru.dbotthepony.mc.otm.core.math.Decimal
|
import ru.dbotthepony.mc.otm.core.math.Decimal
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
@ -16,21 +22,21 @@ open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<Upgrad
|
|||||||
get() = setOf()
|
get() = setOf()
|
||||||
|
|
||||||
override val speedBonus: Double
|
override val speedBonus: Double
|
||||||
get() = stream().filter { it.isNotEmpty }.mapToDouble { it.getCapability(MatteryCapability.UPGRADE).map { it.speedBonus }.orElse(0.0) * it.count }.sum()
|
get() = iterator().filter { it.isNotEmpty }.mapToDouble { it.getCapability(MatteryCapability.UPGRADE).map { it.speedBonus }.orElse(0.0) * it.count }.sum()
|
||||||
override val processingItems: Int
|
override val processingItems: Int
|
||||||
get() = stream().filter { it.isNotEmpty }.mapToInt { it.getCapability(MatteryCapability.UPGRADE).map { it.processingItems }.orElse(0).coerceAtLeast(0) * it.count }.sum()
|
get() = iterator().filter { it.isNotEmpty }.mapToInt { it.getCapability(MatteryCapability.UPGRADE).map { it.processingItems }.orElse(0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b }
|
||||||
override val energyStorageFlat: Decimal
|
override val energyStorageFlat: Decimal
|
||||||
get() = stream().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyStorageFlat }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
get() = iterator().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyStorageFlat }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
override val energyStorage: Decimal
|
override val energyStorage: Decimal
|
||||||
get() = stream().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyStorage }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
get() = iterator().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyStorage }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
override val energyConsumed: Decimal
|
override val energyConsumed: Decimal
|
||||||
get() = stream().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyConsumed }.orElse(Decimal.ZERO) * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
get() = iterator().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyConsumed }.orElse(Decimal.ZERO) * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
override val failureMultiplier: Double
|
override val failureMultiplier: Double
|
||||||
get() = stream().filter { it.isNotEmpty }.mapToDouble { it.getCapability(MatteryCapability.UPGRADE).map { it.failureMultiplier }.orElse(1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b }
|
get() = iterator().filter { it.isNotEmpty }.mapToDouble { it.getCapability(MatteryCapability.UPGRADE).map { it.failureMultiplier }.orElse(1.0).coerceAtLeast(0.0).pow(it.count.toDouble()) }.reduce(1.0) { a, b -> a * b }
|
||||||
override val energyThroughputFlat: Decimal
|
override val energyThroughputFlat: Decimal
|
||||||
get() = stream().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyThroughputFlat }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
get() = iterator().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyThroughputFlat }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
override val energyThroughput: Decimal
|
override val energyThroughput: Decimal
|
||||||
get() = stream().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyThroughput }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
get() = iterator().filter { it.isNotEmpty }.map { it.getCapability(MatteryCapability.UPGRADE).map { it.energyThroughput }.orElse(Decimal.ZERO).moreThanZero() * it.count }.reduce(Decimal.ZERO, Decimal::plus)
|
||||||
|
|
||||||
fun transform(values: ConciseBalanceValues): ConciseBalanceValues {
|
fun transform(values: ConciseBalanceValues): ConciseBalanceValues {
|
||||||
return object : ConciseBalanceValues {
|
return object : ConciseBalanceValues {
|
||||||
|
@ -135,6 +135,78 @@ fun <T, R> Iterator<T>.map(mapper: java.util.function.Function<T, R>): Iterator<
|
|||||||
fun <T, R> Iterator<T>.flatMap(mapper: (T) -> Iterator<R>): Iterator<R> = FlatMappingIterator(this, mapper)
|
fun <T, R> Iterator<T>.flatMap(mapper: (T) -> Iterator<R>): Iterator<R> = FlatMappingIterator(this, mapper)
|
||||||
fun <T, R> Iterator<T>.flatMap(mapper: java.util.function.Function<T, Iterator<R>>): Iterator<R> = FlatMappingIterator(this, mapper::apply)
|
fun <T, R> Iterator<T>.flatMap(mapper: java.util.function.Function<T, Iterator<R>>): Iterator<R> = FlatMappingIterator(this, mapper::apply)
|
||||||
|
|
||||||
|
fun interface O2DFunction<T> {
|
||||||
|
fun apply(value: T): Double
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface O2IFunction<T> {
|
||||||
|
fun apply(value: T): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> Iterator<T>.mapToDouble(mapper: O2DFunction<T>): it.unimi.dsi.fastutil.doubles.DoubleIterator {
|
||||||
|
return object : it.unimi.dsi.fastutil.doubles.DoubleIterator {
|
||||||
|
override fun hasNext(): Boolean {
|
||||||
|
return this@mapToDouble.hasNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove() {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nextDouble(): Double {
|
||||||
|
return mapper.apply(this@mapToDouble.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> Iterator<T>.mapToInt(mapper: O2IFunction<T>): it.unimi.dsi.fastutil.ints.IntIterator {
|
||||||
|
return object : it.unimi.dsi.fastutil.ints.IntIterator {
|
||||||
|
override fun hasNext(): Boolean {
|
||||||
|
return this@mapToInt.hasNext()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun remove() {
|
||||||
|
throw UnsupportedOperationException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun nextInt(): Int {
|
||||||
|
return mapper.apply(this@mapToInt.next())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun it.unimi.dsi.fastutil.doubles.DoubleIterator.sum(): Double {
|
||||||
|
var value = 0.0
|
||||||
|
while (hasNext()) value += nextDouble()
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun it.unimi.dsi.fastutil.ints.IntIterator.sum(): Int {
|
||||||
|
var value = 0
|
||||||
|
while (hasNext()) value += nextInt()
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface DD2DFunction {
|
||||||
|
fun apply(a: Double, b: Double): Double
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface II2IFunction {
|
||||||
|
fun apply(a: Int, b: Int): Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun it.unimi.dsi.fastutil.doubles.DoubleIterator.reduce(identity: Double, reducer: DD2DFunction): Double {
|
||||||
|
var result = identity
|
||||||
|
while (hasNext()) result = reducer.apply(result, nextDouble())
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun it.unimi.dsi.fastutil.ints.IntIterator.reduce(identity: Int, reducer: II2IFunction): Int {
|
||||||
|
var result = identity
|
||||||
|
while (hasNext()) result = reducer.apply(result, nextInt())
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun <T> Iterator<T>.reduce(identity: T, reducer: (T, T) -> T): T {
|
fun <T> Iterator<T>.reduce(identity: T, reducer: (T, T) -> T): T {
|
||||||
var result = identity
|
var result = identity
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user