Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: ReputationHelper "Rewrite" #3207

Open
wants to merge 7 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ enum class TabWidget(
),
REPUTATION(
// language=RegExp
"(?:§.)*(Barbarian|Mage) Reputation:",
"(?:§.)*(?<faction>Barbarian|Mage) Reputation:",
),
FACTION_QUESTS(
// language=RegExp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ abstract class GuiContainerEvent(open val gui: GuiContainer, open val container:
val slot: Slot?,
val slotId: Int,
val clickedButton: Int,
@Deprecated("old", ReplaceWith("clickTypeEnum"))
val clickType: Int,
val clickTypeEnum: ClickType? = ClickType.getTypeById(clickType),
val clickType: ClickType?,
) : GuiContainerEvent(gui, container) {

fun makePickblock() {
if (this.clickedButton == 2 && this.clickTypeEnum == ClickType.MIDDLE) return
if (this.clickedButton == 2 && this.clickType == ClickType.MIDDLE) return
slot?.slotNumber?.let { slotNumber ->
InventoryUtils.clickSlot(slotNumber, container.windowId, 2, 3)
isCanceled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object VisitorRewardWarning {
}

// all but shift click types work for accepting visitor
if (event.clickTypeEnum == GuiContainerEvent.ClickType.SHIFT) return
if (event.clickType == GuiContainerEvent.ClickType.SHIFT) return
if (isRefuseSlot) {
VisitorAPI.changeStatus(visitor, VisitorAPI.VisitorStatus.REFUSED, "refused")
// fallback if tab list is disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ object HarpFeatures {
if (isHarpGui(InventoryUtils.openInventoryName())) {
if (config.keybinds) {
// needed to not send duplicate clicks via keybind feature
if (event.clickTypeEnum == GuiContainerEvent.ClickType.HOTBAR) {
if (event.clickType == GuiContainerEvent.ClickType.HOTBAR) {
event.cancel()
return
}
Expand All @@ -172,8 +172,9 @@ object HarpFeatures {
event.container.inventory.filterNotNull().indexOfFirst {
songSelectedPattern.anyMatches(it.getLore())
}.takeIf { it != -1 }?.let {
val clickType = event.clickType?.id ?: return
event.cancel()
InventoryUtils.clickSlot(it, event.container.windowId, event.clickedButton, event.clickType)
InventoryUtils.clickSlot(it, event.container.windowId, event.clickedButton, clickType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object ChocolateFactoryInventory {
) return

// this would break ChocolateFactoryKeybinds otherwise
if (event.clickTypeEnum == GuiContainerEvent.ClickType.HOTBAR) return
if (event.clickType == GuiContainerEvent.ClickType.HOTBAR) return

// if the user is holding shift, we don't want to pickblock, handled by hypixel as +10 levels for rabbits
if (KeyboardManager.isShiftKeyDown() && slotNumber in ChocolateFactoryAPI.rabbitSlots.keys) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object ChocolateFactoryKeybinds {
if (!ChocolateFactoryAPI.inChocolateFactory) return

// needed to not send duplicate clicks via keybind feature
if (event.clickTypeEnum == GuiContainerEvent.ClickType.HOTBAR) {
if (event.clickType == GuiContainerEvent.ClickType.HOTBAR) {
event.cancel()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ import at.hannibal2.skyhanni.config.features.crimsonisle.ReputationHelperConfig.
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.CrimsonIsleReputationJson
import at.hannibal2.skyhanni.data.model.TabWidget
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.events.WidgetUpdateEvent
import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.DailyQuestHelper
import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.QuestLoader
import at.hannibal2.skyhanni.features.nether.reputationhelper.kuudra.DailyKuudraBossHelper
import at.hannibal2.skyhanni.features.nether.reputationhelper.miniboss.DailyMiniBossHelper
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiInventory
Expand All @@ -42,7 +44,7 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {

var factionType = FactionType.NONE

private var display = emptyList<List<Any>>()
private var display = emptyList<Renderable>()
private var dirty = true
var tabListQuestsMissing = false

Expand Down Expand Up @@ -95,6 +97,15 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {
dirty = true
}

@HandleEvent
fun onWidgetUpdate(event: WidgetUpdateEvent) {
if (!event.isWidget(TabWidget.REPUTATION)) return

TabWidget.REPUTATION.matchMatcherFirstLine {
factionType = FactionType.fromName(group("faction"))
}
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!IslandType.CRIMSON_ISLE.isInIsland()) return
Expand All @@ -106,39 +117,31 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {
dirty = false
updateRender()
}

if (event.repeatSeconds(3)) {
val list = TabListData.getTabList().filter { it.contains("Reputation:") }
for (line in list) {
factionType = if (line.contains("Mage")) {
FactionType.MAGE
} else if (line.contains("Barbarian")) {
FactionType.BARBARIAN
} else {
FactionType.NONE
}
}
}
}

private fun updateRender() {
val newList = mutableListOf<List<Any>>()

// TODO test
if (factionType == FactionType.NONE) return

newList.addAsSingletonList("§e§lReputation Helper")
if (tabListQuestsMissing) {
newList.addAsSingletonList("§cFaction Quests Widget not found!")
newList.addAsSingletonList("§7Open §e/tab §7and enable it!")
} else {
questHelper.render(newList)
miniBossHelper.render(newList)
kuudraBossHelper.render(newList)
}

display = buildList {
addString("§e§lReputation Helper")
if (factionType == FactionType.NONE) {
addString("§cFaction not found!")
return
}

display = newList
if (tabListQuestsMissing) {
addString("§cFaction Quests Widget not found!")
addString("§7Open §e/tab §7and enable it!")
} else {
questHelper.run {
addQuests()
}
miniBossHelper.run {
addDailyMiniBoss()
}
kuudraBossHelper.run {
addKuudraBoss()
}
}
}
}

@SubscribeEvent(priority = EventPriority.LOWEST)
Expand All @@ -150,7 +153,7 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {
return
}

config.position.renderStringsAndItems(
config.position.renderRenderables(
display,
posLabel = "Crimson Isle Reputation Helper",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package at.hannibal2.skyhanni.features.nether.reputationhelper

enum class FactionType {
BARBARIAN,
MAGE,
enum class FactionType(val factionName: String) {
BARBARIAN("Barbarian"),
MAGE("Mage"),
NONE("None"),
;

NONE
companion object {
fun fromName(name: String) = entries.firstOrNull { it.factionName.equals(name, ignoreCase = true) } ?: NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.quest.T
import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.quest.UnknownQuest
import at.hannibal2.skyhanni.features.nether.reputationhelper.miniboss.CrimsonMiniBoss
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.ConditionalUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
Expand All @@ -45,6 +46,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.removeWordsAtEnd
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
Expand Down Expand Up @@ -227,23 +229,23 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) {
state == QuestState.READY_TO_COLLECT || (this is RescueMissionQuest && state == QuestState.ACCEPTED)
}

fun render(display: MutableList<List<Any>>) {
fun MutableList<Renderable>.addQuests() {
if (greatSpook) {
display.addAsSingletonList("")
display.addAsSingletonList("§7Daily Quests (§cdisabled§7)")
display.addAsSingletonList(" §5§lThe Great Spook §7happened :O")
addString("")
addString("§7Daily Quests (§cdisabled§7)")
addString(" §5§lThe Great Spook §7happened :O")
return
}
val done = quests.count { it.state == QuestState.COLLECTED }
display.addAsSingletonList("")
display.addAsSingletonList("§7Daily Quests (§e$done§8/§e5 collected§7)")
addString("")
addString("§7Daily Quests (§e$done§8/§e5 collected§7)")
if (done != 5) {
val filteredQuests = quests.filter { !config.hideComplete.get() || it.state != QuestState.COLLECTED }
filteredQuests.mapTo(display) { renderQuest(it) }
addAll(filteredQuests.map { renderQuest(it) })
}
}

private fun renderQuest(quest: Quest): List<Any> {
private fun renderQuest(quest: Quest): Renderable {
val category = quest.category
val state = quest.state.displayName
val stateColor = quest.state.color
Expand Down Expand Up @@ -275,7 +277,6 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) {
""
}

val result = mutableListOf<Any>()
val item = quest.displayItem.getItemStack()

val displayName = if (category == QuestCategory.FETCH || category == QuestCategory.FISHING) {
Expand All @@ -287,10 +288,13 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) {

val categoryName = category.displayName

result.add(" $stateText$categoryName: ")
result.add(item)
result.add("§f$displayName$progressText$sacksText")
return result
return Renderable.horizontalContainer(
buildList {
addString(" $stateText$categoryName: ")
addItemStack(item)
addString("§f$displayName$progressText$sacksText")
},
)
}

fun finishMiniBoss(miniBoss: CrimsonMiniBoss) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import at.hannibal2.skyhanni.events.kuudra.KuudraCompleteEvent
import at.hannibal2.skyhanni.features.nether.kuudra.KuudraTier
import at.hannibal2.skyhanni.features.nether.reputationhelper.CrimsonIsleReputationHelper
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class DailyKuudraBossHelper(private val reputationHelper: CrimsonIsleReputationHelper) {
Expand Down Expand Up @@ -52,21 +54,25 @@ class DailyKuudraBossHelper(private val reputationHelper: CrimsonIsleReputationH
reputationHelper.update()
}

fun render(display: MutableList<List<Any>>) {
fun MutableList<Renderable>.addKuudraBoss() {
val done = kuudraTiers.count { it.doneToday }
display.addAsSingletonList("")
display.addAsSingletonList("§7Daily Kuudra (§e$done§8/§e5 killed§7)")
addString("")
addString("§7Daily Kuudra (§e$done§8/§e5 killed§7)")
if (done < 5) {
for (tier in kuudraTiers) {
if (config.hideComplete.get() && tier.doneToday) continue
val result = if (tier.doneToday) "§aDone" else "§bTodo"
val displayName = tier.getDisplayName()
val displayItem = tier.displayItem
val lineList = mutableListOf<Any>()
lineList.add(" ")
lineList.add(displayItem.getItemStack())
lineList.add("$displayName: $result")
display.add(lineList)

val row = Renderable.horizontalContainer(
buildList {
addString(" ")
addItemStack(displayItem.getItemStack())
addString("$displayName: $result")
},
)
add(row)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import at.hannibal2.skyhanni.features.combat.damageindicator.DamageIndicatorMana
import at.hannibal2.skyhanni.features.nether.reputationhelper.CrimsonIsleReputationHelper
import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.quest.MiniBossQuest
import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.quest.QuestState
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class DailyMiniBossHelper(private val reputationHelper: CrimsonIsleReputationHelper) {
Expand Down Expand Up @@ -64,22 +66,27 @@ class DailyMiniBossHelper(private val reputationHelper: CrimsonIsleReputationHel
reputationHelper.update()
}

fun render(display: MutableList<List<Any>>) {
fun MutableList<Renderable>.addDailyMiniBoss() {
val done = miniBosses.count { it.doneToday }
display.addAsSingletonList("")
display.addAsSingletonList("§7Daily Bosses (§e$done§8/§e5 killed§7)")

addString("")
addString("§7Daily Bosses (§e$done§8/§e5 killed§7)")

if (done != 5) {
for (miniBoss in miniBosses) {
if (config.hideComplete.get() && miniBoss.doneToday) continue
val result = if (miniBoss.doneToday) "§aDone" else "§bTodo"
val displayName = miniBoss.displayName
val displayItem = miniBoss.displayItem

val lineList = mutableListOf<Any>()
lineList.add(" ")
lineList.add(displayItem.getItemStack())
lineList.add("§5$displayName§7: $result")
display.add(lineList)
val row = Renderable.horizontalContainer(
buildList {
addString(" ")
addItemStack(displayItem.getItemStack())
addString("§5$displayName§7: $result")
},
)
add(row)
}
}
}
Expand Down
Loading
Loading