51 lines
1.2 KiB
Scala
51 lines
1.2 KiB
Scala
package fmon.stat
|
|
|
|
import scala.util.Random
|
|
|
|
import fmon.battle.Action
|
|
import fmon.stat.Target._
|
|
|
|
class Party(val trainer: TrainerID, val lead: MonsterPtr, var sideboard: IndexedSeq[Monster]) {
|
|
def pollAction(them: Party)(implicit rng: Random): Action = {
|
|
if (hasBackup && shouldSwitch(them)) {
|
|
val sub = pollReplacement(them: Party)
|
|
val move = new SwitchOut(this, sub)
|
|
Action(lead, move, lead)
|
|
} else {
|
|
val move = pollMove
|
|
val target = pollTarget(move, lead, them)
|
|
Action(lead, move, target)
|
|
}
|
|
}
|
|
|
|
def pollMove(implicit rng: Random): MoveTurn = rng.pick(lead.base.moves)
|
|
def pollTarget(move: MoveTurn, user: MonsterPtr, them: Party)(implicit rng: Random): MonsterPtr = {
|
|
if (move.target == Self) {
|
|
user
|
|
} else {
|
|
them.lead
|
|
}
|
|
}
|
|
|
|
def pollReplacement(them: Party)(implicit rng: Random): Monster = {
|
|
sideboard.filter(_.isAlive).head
|
|
}
|
|
|
|
def switchIn(mon: Monster) = {
|
|
val index = sideboard.indexOf(mon)
|
|
sideboard = sideboard.updated(index, lead.mon)
|
|
lead.mon = mon
|
|
}
|
|
|
|
def shouldSwitch(them: Party)(implicit rng: Random): Boolean = {
|
|
false
|
|
}
|
|
|
|
def canFight: Boolean = {
|
|
lead.isAlive || hasBackup
|
|
}
|
|
|
|
def hasBackup: Boolean = {
|
|
sideboard.exists(_.isAlive)
|
|
}
|
|
} |