Commit 7a2b1421 authored by Mathias O. Myklebust's avatar Mathias O. Myklebust 🦆
Browse files

Merge branch 'i68/spell-cooldown' into 'master'

Enforce cooldown on Spells

Closes #68

See merge request !56
parents bab3564b dad1579f
Pipeline #175815 passed with stages
in 16 minutes and 39 seconds
......@@ -148,6 +148,11 @@ class BattleController(
if (battle.yourTurn) {
turnStartMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime())
turnCounterSeconds = 0
battle.hero1.spell.decreaseCooldown()
view.spellCooldownRemaining = battle.hero1.spell.remainingCooldown
} else {
battle.hero2.spell.decreaseCooldown()
view.spellCooldownRemaining = battle.hero2.spell.remainingCooldown
}
}
......
......@@ -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>>
}
......@@ -141,6 +141,8 @@ class BattleView(
field = yourTurn
}
var spellCooldownRemaining: Int = 0
init {
backgroundSprite.setPosition(position.x, position.y)
backgroundSprite.setSize(infoBackgroundWidth, infoBackgroundHeight)
......@@ -151,18 +153,32 @@ class BattleView(
}
private fun newSpellModal(): Modal {
return Modal(
hero.spell.title,
"${hero.spell.description}\nCooldown: ${hero.spell.cooldown}",
// TODO: Fix auto linebreak
ModalType.Question(
onYes = { observer?.onCastSpell() }
),
stage,
contentActors = listOf(textTable),
prefHeight = PREF_MODAL_HEIGHT,
prefWidth = PREF_MODAL_WIDTH
)
return if (spellCooldownRemaining <= 0) {
Modal(
hero.spell.title,
"${hero.spell.description}\nCooldown: ${hero.spell.cooldown}",
// TODO: Fix auto linebreak
ModalType.Question(
onYes = { observer?.onCastSpell() }
),
stage,
contentActors = listOf(textTable),
prefHeight = PREF_MODAL_HEIGHT,
prefWidth = PREF_MODAL_WIDTH
)
} else {
Modal(
hero.spell.title,
"${hero.spell.description}\nCooldown: ${hero.spell.cooldown}\n" +
"Cooldown remaining: $spellCooldownRemaining",
// TODO: Fix auto linebreak
ModalType.Info(),
stage,
contentActors = listOf(textTable),
prefHeight = PREF_MODAL_HEIGHT,
prefWidth = PREF_MODAL_WIDTH
)
}
}
private fun newSurrenderModal(): Modal {
......
......@@ -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