Start creating views
This commit is contained in:
parent
815ab5b372
commit
fd3a4670ea
@ -6,6 +6,7 @@ import com.badlogic.gdx.math.MathUtils.random
|
||||
class Stats(var atk : Int, var def : Int, var spd : Int, var hp : Int)
|
||||
|
||||
class Creature {
|
||||
var name = ""
|
||||
val genes = Stats(5,5,5,5)
|
||||
val growth = Stats(0,0,0,0)
|
||||
val attributes = mutableMapOf<Attribute, Float>()
|
||||
@ -25,7 +26,7 @@ class Creature {
|
||||
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 * attacker.atkMod() * defMod()
|
||||
val power = (((0.4 * attacker.level) + 2) * dmg.power * (attacker.atk / def)) / 50 + 2
|
||||
val total = (power * modifier).toInt()
|
||||
currentHp = clamp(currentHp - total, 0, maxHp)
|
||||
@ -60,6 +61,9 @@ class Creature {
|
||||
|
||||
inline fun <reified S : Status> hasStatus() = statuses.filterIsInstance<S>().isNotEmpty()
|
||||
|
||||
private fun atkMod() = statuses.fold(1.0) { value, status -> value * status.attackMod(this) }
|
||||
private fun defMod() = statuses.map{ it.defenseMod(this) }.fold(1.0) { a, b -> a * b }
|
||||
|
||||
private fun statFormula(gene : Int, growth : Int) = (2 * gene + growth / 4) * level / 100 + 5
|
||||
private fun hpStatFormula(gene : Int, growth : Int) = (2 * gene + growth / 4) * level / 100 + level + 10
|
||||
}
|
@ -65,6 +65,8 @@ fun skill(name : String, attribute : Attribute = Attribute.Neutral, block : Skil
|
||||
return ret
|
||||
}
|
||||
|
||||
object Skills {
|
||||
|
||||
val Ignore = skill("Ignore") {
|
||||
}
|
||||
|
||||
@ -97,3 +99,4 @@ val Ember = skill("Ember", Attribute.Fire) {
|
||||
statusChance = 10
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ sealed class Status {
|
||||
open fun onTurnEnd(engine : Engine) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
open fun attackMod(creature : Creature) = 1.0
|
||||
open fun defenseMod(creature : Creature) = 1.0
|
||||
}
|
||||
|
||||
sealed class VisibleStatus(val label : String = "") : Status()
|
||||
|
56
core/src/me/msoucy/ptures/view/TextView.kt
Normal file
56
core/src/me/msoucy/ptures/view/TextView.kt
Normal file
@ -0,0 +1,56 @@
|
||||
package me.msoucy.ptures.view
|
||||
|
||||
import me.msoucy.ptures.model.Creature
|
||||
import me.msoucy.ptures.model.Skill
|
||||
import me.msoucy.ptures.model.Skills
|
||||
import me.msoucy.ptures.model.VisibleStatus
|
||||
|
||||
class SkillViewText(val skill : Skill) : SkillView() {
|
||||
override fun display() {
|
||||
println(skill.name)
|
||||
}
|
||||
|
||||
override fun displayEnumerated(idx: Int) {
|
||||
println("${idx}: ${skill.name}")
|
||||
}
|
||||
}
|
||||
|
||||
class CreatureViewText(val creature : Creature) : CreatureView() {
|
||||
|
||||
private val skillViews = creature.skills.map { SkillViewText(it) }
|
||||
|
||||
override val skillChoice : Skill get() {
|
||||
println("Skills:")
|
||||
println("=======")
|
||||
skillViews.forEachIndexed { index, skillView ->
|
||||
skillView.displayEnumerated(index)
|
||||
}
|
||||
var idx = -1
|
||||
while(idx != -1) {
|
||||
print("> ")
|
||||
val tmpIdx = readLine()?.toIntOrNull() ?: -1
|
||||
if (tmpIdx in creature.skills.indices)
|
||||
{
|
||||
idx = tmpIdx
|
||||
}
|
||||
}
|
||||
|
||||
return creature.skills[idx]
|
||||
}
|
||||
|
||||
override fun displayName() {
|
||||
println(creature.name)
|
||||
}
|
||||
|
||||
override fun displaySkills() {
|
||||
skillViews.forEach { skillView ->
|
||||
skillView.display()
|
||||
}
|
||||
}
|
||||
|
||||
override fun displayStatuses() {
|
||||
creature.statuses.filterIsInstance<VisibleStatus>().forEach {
|
||||
println(it.label)
|
||||
}
|
||||
}
|
||||
}
|
17
core/src/me/msoucy/ptures/view/ViewBase.kt
Normal file
17
core/src/me/msoucy/ptures/view/ViewBase.kt
Normal file
@ -0,0 +1,17 @@
|
||||
package me.msoucy.ptures.view
|
||||
|
||||
import me.msoucy.ptures.model.Skill
|
||||
|
||||
abstract class SkillView {
|
||||
abstract fun display()
|
||||
abstract fun displayEnumerated(idx : Int)
|
||||
}
|
||||
|
||||
abstract class CreatureView {
|
||||
|
||||
abstract val skillChoice : Skill
|
||||
|
||||
abstract fun displayName()
|
||||
abstract fun displaySkills()
|
||||
abstract fun displayStatuses()
|
||||
}
|
Loading…
Reference in New Issue
Block a user