1+ /*
2+ * Skytils - Hypixel Skyblock Quality of Life Mod
3+ * Copyright (C) 2020-2024 Skytils
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Affero General Public License as published
7+ * by the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Affero General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Affero General Public License
16+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17+ */
18+
19+ package gg.skytils.skytilsmod.features.impl.crimson
20+
21+ import gg.essential.universal.ChatColor
22+ import gg.essential.universal.UGraphics
23+ import gg.essential.universal.wrappers.UPlayer
24+ import gg.skytils.skytilsmod.Skytils
25+ import gg.skytils.skytilsmod.core.API
26+ import gg.skytils.skytilsmod.core.Config
27+ import gg.skytils.skytilsmod.core.structure.GuiElement
28+ import gg.skytils.skytilsmod.utils.*
29+ import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
30+ import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
31+ import net.minecraftforge.client.event.ClientChatReceivedEvent
32+ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
33+
34+ object TrophyFish {
35+ private val trophyFish = mutableMapOf<String , Fish >()
36+ private val trophyFishRegex = Regex (" TROPHY FISH! You caught an? (\\ w+) (BRONZE|SILVER|GOLD|DIAMOND)\\ ." )
37+
38+
39+ init {
40+ Skytils .guiManager.registerElement(TrophyFishDisplay ())
41+ }
42+
43+ fun loadFromApi () {
44+ trophyFish.clear()
45+ val trophyFishData = API .getSelectedSkyblockProfileSync(UPlayer .getUUID())?.members?.get(UPlayer .getUUID().nonDashedString())?.trophy_fish
46+ trophyFishData?.fish_count?.forEach { (fish, data) ->
47+ trophyFish[fish] = Fish (data.bronze, data.silver, data.gold, data.diamond)
48+ }
49+ }
50+
51+ @SubscribeEvent
52+ fun onChat (event : ClientChatReceivedEvent ) {
53+ if (! Utils .inSkyblock || SBInfo .mode != SkyblockIsland .CrimsonIsle .mode || ! Config .trophyFishTracker) return
54+ printDevMessage(event.message.formattedText, " trophyspam" )
55+ trophyFishRegex.matchEntire(event.message.formattedText.stripControlCodes())?.destructured?.let { (type, tier) ->
56+ printDevMessage(" Found trophy fish of $type of tier $tier " , " trophy" )
57+ val fish = TrophyFish .entries.find { it.actualName.lowercase() == type.lowercase() } ? : return @let
58+ printDevMessage(" Trophy fish type: ${fish.name} " , " trophy" )
59+ val field = when (tier.lowercase()) {
60+ " diamond" -> Fish ::diamond
61+ " gold" -> Fish ::gold
62+ " silver" -> Fish ::silver
63+ " bronze" -> Fish ::bronze
64+ else -> return @let
65+ }
66+ trophyFish[fish.name]?.let { data ->
67+ printDevMessage(" Updating ${fish.actualName} $tier to ${field.get(data) + 1 } " , " trophy" )
68+ field.set(data, field.get(data) + 1 )
69+ }
70+ }
71+ }
72+
73+ fun generateTrophyFishList (total : Boolean = false) =
74+ trophyFish.entries.sortedBy { (fish, _) -> TrophyFish .entries.indexOfFirst { it.name == fish } }.mapNotNull { (fish, data) ->
75+ val name = TrophyFish .entries.find { it.name == fish }?.formattedName ? : return @mapNotNull null
76+ name + (if (total) " ${ChatColor .DARK_AQUA } [${ChatColor .LIGHT_PURPLE }${data.total}${ChatColor .DARK_AQUA } ] " else " ${ChatColor .DARK_AQUA } » " ) +
77+ " ${ChatColor .DARK_GRAY }${data.bronze}${ChatColor .DARK_AQUA } -" +
78+ " ${ChatColor .GRAY }${data.silver}${ChatColor .DARK_AQUA } -" +
79+ " ${ChatColor .GOLD }${data.gold}${ChatColor .DARK_AQUA } -" +
80+ " ${ChatColor .AQUA }${data.diamond} "
81+ }
82+
83+ class Fish (var bronze : Int = 0 , var silver : Int = 0 , var gold : Int = 0 , var diamond : Int = 0 ) {
84+ val total: Int
85+ get() = bronze + silver + gold + diamond
86+ }
87+
88+ enum class TrophyFish (val actualName : String , val color : ChatColor ) {
89+ sulphur_skitter(" Sulphur Skitter" , ChatColor .WHITE ),
90+ obfuscated_fish_1(" Obfuscated 1" , ChatColor .WHITE ),
91+ steaming_hot_flounder(" Steaming-Hot Flounder" , ChatColor .WHITE ),
92+ gusher(" Gusher" , ChatColor .WHITE ),
93+ blobfish(" Blobfish" , ChatColor .WHITE ),
94+ obfuscated_fish_2(" Obfuscated 2" , ChatColor .GREEN ),
95+ slugfish(" Slugfish" , ChatColor .GREEN ),
96+ flyfish(" Flyfish" , ChatColor .GREEN ),
97+ obfuscated_fish_3(" Obfuscated 3" , ChatColor .BLUE ),
98+ lava_horse(" Lavahorse" , ChatColor .BLUE ),
99+ mana_ray(" Mana Ray" , ChatColor .BLUE ),
100+ volcanic_stonefish(" Volcanic Stonefish" , ChatColor .BLUE ),
101+ vanille(" Vanille" , ChatColor .BLUE ),
102+ skeleton_fish(" Skeleton Fish" , ChatColor .DARK_PURPLE ),
103+ moldfin(" Moldfin" , ChatColor .DARK_PURPLE ),
104+ soul_fish(" Soul Fish" , ChatColor .DARK_PURPLE ),
105+ karate_fish(" Karate Fish" , ChatColor .DARK_PURPLE ),
106+ golden_fish(" Golden Fish" , ChatColor .GOLD );
107+
108+ val formattedName: String
109+ get() = " $color$actualName "
110+ }
111+
112+ class TrophyFishDisplay : GuiElement (" Trophy Fish Display" , 1f , 0 , 0 ) {
113+ val alignment = if (scaleX > sr.scaledWidth / 2f ) SmartFontRenderer .TextAlignment .RIGHT_LEFT else SmartFontRenderer .TextAlignment .LEFT_RIGHT
114+ override fun render () {
115+ if (! toggled || ! Utils .inSkyblock || SBInfo .mode != SkyblockIsland .CrimsonIsle .mode) return
116+ generateTrophyFishList(Config .showTrophyFishTotals).forEachIndexed { idx, str ->
117+ fr.drawString(
118+ str,
119+ 0f ,
120+ (idx * fr.FONT_HEIGHT ).toFloat(),
121+ CommonColors .WHITE ,
122+ alignment,
123+ textShadow
124+ )
125+ }
126+ if (Config .showTotalTrophyFish) {
127+ fr.drawString(
128+ " ${ChatColor .LIGHT_PURPLE } Total ${ChatColor .DARK_AQUA } » ${ChatColor .LIGHT_PURPLE } " + trophyFish.values.fold(0 ) { acc, e ->
129+ acc + e.total
130+ },
131+ 0f ,
132+ (trophyFish.size * fr.FONT_HEIGHT ).toFloat(),
133+ CommonColors .WHITE ,
134+ alignment,
135+ textShadow
136+ )
137+ }
138+ }
139+
140+ override fun demoRender () {
141+ TrophyFish .entries.forEachIndexed { idx, fish ->
142+ fr.drawString(
143+ " ${fish.formattedName} ${ChatColor .DARK_AQUA } » " +
144+ " ${ChatColor .DARK_GRAY } 999${ChatColor .DARK_AQUA } -" +
145+ " ${ChatColor .GRAY } 99${ChatColor .DARK_AQUA } -" +
146+ " ${ChatColor .GOLD } 9${ChatColor .DARK_AQUA } -" +
147+ " ${ChatColor .AQUA } 0" ,
148+ 0f ,
149+ (idx * fr.FONT_HEIGHT ).toFloat(),
150+ CommonColors .WHITE ,
151+ SmartFontRenderer .TextAlignment .LEFT_RIGHT ,
152+ SmartFontRenderer .TextShadow .NORMAL
153+ )
154+ }
155+ if (Config .showTotalTrophyFish) {
156+ fr.drawString(
157+ " ${ChatColor .LIGHT_PURPLE } Total ${ChatColor .DARK_AQUA } » 9999" ,
158+ 0f ,
159+ (trophyFish.size * fr.FONT_HEIGHT ).toFloat(),
160+ CommonColors .WHITE ,
161+ alignment,
162+ textShadow
163+ )
164+ }
165+ }
166+
167+ override val toggled: Boolean
168+ get() = Config .trophyFishTracker
169+
170+ override val height: Int // This converts the boolean to an int (1 for true, 0 for false)
171+ get() = (TrophyFish .entries.size + Config .showTotalTrophyFish.compareTo(false )) * UGraphics .getFontHeight()
172+ override val width: Int
173+ get() = UGraphics .getStringWidth(" Steaming Hot Flounder » 999-99-99-9" )
174+
175+ }
176+ }
0 commit comments