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
......@@ -100,7 +100,7 @@ class BattleController(
if (Gdx.input.justTouched()) {
val touchPoint = Game.unproject(Gdx.input.x.toFloat(), Gdx.input.y.toFloat())
if (Rectangle(view.position.x, view.position.y, view.size.x, view.size.y)
.contains(touchPoint)
.contains(touchPoint)
) {
onCastSpell()
view.position = ScreenVector(view.position.x, view.position.y + view.size.y)
......@@ -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,10 +12,12 @@ class AdrenalineShotActiveSpell(
) : ActiveSpell<AdrenalineShotSpell>(baseSpell, caster, data) {
override fun applyImplementation(battle: Battle, turnsSinceCast: Int) {
caster.applyStatsModifier(
HeroStatsModifier {
it.copy(actionPoints = it.actionPoints + 1)
}
)
if (turnsSinceCast > 0) {
caster.applyStatsModifier(
HeroStatsModifier {
it.copy(actionPoints = it.actionPoints + 1)
}
)
}
}
}
......@@ -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,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment