From 69cfa25c720884f44d6ed99e24d2eb4176f09e37 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Tue, 16 Jan 2024 09:23:55 -0600 Subject: Cleanup calculate() (#689) Cleanup calculate() in Estimated Item Value. #689 --- .../misc/items/EstimatedItemValueCalculator.kt | 67 +++++++++++----------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt index c7a70f12c..601413065 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt @@ -56,48 +56,47 @@ import java.util.Locale object EstimatedItemValueCalculator { private val config get() = SkyHanniMod.feature.misc.estimatedItemValues - - fun calculate(stack: ItemStack, list: MutableList): Pair { - var totalPrice = 0.0 - val basePrice = addBaseItem(stack, list) - totalPrice += basePrice - - totalPrice += addAttributeCost(stack, list) - - totalPrice += addReforgeStone(stack, list) + private val additionalCostFunctions = listOf( + ::addAttributeCost, + ::addReforgeStone, // once - totalPrice += addRecomb(stack, list) - totalPrice += addArtOfWar(stack, list) - totalPrice += addArtOfPeace(stack, list) - totalPrice += addEtherwarp(stack, list) - totalPrice += addPowerScrolls(stack, list) - totalPrice += addWoodSingularity(stack, list) - totalPrice += addJalapenoBook(stack, list) - totalPrice += addStatsBook(stack, list) - totalPrice += addEnrichment(stack, list) + ::addRecomb, + ::addArtOfWar, + ::addArtOfPeace, + ::addEtherwarp, + ::addPowerScrolls, + ::addWoodSingularity, + ::addJalapenoBook, + ::addStatsBook, + ::addEnrichment, // counted - totalPrice += addMasterStars(stack, list) - totalPrice += addHotPotatoBooks(stack, list) - totalPrice += addFarmingForDummies(stack, list) - totalPrice += addSilex(stack, list) - totalPrice += addTransmissionTuners(stack, list) - totalPrice += addManaDisintegrators(stack, list) - totalPrice += addPolarvoidBook(stack, list) - totalPrice += addBookwormBook(stack, list) + ::addMasterStars, + ::addHotPotatoBooks, + ::addFarmingForDummies, + ::addSilex, + ::addTransmissionTuners, + ::addManaDisintegrators, + ::addPolarvoidBook, + ::addBookwormBook, // cosmetic - totalPrice += addHelmetSkin(stack, list) - totalPrice += addArmorDye(stack, list) - totalPrice += addRune(stack, list) + ::addHelmetSkin, + ::addArmorDye, + ::addRune, // dynamic - totalPrice += addAbilityScrolls(stack, list) - totalPrice += addDrillUpgrades(stack, list) - totalPrice += addGemstoneSlotUnlockCost(stack, list) - totalPrice += addGemstones(stack, list) - totalPrice += addEnchantments(stack, list) + ::addAbilityScrolls, + ::addDrillUpgrades, + ::addGemstoneSlotUnlockCost, + ::addGemstones, + ::addEnchantments + ) + + fun calculate(stack: ItemStack, list: MutableList): Pair { + val basePrice = addBaseItem(stack, list) + val totalPrice = additionalCostFunctions.fold(basePrice) { total, function -> total + function(stack, list) } return Pair(totalPrice, basePrice) } -- cgit