diff --git a/core/src/me/msoucy/ptures/model/Creature.kt b/core/src/me/msoucy/ptures/model/Creature.kt index 3fb5bbb..ba90dbf 100644 --- a/core/src/me/msoucy/ptures/model/Creature.kt +++ b/core/src/me/msoucy/ptures/model/Creature.kt @@ -7,8 +7,8 @@ class Stats(var atk : Int, var def : Int, var spd : Int, var hp : Int) class Creature { val genes = Stats(5,5,5,5) - val growth = Stats(5,5,5,5) - val attributes = mutableMapOf() + val growth = Stats(0,0,0,0) + val attributes = mutableMapOf() var level = 1 var currentHp = 1 val skills = mutableListOf() @@ -22,15 +22,19 @@ class Creature { fun apply(dmg : Damage, attacker : Creature) { val critical = if (random(32) < attacker.genes.spd) { 1.5 } else { 1.0 } val randVal = random(0.85f, 1.0f) - val effectiveness = 1.0 + val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f} + val defAttribute = attributes.getOrElse(dmg.attribute) {1.0f} + val effectiveness = atkAttribute / defAttribute val modifier = critical * randVal * effectiveness val power = (((0.4 * attacker.level) + 2) * dmg.power * (attacker.atk / def)) / 50 + 2 - val total : Int = (power * modifier).toInt() + val total = (power * modifier).toInt() currentHp = clamp(currentHp - total, 0, maxHp) if(currentHp == 0) { statuses.clear() addStatus(KnockedOut) + } else { + dmg.applyStatus(this) } } @@ -56,5 +60,5 @@ class Creature { inline fun hasStatus() = statuses.filter { it is S }.isNotEmpty() - private fun statFormula(gene : Int, growth : Int) = (2 * gene + growth) * level / 100 + 5 + 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 be4264a..5cd5d68 100644 --- a/core/src/me/msoucy/ptures/model/Engine.kt +++ b/core/src/me/msoucy/ptures/model/Engine.kt @@ -16,29 +16,24 @@ class Engine(private vararg val creatures : Pair) { .filter { (_, c) -> !c.first.hasStatus() } .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 moves = activeCreatures.map { (_, _) -> Pair(Ignore, 0) } for ((i, c) in activeCreatures) { // Resolve move val (skill, target) = moves[i] currentCreature = i for (step in skill.damageSteps) { - val targets = getTargetList(step.target, target) - for (t in targets) { + for (t in getTargetList(step.target, target)) { val (targetCreature, _) = creatures[t] if (attacker.hits(targetCreature, step)) { - targetCreature.apply(step, c.first) - if (wasHit.any { it.first == targetCreature }) { - wasHit.add(Pair(targetCreature, t)) - } + targetCreature.apply(step, attacker) + step.applyStatus(targetCreature) } } } - for(step in skill.statusSteps) { - for ((targetCreature, t) in wasHit) { - if (t in getTargetList(step.target, t)) { - step.applier(targetCreature) - } + for(step in skill.postSteps) { + for (t in getTargetList(step.target, target)) { + val (targetCreature, _) = creatures[t] + step.apply(targetCreature) } } } diff --git a/core/src/me/msoucy/ptures/model/Skills.kt b/core/src/me/msoucy/ptures/model/Skills.kt index 09dc594..dfda39f 100644 --- a/core/src/me/msoucy/ptures/model/Skills.kt +++ b/core/src/me/msoucy/ptures/model/Skills.kt @@ -1,5 +1,7 @@ package me.msoucy.ptures.model +import com.badlogic.gdx.math.MathUtils.random + @DslMarker annotation class SkillMarker @@ -20,30 +22,40 @@ enum class Attribute { Wood } -class Damage(val power : Int) { +class Damage(val power : Int, val attribute : Attribute = Attribute.Neutral) { var target = Target.Selected var accuracy = 100 + + var status : () -> Status? = {null} + var statusChance = 0 + + fun applyStatus(creature : Creature) { + val appStatus = status() + if (appStatus != null && random(100) < statusChance) { + creature.addStatus(appStatus) + } + } } -class StatusApplier(val target : Target, val applier : (Creature) -> Unit) +class StatusApplier(val target : Target, val apply : (Creature) -> Unit) @SkillMarker class Skill(val name : String, val attribute : Attribute) { val damageSteps = mutableListOf() - val statusSteps = mutableListOf() + val postSteps = mutableListOf() fun damage(power : Int, block : Damage.() -> Unit = {}) { - val d = Damage(power) + val d = Damage(power, attribute) d.block() damageSteps.add(d) } fun addStatus(status : Status, target : Target = Target.Selected) { - statusSteps.add (StatusApplier(target) { c -> c.addStatus(status) }) + postSteps.add (StatusApplier(target) { c -> c.addStatus(status) }) } fun removeStatus(status : Status, target : Target = Target.Selected) { - statusSteps.add (StatusApplier(target) { c -> c.removeStatus(status) }) + postSteps.add (StatusApplier(target) { c -> c.removeStatus(status) }) } } @@ -69,12 +81,19 @@ val DoubleKick = skill("Double Kick") { } val DoubleEdge = skill("Double Edge") { - damage(20) - damage(10) { + damage(80) + damage(15) { target = Target.Self } } val Fly = skill("Fly") { addStatus(Flying(), Target.Self) +} + +val Ember = skill("Ember", Attribute.Fire) { + damage(40) { + status = {Burned} + statusChance = 10 + } } \ No newline at end of file diff --git a/core/src/me/msoucy/ptures/model/Status.kt b/core/src/me/msoucy/ptures/model/Status.kt index 74ff7cb..68cc61c 100644 --- a/core/src/me/msoucy/ptures/model/Status.kt +++ b/core/src/me/msoucy/ptures/model/Status.kt @@ -17,7 +17,7 @@ sealed class Status { sealed class VisibleStatus(val label : String = "") : Status() -sealed class CountdownStatus(var turns : Int) : Status() +sealed class CountdownStatus(private var turns : Int) : Status() { override fun onTurnEnd(engine : Engine) { turns--