diff --git a/core/src/me/msoucy/ptures/model/Engine.kt b/core/src/me/msoucy/ptures/model/Engine.kt index 0535aad..be4264a 100644 --- a/core/src/me/msoucy/ptures/model/Engine.kt +++ b/core/src/me/msoucy/ptures/model/Engine.kt @@ -1,11 +1,11 @@ package me.msoucy.ptures.model -class Engine(vararg val creatures : Pair) { +class Engine(private vararg val creatures : Pair) { init { assert(creatures.isNotEmpty()) } - var currentCreature = 0 + private var currentCreature = 0 val attacker : Creature get() { return creatures[currentCreature].first @@ -17,35 +17,39 @@ class Engine(vararg val creatures : Pair) { .sortedBy { (_, c) -> c.first.spd } // Get the moves each creature will use this turn val moves = activeCreatures.map { (_, c) -> Pair(c.first.skills[0], 0) } - val wasHit = mutableListOf() + val wasHit = mutableListOf>() for ((i, c) in activeCreatures) { // Resolve move val (skill, target) = moves[i] currentCreature = i for (step in skill.damageSteps) { - val targets = getTargetList(step.target, currentCreature, target) + val targets = getTargetList(step.target, target) for (t in targets) { val (targetCreature, _) = creatures[t] if (attacker.hits(targetCreature, step)) { targetCreature.apply(step, c.first) - wasHit.add(targetCreature) + if (wasHit.any { it.first == targetCreature }) { + wasHit.add(Pair(targetCreature, t)) + } } } } - for(creature in wasHit) { - for(step in skill.statusSteps) { - step(creature) + for(step in skill.statusSteps) { + for ((targetCreature, t) in wasHit) { + if (t in getTargetList(step.target, t)) { + step.applier(targetCreature) + } } } } } - private fun getTargetList(target : Target, active : Int, selected : Int) : List { + private fun getTargetList(target : Target, selected : Int) : List { return when(target) { - Target.Self -> listOf(active) + Target.Self -> listOf(currentCreature) Target.Selected -> listOf(selected) - Target.Others -> creatures.indices.filter { it != active } - Target.Opponents -> creatures.indices.filter { creatures[it].second != creatures[active].second } + Target.Others -> creatures.indices.filter { it != currentCreature } + Target.Opponents -> creatures.indices.filter { creatures[it].second != creatures[currentCreature].second } Target.All -> creatures.indices.toList() } } diff --git a/core/src/me/msoucy/ptures/model/Skills.kt b/core/src/me/msoucy/ptures/model/Skills.kt index 5e8311e..09dc594 100644 --- a/core/src/me/msoucy/ptures/model/Skills.kt +++ b/core/src/me/msoucy/ptures/model/Skills.kt @@ -23,16 +23,14 @@ enum class Attribute { class Damage(val power : Int) { var target = Target.Selected var accuracy = 100 - - infix fun hits (target : Creature) { - - } } +class StatusApplier(val target : Target, val applier : (Creature) -> Unit) + @SkillMarker class Skill(val name : String, val attribute : Attribute) { val damageSteps = mutableListOf() - val statusSteps = mutableListOf<(Creature) -> Unit>() + val statusSteps = mutableListOf() fun damage(power : Int, block : Damage.() -> Unit = {}) { val d = Damage(power) @@ -41,11 +39,11 @@ class Skill(val name : String, val attribute : Attribute) { } fun addStatus(status : Status, target : Target = Target.Selected) { - statusSteps.add { c -> c.addStatus(status) } + statusSteps.add (StatusApplier(target) { c -> c.addStatus(status) }) } fun removeStatus(status : Status, target : Target = Target.Selected) { - statusSteps.add { c -> c.removeStatus(status) } + statusSteps.add (StatusApplier(target) { c -> c.removeStatus(status) }) } }