Renamed the root package to fmon and added paralysis, burn, and sleep status effects
This commit is contained in:
14
FakeMon/src/fmon/battle/Action.scala
Normal file
14
FakeMon/src/fmon/battle/Action.scala
Normal file
@@ -0,0 +1,14 @@
|
||||
package fmon.battle
|
||||
|
||||
import fmon.stat._
|
||||
import fmon.stat.Statistic.Speed
|
||||
|
||||
case class Action(user : MonsterPtr, move : MoveTurn, target : MonsterPtr) extends Comparable[Action] {
|
||||
override def compareTo(other : Action) = {
|
||||
if (move.prior == other.move.prior) {
|
||||
other.user(Speed) compareTo user(Speed)
|
||||
} else {
|
||||
other.move.prior compareTo move.prior
|
||||
}
|
||||
}
|
||||
}
|
||||
59
FakeMon/src/fmon/battle/BattleEngine.scala
Normal file
59
FakeMon/src/fmon/battle/BattleEngine.scala
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
FakeMon/src/fmon/battle/package.scala
Normal file
12
FakeMon/src/fmon/battle/package.scala
Normal file
@@ -0,0 +1,12 @@
|
||||
package fmon
|
||||
|
||||
import scala.language.implicitConversions
|
||||
import scala.util.Random
|
||||
|
||||
import fmon.util._
|
||||
|
||||
|
||||
package object battle {
|
||||
implicit def rngDice(rng : Random) = new Dice(rng)
|
||||
implicit def int2Helper(x : Int) = new IntFraction(x)
|
||||
}
|
||||
Reference in New Issue
Block a user