From 078d76e05b330c0511200b22487961246c6ded8a Mon Sep 17 00:00:00 2001 From: scarf Date: Wed, 9 Oct 2024 18:00:54 +0900 Subject: [PATCH] fix: meteoric shower not exhausting and properly damaging (#258) * refactor: revamp exhaust and partitionByType original function made no sense * fix: properly multiply damge and exhaust burns and cards --- src/main/kotlin/marisa/Iterable.kt | 15 +++++++++++ src/main/kotlin/marisa/Utils.kt | 27 ++++--------------- .../marisa/action/MeteoricShowerAction.kt | 16 ++++++----- 3 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 src/main/kotlin/marisa/Iterable.kt diff --git a/src/main/kotlin/marisa/Iterable.kt b/src/main/kotlin/marisa/Iterable.kt new file mode 100644 index 0000000..76cb570 --- /dev/null +++ b/src/main/kotlin/marisa/Iterable.kt @@ -0,0 +1,15 @@ +package util + +/** + * Partition the [Iterable] into two lists, one containing all elements and the other containing all elements of the given type. + * Type param [X] must be more specific than [Y]. + */ +inline fun Iterable.partitionByType(): Pair, List> { + val xs = ArrayList() + val ys = ArrayList() + for (element in this) { + if (element is X) xs.add(element) + else ys.add(element) + } + return Pair(xs, ys) +} diff --git a/src/main/kotlin/marisa/Utils.kt b/src/main/kotlin/marisa/Utils.kt index 5ce0406..89e6405 100644 --- a/src/main/kotlin/marisa/Utils.kt +++ b/src/main/kotlin/marisa/Utils.kt @@ -1,7 +1,7 @@ package marisa import com.megacrit.cardcrawl.cards.AbstractCard -import com.megacrit.cardcrawl.cards.status.Burn +import util.partitionByType fun countRelic(id: String): Int { if (!p.hasRelic(id)) { @@ -12,27 +12,10 @@ fun countRelic(id: String): Int { return 1 } -inline fun Iterable.partitionByType(): Pair, List> { - val first = ArrayList() - val second = ArrayList() - for (element in this) { - if (element is U) second.add(element) - else first.add(element) - } - return Pair(first, second) -} - -/** - * Exhaust all [Burn] cards in the [Iterable] and return the number of [Burn] cards exhausted. - */ -fun Iterable.exhaustBurns() = onEach { p.hand.moveToExhaustPile(it) } +fun AbstractCard.exhaust() = this.also { p.hand.moveToExhaustPile(it) } /** - * Partition the [Iterable] into two lists, one containing all [AbstractCard]s and the other containing all [Burn]s. - * Burns are automatically exhausted. + * Partition the [Iterable] into two lists, one containing all [AbstractCard]s and the other containing all given types. */ -fun Iterable.withCardsBurned(): Pair, List> { - val (regular, burns) = this.partitionByType() - burns.exhaustBurns() - return Pair(regular, burns) -} +inline fun Iterable.partitionByType(): Pair, List> = + partitionByType() diff --git a/src/main/kotlin/marisa/action/MeteoricShowerAction.kt b/src/main/kotlin/marisa/action/MeteoricShowerAction.kt index 57d17c1..4a2f209 100644 --- a/src/main/kotlin/marisa/action/MeteoricShowerAction.kt +++ b/src/main/kotlin/marisa/action/MeteoricShowerAction.kt @@ -1,15 +1,17 @@ package marisa.action import com.megacrit.cardcrawl.actions.AbstractGameAction +import com.megacrit.cardcrawl.cards.status.Burn import com.megacrit.cardcrawl.core.CardCrawlGame import com.megacrit.cardcrawl.core.Settings import com.megacrit.cardcrawl.dungeons.AbstractDungeon import com.megacrit.cardcrawl.relics.ChemicalX import com.megacrit.cardcrawl.ui.panels.EnergyPanel import marisa.countRelic +import marisa.exhaust import marisa.fx.MeteoricShowerEffect import marisa.p -import marisa.withCardsBurned +import marisa.partitionByType class MeteoricShowerAction(val energyOnUse: Int, val dmg: Int, val freeToPlay: Boolean) : AbstractGameAction() { @@ -31,11 +33,14 @@ class MeteoricShowerAction(val energyOnUse: Int, val dmg: Int, val freeToPlay: B return } if (!AbstractDungeon.handCardSelectScreen.wereCardsRetrieved) { - val (regular, burns) = AbstractDungeon.handCardSelectScreen.selectedCards.group.withCardsBurned() - val cnt = regular.size * 3 + burns.size * 2 + val cards = AbstractDungeon.handCardSelectScreen.selectedCards.group + val (burns, regular) = cards.partitionByType() + val cnt = regular.size * 2 + burns.size * 3 AbstractDungeon.handCardSelectScreen.wereCardsRetrieved = true - AbstractDungeon.handCardSelectScreen.selectedCards.group.clear() + cards.forEach { it.exhaust() } + cards.clear() + addToBot(MeteoricShowerEffect.toVfx(cnt)) addToBot(RandomDamageAction(cnt) { dmg }) AbstractDungeon.gridSelectScreen.selectedCards.clear() @@ -48,8 +53,7 @@ class MeteoricShowerAction(val energyOnUse: Int, val dmg: Int, val freeToPlay: B } companion object { - private val uiStrings = CardCrawlGame.languagePack - .getUIString("ExhaustAction") + private val uiStrings = CardCrawlGame.languagePack.getUIString("ExhaustAction") val TEXT = uiStrings.TEXT } }