diff --git a/FakeMon/src/mon/Game.scala b/FakeMon/src/mon/Game.scala index e2c1d27..5867021 100644 --- a/FakeMon/src/mon/Game.scala +++ b/FakeMon/src/mon/Game.scala @@ -23,10 +23,11 @@ object Game { val movepool2 = IndexedSeq(Move("Absorb")) val p1 = TrainerID("Jaeda", Gender.Female, 0) val p2 = TrainerID("Wild Monster", Gender.Male, 0) - val party1 = new Party(p1, new MonsterPtr(new Monster(new StorageMon("Allied Mon", Gene.randomGene(null, form1), form1, Statistic.emptyEvs, movepool1))), IndexedSeq()) - val party2 = new Party(p2, new MonsterPtr(new Monster(new StorageMon("Wild Mon", Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2))), IndexedSeq( - new Monster(new StorageMon("Sideboard Mon", Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2)) + val party1 = new Party(p1, new MonsterPtr(new Monster(new StorageMon("Allied Mon", 500, Gene.randomGene(null, form1), form1, Statistic.emptyEvs, movepool1))), IndexedSeq()) + val party2 = new Party(p2, new MonsterPtr(new Monster(new StorageMon("Wild Mon", 500, Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2))), IndexedSeq( + new Monster(new StorageMon("Sideboard Mon", 500, Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2)) )) + println(form1.xpCurve) val engine = new BattleEngine(party1, party2) engine.play() println(party1.lead.elements) diff --git a/FakeMon/src/mon/battle/BattleEngine.scala b/FakeMon/src/mon/battle/BattleEngine.scala index c7fc44c..fa64e1f 100644 --- a/FakeMon/src/mon/battle/BattleEngine.scala +++ b/FakeMon/src/mon/battle/BattleEngine.scala @@ -9,6 +9,7 @@ import mon.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() } diff --git a/FakeMon/src/mon/stat/Form.scala b/FakeMon/src/mon/stat/Form.scala index 4328d1c..6c31469 100644 --- a/FakeMon/src/mon/stat/Form.scala +++ b/FakeMon/src/mon/stat/Form.scala @@ -2,6 +2,8 @@ package mon.stat import scala.io.Source +import com.fasterxml.jackson.module.scala.JsonScalaEnumeration + import Statistic._ import mon.util.YamlHelper @@ -16,6 +18,7 @@ abstract class Form { // val appearance // animation // moves // abilities + val xpCurve : XpCurve val catchRate : Int // val color @@ -29,6 +32,7 @@ case class FormToken( val desc : String, val elements : IndexedSeq[String], val baseStats : Map[String, Int], + @JsonScalaEnumeration(classOf[XpCurveType]) val xpCurve : XpCurve, val catchRate : Int = 255 ) { @@ -39,6 +43,7 @@ case class FormToken( val desc = self.desc val elements = self.elements.map(Element(_)) val baseStats = self.baseStats.map{ case (s, i) => (Statistic(s), i)} + val xpCurve = self.xpCurve val catchRate = self.catchRate } } @@ -47,16 +52,6 @@ case class FormToken( object Form { def apply(name : String) = byName(name) - def fromMap(dict : Map[String, Any]) = { - new Form { - val name = dict("name").toString - val desc = dict("desc").toString() - val elements = IndexedSeq() - val baseStats = Statistic.buildMap(_ => 10) - val catchRate = 255 - } - } - val forms = YamlHelper.extractSeq[FormToken](Form.getClass.getResourceAsStream("data/forms.yaml")).map(_.instantiate()) val byName = forms.map(f => (f.name, f)).toMap } \ No newline at end of file diff --git a/FakeMon/src/mon/stat/Gene.scala b/FakeMon/src/mon/stat/Gene.scala index da43cee..df7fbe1 100644 --- a/FakeMon/src/mon/stat/Gene.scala +++ b/FakeMon/src/mon/stat/Gene.scala @@ -2,7 +2,7 @@ package mon.stat import scala.util.Random -case class Gene(val gender : Gender, val ivs : Map[Stat, Int], ot : TrainerID) { +case class Gene(val gender : Gender, val nature : Nature, val ivs : Map[Stat, Int], ot : TrainerID) { } @@ -11,6 +11,6 @@ object Gene { def randomGene(ot : TrainerID, form : Form)(implicit rng : Random) = { val gender = Gender.Neuter // TODO val ivs = Statistic.values.map(s => (s, rng.nextInt(MaxIV + 1))).toMap - Gene(gender, ivs, ot) + Gene(gender, Nature.randomNature, ivs, ot) } } \ No newline at end of file diff --git a/FakeMon/src/mon/stat/Monster.scala b/FakeMon/src/mon/stat/Monster.scala index 144a055..4b5155d 100644 --- a/FakeMon/src/mon/stat/Monster.scala +++ b/FakeMon/src/mon/stat/Monster.scala @@ -8,7 +8,7 @@ import Monster._ import Statistic._ class Monster(val base : StorageMon) { - val level = 10 + def level = base.level val stats = Statistic.buildMap(computeStat) var boosts = Statistic.buildMap(_ => 0) var hp = stats(Hp) @@ -49,10 +49,11 @@ class Monster(val base : StorageMon) { val num = 2 * base.form.baseStats(s) + base.gene.ivs(s) + base.evs(s) / 4 val frac = num * level / 100 val score = if(s == Hp) frac + 10 + level else frac + 5 - score + (score * base.gene.nature(s)).toInt } - override def toString = base.nickname + def name = if (base.nickname != null) base.nickname else base.form.name + override def toString = name } object Monster { diff --git a/FakeMon/src/mon/stat/Nature.scala b/FakeMon/src/mon/stat/Nature.scala new file mode 100644 index 0000000..b71b3e0 --- /dev/null +++ b/FakeMon/src/mon/stat/Nature.scala @@ -0,0 +1,40 @@ +package mon.stat + +import scala.util.Random + +import Statistic._ + +object Nature extends Enumeration { + case class Val protected(boosts : Map[Stat, Double]) extends super.Val { + def apply(s : Stat) = boosts.getOrElse(s, 1.0) + } + + val Hardy = Val(Map()) + val Lonely = Val(Map(PAtk -> 1.1, PDef -> 0.9)) + val Brave = Val(Map(PAtk -> 1.1, Speed -> 0.9)) + val Adamant = Val(Map(PAtk -> 1.1, MAtk -> 0.9)) + val Naughty = Val(Map(PAtk -> 1.1, MDef -> 0.9)) + val Bold = Val(Map(PDef -> 1.1, PAtk -> 0.9)) + val Docile = Val(Map()) + val Relaxed = Val(Map(PDef -> 1.1, Speed -> 0.9)) + val Impish = Val(Map(PDef -> 1.1, MAtk -> 0.9)) + val Lax = Val(Map(PDef -> 1.1, MDef -> 0.9)) + val Timid = Val(Map(Speed -> 1.1, PAtk -> 0.9)) + val Hasty = Val(Map(Speed -> 1.1, PDef -> 0.9)) + val Serious = Val(Map()) + val Jolly = Val(Map(Speed -> 1.1, MAtk -> 0.9)) + val Naive = Val(Map(Speed -> 1.1, MDef -> 0.9)) + val Modest = Val(Map(MAtk -> 1.1, PAtk -> 0.9)) + val Mild = Val(Map(MAtk -> 1.1, PDef -> 0.9)) + val Quiet = Val(Map(MAtk -> 1.1, Speed -> 0.9)) + val Bashful = Val(Map()) + val Rash = Val(Map(MAtk -> 1.1, MDef -> 0.9)) + val Calm = Val(Map(MDef -> 1.1, PAtk -> 0.9)) + val Gentle = Val(Map(MDef -> 1.1, PDef -> 0.9)) + val Sassy = Val(Map(MDef -> 1.1, Speed -> 0.9)) + val Careful = Val(Map(MDef -> 1.1, MAtk -> 0.9)) + val Quirky = Val(Map()) + + def randomNature(implicit rng: Random) : Nature = rng.pick(natures) + val natures = values.toIndexedSeq.map(_.asInstanceOf[Val]) +} \ No newline at end of file diff --git a/FakeMon/src/mon/stat/StorageMon.scala b/FakeMon/src/mon/stat/StorageMon.scala index 031258a..ad35a7f 100644 --- a/FakeMon/src/mon/stat/StorageMon.scala +++ b/FakeMon/src/mon/stat/StorageMon.scala @@ -1,5 +1,5 @@ package mon.stat -class StorageMon(val nickname : String, val gene : Gene, val form : Form, val evs : Map[Stat, Int], val moves : IndexedSeq[Move]) { - +class StorageMon(val nickname : String, val xp: Int, val gene : Gene, val form : Form, val evs : Map[Stat, Int], val moves : IndexedSeq[Move]) { + def level = form.xpCurve(xp) } \ No newline at end of file diff --git a/FakeMon/src/mon/stat/XpCurve.scala b/FakeMon/src/mon/stat/XpCurve.scala new file mode 100644 index 0000000..4056107 --- /dev/null +++ b/FakeMon/src/mon/stat/XpCurve.scala @@ -0,0 +1,15 @@ +package mon.stat + +import mon.util.TypeReference + +object XpCurve extends Enumeration { + case class Val protected(val curve: Int => Int) extends super.Val { + def apply(xp : Int) = curve(xp) + } + + val Fast = Val(xp => Math.cbrt(1.2 * xp).toInt) + val MediumFast = Val(xp => Math.cbrt(xp).toInt) + val MediumSlow = Val(xp => Math.cbrt(0.85 * xp).toInt) + val Slow = Val(xp => Math.cbrt(0.75 * xp).toInt) +} +class XpCurveType extends TypeReference[XpCurve.type] \ No newline at end of file diff --git a/FakeMon/src/mon/stat/data/forms.yaml b/FakeMon/src/mon/stat/data/forms.yaml index b3ac151..8ea233a 100644 --- a/FakeMon/src/mon/stat/data/forms.yaml +++ b/FakeMon/src/mon/stat/data/forms.yaml @@ -9,6 +9,7 @@ matk: 70 mdef: 70 spd: 60 + xpCurve: MediumSlow - name: Diabolo desc: This is a ball of lightning from Hell itself. @@ -21,4 +22,5 @@ pdef: 30 matk: 130 mdef: 40 - spd: 130 \ No newline at end of file + spd: 130 + xpCurve: Slow \ No newline at end of file diff --git a/FakeMon/src/mon/stat/package.scala b/FakeMon/src/mon/stat/package.scala index 07e8d6b..88fe6a0 100644 --- a/FakeMon/src/mon/stat/package.scala +++ b/FakeMon/src/mon/stat/package.scala @@ -11,7 +11,9 @@ package object stat { type Stat = Statistic.Value type MoveType = MoveType.Value type Gender = Gender.Value + type Nature = Nature.Val type Target = Target.Value + type XpCurve = XpCurve.Val implicit val formats = DefaultFormats + new EnumNameSerializer(MoveType) + new EnumNameSerializer(Gender) implicit def rngDice(rng : Random) = new Dice(rng)