Improve status capability

This commit is contained in:
Matt Soucy 2019-11-24 13:58:57 -05:00
parent aff5cb573d
commit f3b25e752c
2 changed files with 21 additions and 19 deletions

View File

@ -1,11 +1,11 @@
package me.msoucy.ptures.model package me.msoucy.ptures.model
class Engine(vararg val creatures : Pair<Creature, Int>) { class Engine(private vararg val creatures : Pair<Creature, Int>) {
init { init {
assert(creatures.isNotEmpty()) assert(creatures.isNotEmpty())
} }
var currentCreature = 0 private var currentCreature = 0
val attacker : Creature get() { val attacker : Creature get() {
return creatures[currentCreature].first return creatures[currentCreature].first
@ -17,35 +17,39 @@ class Engine(vararg val creatures : Pair<Creature, Int>) {
.sortedBy { (_, c) -> c.first.spd } .sortedBy { (_, c) -> c.first.spd }
// Get the moves each creature will use this turn // Get the moves each creature will use this turn
val moves = activeCreatures.map { (_, c) -> Pair(c.first.skills[0], 0) } val moves = activeCreatures.map { (_, c) -> Pair(c.first.skills[0], 0) }
val wasHit = mutableListOf<Creature>() val wasHit = mutableListOf<Pair<Creature, Int>>()
for ((i, c) in activeCreatures) { for ((i, c) in activeCreatures) {
// Resolve move // Resolve move
val (skill, target) = moves[i] val (skill, target) = moves[i]
currentCreature = i currentCreature = i
for (step in skill.damageSteps) { for (step in skill.damageSteps) {
val targets = getTargetList(step.target, currentCreature, target) val targets = getTargetList(step.target, target)
for (t in targets) { for (t in targets) {
val (targetCreature, _) = creatures[t] val (targetCreature, _) = creatures[t]
if (attacker.hits(targetCreature, step)) { if (attacker.hits(targetCreature, step)) {
targetCreature.apply(step, c.first) 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) { for(step in skill.statusSteps) {
step(creature) 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<Int> { private fun getTargetList(target : Target, selected : Int) : List<Int> {
return when(target) { return when(target) {
Target.Self -> listOf(active) Target.Self -> listOf(currentCreature)
Target.Selected -> listOf(selected) Target.Selected -> listOf(selected)
Target.Others -> creatures.indices.filter { it != active } Target.Others -> creatures.indices.filter { it != currentCreature }
Target.Opponents -> creatures.indices.filter { creatures[it].second != creatures[active].second } Target.Opponents -> creatures.indices.filter { creatures[it].second != creatures[currentCreature].second }
Target.All -> creatures.indices.toList() Target.All -> creatures.indices.toList()
} }
} }

View File

@ -23,16 +23,14 @@ enum class Attribute {
class Damage(val power : Int) { class Damage(val power : Int) {
var target = Target.Selected var target = Target.Selected
var accuracy = 100 var accuracy = 100
infix fun hits (target : Creature) {
}
} }
class StatusApplier(val target : Target, val applier : (Creature) -> Unit)
@SkillMarker @SkillMarker
class Skill(val name : String, val attribute : Attribute) { class Skill(val name : String, val attribute : Attribute) {
val damageSteps = mutableListOf<Damage>() val damageSteps = mutableListOf<Damage>()
val statusSteps = mutableListOf<(Creature) -> Unit>() val statusSteps = mutableListOf<StatusApplier>()
fun damage(power : Int, block : Damage.() -> Unit = {}) { fun damage(power : Int, block : Damage.() -> Unit = {}) {
val d = Damage(power) val d = Damage(power)
@ -41,11 +39,11 @@ class Skill(val name : String, val attribute : Attribute) {
} }
fun addStatus(status : Status, target : Target = Target.Selected) { 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) { fun removeStatus(status : Status, target : Target = Target.Selected) {
statusSteps.add { c -> c.removeStatus(status) } statusSteps.add (StatusApplier(target) { c -> c.removeStatus(status) })
} }
} }