Fixed energy consumption not being merged properly
This commit is contained in:
parent
b3651b1f86
commit
9800eb35ba
@ -16,32 +16,38 @@ open class UpgradeContainer(slotCount: Int, open val allowedUpgrades: Set<Upgrad
|
||||
final override val upgradeTypes: Set<UpgradeType>
|
||||
get() = setOf()
|
||||
|
||||
protected fun decimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal {
|
||||
protected fun positiveDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal {
|
||||
return iterator()
|
||||
.map { it.getCapability(MatteryCapability.UPGRADE).map(fn).orElse(Decimal.ZERO).moreThanZero() * it.count }
|
||||
.reduce(Decimal.ZERO, reducer)
|
||||
}
|
||||
|
||||
protected fun anyDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal {
|
||||
return iterator()
|
||||
.map { it.getCapability(MatteryCapability.UPGRADE).map(fn).orElse(Decimal.ZERO) * it.count }
|
||||
.reduce(Decimal.ZERO, reducer)
|
||||
}
|
||||
|
||||
override val speedBonus: Double
|
||||
get() = iterator().map { it.getCapability(MatteryCapability.UPGRADE).map { it.speedBonus }.orElse(0.0) * it.count }.reduce(0.0) { a, b -> a + b }
|
||||
override val processingItems: Int
|
||||
get() = iterator().map { it.getCapability(MatteryCapability.UPGRADE).map { it.processingItems }.orElse(0).coerceAtLeast(0) * it.count }.reduce(0) { a, b -> a + b }
|
||||
override val energyStorageFlat: Decimal
|
||||
get() = decimals(IMatteryUpgrade::energyStorageFlat, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyStorageFlat, Decimal::plus)
|
||||
override val energyStorage: Decimal
|
||||
get() = decimals(IMatteryUpgrade::energyStorage, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyStorage, Decimal::plus)
|
||||
override val matterStorageFlat: Decimal
|
||||
get() = decimals(IMatteryUpgrade::matterStorageFlat, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::matterStorageFlat, Decimal::plus)
|
||||
override val matterStorage: Decimal
|
||||
get() = decimals(IMatteryUpgrade::matterStorage, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::matterStorage, Decimal::plus)
|
||||
override val energyConsumed: Decimal
|
||||
get() = decimals(IMatteryUpgrade::energyConsumed, Decimal::plus)
|
||||
get() = anyDecimals(IMatteryUpgrade::energyConsumed, Decimal::plus)
|
||||
override val failureMultiplier: Double
|
||||
get() = iterator().map { 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
|
||||
get() = decimals(IMatteryUpgrade::energyThroughputFlat, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyThroughputFlat, Decimal::plus)
|
||||
override val energyThroughput: Decimal
|
||||
get() = decimals(IMatteryUpgrade::energyThroughput, Decimal::plus)
|
||||
get() = positiveDecimals(IMatteryUpgrade::energyThroughput, Decimal::plus)
|
||||
|
||||
fun transform(values: EnergyBalanceValues): EnergyBalanceValues {
|
||||
return object : EnergyBalanceValues {
|
||||
|
Loading…
Reference in New Issue
Block a user