From ee5f9ca2d05889f93fe2a253ece548854099478e Mon Sep 17 00:00:00 2001 From: Matt Soucy Date: Sat, 23 Nov 2019 19:10:01 -0500 Subject: [PATCH] Start creating skill system --- build.gradle | 4 +- core/src/me/msoucy/ptures/model/Creature.kt | 41 ++++++++++++ core/src/me/msoucy/ptures/model/Engine.kt | 13 ++++ core/src/me/msoucy/ptures/model/Skills.kt | 72 +++++++++++++++++++++ core/src/me/msoucy/ptures/model/Status.kt | 42 ++++++++++++ 5 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 core/src/me/msoucy/ptures/model/Creature.kt create mode 100644 core/src/me/msoucy/ptures/model/Engine.kt create mode 100644 core/src/me/msoucy/ptures/model/Skills.kt create mode 100644 core/src/me/msoucy/ptures/model/Status.kt diff --git a/build.gradle b/build.gradle index f3722a2..632fd46 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlinVersion = '1.3.50' + ext.kotlinVersion = '1.3.60' repositories { mavenLocal() @@ -25,7 +25,7 @@ allprojects { gdxVersion = '1.9.10' roboVMVersion = '2.3.7' box2DLightsVersion = '1.4' - ashleyVersion = '1.7.0' + ashleyVersion = '1.7.3' aiVersion = '1.8.0' ktxVersion = '1.9.10-b2' } diff --git a/core/src/me/msoucy/ptures/model/Creature.kt b/core/src/me/msoucy/ptures/model/Creature.kt new file mode 100644 index 0000000..b0057cd --- /dev/null +++ b/core/src/me/msoucy/ptures/model/Creature.kt @@ -0,0 +1,41 @@ +package me.msoucy.ptures.model + +import com.badlogic.gdx.math.MathUtils.clamp + +class Stats(var atk : Int, var def : Int, var spd : Int, var hp : Int) + +class Creature { + var genes = Stats(5,5,5,5) + var growth = Stats(5,5,5,5) + var level = 1 + var currentHp = 1 + val statuses = mutableListOf() + + val atk : Int get() = statFormula(genes.atk, growth.atk) + val def : Int get() = statFormula(genes.atk, growth.atk) + val spd : Int get() = statFormula(genes.atk, growth.atk) + val maxHp : Int get() = statFormula(genes.atk, growth.atk) + + fun apply(dmg : Damage) { + currentHp = clamp(currentHp - dmg.power, 0, maxHp) + } + + fun addStatus(status : Status) { + if(status !in statuses) + { + statuses.add(status) + status.onAdd(this) + } + } + + fun removeStatus(status : Status) { + statuses.remove(status) + } + + fun fullHeal() { + currentHp = maxHp + statuses.clear() + } + + private fun statFormula(gene : Int, growth : Int) = (2 * gene + growth) * 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 new file mode 100644 index 0000000..75afd03 --- /dev/null +++ b/core/src/me/msoucy/ptures/model/Engine.kt @@ -0,0 +1,13 @@ +package me.msoucy.ptures.model + +class Engine(vararg val creatures : Creature) { + init { + assert(creatures.isNotEmpty()) + } + + var currentCreature = 0 + + val attacker : Creature get() { + return creatures[currentCreature] + } +} \ No newline at end of file diff --git a/core/src/me/msoucy/ptures/model/Skills.kt b/core/src/me/msoucy/ptures/model/Skills.kt new file mode 100644 index 0000000..ee2c4b1 --- /dev/null +++ b/core/src/me/msoucy/ptures/model/Skills.kt @@ -0,0 +1,72 @@ +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 +} + +@SkillMarker +class Skill(val name : String, val attribute : Attribute) { + val preSteps = mutableListOf>() + val damageSteps = mutableListOf() + val postSteps = mutableListOf>() + + fun damage(power : Int, block : Damage.() -> Unit = {}) { + val d = Damage(power) + d.block() + damageSteps.add(d) + } + + fun addStatus(status : Status, target : Target = Target.Selected) { + postSteps.add(Pair(status, target)) + } +} + +fun skill(name : String, attribute : Attribute = Attribute.Neutral, block : Skill.() -> Unit) : Skill { + val ret = Skill(name, attribute) + ret.block() + return ret +} + +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) +} \ 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 new file mode 100644 index 0000000..3baaccb --- /dev/null +++ b/core/src/me/msoucy/ptures/model/Status.kt @@ -0,0 +1,42 @@ +package me.msoucy.ptures.model + +sealed class Status { + + open fun onAdd(creature : Creature) { + // Do nothing + } + + open fun onTurnEnd(engine : Engine) { + // Do nothing by default + } +} + +sealed class VisibleStatus(val label : String = "") : Status() + +sealed class CountdownStatus(var turns : Int) : Status() +{ + override fun onTurnEnd(engine : Engine) { + turns-- + if(turns == 0) { + onCountdownReached(engine) + engine.attacker.removeStatus(this) + } + } + + open fun onCountdownReached(engine : Engine) { + } +} + +object KnockedOut : VisibleStatus("ko") +object Burned : VisibleStatus("burned") { + override fun onTurnEnd(engine : Engine) { + // Deal a small amount of damage + } +} +object Stunned : VisibleStatus("stunned") +object Poisoned : VisibleStatus("poisoned") +class Flying : CountdownStatus(1) { + override fun onCountdownReached(engine: Engine) { + super.onCountdownReached(engine) + } +}