Skip to content

Commit

Permalink
ReforgeHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Apr 13, 2024
1 parent e3f1794 commit 3e2e3bc
Show file tree
Hide file tree
Showing 12 changed files with 771 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni
import at.hannibal2.skyhanni.api.CollectionAPI
import at.hannibal2.skyhanni.api.DataWatcherAPI
import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.api.ReforgeAPI
import at.hannibal2.skyhanni.api.SkillAPI
import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigManager
Expand Down Expand Up @@ -244,6 +245,7 @@ import at.hannibal2.skyhanni.features.inventory.ItemStars
import at.hannibal2.skyhanni.features.inventory.MaxPurseItems
import at.hannibal2.skyhanni.features.inventory.PowerStoneGuideFeatures
import at.hannibal2.skyhanni.features.inventory.QuickCraftFeatures
import at.hannibal2.skyhanni.features.inventory.ReforgeHelper
import at.hannibal2.skyhanni.features.inventory.RngMeterInventory
import at.hannibal2.skyhanni.features.inventory.SackDisplay
import at.hannibal2.skyhanni.features.inventory.ShiftClickBrewing
Expand Down Expand Up @@ -412,6 +414,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternManager
Expand Down Expand Up @@ -501,6 +504,7 @@ class SkyHanniMod {
loadModule(GardenBestCropTime())
loadModule(ActionBarData)
loadModule(TrackerManager)
loadModule(SkyBlockItemModifierUtils)
loadModule(ScoreboardPattern)
loadModule(UtilsPatterns)
loadModule(BossbarData)
Expand Down Expand Up @@ -539,6 +543,7 @@ class SkyHanniMod {
loadModule(LorenzUtils)
loadModule(NEUItems)
loadModule(PestAPI)
loadModule(ReforgeAPI)

// features
loadModule(BazaarOrderHelper())
Expand Down Expand Up @@ -568,6 +573,7 @@ class SkyHanniMod {
loadModule(BazaarBestSellMethod())
loadModule(ShiftClickBrewing())
loadModule(BazaarOpenPriceWebsite())
loadModule(ReforgeHelper())
loadModule(AuctionHouseCopyUnderbidPrice())
loadModule(AnvilCombineHelper())
loadModule(SeaCreatureMessageShortener())
Expand Down
149 changes: 149 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/api/ReforgeAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuReforgeJson
import at.hannibal2.skyhanni.data.model.SkyblockStatList
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object ReforgeAPI {
var reforgeList: List<Reforge> = emptyList()
private set(value) {
field = value
nonePowerStoneReforge = value.filterNot { it.isReforgeStone }
onlyPowerStoneReforge = value.filter { it.isReforgeStone }
}

var nonePowerStoneReforge: List<Reforge> = emptyList()
private set

var onlyPowerStoneReforge: List<Reforge> = emptyList()
private set

enum class ReforgeType {
SWORD, BOW, ARMOR, CHESTPLATE, HELMET, CLOAK, AXE, HOE, AXE_AND_HOE, PICKAXE, EQUIPMENT, ROD, SWORD_AND_ROD, SPECIAL_ITEMS, VACUUM
}

class Reforge(
val name: String,
val type: ReforgeType,
val stats: Map<LorenzRarity, SkyblockStatList>,
val reforgeStone: NEUInternalName? = null,
val specialItems: List<NEUInternalName>? = null,
val extraProperty: Map<LorenzRarity, String> = emptyMap(),
val costs: Map<LorenzRarity, Long>? = null
) {

val isReforgeStone = reforgeStone != null

val rawReforgeStoneName = reforgeStone?.itemNameWithoutColor

val lowercaseName = name.lowercase()

fun isValid(itemStack: ItemStack) = isValid(itemStack.getItemCategoryOrNull(), itemStack.getInternalName())

fun isValid(itemCategory: ItemCategory?, internalName: NEUInternalName) =
when (type) {
ReforgeType.SWORD -> setOf(
ItemCategory.SWORD,
ItemCategory.GAUNTLET,
ItemCategory.LONGSWORD,
ItemCategory.FISHING_WEAPON
).contains(itemCategory)

ReforgeType.BOW -> itemCategory == ItemCategory.BOW || itemCategory == ItemCategory.SHORT_BOW
ReforgeType.ARMOR -> setOf(
ItemCategory.HELMET,
ItemCategory.CHESTPLATE,
ItemCategory.LEGGINGS,
ItemCategory.BOOTS
).contains(itemCategory)

ReforgeType.CHESTPLATE -> itemCategory == ItemCategory.CHESTPLATE
ReforgeType.HELMET -> itemCategory == ItemCategory.HELMET
ReforgeType.CLOAK -> itemCategory == ItemCategory.CLOAK
ReforgeType.AXE -> itemCategory == ItemCategory.AXE
ReforgeType.HOE -> itemCategory == ItemCategory.HOE
ReforgeType.AXE_AND_HOE -> itemCategory == ItemCategory.HOE || itemCategory == ItemCategory.AXE
ReforgeType.PICKAXE -> itemCategory == ItemCategory.PICKAXE || itemCategory == ItemCategory.DRILL || itemCategory == ItemCategory.GAUNTLET
ReforgeType.EQUIPMENT -> setOf(
ItemCategory.CLOAK,
ItemCategory.BELT,
ItemCategory.NECKLACE,
ItemCategory.BRACELET,
ItemCategory.GLOVES
).contains(itemCategory)

ReforgeType.ROD -> itemCategory == ItemCategory.FISHING_ROD || itemCategory == ItemCategory.FISHING_WEAPON
ReforgeType.SWORD_AND_ROD -> setOf(
ItemCategory.SWORD,
ItemCategory.GAUNTLET,
ItemCategory.LONGSWORD,
ItemCategory.FISHING_ROD,
ItemCategory.FISHING_WEAPON
).contains(itemCategory)

ReforgeType.VACUUM -> itemCategory == ItemCategory.VACUUM
ReforgeType.SPECIAL_ITEMS -> specialItems?.contains(internalName) ?: false
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Reforge

if (name != other.name) return false
if (type != other.type) return false
if (stats != other.stats) return false
if (reforgeStone != other.reforgeStone) return false
if (specialItems != other.specialItems) return false
if (extraProperty != other.extraProperty) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + type.hashCode()
result = 31 * result + stats.hashCode()
result = 31 * result + (reforgeStone?.hashCode() ?: 0)
result = 31 * result + (specialItems?.hashCode() ?: 0)
result = 31 * result + extraProperty.hashCode()
return result
}

override fun toString(): String {
return "Reforge $name"
}

}

@SubscribeEvent
fun onNeuRepoReload(event: NeuRepositoryReloadEvent) {
val reforgeStoneData = event.readConstant<Map<String, NeuReforgeJson>>("reforgestones").values
val reforgeData = event.readConstant<Map<String, NeuReforgeJson>>("reforges").values
reforgeList = (reforgeStoneData + reforgeData).map(::mapReforge)
}

private fun mapReforge(it: NeuReforgeJson): Reforge {
val type = it.itemType
return Reforge(
name = it.reforgeName,
type = LorenzUtils.enumValueOf<ReforgeType>(type.first),
stats = it.reforgeStats ?: emptyMap(),
reforgeStone = it.internalName,
specialItems = type.second.takeIf { it.isNotEmpty() },
extraProperty = it.reforgeAbility,
costs = it.reforgeCosts
)
}

}
68 changes: 68 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.JacobContestsJson
import at.hannibal2.skyhanni.data.jsonobjects.local.KnownFeaturesJson
import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson
import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish
import at.hannibal2.skyhanni.data.model.SkyblockStat
import at.hannibal2.skyhanni.data.model.SkyblockStatList
import at.hannibal2.skyhanni.events.LorenzEvent
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
Expand All @@ -20,6 +23,7 @@ import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NumberUtil.isInt
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
Expand All @@ -29,6 +33,7 @@ import com.google.gson.JsonObject
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink
import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory
Expand Down Expand Up @@ -148,6 +153,58 @@ class ConfigManager {
return reader.nextString().toLong().asTimeMark()
}
}.nullSafe())
.registerTypeAdapter(HypixelApiTrophyFish::class.java, object : TypeAdapter<HypixelApiTrophyFish>() {
override fun write(out: JsonWriter, value: HypixelApiTrophyFish) {}

override fun read(reader: JsonReader): HypixelApiTrophyFish {
val trophyFish = mutableMapOf<String, Int>()
var totalCaught = 0
reader.beginObject()
while (reader.hasNext()) {
val key = reader.nextName()
if (key == "total_caught") {
totalCaught = reader.nextInt()
continue
}
if (reader.peek() == JsonToken.NUMBER) {
val valueAsString = reader.nextString()
if (valueAsString.isInt()) {
trophyFish[key] = valueAsString.toInt()
continue
}
}
reader.skipValue()
}
reader.endObject()
return HypixelApiTrophyFish(totalCaught, trophyFish)
}
}.nullSafe())
.registerTypeAdapter(SkyblockStat::class.java, object : TypeAdapter<SkyblockStat>() {
override fun write(out: JsonWriter, value: SkyblockStat) {
out.value(value.name.lowercase()) // F you guy who made the stats lowercase
}

override fun read(reader: JsonReader): SkyblockStat {
return SkyblockStat.valueOf(reader.nextString().uppercase())
}
}.nullSafe())
.registerTypeAdapter<SkyblockStatList>({ out, value ->
out.beginObject()
value.forEach {
out.name(it.key.name.lowercase()).value(it.value)
}
out.endObject()
}, { reader ->
reader.beginObject()
val list = SkyblockStatList()
while (reader.hasNext()) {
val name = reader.nextName()
val value = reader.nextDouble()
list[SkyblockStat.valueOf(name.uppercase())] = value
}
reader.endObject()
list
})
.enableComplexMapKeySerialization()
}

