Added a configuration file for seting up parameters
This commit is contained in:
parent
b6fc98f44e
commit
a475126a3f
21
FakeMon/src/fmon/Config.scala
Normal file
21
FakeMon/src/fmon/Config.scala
Normal file
@ -0,0 +1,21 @@
|
||||
package fmon
|
||||
|
||||
import fmon.util.YamlHelper
|
||||
|
||||
case class Config(
|
||||
val title: String,
|
||||
val crit: Double,
|
||||
val stab: Double,
|
||||
val maxBoost: Int
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
object Config {
|
||||
val config = YamlHelper.extract[Config](getClass.getResourceAsStream("config.yaml"))
|
||||
|
||||
def title = config.title
|
||||
def crit = config.crit
|
||||
def stab = config.stab
|
||||
def maxBoost = config.maxBoost
|
||||
}
|
@ -40,7 +40,7 @@ class Game extends Application {
|
||||
val engine = new BattleEngine(party1, party2)
|
||||
controller.setEngine(engine)
|
||||
|
||||
primaryStage.setTitle("FakeMon Battle Simulator")
|
||||
primaryStage.setTitle(Config.title)
|
||||
primaryStage.setScene(scene)
|
||||
primaryStage.show()
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import javafx.scene.{control => jfxsc}
|
||||
import scalafx.Includes._
|
||||
import scalafx.scene.control._
|
||||
|
||||
import fmon._
|
||||
import fmon.stat.Monster
|
||||
import fmon.stat._
|
||||
|
||||
|
@ -1,12 +1,5 @@
|
||||
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)
|
||||
|
||||
}
|
4
FakeMon/src/fmon/config.yaml
Normal file
4
FakeMon/src/fmon/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
title: FakeMon Engine Demo
|
||||
crit: 1.5
|
||||
stab: 1.5
|
||||
maxBoost: 6
|
13
FakeMon/src/fmon/package.scala
Normal file
13
FakeMon/src/fmon/package.scala
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
import scala.language.implicitConversions
|
||||
import scala.util.Random
|
||||
|
||||
import fmon.stat._
|
||||
import fmon.util.{Dice, IntFraction}
|
||||
|
||||
package object fmon {
|
||||
|
||||
implicit def rngDice(rng : Random) = new Dice(rng)
|
||||
implicit def int2Helper(x : Int) = new IntFraction(x)
|
||||
implicit def ptrToMonster(ptr : MonsterPtr) : Monster = ptr.mon
|
||||
}
|
@ -53,10 +53,10 @@ object Ability {
|
||||
private val header = """
|
||||
|import scala.util.Random
|
||||
|import fmon.battle.msg._
|
||||
|import fmon._
|
||||
|import fmon.stat._
|
||||
|import fmon.stat.MoveType._
|
||||
|import fmon.stat.Statistic._
|
||||
|import fmon.util._
|
||||
"""
|
||||
private val helper = """
|
||||
implicit val gen = rng
|
||||
|
@ -2,6 +2,7 @@ package fmon.stat
|
||||
|
||||
import scala.util._
|
||||
|
||||
import fmon._
|
||||
import fmon.battle.msg._
|
||||
import fmon.util._
|
||||
|
||||
@ -69,7 +70,7 @@ class Monster(val base : StorageMon) {
|
||||
|
||||
def applyBoost(s : Stat, boost : Int, effect: EffectSource)(implicit reader: SignalConsumer, rng: Random) {
|
||||
val modified = boosts.getOrElse(s, 0) + boost
|
||||
boosts = boosts.updated(s, Math.min(MaxBoost, Math.max(-MaxBoost, modified)))
|
||||
boosts = boosts.updated(s, Math.min(Config.maxBoost, Math.max(-Config.maxBoost, modified)))
|
||||
if (boost > 0) {
|
||||
reader ! Message(s"$this's $s rose!")
|
||||
} else if (boost < 0) {
|
||||
@ -93,8 +94,6 @@ class Monster(val base : StorageMon) {
|
||||
}
|
||||
|
||||
object Monster {
|
||||
final val MaxBoost = 6
|
||||
|
||||
def generate(nickname: String, ot: TrainerID, xp: Int, form: Form, moves: IndexedSeq[Move])(implicit rng: Random) = {
|
||||
new Monster(StorageMon.generate(nickname, ot, xp, form, moves))
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import scala.io.Source
|
||||
import scala.util.Random
|
||||
|
||||
import Statistic._
|
||||
import fmon._
|
||||
import fmon.battle.msg.{Message, SignalConsumer}
|
||||
import fmon.util._
|
||||
|
||||
@ -142,7 +143,7 @@ abstract class Move extends MoveTurn {
|
||||
val actualPow = if (powCallback != null) powCallback(user, this, target, reader, rng) else pow
|
||||
val baseDmg = (2 * user.level / 5 + 2) * actualPow * user(atkStat) / (target(defStat) * 50) + 2
|
||||
val effectiveness = target.effectiveness(element)
|
||||
val multiplier = effectiveness * critMultiplier(user, target)
|
||||
val multiplier = effectiveness * critMultiplier(user, target) * stabMultiplier(user)
|
||||
if (effectiveness > 1.0) {
|
||||
reader ! Message("It's super effective!")
|
||||
} else if (effectiveness < 1.0) {
|
||||
@ -160,7 +161,15 @@ abstract class Move extends MoveTurn {
|
||||
val chance = (1 << stage) \\ 16 // Doubles per stage
|
||||
if (rng.chance(chance)) {
|
||||
reader ! Message("A critical hit!")
|
||||
1.5
|
||||
Config.crit
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
}
|
||||
|
||||
def stabMultiplier(user: Monster) = {
|
||||
if (user.elements.contains(element)) {
|
||||
Config.stab
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
@ -259,6 +268,7 @@ object Move {
|
||||
val tree = tb.parse(
|
||||
s"""
|
||||
|import scala.util.Random
|
||||
|import fmon._
|
||||
|import fmon.battle.msg._
|
||||
|import fmon.stat._
|
||||
|import fmon.stat.Statistic._
|
||||
|
@ -2,6 +2,8 @@ package fmon.stat
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon._
|
||||
|
||||
import Statistic._
|
||||
|
||||
object Nature extends Enumeration {
|
||||
|
@ -2,6 +2,7 @@ package fmon.stat
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon._
|
||||
import fmon.battle.Action
|
||||
import fmon.stat.Target._
|
||||
|
||||
|
@ -7,6 +7,7 @@ import scala.util.Random
|
||||
|
||||
import scala.io.Source
|
||||
|
||||
import fmon._
|
||||
import fmon.battle.msg._
|
||||
import fmon.util._
|
||||
import EffectType.Volatile
|
||||
@ -124,10 +125,11 @@ object Status {
|
||||
private val header = """
|
||||
import scala.util.Random
|
||||
import fmon.battle.msg._
|
||||
import fmon._
|
||||
import fmon.stat._
|
||||
import fmon.stat.MoveType._
|
||||
import fmon.stat.Statistic._
|
||||
import fmon.util._
|
||||
import fmon.util.Fraction
|
||||
"""
|
||||
private val helpers = """
|
||||
def msg(text: String): Unit = {
|
||||
|
@ -2,7 +2,7 @@ package fmon.stat
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon.util._
|
||||
import fmon._
|
||||
|
||||
class StorageMon(val nickname : String, val xp: Int, val gene : Gene, val form : Form, val evs : Map[Stat, Int], val moves : IndexedSeq[Move], val ability: Ability) {
|
||||
def level = form.xpCurve(xp)
|
||||
|
@ -15,8 +15,6 @@ package object stat {
|
||||
type Target = Target.Value
|
||||
type XpCurve = XpCurve.Val
|
||||
|
||||
implicit def rngDice(rng : Random) = new Dice(rng)
|
||||
implicit def ptrToMonster(ptr : MonsterPtr) : Monster = ptr.mon
|
||||
implicit def templateToStatus(status: StatusTemplate): Status = status.build
|
||||
|
||||
}
|
@ -42,5 +42,4 @@ package object util {
|
||||
new BufferedInputStream(new FileInputStream(filename))
|
||||
}
|
||||
|
||||
implicit def int2Helper(x : Int) = new IntFraction(x)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user