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 Stats(var atk : Int, var def : Int, var spd : Int, var hp : Int)
|
||||||
|
|
||||||
class Creature {
|
class Creature {
|
||||||
|
var name = ""
|
||||||
val genes = Stats(5,5,5,5)
|
val genes = Stats(5,5,5,5)
|
||||||
val growth = Stats(0,0,0,0)
|
val growth = Stats(0,0,0,0)
|
||||||
val attributes = mutableMapOf<Attribute, Float>()
|
val attributes = mutableMapOf<Attribute, Float>()
|
||||||
@ -25,7 +26,7 @@ class Creature {
|
|||||||
val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f}
|
val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f}
|
||||||
val defAttribute = attributes.getOrElse(dmg.attribute) {1.0f}
|
val defAttribute = attributes.getOrElse(dmg.attribute) {1.0f}
|
||||||
val effectiveness = atkAttribute / defAttribute
|
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 power = (((0.4 * attacker.level) + 2) * dmg.power * (attacker.atk / def)) / 50 + 2
|
||||||
val total = (power * modifier).toInt()
|
val total = (power * modifier).toInt()
|
||||||
currentHp = clamp(currentHp - total, 0, maxHp)
|
currentHp = clamp(currentHp - total, 0, maxHp)
|
||||||
@ -60,6 +61,9 @@ class Creature {
|
|||||||
|
|
||||||
inline fun <reified S : Status> hasStatus() = statuses.filterIsInstance<S>().isNotEmpty()
|
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 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
|
private fun hpStatFormula(gene : Int, growth : Int) = (2 * gene + growth / 4) * level / 100 + level + 10
|
||||||
}
|
}
|
@ -65,35 +65,38 @@ fun skill(name : String, attribute : Attribute = Attribute.Neutral, block : Skil
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
val Ignore = skill("Ignore") {
|
object Skills {
|
||||||
}
|
|
||||||
|
|
||||||
val Tackle = skill("Tackle") {
|
val Ignore = skill("Ignore") {
|
||||||
damage(20)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val DoubleKick = skill("Double Kick") {
|
val Tackle = skill("Tackle") {
|
||||||
repeat(2) {
|
damage(20)
|
||||||
damage(35) {
|
}
|
||||||
accuracy = 85
|
|
||||||
|
val DoubleKick = skill("Double Kick") {
|
||||||
|
repeat(2) {
|
||||||
|
damage(35) {
|
||||||
|
accuracy = 85
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val DoubleEdge = skill("Double Edge") {
|
val DoubleEdge = skill("Double Edge") {
|
||||||
damage(80)
|
damage(80)
|
||||||
damage(15) {
|
damage(15) {
|
||||||
target = Target.Self
|
target = Target.Self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val Fly = skill("Fly") {
|
val Fly = skill("Fly") {
|
||||||
addStatus(Flying(), Target.Self)
|
addStatus(Flying(), Target.Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
val Ember = skill("Ember", Attribute.Fire) {
|
val Ember = skill("Ember", Attribute.Fire) {
|
||||||
damage(40) {
|
damage(40) {
|
||||||
status = {Burned}
|
status = { Burned }
|
||||||
statusChance = 10
|
statusChance = 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,6 +13,9 @@ sealed class Status {
|
|||||||
open fun onTurnEnd(engine : Engine) {
|
open fun onTurnEnd(engine : Engine) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun attackMod(creature : Creature) = 1.0
|
||||||
|
open fun defenseMod(creature : Creature) = 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class VisibleStatus(val label : String = "") : Status()
|
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