Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Pest Profit Tracker #1321

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ import at.hannibal2.skyhanni.features.garden.inventory.plots.GardenPlotMenuHighl
import at.hannibal2.skyhanni.features.garden.pests.PestAPI
import at.hannibal2.skyhanni.features.garden.pests.PestFinder
import at.hannibal2.skyhanni.features.garden.pests.PestParticleWaypoint
import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker
import at.hannibal2.skyhanni.features.garden.pests.PestSpawn
import at.hannibal2.skyhanni.features.garden.pests.PestSpawnTimer
import at.hannibal2.skyhanni.features.garden.pests.SprayDisplay
Expand Down Expand Up @@ -806,6 +807,7 @@ class SkyHanniMod {
loadModule(LimboPlaytime())
loadModule(RareDropMessages())
loadModule(CraftMaterialsFromBazaar())
loadModule(PestProfitTracker)

init()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import at.hannibal2.skyhanni.features.garden.farming.GardenStartLocation
import at.hannibal2.skyhanni.features.garden.farming.lane.FarmingLaneCreator
import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear
import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI
import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker
import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics
import at.hannibal2.skyhanni.features.mining.KingTalismanHelper
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker
Expand Down Expand Up @@ -246,6 +247,10 @@ object Commands {
"shresetdianaprofittracker",
"Resets the Diana Profit Tracker"
) { DianaProfitTracker.resetCommand(it) }
registerCommand(
"shresetpestprofittracker",
"Resets the Pest Profit Tracker"
) { PestProfitTracker.resetCommand(it) }
registerCommand(
"shresetmythologicalcreatureracker",
"Resets the Mythological Creature Tracker"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package at.hannibal2.skyhanni.config.features.garden.pests;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigEditorSlider;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

public class PestProfitTrackerConfig {

@Expose
@ConfigOption(
name = "Enabled",
desc = "Count all items you pick up when killing pests."
)
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = true;

@Expose
@ConfigOption(
name = "Hide messages",
desc = "Hides regular pest drop messages."
)
@ConfigEditorBoolean
public boolean hideChat = true;

@Expose
@ConfigOption(name = "Time Displayed", desc = "Time displayed after killing a pest.")
@ConfigEditorSlider(minValue = 5, maxValue = 60, minStep = 1)
public int timeDisplayed = 30;

@Expose
public Position position = new Position(20, 20, false, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class PestsConfig {
@Accordion
public PestTimerConfig pestTimer = new PestTimerConfig();

@Expose
@ConfigOption(name = "Pest Profit Tracker", desc = "")
@Accordion
public PestProfitTrackerConfig pestProfitTacker = new PestProfitTrackerConfig();

@Expose
@ConfigOption(name = "Spray", desc = "")
@Accordion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import at.hannibal2.skyhanni.features.garden.farming.DicerRngDropTracker;
import at.hannibal2.skyhanni.features.garden.farming.lane.FarmingLane;
import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems;
import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker;
import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward;
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker;
import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker;
Expand Down Expand Up @@ -283,6 +284,9 @@ public static class FarmingWeightConfig {

@Expose
public Map<String, LorenzVec> npcVisitorLocations = new HashMap<>();

@Expose
public PestProfitTracker.Data pestProfitTracker = new PestProfitTracker.Data();
}

@Expose
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package at.hannibal2.skyhanni.features.garden.pests

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.PurseChangeCause
import at.hannibal2.skyhanni.events.PurseChangeEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import at.hannibal2.skyhanni.utils.tracker.ItemTrackerData
import at.hannibal2.skyhanni.utils.tracker.SkyHanniItemTracker
import com.google.gson.annotations.Expose
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds

object PestProfitTracker {
val config get() = SkyHanniMod.feature.garden.pests.pestProfitTacker

private val patternGroup = RepoPattern.group("garden.pests.tracker")

/**
* REGEX-TEST: §eYou received §a7x Enchanted Potato §efor killing a §6Locust§e!
* REGEX-TEST: §eYou received §a6x Enchanted Cocoa Beans §efor killing a §6Moth§e!
*/
private val pestLootPattern by patternGroup.pattern(
"loot",
"§eYou received §a(?<amount>[0-9]*)x (?<item>.*) §efor killing an? §6(?<pest>.*)§e!"
)

/**
* REGEX-TEST: §6§lRARE DROP! §9Mutant Nether Wart §6(§6+1,344☘)
* REGEX-TEST: §6§lPET DROP! §r§5Slug §6(§6+1300☘)
*/
private val pestRareDropPattern by patternGroup.pattern(
"raredrop",
"§6§l(?:RARE|PET) DROP! (?:§.)*(?<item>.+) §6\\(§6\\+.*☘\\)"
)

private var lastPestKillTime = SimpleTimeMark.farPast()
private val tracker = SkyHanniItemTracker(
"Pest Profit Tracker",
{ Data() },
{ it.garden.pestProfitTracker }) { drawDisplay(it) }

class Data : ItemTrackerData() {
override fun resetItems() {
totalPestsKills = 0L
}

override fun getDescription(timesGained: Long): List<String> {
val percentage = timesGained.toDouble() / totalPestsKills
val dropRate = LorenzUtils.formatPercentage(percentage.coerceAtMost(1.0))
return listOf(
"§7Dropped §e${timesGained.addSeparators()} §7times.",
"§7Your drop rate: §c$dropRate."
)
}

override fun getCoinName(item: TrackedItem) = "§6Pest Kill Coins"

override fun getCoinDescription(item: TrackedItem): List<String> {
val pestsCoinsFormat = NumberUtil.format(item.totalAmount)
return listOf(
"§7Killing pests gives you coins.",
"§7You got §6$pestsCoinsFormat coins §7that way."
)
}

@Expose
var totalPestsKills = 0L
}

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
pestLootPattern.matchMatcher(event.message) {
val amount = group("amount").toInt()
val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return

tracker.addItem(internalName, amount)
addKill()
if (config.hideChat) event.blockedReason = "pest_drop"
}
pestRareDropPattern.matchMatcher(event.message) {
val internalName = NEUInternalName.fromItemNameOrNull(group("item")) ?: return

tracker.addItem(internalName, 1)
// pests always have guaranteed loot, therefore there's no need to add kill here
}
}

private fun addKill() {
tracker.modify {
it.totalPestsKills++
}
lastPestKillTime = SimpleTimeMark.now()
}

private fun drawDisplay(data: Data): List<List<Any>> = buildList {
addAsSingletonList("§e§lPest Profit Tracker")
val profit = tracker.drawItems(data, { true }, this)

val pestsKilled = data.totalPestsKills
addAsSingletonList(
Renderable.hoverTips(
"§7Pests killed: §e${pestsKilled.addSeparators()}",
listOf("§7You killed pests §e${pestsKilled.addSeparators()} §7times.")
)
)
addAsSingletonList(tracker.addTotalProfit(profit, data.totalPestsKills, "kill"))

tracker.addPriceFromButton(this)
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent) {
if (!isEnabled()) return
if (GardenAPI.isCurrentlyFarming()) return
if (lastPestKillTime.passedSince() > config.timeDisplayed.seconds && !PestAPI.hasVacuumInHand()) return

tracker.renderDisplay(config.position)
}

@SubscribeEvent
fun onPurseChange(event: PurseChangeEvent) {
if (!isEnabled()) return
val coins = event.coins
if (event.reason == PurseChangeCause.GAIN_MOB_KILL && lastPestKillTime.passedSince() < 2.seconds) {
tracker.addCoins(coins.toInt())
}
}

fun resetCommand(args: Array<String>) {
tracker.resetCommand(args, "shresetpestprofittracker")
}

fun isEnabled() = GardenAPI.inGarden() && config.enabled
}
Loading