diff options
Diffstat (limited to 'src')
4 files changed, 86 insertions, 24 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/RewardWarningConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/RewardWarningConfig.java index d136894dd..eb160afcc 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/RewardWarningConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/RewardWarningConfig.java @@ -78,7 +78,29 @@ public class RewardWarningConfig { public boolean preventAcceptingCopper = false; @Expose - @ConfigOption(name = "Block Refusing New Visitors", desc = "Prevent refusing visitors you've never completed an offer with.") + @ConfigOption( + name = "Acceptable Coin Loss", + desc = "The price to use for the below options.\n" + + "Requires one of the below options to be on.\n" + + "Above options take precedence." + ) + @ConfigEditorSlider(minValue = 1, maxValue = 500_000, minStep = 1000) + public int coinsLossThreshold = 150_000; + + @Expose + @ConfigOption(name = "Block Refusing Low Loss", desc = "Prevent refusing a visitor with a net loss lower than a certain value.") + @ConfigEditorBoolean + @FeatureToggle + public boolean preventRefusingLowLoss = false; + + @Expose + @ConfigOption(name = "Block Accepting High Loss", desc = "Prevent accepting a visitor with a net loss higher than a certain value.") + @ConfigEditorBoolean + @FeatureToggle + public boolean preventAcceptingHighLoss = false; + + @Expose + @ConfigOption(name = "Block Refusing New Visitors", desc = "Prevents refusing a visitor you've never completed an offer with.") @ConfigEditorBoolean @FeatureToggle public boolean preventRefusingNew = true; diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index e1e42ad29..fc7397043 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -41,6 +41,7 @@ import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice @@ -97,6 +98,7 @@ object GardenVisitorFeatures { private val logger = LorenzLogger("garden/visitors") private var lastFullPrice = 0.0 + private val greenThumb = "GREEN_THUMB;1".asInternalName() @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -371,6 +373,10 @@ object GardenVisitorFeatures { val copper = group("amount").formatInt() val pricePerCopper = NumberUtil.format((totalPrice / copper).toInt()) visitor.pricePerCopper = (totalPrice / copper).toInt() + visitor.totalPrice = totalPrice + // Estimate could be changed to most value per copper item, instead of green thumb + val estimatedCopperValue = greenThumb.getPrice() / 1500 + visitor.totalReward = copper * estimatedCopperValue val timePerCopper = (farmingTimeRequired / copper).format() var copperLine = formattedLine if (config.inventory.copperPrice) copperLine += " §7(§6$pricePerCopper §7per)" diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt index b89981257..4c0fe34f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorAPI.kt @@ -131,6 +131,8 @@ object VisitorAPI { ) { var offersAccepted: Int? = null var pricePerCopper: Int? = null + var totalPrice: Double? = null + var totalReward: Double? = null var lore: List<String> = emptyList() var allRewards = listOf<NEUInternalName>() var lastLore = listOf<String>() @@ -195,11 +197,16 @@ object VisitorAPI { fun Visitor.blockReason(): VisitorBlockReason? = with(config.rewardWarning) { val pricePerCopper = pricePerCopper ?: error("pricePerCopper is null") + val totalPrice = totalPrice ?: error("totalPrice is null") + val totalReward = totalReward ?: error("totalReward is null") + val loss = totalPrice - totalReward; return when { preventRefusing && hasReward() != null -> VisitorBlockReason.RARE_REWARD preventRefusingNew && offersAccepted == 0 -> VisitorBlockReason.NEVER_ACCEPTED preventRefusingCopper && pricePerCopper <= coinsPerCopperPrice -> VisitorBlockReason.CHEAP_COPPER preventAcceptingCopper && pricePerCopper > coinsPerCopperPrice -> VisitorBlockReason.EXPENSIVE_COPPER + preventRefusingLowLoss && loss <= coinsLossThreshold -> VisitorBlockReason.LOW_LOSS + preventAcceptingHighLoss && loss > coinsLossThreshold -> VisitorBlockReason.HIGH_LOSS else -> null } @@ -209,6 +216,8 @@ object VisitorAPI { NEVER_ACCEPTED("§cNever accepted", true), RARE_REWARD("§aRare visitor reward found", true), CHEAP_COPPER("§aCheap copper", true), - EXPENSIVE_COPPER("§cExpensive copper", false) + EXPENSIVE_COPPER("§cExpensive copper", false), + LOW_LOSS("§cLow Loss", true), + HIGH_LOSS("§aHigh Loss", false) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt index 2336ce65a..ba56595bd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt @@ -18,6 +18,7 @@ import net.minecraft.inventory.Slot import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.math.absoluteValue class VisitorRewardWarning { private val config get() = VisitorAPI.config.rewardWarning @@ -25,7 +26,6 @@ class VisitorRewardWarning { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!VisitorAPI.inInventory) return - if (!config.preventRefusing && !config.preventRefusingCopper && !config.preventAcceptingCopper) return val visitor = VisitorAPI.getVisitor(lastClickedNpc) ?: return val refuseOfferSlot = event.gui.inventorySlots.getSlot(REFUSE_SLOT) @@ -92,29 +92,54 @@ class VisitorRewardWarning { if (!blockReason.blockRefusing && !isAcceptSlot) return if (visitor.blockedLore.isEmpty()) { - val copiedTooltip = event.toolTip.toList() - val blockedToolTip = mutableListOf<String>() - - for (line in copiedTooltip) { - if (line.contains("§aAccept Offer§r")) { - blockedToolTip.add(line.replace("§aAccept Offer§r", "§7Accept Offer§8")) - } else if (line.contains("§cRefuse Offer§r")) { - blockedToolTip.add(line.replace("§cRefuse Offer§r", "§7Refuse Offer§8")) - } else if (!line.contains("minecraft:") && !line.contains("NBT:")) { - blockedToolTip.add("§8" + line.removeColor()) - } - } - blockedToolTip.add("") - val pricePerCopper = visitor.pricePerCopper?.let { NumberUtil.format(it) } - blockedToolTip.add( - if (blockReason == VisitorBlockReason.CHEAP_COPPER || blockReason == VisitorBlockReason.EXPENSIVE_COPPER) - "${blockReason.description} §7(§6$pricePerCopper §7per)" else blockReason.description - ) - blockedToolTip.add(" §7(Bypass by holding ${KeyboardManager.getKeyName(config.bypassKey)})") - - visitor.blockedLore = blockedToolTip + updateBlockedLore(event.toolTip.toList(), visitor, blockReason) } event.toolTip.clear() event.toolTip.addAll(visitor.blockedLore) } + + private fun updateBlockedLore( + copiedTooltip: List<String>, + visitor: VisitorAPI.Visitor, + blockReason: VisitorBlockReason, + ) { + val blockedToolTip = mutableListOf<String>() + for (line in copiedTooltip) { + if (line.contains("§aAccept Offer§r")) { + blockedToolTip.add(line.replace("§aAccept Offer§r", "§7Accept Offer§8")) + } else if (line.contains("§cRefuse Offer§r")) { + blockedToolTip.add(line.replace("§cRefuse Offer§r", "§7Refuse Offer§8")) + } else if (!line.contains("minecraft:") && !line.contains("NBT:")) { + blockedToolTip.add("§8" + line.removeColor()) + } + } + + blockedToolTip.add("") + val pricePerCopper = visitor.pricePerCopper?.let { NumberUtil.format(it) } + // TODO remove !! - best by creating new class LoadedVisitor without any nullable objects + val loss = visitor.totalPrice!! - visitor.totalReward!! + val formattedLoss = NumberUtil.format(loss.absoluteValue) + blockedToolTip.add(blockReason(blockReason, pricePerCopper, loss, formattedLoss)) + blockedToolTip.add(" §7(Bypass by holding ${KeyboardManager.getKeyName(config.bypassKey)})") + + visitor.blockedLore = blockedToolTip + } + + private fun blockReason( + blockReason: VisitorBlockReason, + pricePerCopper: String?, + loss: Double, + formattedLoss: String, + ) = when (blockReason) { + VisitorBlockReason.CHEAP_COPPER, VisitorBlockReason.EXPENSIVE_COPPER -> + "${blockReason.description} §7(§6$pricePerCopper §7per)" + + VisitorBlockReason.LOW_LOSS, VisitorBlockReason.HIGH_LOSS -> + if (loss > 0) + "${blockReason.description} §7(§6$formattedLoss §7selling §9Green Thumb I§7)" + else + "§7(§6$formattedLoss §7profit §7selling §9Green Thumb I§7)" + + else -> blockReason.description + } } |