Expand All @@ -156,6 +213,17 @@ class ConfigManager {
.create()

var configDirectory = File("config/skyhanni")

private inline fun <reified T> GsonBuilder.registerTypeAdapter(
crossinline write: (JsonWriter, T) -> Unit,
crossinline read: (JsonReader) -> T
): GsonBuilder {
this.registerTypeAdapter(T::class.java, object : TypeAdapter<T>() {
override fun write(out: JsonWriter, value: T) = write(out, value)
override fun read(reader: JsonReader) = read(reader)
}.nullSafe())
return this
}
}

val features get() = jsonHolder[ConfigFileType.FEATURES] as Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public static class HarpConfig {
@ConfigOption(name = "Tia Relay Abiphone Network Maintenance", desc = "")
@Accordion
public TiaRelayConfig tiaRelay = new TiaRelayConfig();

@Expose
@ConfigOption(name = "Reforge Helper", desc = "")
@Accordion
public ReforgeHelperConfig reforge = new ReforgeHelperConfig();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package at.hannibal2.skyhanni.config.features.inventory.helper;

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.ConfigOption;

public class ReforgeHelperConfig {

@Expose
public Position posList = new Position(-200, 85, true, true);
@Expose
public Position posCurrent = new Position(280, 45, true, true);

@Expose
@ConfigOption(name = "Enable", desc = "Enables the reforge helper")
@ConfigEditorBoolean
@FeatureToggle
public boolean enable = true;

@Expose
@ConfigOption(name = "Reforge Stones Hex Only", desc = "Displays reforge stones only when in Hex")
@ConfigEditorBoolean
public boolean reforgeStonesOnlyHex = true;

@Expose
@ConfigOption(name = "Hide chat", desc = "Hides the vanilla chat messages from reforging")
@ConfigEditorBoolean
public boolean hideChat = false;
}
Loading

0 comments on commit 3e2e3bc

Please sign in to comment.