Report damage & handle selection
This commit is contained in:
parent
7a2eed338b
commit
97960ec734
@ -69,7 +69,7 @@ class Engine(private val battle: BattleType) {
|
||||
|
||||
// Get the moves each creature will use this turn
|
||||
activeCreatures.forEach {
|
||||
it.chooseSkill(activeCreatures.map { c -> c.creature })
|
||||
it.chooseSkill(activeCreatures)
|
||||
}
|
||||
|
||||
// Resolve each move
|
||||
@ -83,8 +83,8 @@ class Engine(private val battle: BattleType) {
|
||||
for (step in skill.damageSteps) {
|
||||
for (targetCreature in targets) {
|
||||
if (attackingCreature.creature.hits(targetCreature, step)) {
|
||||
targetCreature.apply(step, attackingCreature.creature)
|
||||
step.applyStatus(targetCreature)
|
||||
val dmg = targetCreature.apply(step, attackingCreature.creature)
|
||||
view.reportDamage(dmg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class Creature {
|
||||
val spd : Int get() = statFormula(genes.spd, growth.spd)
|
||||
val maxHp : Int get() = hpStatFormula(genes.hp, growth.hp)
|
||||
|
||||
fun apply(dmg : Damage, attacker : Creature) {
|
||||
fun apply(dmg : Damage, attacker : Creature) : Int {
|
||||
val critical = if (random(32) < attacker.genes.spd) { 1.5 } else { 1.0 }
|
||||
val randVal = random(0.85f, 1.0f)
|
||||
val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f}
|
||||
@ -39,6 +39,8 @@ class Creature {
|
||||
} else {
|
||||
dmg.applyStatus(this)
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
fun addStatus(status : Status) {
|
||||
|
@ -3,6 +3,7 @@ package me.msoucy.ptures.view
|
||||
import me.msoucy.ptures.model.Creature
|
||||
import me.msoucy.ptures.model.Skill
|
||||
import me.msoucy.ptures.model.SkillChoice
|
||||
import me.msoucy.ptures.model.Target
|
||||
import me.msoucy.ptures.model.VisibleStatus
|
||||
|
||||
class SkillViewText(skill: Skill) : SkillView(skill) {
|
||||
@ -10,7 +11,7 @@ class SkillViewText(skill: Skill) : SkillView(skill) {
|
||||
println(skill.name)
|
||||
}
|
||||
|
||||
override fun displayEnumerated(idx : Int) {
|
||||
override fun displayEnumerated(idx: Int) {
|
||||
println("- ${skill.name}")
|
||||
}
|
||||
}
|
||||
@ -25,28 +26,52 @@ class CreatureViewText(playerId: Int, creature: Creature) : CreatureView(playerI
|
||||
skillViews.forEachIndexed { index, skillView ->
|
||||
skillView.displayEnumerated(index)
|
||||
}
|
||||
var chosenSkill : Skill? = null
|
||||
var chosenSkill: Skill? = null
|
||||
while (chosenSkill == null) {
|
||||
print("> ")
|
||||
val tmpName = readLine() ?: ""
|
||||
val possibleSkills = creature.skills.filter { it.name == tmpName }
|
||||
if(possibleSkills.isNotEmpty())
|
||||
{
|
||||
if (possibleSkills.isNotEmpty()) {
|
||||
chosenSkill = possibleSkills.first()
|
||||
}
|
||||
}
|
||||
return chosenSkill
|
||||
}
|
||||
|
||||
private fun chooseTarget(skill: Skill, possibleTargets: List<Creature>): List<Creature> {
|
||||
return possibleTargets
|
||||
private fun selectSingleTarget(possibleTargets: List<CreatureView>): Creature {
|
||||
println("Targets:")
|
||||
println("========")
|
||||
possibleTargets.forEach { c ->
|
||||
println("- ${c.creature.name}")
|
||||
}
|
||||
var chosen: Creature? = null
|
||||
while (chosen == null) {
|
||||
print("> ")
|
||||
val tmpName = readLine() ?: ""
|
||||
val possible = possibleTargets.filter { it.creature.name == tmpName }
|
||||
if (possible.isNotEmpty()) {
|
||||
chosen = possible.first().creature
|
||||
}
|
||||
}
|
||||
return chosen
|
||||
}
|
||||
|
||||
override fun chooseSkill(possibleTargets: List<Creature>) {
|
||||
private fun chooseTargets(skill: Skill, possibleTargets: List<CreatureView>): List<Creature> {
|
||||
val target = skill.damageSteps[0].target
|
||||
return when (target) {
|
||||
Target.Self -> listOf(creature)
|
||||
Target.Selected -> listOf(selectSingleTarget(possibleTargets))
|
||||
Target.Others -> possibleTargets.filter { it.creature != creature }.map { it.creature }
|
||||
Target.Opponents -> possibleTargets.filter { it.playerId != playerId }.map { it.creature }
|
||||
Target.All -> possibleTargets.map { it.creature }
|
||||
}
|
||||
}
|
||||
|
||||
override fun chooseSkill(possibleTargets: List<CreatureView>) {
|
||||
|
||||
if (creature.activeSkill == null) {
|
||||
val skill = chooseSkillName()
|
||||
val targets = chooseTarget(skill, possibleTargets)
|
||||
val targets = chooseTargets(skill, possibleTargets)
|
||||
creature.activeSkill = SkillChoice(skill, targets)
|
||||
}
|
||||
}
|
||||
@ -67,7 +92,7 @@ class CreatureViewText(playerId: Int, creature: Creature) : CreatureView(playerI
|
||||
|
||||
override fun displayStatuses() {
|
||||
val displayables = creature.statuses.filterIsInstance<VisibleStatus>()
|
||||
if(displayables.isNotEmpty()) {
|
||||
if (displayables.isNotEmpty()) {
|
||||
println("Statuses")
|
||||
println("--------")
|
||||
displayables.forEach {
|
||||
@ -83,8 +108,16 @@ class PlayerViewText(playerId: Int) : PlayerView(playerId) {
|
||||
|
||||
class BattleViewText : BattleView() {
|
||||
|
||||
override fun useSkill(skillChoice: SkillChoice, attacker : Creature) {
|
||||
override fun useSkill(skillChoice: SkillChoice, attacker: Creature) {
|
||||
println("${attacker.name} used ${skillChoice.skill.name}!")
|
||||
}
|
||||
|
||||
override fun reportDamage(dmg: Int) {
|
||||
if (dmg > 0) {
|
||||
println("Dealt $dmg damage!")
|
||||
} else if (dmg < 0) {
|
||||
println("Healed ${-dmg} health!")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,7 @@ abstract class SkillView(val skill : Skill) {
|
||||
|
||||
abstract class CreatureView(val playerId : Int, val creature: Creature) {
|
||||
|
||||
abstract fun chooseSkill(possibleTargets : List<Creature>)
|
||||
abstract fun chooseSkill(possibleTargets : List<CreatureView>)
|
||||
|
||||
abstract fun displayHeader()
|
||||
abstract fun displayName()
|
||||
@ -22,6 +22,7 @@ abstract class CreatureView(val playerId : Int, val creature: Creature) {
|
||||
abstract class BattleView {
|
||||
|
||||
abstract fun useSkill(skillChoice: SkillChoice, attacker : Creature)
|
||||
abstract fun reportDamage(dmg : Int)
|
||||
}
|
||||
|
||||
abstract class PlayerView(val playerId : Int) {
|
||||
|
Loading…
Reference in New Issue
Block a user