feat: Allow using fine gemstones for pristine profit tracker
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package moe.nea.firmament.features.mining
|
package moe.nea.firmament.features.mining
|
||||||
|
|
||||||
import io.github.notenoughupdates.moulconfig.xml.Bind
|
import io.github.notenoughupdates.moulconfig.xml.Bind
|
||||||
@@ -21,113 +20,125 @@ import moe.nea.firmament.util.parseIntWithComma
|
|||||||
import moe.nea.firmament.util.useMatch
|
import moe.nea.firmament.util.useMatch
|
||||||
|
|
||||||
object PristineProfitTracker : FirmamentFeature {
|
object PristineProfitTracker : FirmamentFeature {
|
||||||
override val identifier: String
|
override val identifier: String
|
||||||
get() = "pristine-profit"
|
get() = "pristine-profit"
|
||||||
|
|
||||||
enum class GemstoneKind(
|
enum class GemstoneKind(
|
||||||
val label: String,
|
val label: String,
|
||||||
val flawedId: SkyblockId,
|
) {
|
||||||
) {
|
SAPPHIRE("Sapphire"),
|
||||||
SAPPHIRE("Sapphire", SkyblockId("FLAWED_SAPPHIRE_GEM")),
|
RUBY("Ruby"),
|
||||||
RUBY("Ruby", SkyblockId("FLAWED_RUBY_GEM")),
|
AMETHYST("Amethyst"),
|
||||||
AMETHYST("Amethyst", SkyblockId("FLAWED_AMETHYST_GEM")),
|
AMBER("Amber"),
|
||||||
AMBER("Amber", SkyblockId("FLAWED_AMBER_GEM")),
|
TOPAZ("Topaz"),
|
||||||
TOPAZ("Topaz", SkyblockId("FLAWED_TOPAZ_GEM")),
|
JADE("Jade"),
|
||||||
JADE("Jade", SkyblockId("FLAWED_JADE_GEM")),
|
JASPER("Jasper"),
|
||||||
JASPER("Jasper", SkyblockId("FLAWED_JASPER_GEM")),
|
OPAL("Opal"),
|
||||||
OPAL("Opal", SkyblockId("FLAWED_OPAL_GEM")),
|
;
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
val flawedId: SkyblockId = SkyblockId("FLAWED_${name}_GEM")
|
||||||
data class Data(
|
val fineId: SkyblockId = SkyblockId("FINE_${name}_GEM")
|
||||||
var maxMoneyPerSecond: Double = 1.0,
|
}
|
||||||
var maxCollectionPerSecond: Double = 1.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
object DConfig : ProfileSpecificDataHolder<Data>(serializer(), identifier, ::Data)
|
@Serializable
|
||||||
|
data class Data(
|
||||||
|
var maxMoneyPerSecond: Double = 1.0,
|
||||||
|
var maxCollectionPerSecond: Double = 1.0,
|
||||||
|
)
|
||||||
|
|
||||||
override val config: ManagedConfig?
|
object DConfig : ProfileSpecificDataHolder<Data>(serializer(), identifier, ::Data)
|
||||||
get() = TConfig
|
|
||||||
|
|
||||||
object TConfig : ManagedConfig(identifier, Category.MINING) {
|
override val config: ManagedConfig?
|
||||||
val timeout by duration("timeout", 0.seconds, 120.seconds) { 30.seconds }
|
get() = TConfig
|
||||||
val gui by position("position", 80, 30) { Point(0.05, 0.2) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val sellingStrategy = BazaarPriceStrategy.SELL_ORDER
|
object TConfig : ManagedConfig(identifier, Category.MINING) {
|
||||||
|
val timeout by duration("timeout", 0.seconds, 120.seconds) { 30.seconds }
|
||||||
|
val gui by position("position", 80, 30) { Point(0.05, 0.2) }
|
||||||
|
val useFineGemstones by toggle("fine-gemstones") { false }
|
||||||
|
}
|
||||||
|
|
||||||
val pristineRegex =
|
val sellingStrategy = BazaarPriceStrategy.SELL_ORDER
|
||||||
"PRISTINE! You found . Flawed (?<kind>${
|
|
||||||
GemstoneKind.entries.joinToString("|") { it.label }
|
|
||||||
}) Gemstone x(?<count>[0-9,]+)!".toPattern()
|
|
||||||
|
|
||||||
val collectionHistogram = Histogram<Double>(10000, 180.seconds)
|
val pristineRegex =
|
||||||
val moneyHistogram = Histogram<Double>(10000, 180.seconds)
|
"PRISTINE! You found . Flawed (?<kind>${
|
||||||
|
GemstoneKind.entries.joinToString("|") { it.label }
|
||||||
|
}) Gemstone x(?<count>[0-9,]+)!".toPattern()
|
||||||
|
|
||||||
object ProfitHud : MoulConfigHud("pristine_profit", TConfig.gui) {
|
val collectionHistogram = Histogram<Double>(10000, 180.seconds)
|
||||||
@field:Bind
|
|
||||||
var moneyCurrent: Double = 0.0
|
|
||||||
|
|
||||||
@field:Bind
|
/**
|
||||||
var moneyMax: Double = 1.0
|
* Separate histogram for money, since money changes based on gemstone, therefore we cannot calculate money from collection.
|
||||||
|
*/
|
||||||
|
val moneyHistogram = Histogram<Double>(10000, 180.seconds)
|
||||||
|
|
||||||
@field:Bind
|
object ProfitHud : MoulConfigHud("pristine_profit", TConfig.gui) {
|
||||||
var moneyText = ""
|
@field:Bind
|
||||||
|
var moneyCurrent: Double = 0.0
|
||||||
|
|
||||||
@field:Bind
|
@field:Bind
|
||||||
var collectionCurrent = 0.0
|
var moneyMax: Double = 1.0
|
||||||
|
|
||||||
@field:Bind
|
@field:Bind
|
||||||
var collectionMax = 1.0
|
var moneyText = ""
|
||||||
|
|
||||||
@field:Bind
|
@field:Bind
|
||||||
var collectionText = ""
|
var collectionCurrent = 0.0
|
||||||
override fun shouldRender(): Boolean = collectionHistogram.latestUpdate().passedTime() < TConfig.timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
val SECONDS_PER_HOUR = 3600
|
@field:Bind
|
||||||
val ROUGHS_PER_FLAWED = 80
|
var collectionMax = 1.0
|
||||||
|
|
||||||
fun updateUi() {
|
@field:Bind
|
||||||
val collectionPerSecond = collectionHistogram.averagePer({ it }, 1.seconds)
|
var collectionText = ""
|
||||||
val moneyPerSecond = moneyHistogram.averagePer({ it }, 1.seconds)
|
override fun shouldRender(): Boolean = collectionHistogram.latestUpdate().passedTime() < TConfig.timeout
|
||||||
if (collectionPerSecond == null || moneyPerSecond == null) return
|
}
|
||||||
ProfitHud.collectionCurrent = collectionPerSecond
|
|
||||||
ProfitHud.collectionText = Text.stringifiedTranslatable("firmament.pristine-profit.collection",
|
val SECONDS_PER_HOUR = 3600
|
||||||
formatCommas(collectionPerSecond * SECONDS_PER_HOUR,
|
val ROUGHS_PER_FLAWED = 80
|
||||||
1)).formattedString()
|
val FLAWED_PER_FINE = 80
|
||||||
ProfitHud.moneyCurrent = moneyPerSecond
|
val ROUGHS_PER_FINE = ROUGHS_PER_FLAWED * FLAWED_PER_FINE
|
||||||
ProfitHud.moneyText = Text.stringifiedTranslatable("firmament.pristine-profit.money",
|
|
||||||
formatCommas(moneyPerSecond * SECONDS_PER_HOUR, 1))
|
fun updateUi() {
|
||||||
.formattedString()
|
val collectionPerSecond = collectionHistogram.averagePer({ it }, 1.seconds)
|
||||||
val data = DConfig.data
|
val moneyPerSecond = moneyHistogram.averagePer({ it }, 1.seconds)
|
||||||
if (data != null) {
|
if (collectionPerSecond == null || moneyPerSecond == null) return
|
||||||
if (data.maxCollectionPerSecond < collectionPerSecond && collectionHistogram.oldestUpdate()
|
ProfitHud.collectionCurrent = collectionPerSecond
|
||||||
.passedTime() > 30.seconds
|
ProfitHud.collectionText = Text.stringifiedTranslatable("firmament.pristine-profit.collection",
|
||||||
) {
|
formatCommas(collectionPerSecond * SECONDS_PER_HOUR,
|
||||||
data.maxCollectionPerSecond = collectionPerSecond
|
1)).formattedString()
|
||||||
DConfig.markDirty()
|
ProfitHud.moneyCurrent = moneyPerSecond
|
||||||
}
|
ProfitHud.moneyText = Text.stringifiedTranslatable("firmament.pristine-profit.money",
|
||||||
if (data.maxMoneyPerSecond < moneyPerSecond && moneyHistogram.oldestUpdate().passedTime() > 30.seconds) {
|
formatCommas(moneyPerSecond * SECONDS_PER_HOUR, 1))
|
||||||
data.maxMoneyPerSecond = moneyPerSecond
|
.formattedString()
|
||||||
DConfig.markDirty()
|
val data = DConfig.data
|
||||||
}
|
if (data != null) {
|
||||||
ProfitHud.collectionMax = maxOf(data.maxCollectionPerSecond, collectionPerSecond)
|
if (data.maxCollectionPerSecond < collectionPerSecond && collectionHistogram.oldestUpdate()
|
||||||
ProfitHud.moneyMax = maxOf(data.maxMoneyPerSecond, moneyPerSecond)
|
.passedTime() > 30.seconds
|
||||||
}
|
) {
|
||||||
}
|
data.maxCollectionPerSecond = collectionPerSecond
|
||||||
|
DConfig.markDirty()
|
||||||
|
}
|
||||||
|
if (data.maxMoneyPerSecond < moneyPerSecond && moneyHistogram.oldestUpdate().passedTime() > 30.seconds) {
|
||||||
|
data.maxMoneyPerSecond = moneyPerSecond
|
||||||
|
DConfig.markDirty()
|
||||||
|
}
|
||||||
|
ProfitHud.collectionMax = maxOf(data.maxCollectionPerSecond, collectionPerSecond)
|
||||||
|
ProfitHud.moneyMax = maxOf(data.maxMoneyPerSecond, moneyPerSecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onMessage(it: ProcessChatEvent) {
|
fun onMessage(it: ProcessChatEvent) {
|
||||||
pristineRegex.useMatch(it.unformattedString) {
|
pristineRegex.useMatch(it.unformattedString) {
|
||||||
val gemstoneKind = GemstoneKind.valueOf(group("kind").uppercase())
|
val gemstoneKind = GemstoneKind.valueOf(group("kind").uppercase())
|
||||||
val flawedCount = parseIntWithComma(group("count"))
|
val flawedCount = parseIntWithComma(group("count"))
|
||||||
val moneyAmount = sellingStrategy.getSellPrice(gemstoneKind.flawedId) * flawedCount
|
val moneyAmount =
|
||||||
moneyHistogram.record(moneyAmount)
|
if (TConfig.useFineGemstones) sellingStrategy.getSellPrice(gemstoneKind.fineId) * flawedCount / FLAWED_PER_FINE
|
||||||
val collectionAmount = flawedCount * ROUGHS_PER_FLAWED
|
else sellingStrategy.getSellPrice(gemstoneKind.flawedId) * flawedCount
|
||||||
collectionHistogram.record(collectionAmount.toDouble())
|
moneyHistogram.record(moneyAmount)
|
||||||
updateUi()
|
val collectionAmount = flawedCount * ROUGHS_PER_FLAWED
|
||||||
}
|
collectionHistogram.record(collectionAmount.toDouble())
|
||||||
}
|
updateUi()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,6 +157,8 @@
|
|||||||
"firmament.config.price-data.enable-keybind": "Enable only with Keybinding",
|
"firmament.config.price-data.enable-keybind": "Enable only with Keybinding",
|
||||||
"firmament.config.price-data.enable-keybind.description": "Only show auction/bazaar prices when holding this keybinding. Unbind to always show.",
|
"firmament.config.price-data.enable-keybind.description": "Only show auction/bazaar prices when holding this keybinding. Unbind to always show.",
|
||||||
"firmament.config.pristine-profit": "Pristine Profit Tracker",
|
"firmament.config.pristine-profit": "Pristine Profit Tracker",
|
||||||
|
"firmament.config.pristine-profit.fine-gemstones": "Use Fine Gemstones",
|
||||||
|
"firmament.config.pristine-profit.fine-gemstones.description": "Use the (more stable) price of fine gemstones, instead of flawed gemstones.",
|
||||||
"firmament.config.pristine-profit.position": "Position",
|
"firmament.config.pristine-profit.position": "Position",
|
||||||
"firmament.config.pristine-profit.position.description": "Edit the pristine profit hud location.",
|
"firmament.config.pristine-profit.position.description": "Edit the pristine profit hud location.",
|
||||||
"firmament.config.pristine-profit.timeout": "Timeout (0 = disabled)",
|
"firmament.config.pristine-profit.timeout": "Timeout (0 = disabled)",
|
||||||
|
|||||||
Reference in New Issue
Block a user