|
| 1 | +package me.owdding.mortem.features |
| 2 | + |
| 3 | +import me.owdding.ktmodules.Module |
| 4 | +import me.owdding.mortem.config.category.MiscConfig |
| 5 | +import me.owdding.mortem.utils.GfsQueue |
| 6 | +import me.owdding.mortem.utils.extensions.sendWithPrefix |
| 7 | +import tech.thatgravyboat.skyblockapi.api.events.base.Subscription |
| 8 | +import tech.thatgravyboat.skyblockapi.api.events.dungeon.DungeonEnterEvent |
| 9 | +import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent |
| 10 | +import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent.Companion.argument |
| 11 | +import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId |
| 12 | +import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId.Companion.getSkyBlockId |
| 13 | +import tech.thatgravyboat.skyblockapi.helpers.McPlayer |
| 14 | +import tech.thatgravyboat.skyblockapi.utils.command.EnumArgument |
| 15 | +import tech.thatgravyboat.skyblockapi.utils.text.Text |
| 16 | + |
| 17 | +@Module |
| 18 | +object ItemRefill { |
| 19 | + |
| 20 | + @Subscription |
| 21 | + fun onCommand(event: RegisterCommandsEvent) { |
| 22 | + event.register("mortem refill") { |
| 23 | + thenCallback("item", EnumArgument<RefillItems>()) { |
| 24 | + refill(argument<RefillItems>("item")) |
| 25 | + } |
| 26 | + |
| 27 | + callback { |
| 28 | + refill(*MiscConfig.itemRefill) |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + @Subscription |
| 34 | + fun onEnter(event: DungeonEnterEvent) { |
| 35 | + if (!MiscConfig.automaticRefillOnEnter) return |
| 36 | + |
| 37 | + refill(*MiscConfig.itemRefill) |
| 38 | + } |
| 39 | + |
| 40 | + private fun refill(vararg items: RefillItems, sendOutput: Boolean = true) { |
| 41 | + val output = items.mapNotNull { |
| 42 | + val count = countItem(it.id) |
| 43 | + if (count < it.maxStackSize) { |
| 44 | + GfsQueue.add(it.id, it.maxStackSize - count) |
| 45 | + "${it.maxStackSize - count}x ${it.name}" |
| 46 | + } else null |
| 47 | + } |
| 48 | + |
| 49 | + if (sendOutput) { |
| 50 | + // TODO fancy colors |
| 51 | + Text.join("Item Refill | ", output.joinToString(", ")).sendWithPrefix() |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private fun countItem(id: SkyBlockId) = McPlayer.inventory.filter { it.getSkyBlockId() == id }.sumOf { it.count } |
| 56 | + |
| 57 | + enum class RefillItems(val maxStackSize: Int = 64, id: String? = null) { |
| 58 | + SPIRIT_LEAP(maxStackSize = 16), |
| 59 | + SUPERBOOM_TNT, |
| 60 | + ENDER_PEARL(maxStackSize = 16), |
| 61 | + DECOY, |
| 62 | + INFLATABLE_JERRY, |
| 63 | + ; |
| 64 | + |
| 65 | + val id = SkyBlockId.item(id ?: name) |
| 66 | + } |
| 67 | +} |
0 commit comments