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: Draconic Sacrifice Tracker #2077

Open
wants to merge 21 commits into
base: beta
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .idea/dictionaries/default_user.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ object Commands {
event.register("shcopytranslation") {
description =
"Copy the translation of a message in another language to your clipboard.\n" +
"Uses a 2 letter language code that can be found at the end of a translation message."
"Uses a 2 letter language code that can be found at the end of a translation message."
category = CommandCategory.USERS_ACTIVE
callback { Translator.fromNativeLanguage(it) }
}
Expand Down Expand Up @@ -588,7 +588,7 @@ object Commands {
event.register("shdebugscoreboard") {
description =
"Monitors the scoreboard changes: " +
"Prints the raw scoreboard lines in the console after each update, with time since last update."
"Prints the raw scoreboard lines in the console after each update, with time since last update."
category = CommandCategory.DEVELOPER_DEBUG
callback { ScoreboardData.toggleMonitor() }
}
Expand Down Expand Up @@ -744,8 +744,8 @@ object Commands {
event.register("shresetconfig") {
description =
"Reloads the config manager and rendering processors of MoulConfig. " +
"This §cWILL RESET §7your config, but also updating the java config files " +
"(names, description, orderings and stuff)."
"This §cWILL RESET §7your config, but also updating the java config files " +
"(names, description, orderings and stuff)."
category = CommandCategory.DEVELOPER_TEST
callback { SkyHanniDebugsAndTests.resetConfigCommand() }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package at.hannibal2.skyhanni.config.features.misc;

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

public class DraconicSacrificeTrackerConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Enable the Draconic sacrifice tracker.")
@ConfigEditorBoolean
superhize marked this conversation as resolved.
Show resolved Hide resolved
@FeatureToggle
public boolean enabled = true;

@Expose
@ConfigOption(name = "Only In Void Slate", desc = "Show the tracker only when inside the Void Slate area.")
@ConfigEditorBoolean
public boolean onlyInVoidSlate = true;

@Expose
@ConfigLink(owner = DraconicSacrificeTrackerConfig.class, field = "enabled")
public Position position = new Position(201, 199, false, true);

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public class MiscConfig {
@Accordion
public PatcherCoordsWaypointConfig patcherCoordsWaypoint = new PatcherCoordsWaypointConfig();

@Expose
@ConfigOption(name = "Draconic Sacrifice Tracker", desc = "")
@Accordion
public DraconicSacrificeTrackerConfig draconicSacrificeTracker = new DraconicSacrificeTrackerConfig();
superhize marked this conversation as resolved.
Show resolved Hide resolved

@Expose
@ConfigOption(name = "Reminders", desc = "")
@Accordion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker;
import at.hannibal2.skyhanni.features.mining.glacitemineshaft.CorpseTracker;
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker;
import at.hannibal2.skyhanni.features.misc.DraconicSacrificeTracker;
import at.hannibal2.skyhanni.features.misc.trevor.TrevorTracker;
import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker;
import at.hannibal2.skyhanni.features.rift.area.westvillage.kloon.KloonTerminal;
Expand Down Expand Up @@ -724,6 +725,9 @@ public static class WardrobeStorage {
public Integer currentSlot = null;
}

@Expose
public DraconicSacrificeTracker.Data draconicSacrificeTracker = new DraconicSacrificeTracker.Data();

@Expose
public UpgradeReminder.CommunityShopUpgrade communityShopProfileUpgrade = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package at.hannibal2.skyhanni.features.misc

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.config.commands.CommandCategory
import at.hannibal2.skyhanni.config.commands.CommandRegistrationEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside
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.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.renderables.Searchable
import at.hannibal2.skyhanni.utils.renderables.toSearchable
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.minecraft.util.AxisAlignedBB
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object DraconicSacrificeTracker {

private val config get() = SkyHanniMod.feature.misc.draconicSacrificeTracker
private val patternGroup = RepoPattern.group("misc.draconicsacrifice")

/**
* REGEX-TEST: §c§lSACRIFICE! §r§eYou turned §r§5Ender Boots §r§einto §r§d3 Dragon Essence§r§e!
* REGEX-TEST: §c§lSACRIFICE! §r§eYou turned §r§5Ender Helmet §r§einto §r§d3 Dragon Essence§r§e!
* REGEX-TEST: §c§lSACRIFICE! §r§eYou turned §r§6Old Dragon Helmet §r§einto §r§d25 Dragon Essence§r§e!
* REGEX-TEST: §c§lSACRIFICE! §r§eYou turned §r§6Wise Dragon Helmet §r§einto §r§d25 Dragon Essence§r§e!
*/
private val sacrificeLoot by patternGroup.pattern(
"sacrifice",
"§c§lSACRIFICE! §r§eYou turned §r(?<item>.*) §r§einto §r§d(?<amount>\\d+) Dragon Essence§r§e!",
)

/**
* REGEX-TEST: §c§lBONUS LOOT! §r§eYou also received §r§817x §r§5Wise Dragon Fragment §r§efrom your sacrifice!
*/
private val bonusLoot by patternGroup.pattern(
"bonus",
"§c§lBONUS LOOT! §r§eYou also received §r(?:§\\w(?<amount>\\d+)?x)?(?: §r)?(?<item>.*) §r§efrom your sacrifice!",
)

private val tracker =
SkyHanniItemTracker("Draconic Sacrifice Profit Tracker", { Data() }, { it.draconicSacrificeTracker }) {
drawDisplay(it)
}

private val altarArea = AxisAlignedBB(-601.0, 4.0, -282.0, -586.0, 15.0, -269.0)
private val ESSENCE_DRAGON = "ESSENCE_DRAGON".asInternalName()

class Data : ItemTrackerData() {
override fun resetItems() {
sacrificedItemsMap.clear()
itemsSacrificed = 0
}

override fun getDescription(timesGained: Long): List<String> {
val percentage = timesGained.toDouble() / itemsSacrificed
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) = "§dDragon Essence"

override fun getCoinDescription(item: TrackedItem): List<String> {
val essences = item.totalAmount.addSeparators()
return listOf(
"§7Sacrificed items give you dragon essence.",
"§7You got §6$essences essence §7that way.",
)
}

@Expose
var itemsSacrificed = 0L

@Expose
var sacrificedItemsMap: MutableMap<String, Long> = mutableMapOf()
}

private fun drawDisplay(data: Data): List<Searchable> = buildList {
addSearchString("§5§lDraconic Sacrifice Profit Tracker")
val profit = tracker.drawItems(data, { true }, this)

add(
Renderable.hoverTips(
"§b${data.itemsSacrificed.addSeparators()} §6Items Sacrificed",
data.sacrificedItemsMap.map { (item, amount) -> "$item: §b$amount" },
).toSearchable()
)

add(tracker.addTotalProfit(profit, data.itemsSacrificed, "sacrifice"))

tracker.addPriceFromButton(this)
}

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
sacrificeLoot.matchMatcher(event.message) {
val amount = group("amount").toInt()
val item = group("item")
tracker.addItem(ESSENCE_DRAGON, amount, command = false)
tracker.modify {
it.itemsSacrificed += 1
it.sacrificedItemsMap.addOrPut(item, 1)
}
}

bonusLoot.matchMatcher(event.message) {
val item = group("item")
val amount = groupOrNull("amount")?.toInt() ?: 1
val internalName = NEUInternalName.fromItemNameOrNull(item) ?: return
tracker.addItem(internalName, amount, command = false)
}
tracker.update()
}

@SubscribeEvent
fun onRender(event: GuiRenderEvent) {
if (!isEnabled()) return
if (config.onlyInVoidSlate && !altarArea.isPlayerInside()) return

tracker.renderDisplay(config.position)
}

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
event.register("shresetdraconicsacrificetracker") {
description = "Resets the Draconic Sacrifice Tracker."
category = CommandCategory.USERS_RESET
callback { tracker.resetCommand() }
}
}

private fun isEnabled() = IslandType.THE_END.isInIsland() && config.enabled
}
Loading