Verified Commit 6d8e162d authored by Lars Mitsem Selbekk's avatar Lars Mitsem Selbekk
Browse files

Enforce cooldown on Spells

Closes #68
parent bab3564b
......@@ -148,6 +148,9 @@ class BattleController(
if (battle.yourTurn) {
turnStartMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime())
turnCounterSeconds = 0
battle.hero1.spell.decreaseCooldown()
} else {
battle.hero2.spell.decreaseCooldown()
}
}
......
......@@ -10,7 +10,7 @@ class AdrenalineShotSpell : Spell<SpellData.AdrenalineShot>(
// the (presumably) only action point
6
) {
override fun cast(
override fun castImplementation(
caster: Hero,
data: SpellData.AdrenalineShot
): ActiveSpell<AdrenalineShotSpell> {
......
......@@ -12,7 +12,10 @@ class Bird52Spell : Spell<SpellData.Bird52>(
val numColumnsToAttack = 2
val attackDamage = 30
override fun cast(caster: Hero, data: SpellData.Bird52): ActiveSpell<Bird52Spell> {
override fun castImplementation(
caster: Hero,
data: SpellData.Bird52
): ActiveSpell<Bird52Spell> {
return Bird52ActiveSpell(this, caster, data)
}
}
......@@ -10,7 +10,7 @@ class EphemeralAllegianceSpell : Spell<SpellData.EphemeralAllegiance>(
// turn when casting uses the (presumably) only action point
5
) {
override fun cast(
override fun castImplementation(
caster: Hero,
data: SpellData.EphemeralAllegiance
): ActiveSpell<EphemeralAllegianceSpell> {
......
package se.battlegoo.battlegoose.models.spells
import com.badlogic.gdx.utils.Logger
import se.battlegoo.battlegoose.Game
import se.battlegoo.battlegoose.datamodels.SpellData
import se.battlegoo.battlegoose.models.heroes.Hero
import java.lang.IllegalStateException
import java.lang.Integer.max
abstract class Spell<T : SpellData>(
val title: String,
......@@ -9,5 +13,21 @@ abstract class Spell<T : SpellData>(
val duration: Int,
val cooldown: Int
) {
abstract fun cast(caster: Hero, data: T): ActiveSpell<out Spell<T>>
var remainingCooldown: Int = 0
private set
fun decreaseCooldown() {
remainingCooldown = max(0, remainingCooldown - 1)
Logger(Game.LOGGER_TAG, Logger.INFO).info("Cooldown now $remainingCooldown")
}
fun cast(caster: Hero, data: T): ActiveSpell<out Spell<T>> {
if (remainingCooldown > 0) {
throw IllegalStateException("Remaining cooldown on $data for $caster, cannot cast")
}
remainingCooldown = cooldown
return castImplementation(caster, data)
}
abstract fun castImplementation(caster: Hero, data: T): ActiveSpell<out Spell<T>>
}
......@@ -297,7 +297,10 @@ class SpellTest {
val testDuration = 5
class TestSpell : Spell<SpellData.Bird52>("test", "t2", testDuration, 2) {
override fun cast(caster: Hero, data: SpellData.Bird52): ActiveSpell<TestSpell> {
override fun castImplementation(
caster: Hero,
data: SpellData.Bird52
): ActiveSpell<TestSpell> {
return object : ActiveSpell<TestSpell>(this, hero1, data) {
override fun applyImplementation(battle: Battle, turnsSinceCast: Int) {
counter += 1
......
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