diff --git a/core/src/me/msoucy/ptures/model/Creature.kt b/core/src/me/msoucy/ptures/model/Creature.kt index ba90dbf..093aa1b 100644 --- a/core/src/me/msoucy/ptures/model/Creature.kt +++ b/core/src/me/msoucy/ptures/model/Creature.kt @@ -58,7 +58,7 @@ class Creature { fun hits(creature : Creature, damage : Damage) = random(100) < damage.accuracy + spd - creature.spd - inline fun hasStatus() = statuses.filter { it is S }.isNotEmpty() + inline fun hasStatus() = statuses.filterIsInstance().isNotEmpty() private fun statFormula(gene : Int, growth : Int) = (2 * gene + growth / 4) * level / 100 + 5 } \ No newline at end of file diff --git a/core/src/me/msoucy/ptures/model/Engine.kt b/core/src/me/msoucy/ptures/model/Engine.kt index 5cd5d68..496ed28 100644 --- a/core/src/me/msoucy/ptures/model/Engine.kt +++ b/core/src/me/msoucy/ptures/model/Engine.kt @@ -11,13 +11,22 @@ class Engine(private vararg val creatures : Pair) { return creatures[currentCreature].first } + val activeCreatures get() = creatures.withIndex() + .filter { (_, c) -> !c.first.hasStatus() } + .sortedBy { (_, c) -> c.first.spd } + .map { (i, _) -> i} + fun resolveTurn() { - val activeCreatures = creatures.withIndex() - .filter { (_, c) -> !c.first.hasStatus() } - .sortedBy { (_, c) -> c.first.spd } + // All preconditions + for (i in activeCreatures) { + val creature = creatures[i] + for (status in creature.first.statuses) { + status.onTurnStart(this) + } + } // Get the moves each creature will use this turn - val moves = activeCreatures.map { (_, _) -> Pair(Ignore, 0) } - for ((i, c) in activeCreatures) { + val moves = activeCreatures.map { i -> Pair(Ignore, nextOpponent(i)) } + for (i in activeCreatures) { // Resolve move val (skill, target) = moves[i] currentCreature = i @@ -37,6 +46,13 @@ class Engine(private vararg val creatures : Pair) { } } } + // All post conditions + for (i in activeCreatures) { + val creature = creatures[i] + for (status in creature.first.statuses) { + status.onTurnEnd(this) + } + } } private fun getTargetList(target : Target, selected : Int) : List { @@ -48,4 +64,16 @@ class Engine(private vararg val creatures : Pair) { Target.All -> creatures.indices.toList() } } + + private fun nextOpponent(idx : Int) : Int { + var nextIdx = idx + 1 + while (nextIdx != idx) { + if (creatures[nextIdx].second != creatures[idx].second) { + return nextIdx + } + nextIdx = (nextIdx + 1) % creatures.size + } + // There are no opponents... so use the "none" index + return -1 + } } \ No newline at end of file