Skip to content
Snippets Groups Projects
Verified Commit f0715abc authored by Lars Mitsem Selbekk's avatar Lars Mitsem Selbekk Committed by Mathias O. Myklebust
Browse files

Apply spells immediately on cast

This fixes a crash when BattleController would pick a unit to target
using EphemeralAllegiance, and then that unit would move before the
spell was applied.

AdrenalineShot was correspondingly changed to apply on turnsSinceCast
= 1, and extended with 1 turn duration, to keep the past behavior.
EphemeralAllegiance was also extended with 1 duration because it's not
much help the first turn, since the caster presumably has used their
action points.

Closes #64
parent 64e9e0d6
No related branches found
No related tags found
1 merge request!55Various spellcasting fixes
......@@ -257,7 +257,8 @@ class BattleController(
spell.cast(battle.hero2, spellData)
}
}
battle.activeSpells.second.add(activeSpell)
battle.activeSpells.second += activeSpell
activeSpell.apply(battle)
}
private fun doAction(action: ActionData) {
......@@ -305,6 +306,7 @@ class BattleController(
)
}
battle.activeSpells.first += activeSpell
activeSpell.apply(battle)
doAction(ActionData.CastSpell(playerID, spellData))
}
}
......
......@@ -12,6 +12,7 @@ class AdrenalineShotActiveSpell(
) : ActiveSpell<AdrenalineShotSpell>(baseSpell, caster, data) {
override fun applyImplementation(battle: Battle, turnsSinceCast: Int) {
if (turnsSinceCast > 0) {
caster.applyStatsModifier(
HeroStatsModifier {
it.copy(actionPoints = it.actionPoints + 1)
......@@ -19,3 +20,4 @@ class AdrenalineShotActiveSpell(
)
}
}
}
......@@ -6,7 +6,7 @@ import se.battlegoo.battlegoose.models.heroes.Hero
class AdrenalineShotSpell : Spell<SpellData.AdrenalineShot>(
"Adrenaline Shot",
"Get an extra action point every turn for the following 3 turns.",
3,
4,
6
) {
override fun cast(
......
......@@ -6,7 +6,8 @@ import se.battlegoo.battlegoose.models.heroes.Hero
class EphemeralAllegianceSpell : Spell<SpellData.EphemeralAllegiance>(
"Ephemeral Allegiance",
"Convert 1 random unit from the opponent to control for 3 turns.",
4, // Needs an extra (3+1) for cleanup
5, // Needs an extra (1+3+1) for cleanup, and one because the spell isn't helpful the first
// turn when casting uses the (presumably) only action point
5
) {
override fun cast(
......
......@@ -50,7 +50,12 @@ class SpellTest {
1,
hero.currentStats.actionPoints
)
for (i in 1..spell.baseSpell.duration) {
spell.apply(battle)
assertEquals(
"Should have no effect on first application", 1,
hero.currentStats.actionPoints
)
for (i in 2..spell.baseSpell.duration) {
spell.apply(battle)
assertEquals(
"Wrong number of action points after $i applications", 2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment