diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-04-07 10:30:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-07 10:30:03 +0200 |
commit | 31bfd8a1d3437f4bdbefa7bcba75143e37c4ac90 (patch) | |
tree | cc443ddafd6ed278991ae6e4814debff9734a704 /src/main/java/at/hannibal2/skyhanni | |
parent | 290ec20019977dfb1dbd3a8e6c152693c3337918 (diff) | |
download | skyhanni-31bfd8a1d3437f4bdbefa7bcba75143e37c4ac90.tar.gz skyhanni-31bfd8a1d3437f4bdbefa7bcba75143e37c4ac90.tar.bz2 skyhanni-31bfd8a1d3437f4bdbefa7bcba75143e37c4ac90.zip |
Backend: Mayor Overwrite (#1302)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
8 files changed, 76 insertions, 40 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java index c43680efe..f3548b548 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java @@ -1,10 +1,13 @@ package at.hannibal2.skyhanni.config.features.dev; import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.data.Mayor; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.moulberry.moulconfig.observer.Property; import org.lwjgl.input.Keyboard; public class DebugConfig { @@ -119,6 +122,11 @@ public class DebugConfig { public boolean currentAreaDebug = true; @Expose + @ConfigOption(name = "Assume Mayor", desc = "Select a mayor to assume.") + @ConfigEditorDropdown + public Property<Mayor> assumeMayor = Property.of(Mayor.DISABLED); + + @Expose @ConfigOption(name = "Always April Fools", desc = "Always show April fools jokes.") @ConfigEditorBoolean public boolean alwaysFunnyTime = false; diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.java index 9c46400f5..dea5b4fb7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/diana/DianaConfig.java @@ -66,11 +66,6 @@ public class DianaConfig { public boolean petWarning = true; @Expose - @ConfigOption(name = "Always Diana", desc = "Forcefully set the Diana event to be active. This is useful if the auto mayor detection fails.") - @ConfigEditorBoolean - public boolean alwaysDiana = false; - - @Expose @ConfigOption(name = "Diana Profit Tracker", desc = "") @Accordion public DianaProfitTrackerConfig dianaProfitTracker = new DianaProfitTrackerConfig(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java index b19a706f0..4496b8731 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java @@ -215,11 +215,6 @@ public class GardenConfig { public boolean jacobContestSummary = true; @Expose - @ConfigOption(name = "Always Finnegan", desc = "Forcefully set the Finnegan Farming Simulator perk to be active. This is useful if the auto mayor detection fails.") - @ConfigEditorBoolean - public boolean forcefullyEnabledAlwaysFinnegan = false; - - @Expose public Position cropSpeedMeterPos = new Position(278, -236, false, true); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt index 2a5fcb0c9..faddae346 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt @@ -2,12 +2,15 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigManager -import at.hannibal2.skyhanni.data.Mayor.Companion.setMayorWithActivePerks +import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayor +import at.hannibal2.skyhanni.data.Mayor.Companion.setAssumeMayorJson import at.hannibal2.skyhanni.data.jsonobjects.local.MayorJson +import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.CollectionUtils.put +import at.hannibal2.skyhanni.utils.ConditionalUtils.onToggle import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark @@ -43,15 +46,13 @@ object MayorAPI { /** * @param input: The name of the mayor - * @return: The neu color of the mayor; If no mayor was found, it will return "§cUnknown: §7" + * @return: The neu color of the mayor; If no mayor was found, it will return "§c" */ - fun mayorNameToColorCode(input: String): String { - return Mayor.getMayorFromName(input).color - } + fun mayorNameToColorCode(input: String): String = Mayor.getMayorFromName(input)?.color ?: "§c" /** * @param input: The name of the mayor - * @return: The neu color of the mayor + the name of the mayor; If no mayor was found, it will return "§cUnknown: §7[input]" + * @return: The neu color of the mayor + the name of the mayor; If no mayor was found, it will return "§c[input]" */ fun mayorNameWithColorCode(input: String) = mayorNameToColorCode(input) + input @@ -88,7 +89,7 @@ object MayorAPI { // Check if it is still the mayor from the old SkyBlock year currentMayor = candidates[nextMayorTime.toSkyBlockTime().year - 1]?.let { // TODO: Once Jerry is active, add the sub mayor perks in here - setMayorWithActivePerks(it.name, it.perks) + setAssumeMayorJson(it.name, it.perks) } } @@ -116,6 +117,20 @@ object MayorAPI { private fun List<MayorJson.Candidate>.bestCandidate() = maxBy { it.votes } @SubscribeEvent + fun onConfigReload(event: ConfigLoadEvent) { + SkyHanniMod.feature.dev.debug.assumeMayor.onToggle { + val mayor = SkyHanniMod.feature.dev.debug.assumeMayor.get() + + if (mayor == Mayor.DISABLED) { + checkCurrentMayor() + } else { + mayor.setAssumeMayor(mayor.perks.toList()) + currentMayor = mayor + } + } + } + + @SubscribeEvent fun onDebugDataCollect(event: DebugDataCollectEvent) { event.title("Mayor") event.addIrrelevant { diff --git a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt index b956da0fd..f431f7928 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/Mayors.kt @@ -2,19 +2,28 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.data.MayorAPI.foxyExtraEventPattern import at.hannibal2.skyhanni.data.jsonobjects.local.MayorJson +import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher enum class Mayor( val mayorName: String, val color: String, - private vararg val perks: Perk, + vararg val perks: Perk, ) { AATROX("Aatrox", "§3", Perk.SLASHED_PRICING, Perk.SLAYER_XP_BUFF, Perk.PATHFINDER), COLE("Cole", "§e", Perk.PROSPECTION, Perk.MINING_XP_BUFF, Perk.MINING_FIESTA), DIANA("Diana", "§2", Perk.LUCKY, Perk.MYTHOLOGICAL_RITUAL, Perk.PET_XP_BUFF), DIAZ("Diaz", "§6", Perk.BARRIER_STREET, Perk.SHOPPING_SPREE), FINNEGAN("Finnegan", "§c", Perk.FARMING_SIMULATOR, Perk.PELT_POCALYPSE, Perk.GOATED), - FOXY("Foxy", "§d", Perk.SWEET_TOOTH, Perk.BENEVOLENCE, Perk.EXTRA_EVENT_MINING, Perk.EXTRA_EVENT_FISHING, Perk.EXTRA_EVENT_SPOOKY), + FOXY( + "Foxy", + "§d", + Perk.SWEET_TOOTH, + Perk.BENEVOLENCE, + Perk.EXTRA_EVENT_MINING, + Perk.EXTRA_EVENT_FISHING, + Perk.EXTRA_EVENT_SPOOKY + ), MARINA("Marina", "§b", Perk.FISHING_XP_BUFF, Perk.LUCK_OF_THE_SEA, Perk.FISHING_FESTIVAL), PAUL("Paul", "§c", Perk.MARAUDER, Perk.EZPZ, Perk.BENEDICTION), @@ -22,28 +31,46 @@ enum class Mayor( JERRY("Jerry", "§d", Perk.PERKPOCALYPSE, Perk.STATSPOCALYPSE, Perk.JERRYPOCALYPSE), DERPY("Derpy", "§d", Perk.TURBO_MINIONS, Perk.AH_CLOSED, Perk.DOUBLE_MOBS_HP, Perk.MOAR_SKILLZ), - UNKNOWN("Unknown", "§c"), + DISABLED("§cDisabled", "§7"), ; val activePerks: MutableList<Perk> = mutableListOf() + override fun toString() = mayorName + companion object { - fun getMayorFromName(name: String) = entries.firstOrNull { it.mayorName == name } ?: UNKNOWN - fun setMayorWithActivePerks(name: String, perks: ArrayList<MayorJson.Perk>): Mayor { - val mayor = getMayorFromName(name) + fun getMayorFromName(name: String): Mayor? = entries.firstOrNull { it.mayorName == name } - mayor.perks.forEach { it.isActive = false } - mayor.activePerks.clear() - perks.mapNotNull { perk -> Perk.entries.firstOrNull { it.perkName == perk.renameIfFoxyExtraEventPerkFound() } } - .filter { mayor.perks.contains(it) }.forEach { - it.isActive = true - mayor.activePerks.add(it) - } + fun setAssumeMayorJson(name: String, perksJson: ArrayList<MayorJson.Perk>): Mayor? { + val mayor = getMayorFromName(name) + if (mayor == null) { + ErrorManager.logErrorStateWithData( + "Unknown mayor found", + "mayor name not in Mayor enum", + "name" to name, + "perksJson" to perksJson, + betaOnly = true + ) + return null + } + val perks = perksJson.mapNotNull { perk -> + Perk.entries.firstOrNull { it.perkName == perk.renameIfFoxyExtraEventPerkFound() } + } + mayor.setAssumeMayor(perks) return mayor } + fun Mayor.setAssumeMayor(perks: List<Perk>) { + perks.forEach { it.isActive = false } + activePerks.clear() + perks.filter { perks.contains(it) }.forEach { + it.isActive = true + activePerks.add(it) + } + } + private fun MayorJson.Perk.renameIfFoxyExtraEventPerkFound(): String? { val foxyExtraEventPairs = mapOf( "Spooky Festival" to "Extra Event (Spooky)", @@ -101,7 +128,6 @@ enum class Perk(val perkName: String) { EZPZ("EZPZ"), BENEDICTION("Benediction"), - // Scorpius BRIBE("Bribe"), DARKER_AUCTIONS("Darker Auctions"), diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt index e1e420ab4..747c0d02a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt @@ -1,6 +1,5 @@ package at.hannibal2.skyhanni.features.event.diana -import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.Perk import at.hannibal2.skyhanni.data.PetAPI @@ -17,7 +16,7 @@ object DianaAPI { fun hasSpadeInHand() = InventoryUtils.itemInHandId == spade private fun isRitualActive() = Perk.MYTHOLOGICAL_RITUAL.isActive || - Perk.PERKPOCALYPSE.isActive || SkyHanniMod.feature.event.diana.alwaysDiana + Perk.PERKPOCALYPSE.isActive fun hasGriffinPet() = PetAPI.isCurrentPet("Griffin") diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 94145eaca..4fb025097 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -4,6 +4,8 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.EntityMovementData import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.Mayor +import at.hannibal2.skyhanni.data.MayorAPI.currentMayor import at.hannibal2.skyhanni.events.BlockClickEvent import at.hannibal2.skyhanni.events.BurrowDetectEvent import at.hannibal2.skyhanni.events.BurrowDugEvent @@ -323,8 +325,8 @@ object GriffinBurrowHelper { } if (!isEnabled()) { - if (!config.alwaysDiana) { - ChatUtils.clickableChat("§cEnable Always Diana in the config!", "sh always diana") + if (currentMayor != Mayor.DIANA) { + ChatUtils.clickableChat("§cSelect Diana as mayor overwrite!", "sh assume mayor") } else { ChatUtils.userError("Have an Ancestral Spade in the inventory!") } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index b866944d5..691c3777c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -174,11 +174,7 @@ object GardenCropSpeed { secondsStopped = 0 } - fun finneganPerkActive(): Boolean { - val forcefullyEnabledAlwaysFinnegan = config.forcefullyEnabledAlwaysFinnegan - val perkActive = Perk.FARMING_SIMULATOR.isActive - return forcefullyEnabledAlwaysFinnegan || perkActive - } + fun finneganPerkActive() = Perk.FARMING_SIMULATOR.isActive fun isEnabled() = GardenAPI.inGarden() |