Report damage & handle selection

This commit is contained in:
Matt Soucy 2019-12-07 13:07:03 -05:00
parent 7a2eed338b
commit 97960ec734
4 changed files with 51 additions and 15 deletions

View File

@ -69,7 +69,7 @@ class Engine(private val battle: BattleType) {
// Get the moves each creature will use this turn // Get the moves each creature will use this turn
activeCreatures.forEach { activeCreatures.forEach {
it.chooseSkill(activeCreatures.map { c -> c.creature }) it.chooseSkill(activeCreatures)
} }
// Resolve each move // Resolve each move
@ -83,8 +83,8 @@ class Engine(private val battle: BattleType) {
for (step in skill.damageSteps) { for (step in skill.damageSteps) {
for (targetCreature in targets) { for (targetCreature in targets) {
if (attackingCreature.creature.hits(targetCreature, step)) { if (attackingCreature.creature.hits(targetCreature, step)) {
targetCreature.apply(step, attackingCreature.creature) val dmg = targetCreature.apply(step, attackingCreature.creature)
step.applyStatus(targetCreature) view.reportDamage(dmg)
} }
} }
} }

View File

@ -22,7 +22,7 @@ class Creature {
val spd : Int get() = statFormula(genes.spd, growth.spd) val spd : Int get() = statFormula(genes.spd, growth.spd)
val maxHp : Int get() = hpStatFormula(genes.hp, growth.hp) 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 critical = if (random(32) < attacker.genes.spd) { 1.5 } else { 1.0 }
val randVal = random(0.85f, 1.0f) val randVal = random(0.85f, 1.0f)
val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f} val atkAttribute = attacker.attributes.getOrElse(dmg.attribute) {1.0f}
@ -39,6 +39,8 @@ class Creature {
} else { } else {
dmg.applyStatus(this) dmg.applyStatus(this)
} }
return total
} }
fun addStatus(status : Status) { fun addStatus(status : Status) {

View File

@ -3,6 +3,7 @@ package me.msoucy.ptures.view
import me.msoucy.ptures.model.Creature import me.msoucy.ptures.model.Creature
import me.msoucy.ptures.model.Skill import me.msoucy.ptures.model.Skill
import me.msoucy.ptures.model.SkillChoice import me.msoucy.ptures.model.SkillChoice
import me.msoucy.ptures.model.Target
import me.msoucy.ptures.model.VisibleStatus import me.msoucy.ptures.model.VisibleStatus
class SkillViewText(skill: Skill) : SkillView(skill) { class SkillViewText(skill: Skill) : SkillView(skill) {
@ -30,23 +31,47 @@ class CreatureViewText(playerId: Int, creature: Creature) : CreatureView(playerI
print("> ") print("> ")
val tmpName = readLine() ?: "" val tmpName = readLine() ?: ""
val possibleSkills = creature.skills.filter { it.name == tmpName } val possibleSkills = creature.skills.filter { it.name == tmpName }
if(possibleSkills.isNotEmpty()) if (possibleSkills.isNotEmpty()) {
{
chosenSkill = possibleSkills.first() chosenSkill = possibleSkills.first()
} }
} }
return chosenSkill return chosenSkill
} }
private fun chooseTarget(skill: Skill, possibleTargets: List<Creature>): List<Creature> { private fun selectSingleTarget(possibleTargets: List<CreatureView>): Creature {
return possibleTargets 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) { if (creature.activeSkill == null) {
val skill = chooseSkillName() val skill = chooseSkillName()
val targets = chooseTarget(skill, possibleTargets) val targets = chooseTargets(skill, possibleTargets)
creature.activeSkill = SkillChoice(skill, targets) creature.activeSkill = SkillChoice(skill, targets)
} }
} }
@ -87,4 +112,12 @@ class BattleViewText : BattleView() {
println("${attacker.name} used ${skillChoice.skill.name}!") 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!")
}
}
} }

View File

@ -11,7 +11,7 @@ abstract class SkillView(val skill : Skill) {
abstract class CreatureView(val playerId : Int, val creature: Creature) { 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 displayHeader()
abstract fun displayName() abstract fun displayName()
@ -22,6 +22,7 @@ abstract class CreatureView(val playerId : Int, val creature: Creature) {
abstract class BattleView { abstract class BattleView {
abstract fun useSkill(skillChoice: SkillChoice, attacker : Creature) abstract fun useSkill(skillChoice: SkillChoice, attacker : Creature)
abstract fun reportDamage(dmg : Int)
} }
abstract class PlayerView(val playerId : Int) { abstract class PlayerView(val playerId : Int) {