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

Improvement: Add ability to use /shedittracker with CorpseTracker #2582

Closed
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package at.hannibal2.skyhanni.features.mining.glacitemineshaft
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.MiningAPI
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.IslandChangeEvent
import at.hannibal2.skyhanni.events.ItemAddEvent
import at.hannibal2.skyhanni.events.mining.CorpseLootedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.CollectionUtils.sumAllValues
Expand Down Expand Up @@ -136,6 +140,20 @@ object CorpseTracker {
}
}

@SubscribeEvent
fun onItemAdd(event: ItemAddEvent) {
if (!isEnabled()) return
ProfileStorageData.profileSpecific?.mining?.mineshaft?.corpseProfitTracker?.let { trackerData ->
trackerData.getSelectedBucket()?.let {
tracker.addItem(it, event.internalName, event.amount)
ChatUtils.chat("Added ${event.internalName.itemName} §8x${event.amount} to Corpse Tracker §8(${it.displayName}§8)§e.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be abstracted into the bucketed item tracker.
ideally the bucketed item tracker would reuse the logic from skyhann iitem tracker so that this unique chat message is not necessary in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't re-use the logic - they're entirely separate trackers. The item trackers just have the concept of one set of global "loot" that's added to - this is an enum driven base of buckets, the logic doesn't fit. The only way I could think to do this was using the currently-selected bucket.

Best I could do would be to abstract it back to the bucketed item tracker, however that message is going to end up having to be very generic. We can't do it in SkyhanniItemTracker and expect it to work here - the addItem signatures are already overridden for SkyhanniBucketedItemTracker, as it takes a bucket as first param.

We also don't have the context of the tracker instance in the tracker itself, which would prevent actually moving this into the generic SkyhanniBucketedItemTracker, as we need to know the currently selected bucket;

ProfileStorageData.profileSpecific?.mining?.mineshaft?.corpseProfitTracker?.let {
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I could think to do this was using the currently-selected bucket.

I was not expecting anything more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about abstracting the existing item tracker class and creating a new "single bucketed tracker" for everything else?

} ?: ChatUtils.chat(
"§cYou do not have a Corpse Type selected, and cannot add loot to this tracker generically.\n" +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this will clash with the default answer messages from /shedittracker

"§eSelect a type in the GUI in your inventory, then re-run this command."
)
} ?: ErrorManager.skyHanniError("Could not fetch profile storage data for CorpseTracker.")
}

fun resetCommand() {
tracker.resetCommand()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SkyHanniBucketedItemTracker<E : Enum<E>, BucketedData : BucketedItemTracke
addItem(bucket, SKYBLOCK_COIN, coins)
}

fun addItem(bucket: E, internalName: NEUInternalName, amount: Int) {
fun addItem(bucket: E, internalName: NEUInternalName, amount: Int, manuallyAdded: Boolean = false) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned before, i recomment moving this into skyhanni item tracker, avoiding the code duplication alltogether

modify {
it.addItem(bucket, internalName, amount)
}
Expand All @@ -46,10 +46,10 @@ class SkyHanniBucketedItemTracker<E : Enum<E>, BucketedData : BucketedItemTracke
}

val (itemName, price) = SlayerAPI.getItemNameAndPrice(internalName, amount)
if (config.warnings.chat && price >= config.warnings.minimumChat) {
if (config.warnings.chat && price >= config.warnings.minimumChat && !manuallyAdded) {
ChatUtils.chat("§a+Tracker Drop§7: §r$itemName")
}
if (config.warnings.title && price >= config.warnings.minimumTitle) {
if (config.warnings.title && price >= config.warnings.minimumTitle && !manuallyAdded) {
LorenzUtils.sendTitle("§a+ $itemName", 5.seconds)
}
}
Expand Down
Loading