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 {
|
class Creature {
|
||||||
val genes = Stats(5,5,5,5)
|
val genes = Stats(5,5,5,5)
|
||||||
val growth = Stats(5,5,5,5)
|
val growth = Stats(0,0,0,0)
|
||||||
val attributes = mutableMapOf<Attribute, Int>()
|
val attributes = mutableMapOf<Attribute, Float>()
|
||||||
var level = 1
|
var level = 1
|
||||||
var currentHp = 1
|
var currentHp = 1
|
||||||
val skills = mutableListOf<Skill>()
|
val skills = mutableListOf<Skill>()
|
||||||
@ -22,15 +22,19 @@ class Creature {
|
|||||||
fun apply(dmg : Damage, attacker : Creature) {
|
fun apply(dmg : Damage, attacker : Creature) {
|
||||||
val critical = if (random(32) < attacker.genes.spd) { 1.5 } else { 1.0 }
|
val critical = if (random(32) < attacker.genes.spd) { 1.5 } else { 1.0 }
|
||||||
val randVal = random(0.85f, 1.0f)
|
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 modifier = critical * randVal * effectiveness
|
||||||
val power = (((0.4 * attacker.level) + 2) * dmg.power * (attacker.atk / def)) / 50 + 2
|
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)
|
currentHp = clamp(currentHp - total, 0, maxHp)
|
||||||
|
|
||||||
if(currentHp == 0) {
|
if(currentHp == 0) {
|
||||||
statuses.clear()
|
statuses.clear()
|
||||||
addStatus(KnockedOut)
|
addStatus(KnockedOut)
|
||||||
|
} else {
|
||||||
|
dmg.applyStatus(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,5 +60,5 @@ class Creature {
|
|||||||
|
|
||||||
inline fun <reified S : Status> hasStatus() = statuses.filter { it is S }.isNotEmpty()
|
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>() }
|
.filter { (_, c) -> !c.first.hasStatus<KnockedOut>() }
|
||||||
.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 { (_, _) -> Pair(Ignore, 0) }
|
||||||
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, target)
|
for (t in getTargetList(step.target, target)) {
|
||||||
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, attacker)
|
||||||
if (wasHit.any { it.first == targetCreature }) {
|
step.applyStatus(targetCreature)
|
||||||
wasHit.add(Pair(targetCreature, t))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(step in skill.statusSteps) {
|
for(step in skill.postSteps) {
|
||||||
for ((targetCreature, t) in wasHit) {
|
for (t in getTargetList(step.target, target)) {
|
||||||
if (t in getTargetList(step.target, t)) {
|
val (targetCreature, _) = creatures[t]
|
||||||
step.applier(targetCreature)
|
step.apply(targetCreature)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package me.msoucy.ptures.model
|
package me.msoucy.ptures.model
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.MathUtils.random
|
||||||
|
|
||||||
@DslMarker
|
@DslMarker
|
||||||
annotation class SkillMarker
|
annotation class SkillMarker
|
||||||
|
|
||||||
@ -20,30 +22,40 @@ enum class Attribute {
|
|||||||
Wood
|
Wood
|
||||||
}
|
}
|
||||||
|
|
||||||
class Damage(val power : Int) {
|
class Damage(val power : Int, val attribute : Attribute = Attribute.Neutral) {
|
||||||
var target = Target.Selected
|
var target = Target.Selected
|
||||||
var accuracy = 100
|
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
|
@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<StatusApplier>()
|
val postSteps = mutableListOf<StatusApplier>()
|
||||||
|
|
||||||
fun damage(power : Int, block : Damage.() -> Unit = {}) {
|
fun damage(power : Int, block : Damage.() -> Unit = {}) {
|
||||||
val d = Damage(power)
|
val d = Damage(power, attribute)
|
||||||
d.block()
|
d.block()
|
||||||
damageSteps.add(d)
|
damageSteps.add(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addStatus(status : Status, target : Target = Target.Selected) {
|
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) {
|
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") {
|
val DoubleEdge = skill("Double Edge") {
|
||||||
damage(20)
|
damage(80)
|
||||||
damage(10) {
|
damage(15) {
|
||||||
target = Target.Self
|
target = Target.Self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,3 +90,10 @@ val DoubleEdge = skill("Double Edge") {
|
|||||||
val Fly = skill("Fly") {
|
val Fly = skill("Fly") {
|
||||||
addStatus(Flying(), Target.Self)
|
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 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) {
|
override fun onTurnEnd(engine : Engine) {
|
||||||
turns--
|
turns--
|
||||||
|
Loading…
Reference in New Issue
Block a user