Renamed the root package to fmon and added paralysis, burn, and sleep status effects
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package fmon.battle
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon.stat._
|
||||
import fmon.stat.Statistic._
|
||||
import fmon.util.Fraction
|
||||
|
||||
class BattleEngine(val player: Party, val enemy: Party)(implicit val rng: Random) {
|
||||
|
||||
def play() = {
|
||||
println(player.lead.level)
|
||||
while (player.canFight && enemy.canFight) {
|
||||
playTurn()
|
||||
}
|
||||
}
|
||||
|
||||
def playTurn() = {
|
||||
val playerAction = player.pollAction(enemy)
|
||||
val enemyAction = enemy.pollAction(player)
|
||||
|
||||
val actions = Seq(playerAction, enemyAction)
|
||||
val queue = rng.shuffle(actions).sorted // Shuffle to randomize in the event of a tie
|
||||
queue.foreach(useMove)
|
||||
val eotQueue = Seq(player.lead, enemy.lead).sortBy(_(Speed))
|
||||
eotQueue.foreach(mon => mon.status.map(_.onResidual(mon)))
|
||||
|
||||
if (!player.lead.isAlive) {
|
||||
if (player.canFight) {
|
||||
val replace = player.pollReplacement(enemy)
|
||||
player.switchIn(replace)
|
||||
} else {
|
||||
println(s"${player.trainer} has lost!")
|
||||
}
|
||||
}
|
||||
if (!enemy.lead.isAlive) {
|
||||
if (enemy.canFight) {
|
||||
val replace = enemy.pollReplacement(player)
|
||||
enemy.switchIn(replace)
|
||||
} else {
|
||||
println(s"${enemy.trainer} has lost!")
|
||||
}
|
||||
}
|
||||
|
||||
println(s"${player.lead}(${player.lead.hp}/${player.lead(Hp)})")
|
||||
println(s"${enemy.lead}(${enemy.lead.hp}/${enemy.lead(Hp)})")
|
||||
}
|
||||
|
||||
def useMove(action: Action) = {
|
||||
val user = action.user
|
||||
val move = action.move
|
||||
val target = action.target
|
||||
if (user.isAlive) {
|
||||
if (user.status.forall(_.onBeforeMove(user, move, target, rng))) {
|
||||
move.useMove(user, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user