Clean up attaching status effects to damage
This commit is contained in:
parent
f3b25e752c
commit
a51a6485ef
@ -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<Attribute, Int>()
|
||||
val growth = Stats(0,0,0,0)
|
||||
val attributes = mutableMapOf<Attribute, Float>()
|
||||
var level = 1
|
||||
var currentHp = 1
|
||||
val skills = mutableListOf<Skill>()
|
||||
@ -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 <reified S : Status> 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
|
||||
}
|
@ -16,29 +16,24 @@ class Engine(private vararg val creatures : Pair<Creature, Int>) {
|
||||
.filter { (_, c) -> !c.first.hasStatus<KnockedOut>() }
|
||||
.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<Pair<Creature, Int>>()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Damage>()
|
||||
val statusSteps = mutableListOf<StatusApplier>()
|
||||
val postSteps = mutableListOf<StatusApplier>()
|
||||
|
||||
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,8 +81,8 @@ val DoubleKick = skill("Double Kick") {
|
||||
}
|
||||
|
||||
val DoubleEdge = skill("Double Edge") {
|
||||
damage(20)
|
||||
damage(10) {
|
||||
damage(80)
|
||||
damage(15) {
|
||||
target = Target.Self
|
||||
}
|
||||
}
|
||||
@ -78,3 +90,10 @@ val DoubleEdge = skill("Double Edge") {
|
||||
val Fly = skill("Fly") {
|
||||
addStatus(Flying(), Target.Self)
|
||||
}
|
||||
|
||||
val Ember = skill("Ember", Attribute.Fire) {
|
||||
damage(40) {
|
||||
status = {Burned}
|
||||
statusChance = 10
|
||||
}
|
||||
}
|
@ -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--
|
||||
|
Loading…
Reference in New Issue
Block a user