70 lines
1.9 KiB
Scala
70 lines
1.9 KiB
Scala
package fmon.stat
|
|
|
|
import scala.util.Random
|
|
|
|
import fmon._
|
|
import fmon.battle.Action
|
|
import fmon.battle.msg.SignalConsumer
|
|
import fmon.stat.Target._
|
|
|
|
class Party(val trainer: TrainerID, val lead: MonsterPtr, var sideboard: IndexedSeq[Monster]) {
|
|
def pollAction(them: Party)(implicit reader: SignalConsumer, rng: Random): Action = {
|
|
if (lead.isLocked) {
|
|
val moveNames = lead.statuses.flatMap(s => s.onLockMove(lead)).distinct
|
|
moveNames match {
|
|
case Seq(moveName) => {
|
|
// Use locked move
|
|
val move = Move(moveName)
|
|
// TODO : remember target
|
|
val target = pollTarget(move, lead, them)
|
|
Action(lead, move, target)
|
|
}
|
|
case _ => {
|
|
// Struggle
|
|
val move = Move("struggle")
|
|
val target = pollTarget(move, lead, them)
|
|
Action(lead, move, target)
|
|
}
|
|
}
|
|
} else 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)
|
|
}
|
|
} |