aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt83
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MayorData.java77
5 files changed, 173 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index d6128dd69..12e9929bf 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -135,6 +135,7 @@ public class SkyHanniMod {
loadModule(new GuiEditManager());
loadModule(UpdateManager.INSTANCE);
loadModule(new CropAccessoryData());
+ loadModule(new MayorElectionData());
// APIs
loadModule(new BazaarApi());
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
index 4a2ac82a2..4ac5450ba 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -834,5 +834,10 @@ public class Garden {
public boolean fungiCutterWarn = true;
@Expose
+ @ConfigOption(name = "Always Finnegan", desc = "Forcefully set the Finnegan Farming Simulator perk to be active. This is useful if the auto major detection fails.")
+ @ConfigEditorBoolean
+ public boolean forcefullyEnabledAlwaysFinnegan = false;
+
+ @Expose
public Position cropSpeedMeterPos = new Position(278, -236, false, true);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt b/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt
new file mode 100644
index 000000000..2dd8e19cd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/MayorElectionData.kt
@@ -0,0 +1,83 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.APIUtil
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.sorted
+import at.hannibal2.skyhanni.utils.MayorData
+import at.hannibal2.skyhanni.utils.MayorData.Candidate
+import com.google.gson.GsonBuilder
+import io.github.moulberry.moulconfig.observer.PropertyTypeAdapterFactory
+import io.github.moulberry.notenoughupdates.util.SkyBlockTime
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+
+class MayorElectionData {
+ private var tick = 0
+ private var lastUpdate = 0L
+
+ private val gson = GsonBuilder().setPrettyPrinting()
+ .registerTypeAdapterFactory(PropertyTypeAdapterFactory())
+ .create()
+
+ companion object {
+ var rawMayorData: MayorData? = null
+ var candidates = mapOf<Int, Candidate>()
+ var currentCandidate: Candidate? = null
+
+ fun isPerkActive(mayor: String, perk: String): Boolean {
+ return currentCandidate?.let { currentCandidate ->
+ currentCandidate.name == mayor && currentCandidate.perks.any { it.name == perk }
+ } ?: false
+ }
+
+ }
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START) return
+ if (!LorenzUtils.onHypixel) return
+
+ tick++
+
+ if (tick % 60 == 0) {
+ check()
+ }
+ }
+
+ private fun check() {
+ if (System.currentTimeMillis() > lastUpdate + 60_000 * 5) {
+ lastUpdate = System.currentTimeMillis()
+ SkyHanniMod.coroutineScope.launch {
+ val url = "https://api.hypixel.net/resources/skyblock/election"
+ val jsonObject = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }
+ rawMayorData = gson.fromJson(jsonObject, MayorData::class.java).also {
+ candidates = mapOf(it.mayor.election.getPairs(), it.current.getPairs())
+ }
+ }
+ }
+
+ checkCurrentMayor()
+ }
+
+ private fun checkCurrentMayor() {
+ var currentYear = SkyBlockTime.now().year
+
+ // The time in the current skyblock year when the election circle will restart
+ val month = 3 // Late Spring
+ val nextMayorTime = SkyBlockTime(currentYear, month, day = 27).toMillis()
+
+ // Is it still the major from old sb year?
+ if (nextMayorTime > System.currentTimeMillis()) {
+ currentYear--
+ }
+ currentCandidate = candidates[currentYear]
+ }
+
+ private fun MayorData.Election.getPairs() = year + 1 to candidates.bestCandidate()
+
+ private fun List<MayorData.Candidate>.bestCandidate() = map { it to it.votes }.sorted().last().first
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
index 18b408666..78f3bf836 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.ClickType
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter
+import at.hannibal2.skyhanni.data.MayorElectionData
import at.hannibal2.skyhanni.data.SendTitleHelper
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType
@@ -25,6 +26,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.*
import kotlin.concurrent.fixedRateTimer
+import kotlin.random.Random
class GardenCropMilestoneDisplay {
private var progressDisplay = listOf<List<Any>>()
@@ -127,7 +129,8 @@ class GardenCropMilestoneDisplay {
val crop = item.getCropType() ?: return
if (cultivatingData.containsKey(crop)) {
val old = cultivatingData[crop]!!
- val addedCounter = counter - old
+ val finneganPerkFactor = if (finneganPerkActive() && Random.nextDouble() <= 0.25) 0.5 else 1.0
+ val addedCounter = ((counter - old) * finneganPerkFactor).toInt()
if (GardenCropMilestones.cropCounter.isEmpty()) {
for (innerCrop in CropType.values()) {
@@ -154,6 +157,9 @@ class GardenCropMilestoneDisplay {
}
}
+ private fun finneganPerkActive() =
+ config.forcefullyEnabledAlwaysFinnegan || MayorElectionData.isPerkActive("Finnegan", "Farming Simulator")
+
@SubscribeEvent
fun onBlockClick(event: BlockClickEvent) {
if (!isEnabled()) return
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MayorData.java b/src/main/java/at/hannibal2/skyhanni/utils/MayorData.java
new file mode 100644
index 000000000..1c73572d4
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MayorData.java
@@ -0,0 +1,77 @@
+package at.hannibal2.skyhanni.utils;
+
+import com.google.gson.annotations.Expose;
+
+import java.util.ArrayList;
+
+public class MayorData {
+ @Expose
+ public boolean success;
+ @Expose
+ public long lastUpdated;
+ @Expose
+ public Mayor mayor;
+ @Expose
+ public Election current;
+
+ public class Candidate {
+ @Expose
+ public String key;
+ @Expose
+ public String name;
+ @Expose
+ public ArrayList<Perk> perks;
+ @Expose
+ public int votes;
+
+ @Override
+ public String toString() {
+ return "Candidate{" +
+ "key='" + key + '\'' +
+ ", name='" + name + '\'' +
+ ", perks=" + perks +
+ ", votes=" + votes +
+ '}';
+ }
+ }
+
+// public class Current {
+// @Expose
+// public int year;
+// @Expose
+// public ArrayList<Candidate> candidates;
+// }
+
+ public class Election {
+ @Expose
+ public int year;
+ @Expose
+ public ArrayList<Candidate> candidates;
+ }
+
+ public class Mayor {
+ @Expose
+ public String key;
+ @Expose
+ public String name;
+ @Expose
+ public ArrayList<Perk> perks;
+ @Expose
+ public Election election;
+ }
+
+ public class Perk {
+ @Expose
+ public String name;
+ @Expose
+ public String description;
+
+ @Override
+ public String toString() {
+ return "Perk{" +
+ "name='" + name + '\'' +
+ ", description='" + description + '\'' +
+ '}';
+ }
+ }
+} \ No newline at end of file