Skip to content

Commit

Permalink
Feature: Hitman Statistics (#2991)
Browse files Browse the repository at this point in the history
Co-authored-by: Cal <cwolfson58@gmail.com>
  • Loading branch information
DavidArthurCole and CalMWolfs authored Dec 13, 2024
1 parent 9ebc336 commit 6442565
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public HotspotRabbitStorage(@Nullable Integer year) {
public static class HitmanStatsStorage {
@Expose
@Nullable
public Integer availableEggs;
public Integer availableEggs = null;

@Expose
@Nullable
Expand All @@ -231,6 +231,10 @@ public static class HitmanStatsStorage {
@Expose
@Nullable
public SimpleTimeMark allSlotsCooldown = null;

@Expose
@Nullable
public Integer purchasedSlots = null;
}

@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,15 @@ object HoppityAPI {
// If there is a time since lastHoppityCallAccept, we can assume this is an abiphone call
private fun getBoughtType(): HoppityEggType = if (lastHoppityCallAccept != null) BOUGHT_ABIPHONE else BOUGHT

fun isHoppityEvent() = (SkyblockSeason.currentSeason == SkyblockSeason.SPRING || SkyHanniMod.feature.dev.debug.alwaysHoppitys)
fun getEventEndMark(): SimpleTimeMark? = if (isHoppityEvent()) {
SkyBlockTime.fromSbYearAndMonth(SkyBlockTime.now().year, 3).asTimeMark()
} else null
fun isHoppityEvent() = (SkyblockSeason.SPRING.isSeason() || SkyHanniMod.feature.dev.debug.alwaysHoppitys)

fun getEventEndMark(): SimpleTimeMark? = if (isHoppityEvent()) getEventEndMark(SkyBlockTime.now().year) else null

fun getEventEndMark(year: Int) =
SkyBlockTime.fromSeason(year, SkyblockSeason.SUMMER, SkyblockSeason.SkyblockSeasonModifier.EARLY).asTimeMark()

fun getEventStartMark(year: Int) =
SkyBlockTime.fromSeason(year, SkyblockSeason.SPRING, SkyblockSeason.SkyblockSeasonModifier.EARLY).asTimeMark()

fun rarityByRabbit(rabbit: String): LorenzRarity? = hoppityRarities.firstOrNull {
it.chatColorCode == rabbit.substring(0, 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum class HoppityEggType(
val resetsAt: Int,
var lastResetDay: Int = -1,
private var claimed: Boolean = false,
private val altDay: Boolean = false
val altDay: Boolean = false
) {
BREAKFAST("Breakfast", "§6", 7),
LUNCH("Lunch", "§9", 14),
Expand Down Expand Up @@ -51,6 +51,10 @@ enum class HoppityEggType(
return now.copy(day = now.day + daysToAdd, hour = resetsAt, minute = 0, second = 0).asTimeMark().timeUntil()
}

fun nextTime(): SimpleTimeMark {
return SimpleTimeMark.now() + timeUntil()
}

fun markClaimed(mark: SimpleTimeMark? = null) {
mealLastFound[this] = mark ?: SimpleTimeMark.now()
claimed = true
Expand Down Expand Up @@ -93,6 +97,7 @@ enum class HoppityEggType(
}

val resettingEntries = entries.filter { it.resetsAt != -1 }
val sortedResettingEntries = resettingEntries.sortedBy { it.resetsAt }

fun allFound() = resettingEntries.forEach { it.markClaimed() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ object ChocolateFactoryDataLoader {
"§7Available eggs: §a(?<amount>\\d+)",
)

/**
* REGEX-TEST: §7Purchased slots: §a28§7/§a28
* REGEX-TEST: §7Purchased slots: §e0§7/§a22
*/
private val hitmanPurchasedSlotsPattern by ChocolateFactoryAPI.patternGroup.pattern(
"hitman.purchasedslots",
"§7Purchased slots: §.(?<amount>\\d+)§7\\/§a\\d+",
)

/**
* REGEX-TEST: §7Slot cooldown: §a8m 6s
*/
Expand Down Expand Up @@ -451,6 +460,9 @@ object ChocolateFactoryDataLoader {
val nextAllSlots = (SimpleTimeMark.now() + timeUntilAllSlots)
profileStorage.hitmanStats.allSlotsCooldown = nextAllSlots
}
hitmanPurchasedSlotsPattern.matchMatcher(line) {
profileStorage.hitmanStats.purchasedSlots = group("amount").formatInt()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package at.hannibal2.skyhanni.features.inventory.chocolatefactory
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.features.event.hoppity.HoppityAPI
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEventSummary
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.hitman.HitmanAPI.getHitmanTimeToAll
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.hitman.HitmanAPI.getHitmanTimeToFull
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.hitman.HitmanAPI.getOpenSlots
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ClipboardUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
Expand All @@ -16,6 +20,7 @@ import at.hannibal2.skyhanni.utils.renderables.Renderable
import com.google.gson.JsonElement
import com.google.gson.JsonPrimitive
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration

@SkyHanniModule
object ChocolateFactoryStats {
Expand All @@ -40,6 +45,7 @@ object ChocolateFactoryStats {
config.position.renderRenderables(display, posLabel = "Chocolate Factory Stats")
}

@Suppress("LongMethod", "CyclomaticComplexMethod")
fun updateDisplay() {
val profileStorage = profileStorage ?: return

Expand Down Expand Up @@ -76,7 +82,23 @@ object ChocolateFactoryStats {

val upgradeAvailableAt = ChocolateAmount.CURRENT.formattedTimeUntilGoal(profileStorage.bestUpgradeCost)

val map = buildMap<ChocolateFactoryStat, String> {
val hitmanStats = profileStorage.hitmanStats
val availableHitmanEggs = hitmanStats.availableEggs?.takeIf { it > 0 }?.toString() ?: "§7None"
val hitmanSingleSlotCd = hitmanStats.slotCooldown?.takeIf { it.isInFuture() }?.timeUntil()?.format() ?: "§aAll Ready"
val hitmanAllSlotsCd = hitmanStats.allSlotsCooldown?.takeIf { it.isInFuture() }?.timeUntil()?.format() ?: "§aAll Ready"
val openSlotsNow = hitmanStats.getOpenSlots()
val purchasedSlots = hitmanStats.purchasedSlots ?: 0

val (hitmanAllSlotsTime, allSlotsEventInhibited) = hitmanStats.getHitmanTimeToAll()
val hitmanAllClaimString = hitmanAllSlotsTime.takeIf { it > Duration.ZERO }?.format() ?: "§aAll Ready"
val hitmanAllClaimReady = "${if (allSlotsEventInhibited) "§c" else "§b"}$hitmanAllClaimString"

val (hitmanFullTime, hitmanFullEventInhibited) = hitmanStats.getHitmanTimeToFull()
val hitmanFullString = if (openSlotsNow == 0) "§7Cooldown..."
else hitmanFullTime.takeIf { it > Duration.ZERO }?.format() ?: "§cFull Now"
val hitmanSlotsFull = "${if (hitmanFullEventInhibited) "§c" else "§b"}$hitmanFullString"

val map = buildMap {
put(ChocolateFactoryStat.HEADER, "§6§lChocolate Factory ${ChocolateFactoryAPI.currentPrestige.toRoman()}")

val maxSuffix = if (ChocolateFactoryAPI.isMax()) {
Expand Down Expand Up @@ -118,25 +140,36 @@ object ChocolateFactoryStats {
"§eRaw Per Second: §6${profileStorage.rawChocPerSecond.addSeparators()}",
)

if (ChocolateFactoryAPI.isMaxPrestige()) {
val allTime = ChocolateAmount.ALL_TIME.chocolate()
val nextChocolateMilestone = ChocolateFactoryAPI.getNextMilestoneChocolate(allTime)
val amountUntilNextMilestone = nextChocolateMilestone - allTime
val maxMilestoneEstimate = ChocolateAmount.ALL_TIME.formattedTimeUntilGoal(nextChocolateMilestone)

if (amountUntilNextMilestone >= 0) {
put(ChocolateFactoryStat.TIME_TO_PRESTIGE, "§eTime To Next Milestone: $maxMilestoneEstimate")
put(
ChocolateFactoryStat.CHOCOLATE_UNTIL_PRESTIGE,
"§eChocolate To Next Milestone: §6${amountUntilNextMilestone.addSeparators()}",
)
}
} else {
put(ChocolateFactoryStat.TIME_TO_PRESTIGE, "§eTime To Prestige: $prestigeEstimate")
put(ChocolateFactoryStat.CHOCOLATE_UNTIL_PRESTIGE, "§eChocolate To Prestige: §6$chocolateUntilPrestige")
val allTime = ChocolateAmount.ALL_TIME.chocolate()
val nextChocolateMilestone = ChocolateFactoryAPI.getNextMilestoneChocolate(allTime)
val amountUntilNextMilestone = nextChocolateMilestone - allTime
val amountFormat = amountUntilNextMilestone.addSeparators()
val maxMilestoneEstimate = ChocolateAmount.ALL_TIME.formattedTimeUntilGoal(nextChocolateMilestone)
val prestigeData = when {
!ChocolateFactoryAPI.isMaxPrestige() -> mapOf(
ChocolateFactoryStat.TIME_TO_PRESTIGE to "§eTime To Prestige: $prestigeEstimate",
ChocolateFactoryStat.CHOCOLATE_UNTIL_PRESTIGE to "§eChocolate To Prestige: §6$chocolateUntilPrestige"
)
amountUntilNextMilestone >= 0 -> mapOf(
ChocolateFactoryStat.TIME_TO_PRESTIGE to "§eTime To Next Milestone: $maxMilestoneEstimate",
ChocolateFactoryStat.CHOCOLATE_UNTIL_PRESTIGE to "§eChocolate To Next Milestone: §6$amountFormat"
)
else -> emptyMap()
}
putAll(prestigeData)

put(ChocolateFactoryStat.TIME_TO_BEST_UPGRADE, "§eBest Upgrade: $upgradeAvailableAt")

put(ChocolateFactoryStat.HITMAN_HEADER, "§c§lRabbit Hitman")
put(ChocolateFactoryStat.AVAILABLE_HITMAN_EGGS, "§eAvailable Hitman Eggs: §6$availableHitmanEggs")
put(ChocolateFactoryStat.OPEN_HITMAN_SLOTS, "§eOpen Hitman Slots: §6$openSlotsNow")
put(ChocolateFactoryStat.HITMAN_SLOT_COOLDOWN, "§eHitman Slot Cooldown: §b$hitmanSingleSlotCd")
put(ChocolateFactoryStat.HITMAN_ALL_SLOTS, "§eAll Hitman Slots Cooldown: §b$hitmanAllSlotsCd")

if (HoppityAPI.isHoppityEvent()) {
put(ChocolateFactoryStat.HITMAN_FULL_SLOTS, "§eFull Hitman Slots: §b$hitmanSlotsFull")
put(ChocolateFactoryStat.HITMAN_28_SLOTS, "§e$purchasedSlots Hitman Claims: $hitmanAllClaimReady")
}
}
val text = config.statsDisplayList.filter { it.shouldDisplay() }.flatMap { map[it]?.split("\n").orEmpty() }

Expand Down Expand Up @@ -199,9 +232,13 @@ object ChocolateFactoryStats {
"§eBest Upgrade: §b 59m 4s",
{ ChocolateFactoryAPI.profileStorage?.bestUpgradeCost != 0L },
),
AVAILABLE_HITMAN_EGGS("§eAvailable Hitman Eggs: §b3"),
HITMAN_SLOT_COOLDOWN("§Hitman Slot Cooldown: §b8m 6s"),
HITMAN_HEADER("§c§lRabbit Hitman"),
AVAILABLE_HITMAN_EGGS("§eAvailable Hitman Eggs: §63"),
OPEN_HITMAN_SLOTS("§eOpen Hitman Slots: §63"),
HITMAN_SLOT_COOLDOWN("§eHitman Slot Cooldown: §b8m 6s"),
HITMAN_ALL_SLOTS("§eAll Hitman Slots Cooldown: §b8h 8m 6s"),
HITMAN_FULL_SLOTS("§eFull Hitman Slots: §b2h 10m"),
HITMAN_28_SLOTS("§e28 Hitman Claims: §b3h 20m"),
;

override fun toString(): String {
Expand Down
Loading

0 comments on commit 6442565

Please sign in to comment.