Start creating skill system
This commit is contained in:
		
							
								
								
									
										41
									
								
								core/src/me/msoucy/ptures/model/Creature.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								core/src/me/msoucy/ptures/model/Creature.kt
									
									
									
									
									
										Normal 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
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								core/src/me/msoucy/ptures/model/Engine.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								core/src/me/msoucy/ptures/model/Engine.kt
									
									
									
									
									
										Normal 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]
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								core/src/me/msoucy/ptures/model/Skills.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								core/src/me/msoucy/ptures/model/Skills.kt
									
									
									
									
									
										Normal 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)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								core/src/me/msoucy/ptures/model/Status.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								core/src/me/msoucy/ptures/model/Status.kt
									
									
									
									
									
										Normal 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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user