Skip to content

Commit

Permalink
fix: logic error on damage calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Jul 13, 2024
1 parent 7a20380 commit aa8f20a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
28 changes: 24 additions & 4 deletions src/main/kotlin/marisa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,27 @@ fun countRelic(id: String): Int {
return 1
}

fun Iterable<AbstractCard>.exhaustBurns(): Int =
this.filterIsInstance<Burn>()
.apply { forEach { p.hand.moveToExhaustPile(it) } }
.size
inline fun <T, reified U : T> Iterable<T>.partitionByType(): Pair<List<T>, List<U>> {
val first = ArrayList<T>()
val second = ArrayList<U>()
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<Burn>.exhaustBurns() = onEach { 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.
*/
fun Iterable<AbstractCard>.withCardsBurned(): Pair<List<AbstractCard>, List<Burn>> {
val (regular, burns) = this.partitionByType<AbstractCard, Burn>()
burns.exhaustBurns()
return Pair(regular, burns)
}
8 changes: 4 additions & 4 deletions src/main/kotlin/marisa/action/MeteoricShowerAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import com.megacrit.cardcrawl.dungeons.AbstractDungeon
import com.megacrit.cardcrawl.relics.ChemicalX
import com.megacrit.cardcrawl.ui.panels.EnergyPanel
import marisa.countRelic
import marisa.exhaustBurns
import marisa.fx.MeteoricShowerEffect
import marisa.p

import marisa.withCardsBurned

class MeteoricShowerAction(val energyOnUse: Int, val dmg: Int, val freeToPlay: Boolean) :
AbstractGameAction() {
Expand All @@ -32,8 +31,9 @@ class MeteoricShowerAction(val energyOnUse: Int, val dmg: Int, val freeToPlay: B
return
}
if (!AbstractDungeon.handCardSelectScreen.wereCardsRetrieved) {
val cnt =
2 * AbstractDungeon.handCardSelectScreen.selectedCards.group.exhaustBurns()
val (regular, burns) = AbstractDungeon.handCardSelectScreen.selectedCards.group.withCardsBurned()
val cnt = regular.size * 3 + burns.size * 2

AbstractDungeon.handCardSelectScreen.wereCardsRetrieved = true
AbstractDungeon.handCardSelectScreen.selectedCards.group.clear()
addToBot(MeteoricShowerEffect.toVfx(cnt))
Expand Down

0 comments on commit aa8f20a

Please sign in to comment.