Start creating skill system

This commit is contained in:
Matt Soucy 2019-11-23 19:10:01 -05:00
parent 645dd2e90c
commit ee5f9ca2d0
5 changed files with 170 additions and 2 deletions

View File

@ -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'
}

View File

@ -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<Status>()
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
}

View File

@ -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]
}
}

View File

@ -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<Pair<Status, Target>>()
val damageSteps = mutableListOf<Damage>()
val postSteps = mutableListOf<Pair<Status, Target>>()
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)
}

View File

@ -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)
}
}