Skip to content

Commit

Permalink
fix: meteoric shower not exhausting and properly damaging (#258)
Browse files Browse the repository at this point in the history
* refactor: revamp exhaust and partitionByType

original function made no sense

* fix: properly multiply damge and exhaust burns and cards
  • Loading branch information
scarf005 committed Oct 9, 2024
1 parent 7de5d81 commit 078d76e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/main/kotlin/marisa/Iterable.kt
Original file line number Diff line number Diff line change
@@ -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 <reified X : Y, Y> Iterable<Y>.partitionByType(): Pair<List<X>, List<Y>> {
val xs = ArrayList<X>()
val ys = ArrayList<Y>()
for (element in this) {
if (element is X) xs.add(element)
else ys.add(element)
}
return Pair(xs, ys)
}
27 changes: 5 additions & 22 deletions src/main/kotlin/marisa/Utils.kt
Original file line number Diff line number Diff line change
@@ -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)) {
Expand All @@ -12,27 +12,10 @@ fun countRelic(id: String): Int {
return 1
}

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) }
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<AbstractCard>.withCardsBurned(): Pair<List<AbstractCard>, List<Burn>> {
val (regular, burns) = this.partitionByType<AbstractCard, Burn>()
burns.exhaustBurns()
return Pair(regular, burns)
}
inline fun <reified T : AbstractCard> Iterable<AbstractCard>.partitionByType(): Pair<List<T>, List<AbstractCard>> =
partitionByType<T, AbstractCard>()
16 changes: 10 additions & 6 deletions src/main/kotlin/marisa/action/MeteoricShowerAction.kt
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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<Burn>()
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()
Expand All @@ -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
}
}

0 comments on commit 078d76e

Please sign in to comment.