1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
package at.hannibal2.skyhanni.features.nether.reputationhelper
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.crimsonisle.ReputationHelperConfig.ShowLocationEntry
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.jsonobjects.repo.CrimsonIsleReputationJson
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.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.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.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiInventory
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {
private val config get() = SkyHanniMod.feature.crimsonIsle.reputationHelper
val questHelper = DailyQuestHelper(this)
val miniBossHelper = DailyMiniBossHelper(this)
val kuudraBossHelper = DailyKuudraBossHelper(this)
var factionType = FactionType.NONE
private var lastUpdate = SimpleTimeMark.farPast()
private var display = emptyList<List<Any>>()
private var dirty = true
var tabListQuestsMissing = false
/**
* c - Barbarian Not Accepted
* d - Mage Not Accepted
* e - Accepted
* a - Completed
*/
val tabListQuestPattern by RepoPattern.pattern(
"crimson.reputation.tablist",
" §r§[cdea].*",
)
init {
skyHanniMod.loadModule(questHelper)
skyHanniMod.loadModule(miniBossHelper)
skyHanniMod.loadModule(kuudraBossHelper)
}
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<CrimsonIsleReputationJson>("CrimsonIsleReputation")
miniBossHelper.onRepoReload(data.MINIBOSS)
kuudraBossHelper.onRepoReload(data.KUUDRA)
QuestLoader.quests.clear()
QuestLoader.loadQuests(data.FISHING, "FISHING")
QuestLoader.loadQuests(data.RESCUE, "RESCUE")
QuestLoader.loadQuests(data.FETCH, "FETCH")
QuestLoader.loadQuests(data.DOJO, "DOJO")
update()
}
@SubscribeEvent
fun onConfigLoad(event: ConfigLoadEvent) {
ProfileStorageData.profileSpecific?.crimsonIsle?.let {
miniBossHelper.loadData(it)
kuudraBossHelper.loadData(it)
questHelper.load(it)
}
}
@SubscribeEvent
fun onSackChange(event: SackChangeEvent) {
dirty = true
}
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!IslandType.CRIMSON_ISLE.isInIsland()) return
if (!config.enabled.get()) return
if (!dirty && display.isEmpty()) {
dirty = true
}
if (dirty) {
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
}
}
}
}
@SubscribeEvent
fun onConfigInit(event: ConfigLoadEvent) {
config.hideComplete.afterChange {
updateRender()
}
}
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 = newList
}
@SubscribeEvent(priority = EventPriority.LOWEST)
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!config.enabled.get()) return
if (!IslandType.CRIMSON_ISLE.isInIsland()) return
if (config.useHotkey && !isHotkeyHeld()) {
return
}
config.position.renderStringsAndItems(
display,
posLabel = "Crimson Isle Reputation Helper",
)
}
fun isHotkeyHeld(): Boolean {
val isAllowedGui = Minecraft.getMinecraft().currentScreen.let {
it == null || it is GuiInventory
}
if (!isAllowedGui) return false
if (NEUItems.neuHasFocus()) return false
return config.hotkey.isKeyHeld()
}
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(2, "misc.crimsonIsleReputationHelper", "crimsonIsle.reputationHelper.enabled")
event.move(2, "misc.reputationHelperUseHotkey", "crimsonIsle.reputationHelper.useHotkey")
event.move(2, "misc.reputationHelperHotkey", "crimsonIsle.reputationHelper.hotkey")
event.move(2, "misc.crimsonIsleReputationHelperPos", "crimsonIsle.reputationHelper.position")
event.move(2, "misc.crimsonIsleReputationShowLocation", "crimsonIsle.reputationHelper.showLocation")
event.transform(15, "crimsonIsle.reputationHelper.showLocation") { element ->
ConfigUtils.migrateIntToEnum(element, ShowLocationEntry::class.java)
}
}
fun update() {
ProfileStorageData.profileSpecific?.crimsonIsle?.let {
questHelper.saveConfig(it)
miniBossHelper.saveConfig(it)
kuudraBossHelper.saveConfig(it)
}
dirty = true
}
fun reset() {
ChatUtils.chat("Reset Reputation Helper.")
questHelper.reset()
miniBossHelper.reset()
kuudraBossHelper.reset()
update()
}
fun readLocationData(locations: List<Double>): LorenzVec? {
if (locations.isEmpty()) return null
val (x, y, z) = locations
return LorenzVec(x, y, z).add(-1, 0, -1)
}
fun showLocations() = when (config.showLocation) {
ShowLocationEntry.ALWAYS -> true
ShowLocationEntry.ONLY_HOTKEY -> isHotkeyHeld()
else -> false
}
}
|