-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Trophy frog api #437
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
Open
mariethepolarfox
wants to merge
5
commits into
SkyblockAPI:4.0
Choose a base branch
from
mariethepolarfox:trophy-frog-api
base: 4.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/tech/thatgravyboat/skyblockapi/api/area/atoll/trophyfrog/TrophyFrog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package tech.thatgravyboat.skyblockapi.api.area.atoll.trophyfrog | ||
|
|
||
| import net.minecraft.network.chat.Component | ||
| import net.minecraft.world.item.ItemStack | ||
| import tech.thatgravyboat.skyblockapi.api.datatype.defaults.trophy.TrophyTier | ||
| import tech.thatgravyboat.skyblockapi.utils.text.Text | ||
|
|
||
| data class TrophyFrog(val type: TrophyFrogType, val tier: TrophyTier) { | ||
| val item: ItemStack by lazy { type.getItem(tier) } | ||
| val displayName: Component by lazy { | ||
| if (tier == TrophyTier.NONE) { | ||
| return@lazy type.displayName.copy() | ||
| } | ||
|
|
||
| Text.join(type.displayName, " ", tier.nameSuffix) | ||
| } | ||
|
|
||
| val apiName by lazy { | ||
| if (tier == TrophyTier.NONE) { | ||
| return@lazy type.internalName.lowercase() | ||
| } | ||
|
|
||
| "${type.internalName.lowercase()}_${tier.name.lowercase()}" | ||
| } | ||
|
|
||
| companion object { | ||
| fun fromString(fish: String): TrophyFrog? { | ||
| if (fish.contains("/")) { | ||
| return fish.split("/").let { | ||
| TrophyFrog( | ||
| TrophyFrogType.getByInternalName(it[0]) ?: return null, | ||
| TrophyTier.getByName(it[1]), | ||
| ) | ||
| } | ||
| } | ||
| return null | ||
| } | ||
| } | ||
| } |
120 changes: 120 additions & 0 deletions
120
src/main/kotlin/tech/thatgravyboat/skyblockapi/api/area/atoll/trophyfrog/TrophyFrogAPI.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package tech.thatgravyboat.skyblockapi.api.area.atoll.trophyfrog | ||
|
|
||
| import me.owdding.ktmodules.Module | ||
| import tech.thatgravyboat.skyblockapi.api.data.stored.TrophyFrogStorage | ||
| import tech.thatgravyboat.skyblockapi.api.datatype.defaults.trophy.TrophyTier | ||
| import tech.thatgravyboat.skyblockapi.api.events.base.Subscription | ||
| import tech.thatgravyboat.skyblockapi.api.events.base.predicates.OnlyIn | ||
| import tech.thatgravyboat.skyblockapi.api.events.chat.ChatReceivedEvent | ||
| import tech.thatgravyboat.skyblockapi.api.events.location.atoll.TrophyFrogCaughtEvent | ||
| import tech.thatgravyboat.skyblockapi.api.events.screen.InventoryChangeEvent | ||
| import tech.thatgravyboat.skyblockapi.api.location.SkyBlockIsland | ||
| import tech.thatgravyboat.skyblockapi.utils.extentions.cleanName | ||
| import tech.thatgravyboat.skyblockapi.utils.extentions.getRawLore | ||
| import tech.thatgravyboat.skyblockapi.utils.regex.RegexGroup | ||
| import tech.thatgravyboat.skyblockapi.utils.regex.RegexUtils.match | ||
| import tech.thatgravyboat.skyblockapi.utils.text.CommonText | ||
| import tech.thatgravyboat.skyblockapi.utils.text.Text | ||
| import tech.thatgravyboat.skyblockapi.utils.text.Text.sendWithPrefix | ||
|
|
||
| @Module | ||
| object TrophyFrogAPI { | ||
|
|
||
| private val chatGroup = RegexGroup.CHAT.group("trophy_api") | ||
| private val inventoryGroup = RegexGroup.INVENTORY.group("trophy_api") | ||
|
|
||
| private val trophyFrogCaughtRegex = chatGroup.create( | ||
| "frog_caught", | ||
| "\uE02A TROPHY FROG! You caught an? (?<type>.+?) (?<tier>${TrophyTier.entries.joinToString("|", transform = { it.name })})!", | ||
| ) | ||
|
|
||
| private val trophyFrogDescription = inventoryGroup.create( | ||
| "frog_description", | ||
| "(?<tier>Diamond|Silver|Gold|Bronze) \\S+(?: \\((?<amount>\\d+)\\))?", | ||
| ) | ||
|
|
||
| @Subscription | ||
| @OnlyIn(SkyBlockIsland.LOTUS_ATOLL) | ||
| fun onChat(event: ChatReceivedEvent.Pre) { | ||
| val content = event.text.trim() | ||
| trophyFrogCaughtRegex.match(content, "type", "tier") { (type, tier) -> | ||
| val frogTier = TrophyTier.valueOf(tier) | ||
| val type = TrophyFrogType.getByDisplayName(type) ?: return@match | ||
|
|
||
| Text.of { | ||
| append("Caught: ") | ||
| append(type.displayName) | ||
| append(CommonText.SPACE) | ||
| append(frogTier.nameSuffix) | ||
| }.sendWithPrefix() | ||
| TrophyFrogStorage.addCaught(type, frogTier) | ||
| TrophyFrogCaughtEvent(type, frogTier).post() | ||
| } | ||
| } | ||
|
|
||
| @Subscription | ||
| @OnlyIn(SkyBlockIsland.LOTUS_ATOLL) | ||
| fun onInventory(event: InventoryChangeEvent) { | ||
| if (event.title != "Trophy Frogs") return | ||
| if (event.isInPlayerInventory) return | ||
| if (!event.isInMainPart) return | ||
| if (event.isSkyBlockFiller) return | ||
|
|
||
| val byName = TrophyFrogType.getByDisplayName(event.item.cleanName) ?: return | ||
| val caught = mutableMapOf<TrophyTier, Int>() | ||
| event.item.getRawLore().forEach { | ||
| trophyFrogDescription.match(it, "tier", "amount") { match -> | ||
| val (tierName) = match | ||
| val amount = match["amount"] ?: "0" | ||
| val tier = TrophyTier.getByName(tierName) | ||
| caught[tier] = amount.toInt() | ||
| } | ||
| } | ||
| Text.of { | ||
| append(byName.displayName) | ||
| caught.forEach { (tier, tierAmount) -> | ||
| append(CommonText.SPACE) | ||
| append(tier.nameSuffix) | ||
| append(": $tierAmount") | ||
| } | ||
| }.sendWithPrefix() | ||
| TrophyFrogStorage.setAmounts(byName, caught) | ||
| } | ||
|
|
||
| // TODO: Data | ||
| /*@OptIn(SkyBlockPvRequired::class) | ||
| @Subscription | ||
| @OnlyOnSkyBlock | ||
| fun onPv(event: SkyBlockPvOpenedEvent) { | ||
| val obtained = event.member["trophy_fish"].asMap { key, value -> | ||
| if (!value.isJsonPrimitive) null to 0 | ||
| else key to value.asInt(0) | ||
| }.filterKeysNotNull() | ||
| var hasLoadedAny = false | ||
|
|
||
| val grouped = obtained.entries.groupBy { group -> TrophyFrogType.entries.find { group.key.startsWith(it.internalName, true) } }.filterKeysNotNull() | ||
| val unlocked = grouped.mapValues { entry -> | ||
| val caught = getCaught(entry.key) | ||
| entry.value.associate { value -> | ||
| val tier = TrophyTier.entries.find { value.key.endsWith(it.name, true) } | ||
| val previous = tier?.let(caught::get) ?: 0 | ||
| val value = value.value | ||
|
|
||
| if (tier != null && value > previous) { | ||
| hasLoadedAny = true | ||
| } | ||
|
|
||
| tier to max(value, previous) | ||
| }.filterKeysNotNull() | ||
| } | ||
|
|
||
| if (hasLoadedAny) { | ||
| PvLoadingHelper.markLoaded(LoadedData.TROPHY_FISH) | ||
| } | ||
| unlocked.forEach(TrophyFrogStorage::setAmounts) | ||
| } | ||
|
|
||
| fun getCaught(type: TrophyFrogType): Map<TrophyTier, Int> { | ||
| return TrophyFrogStorage.getCaught(type) | ||
| }*/ | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/tech/thatgravyboat/skyblockapi/api/area/atoll/trophyfrog/TrophyFrogData.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package tech.thatgravyboat.skyblockapi.api.area.atoll.trophyfrog | ||
|
|
||
| import me.owdding.ktcodecs.GenerateCodec | ||
| import tech.thatgravyboat.skyblockapi.api.datatype.defaults.trophy.TrophyTier | ||
| import tech.thatgravyboat.skyblockapi.generated.SkyblockAPICodecs | ||
|
|
||
| @GenerateCodec | ||
| data class TrophyFrogData( | ||
| val data: MutableMap<TrophyFrogType, MutableMap<TrophyTier, Int>> = mutableMapOf(), | ||
| ) { | ||
| companion object { | ||
| val CODEC = SkyblockAPICodecs.getCodec<TrophyFrogData>() | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
src/main/kotlin/tech/thatgravyboat/skyblockapi/api/area/atoll/trophyfrog/TrophyFrogType.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package tech.thatgravyboat.skyblockapi.api.area.atoll.trophyfrog | ||
|
|
||
| import net.minecraft.ChatFormatting | ||
| import net.minecraft.network.chat.Component | ||
| import net.minecraft.world.item.ItemStack | ||
| import tech.thatgravyboat.skyblockapi.api.datatype.defaults.trophy.TrophyTier | ||
| import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId | ||
| import tech.thatgravyboat.skyblockapi.api.repo.apis.SkyBlockItemsRepo | ||
| import tech.thatgravyboat.skyblockapi.utils.lazy.registryBoundLazy | ||
| import tech.thatgravyboat.skyblockapi.utils.text.Text | ||
| import tech.thatgravyboat.skyblockapi.utils.text.TextProperties.stripped | ||
|
|
||
| enum class TrophyFrogType( | ||
| val displayName: Component, | ||
| internalName: String = "", | ||
| ) { | ||
| COMMON_FROG( | ||
| displayName = Text.of("Common Frog") { | ||
| withStyle(ChatFormatting.WHITE) | ||
| }, | ||
| ), | ||
| LEAP_FROG( | ||
| displayName = Text.of("Leap Frog") { | ||
| withStyle(ChatFormatting.GREEN) | ||
| }, | ||
| ), | ||
| WETLANDS_FROG( | ||
| displayName = Text.of("Wetlands Frog") { | ||
| withStyle(ChatFormatting.GREEN) | ||
| }, | ||
| ), | ||
| REALITY_HOPPER( | ||
| displayName = Text.of("Reality Hopper") { | ||
| withStyle(ChatFormatting.GREEN) | ||
| }, | ||
| ), | ||
| EXPLODING_FROG( | ||
| displayName = Text.of("Exploding Frog") { | ||
| withStyle(ChatFormatting.GREEN) | ||
| }, | ||
| ), | ||
| BLESSED_FROG( | ||
| displayName = Text.of("Blessed Frog") { | ||
| withStyle(ChatFormatting.BLUE) | ||
| }, | ||
| ), | ||
| SEA_FROG( | ||
| displayName = Text.of("Sea Frog") { | ||
| withStyle(ChatFormatting.BLUE) | ||
| }, | ||
| ), | ||
| BULLFROG( | ||
| displayName = Text.of("Bullfrog") { | ||
| withStyle(ChatFormatting.BLUE) | ||
| }, | ||
| ), | ||
| TREE_FROG( | ||
| displayName = Text.of("Tree Frog") { | ||
| withStyle(ChatFormatting.DARK_PURPLE) | ||
| }, | ||
| ), | ||
| CAVE_FROG( | ||
| displayName = Text.of("Cave Frog") { | ||
| withStyle(ChatFormatting.DARK_PURPLE) | ||
| }, | ||
| ), | ||
| HIGHLANDS_FROG( | ||
| displayName = Text.of("Highlands Frog") { | ||
| withStyle(ChatFormatting.DARK_PURPLE) | ||
| }, | ||
| ), | ||
| PUDDLE_JUMPER( | ||
| displayName = Text.of("Puddle Jumper") { | ||
| withStyle(ChatFormatting.GOLD) | ||
| }, | ||
| ), | ||
| ; | ||
|
|
||
| val internalName: String = internalName.takeUnless { it.isEmpty() } ?: name | ||
| val strippedName = displayName.stripped | ||
|
|
||
| val bronze by registryBoundLazy { SkyBlockItemsRepo.getItemStackOrDefault("${this.internalName}_BRONZE") } | ||
| val silver by registryBoundLazy { SkyBlockItemsRepo.getItemStackOrDefault("${this.internalName}_SILVER") } | ||
| val gold by registryBoundLazy { SkyBlockItemsRepo.getItemStackOrDefault("${this.internalName}_GOLD") } | ||
| val diamond by registryBoundLazy { SkyBlockItemsRepo.getItemStackOrDefault("${this.internalName}_DIAMOND") } | ||
|
|
||
| fun getItem(tier: TrophyTier): ItemStack { | ||
| return when (tier) { | ||
| TrophyTier.NONE -> bronze | ||
| TrophyTier.BRONZE -> bronze | ||
| TrophyTier.SILVER -> silver | ||
| TrophyTier.GOLD -> gold | ||
| TrophyTier.DIAMOND -> diamond | ||
| } | ||
| } | ||
|
|
||
| fun getId(tier: TrophyTier, default: TrophyTier = TrophyTier.BRONZE): SkyBlockId = SkyBlockId.item("${this.internalName}_${tier.takeUnless { it == TrophyTier.NONE } ?: default}") | ||
|
|
||
| companion object { | ||
| fun getByInternalName(internalName: String): TrophyFrogType? { | ||
| return entries.find { internalName.equals(it.internalName, ignoreCase = true) } | ||
| } | ||
|
|
||
| fun getByDisplayName(name: String): TrophyFrogType? { | ||
| return entries.find { name.equals(it.strippedName, ignoreCase = true) } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/kotlin/tech/thatgravyboat/skyblockapi/api/area/isle/trophyfish/TrophyFishData.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be aswell?