Skip to content

Commit

Permalink
Remove: Rip Out Half-Baked Hitman Replace Feature (#3078)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidArthurCole authored Dec 17, 2024
1 parent 18adf9d commit 7e64df4
Showing 1 changed file with 0 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
package at.hannibal2.skyhanni.features.inventory.chocolatefactory.hitman

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.hoppity.RabbitFoundEvent
import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent
import at.hannibal2.skyhanni.features.event.hoppity.HoppityAPI.hitmanInventoryPattern
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils.isTopInventory
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.getSingleLineLore
import at.hannibal2.skyhanni.utils.ItemUtils.setLore
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.renderables.Renderable
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object HitmanSlots {

// <editor-fold desc="Patterns">
/**
* REGEX-TEST: §cEgg Slot
*/
private val slotOnCooldownPattern by ChocolateFactoryAPI.patternGroup.pattern(
"hitman.slotoncooldown",
"§cEgg Slot",
)

/**
* REGEX-TEST: §7Hitman can store more eggs you miss! §7Cost §620,000,000 Coins §eClick to purchase!
*/
Expand All @@ -44,75 +27,20 @@ object HitmanSlots {
".*§7Cost §6(?<cost>[\\d,]+) Coins.*",
)

// </editor-fold>

private val config get() = ChocolateFactoryAPI.config
private val hitmanRabbits = mutableListOf<HitmanRabbit>()

private var cooldownSlotIndices = emptySet<Int>()
private var slotPricesPaid: List<Long> = emptyList()
private var slotPricesLeft: List<Long> = emptyList()
private var inInventory = false

data class HitmanRabbit(
val rabbitName: String,
val claimedAt: SimpleTimeMark,
var expiresAt: SimpleTimeMark? = null,
var claimedBySlot: Boolean = false,
)

@HandleEvent
fun onRabbitFound(event: RabbitFoundEvent) {
if (event.eggType != HoppityEggType.HITMAN) return
hitmanRabbits.add(HitmanRabbit(event.rabbitName, SimpleTimeMark.now()))
}

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
hitmanRabbits.removeIf { it.expiresAt?.isInPast() == true }
}

@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
// Free all slots when the inventory is closed
hitmanRabbits.forEach { it.claimedBySlot = false }
inInventory = false
}

@HandleEvent
fun replaceItem(event: ReplaceItemEvent) {
if (!config.hitmanSlotInfo) return
if (!inInventory) return
if (!cooldownSlotIndices.contains(event.slot)) return
if (!event.inventory.isTopInventory()) return

val hitmanRabbit = hitmanRabbits.sortedBy { it.claimedAt }.firstOrNull { !it.claimedBySlot }
?: return
hitmanRabbit.claimedBySlot = true
val originalItemStack = event.originalItem
val lore = originalItemStack.getLore().toMutableList()
/**
* Lore will be formatted as follows:
* '§7§7Once you miss your next egg, your'
* '§7Rabbit Hitman will snipe it for you.'
* ''
* '§cOn cooldown: 7h 47m'
*
* We want to add "Rabbit: ..." above the cooldown line.
*/
lore.add(lore.size - 1, "§7Last Rabbit: ${hitmanRabbit.rabbitName}")

// Because the cooldown is constantly changing, we can't cache the replacement itemstack
val newItemStack = originalItemStack.copy()
newItemStack.setLore(lore)
event.replace(newItemStack)
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
inInventory = hitmanInventoryPattern.matches(event.inventoryName)
if (!inInventory) return
handleInventoryHitmanSlotRename(event)
handleSlotStorageUpdate(event)
}

Expand All @@ -126,15 +54,6 @@ object HitmanSlots {
)
}

private fun handleInventoryHitmanSlotRename(event: InventoryOpenEvent) {
if (!config.hitmanSlotInfo) return
if (hitmanRabbits.isEmpty()) return

cooldownSlotIndices = event.inventoryItems.filterValues {
it.hasDisplayName() && slotOnCooldownPattern.matches(it.displayName)
}.keys
}

private fun handleSlotStorageUpdate(event: InventoryOpenEvent) {
if (!config.hitmanCosts) return
val leftToPurchase = event.inventoryItems.filterNotBorderSlots().count { (_, item) ->
Expand Down

0 comments on commit 7e64df4

Please sign in to comment.