package me.msoucy.ptures.model

@DslMarker
annotation class SkillMarker

enum class Target {
    Selected,
    Self,
    Others,
    Opponents,
    All
}

enum class Attribute {
    Neutral,
    Stone,
    Fire,
    Water,
    Air,
    Wood
}

class Damage(val power : Int) {
    var target = Target.Selected
    var accuracy = 100
}

class StatusApplier(val target : Target, val applier : (Creature) -> Unit)

@SkillMarker
class Skill(val name : String, val attribute : Attribute) {
    val damageSteps = mutableListOf<Damage>()
    val statusSteps = mutableListOf<StatusApplier>()

    fun damage(power : Int, block : Damage.() -> Unit = {}) {
        val d = Damage(power)
        d.block()
        damageSteps.add(d)
    }

    fun addStatus(status : Status, target : Target = Target.Selected) {
        statusSteps.add (StatusApplier(target) { c -> c.addStatus(status) })
    }

    fun removeStatus(status : Status, target : Target = Target.Selected) {
        statusSteps.add (StatusApplier(target) { c -> c.removeStatus(status) })
    }
}

fun skill(name : String, attribute : Attribute = Attribute.Neutral, block : Skill.() -> Unit) : Skill {
    val ret = Skill(name, attribute)
    ret.block()
    return ret
}

val Ignore = skill("Ignore") {
}

val Tackle = skill("Tackle") {
    damage(20)
}

val DoubleKick = skill("Double Kick") {
    repeat(2) {
        damage(35) {
            accuracy = 85
        }
    }
}

val DoubleEdge = skill("Double Edge") {
    damage(20)
    damage(10) {
        target = Target.Self
    }
}

val Fly = skill("Fly") {
    addStatus(Flying(), Target.Self)
}