Added natures and xp curves / levels

This commit is contained in:
James Daly 2019-05-30 22:32:49 -04:00
parent 32c6913187
commit d13d5b3bf6
10 changed files with 78 additions and 21 deletions

View File

@ -23,10 +23,11 @@ object Game {
val movepool2 = IndexedSeq(Move("Absorb")) val movepool2 = IndexedSeq(Move("Absorb"))
val p1 = TrainerID("Jaeda", Gender.Female, 0) val p1 = TrainerID("Jaeda", Gender.Female, 0)
val p2 = TrainerID("Wild Monster", Gender.Male, 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 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", Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2))), 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", Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2)) new Monster(new StorageMon("Sideboard Mon", 500, Gene.randomGene(null, form2), form2, Statistic.emptyEvs, movepool2))
)) ))
println(form1.xpCurve)
val engine = new BattleEngine(party1, party2) val engine = new BattleEngine(party1, party2)
engine.play() engine.play()
println(party1.lead.elements) println(party1.lead.elements)

View File

@ -9,6 +9,7 @@ import mon.util.Fraction
class BattleEngine(val player: Party, val enemy: Party)(implicit val rng: Random) { class BattleEngine(val player: Party, val enemy: Party)(implicit val rng: Random) {
def play() = { def play() = {
println(player.lead.level)
while (player.canFight && enemy.canFight) { while (player.canFight && enemy.canFight) {
playTurn() playTurn()
} }

View File

@ -2,6 +2,8 @@ package mon.stat
import scala.io.Source import scala.io.Source
import com.fasterxml.jackson.module.scala.JsonScalaEnumeration
import Statistic._ import Statistic._
import mon.util.YamlHelper import mon.util.YamlHelper
@ -16,6 +18,7 @@ abstract class Form {
// val appearance // animation // val appearance // animation
// moves // moves
// abilities // abilities
val xpCurve : XpCurve
val catchRate : Int val catchRate : Int
// val color // val color
@ -29,6 +32,7 @@ case class FormToken(
val desc : String, val desc : String,
val elements : IndexedSeq[String], val elements : IndexedSeq[String],
val baseStats : Map[String, Int], val baseStats : Map[String, Int],
@JsonScalaEnumeration(classOf[XpCurveType]) val xpCurve : XpCurve,
val catchRate : Int = 255 val catchRate : Int = 255
) { ) {
@ -39,6 +43,7 @@ case class FormToken(
val desc = self.desc val desc = self.desc
val elements = self.elements.map(Element(_)) val elements = self.elements.map(Element(_))
val baseStats = self.baseStats.map{ case (s, i) => (Statistic(s), i)} val baseStats = self.baseStats.map{ case (s, i) => (Statistic(s), i)}
val xpCurve = self.xpCurve
val catchRate = self.catchRate val catchRate = self.catchRate
} }
} }
@ -47,16 +52,6 @@ case class FormToken(
object Form { object Form {
def apply(name : String) = byName(name) 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 forms = YamlHelper.extractSeq[FormToken](Form.getClass.getResourceAsStream("data/forms.yaml")).map(_.instantiate())
val byName = forms.map(f => (f.name, f)).toMap val byName = forms.map(f => (f.name, f)).toMap
} }

View File

@ -2,7 +2,7 @@ package mon.stat
import scala.util.Random 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) = { def randomGene(ot : TrainerID, form : Form)(implicit rng : Random) = {
val gender = Gender.Neuter // TODO val gender = Gender.Neuter // TODO
val ivs = Statistic.values.map(s => (s, rng.nextInt(MaxIV + 1))).toMap val ivs = Statistic.values.map(s => (s, rng.nextInt(MaxIV + 1))).toMap
Gene(gender, ivs, ot) Gene(gender, Nature.randomNature, ivs, ot)
} }
} }

View File

@ -8,7 +8,7 @@ import Monster._
import Statistic._ import Statistic._
class Monster(val base : StorageMon) { class Monster(val base : StorageMon) {
val level = 10 def level = base.level
val stats = Statistic.buildMap(computeStat) val stats = Statistic.buildMap(computeStat)
var boosts = Statistic.buildMap(_ => 0) var boosts = Statistic.buildMap(_ => 0)
var hp = stats(Hp) 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 num = 2 * base.form.baseStats(s) + base.gene.ivs(s) + base.evs(s) / 4
val frac = num * level / 100 val frac = num * level / 100
val score = if(s == Hp) frac + 10 + level else frac + 5 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 { object Monster {

View File

@ -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])
}

View File

@ -1,5 +1,5 @@
package mon.stat 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)
} }

View File

@ -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]

View File

@ -9,6 +9,7 @@
matk: 70 matk: 70
mdef: 70 mdef: 70
spd: 60 spd: 60
xpCurve: MediumSlow
- name: Diabolo - name: Diabolo
desc: This is a ball of lightning from Hell itself. desc: This is a ball of lightning from Hell itself.
@ -21,4 +22,5 @@
pdef: 30 pdef: 30
matk: 130 matk: 130
mdef: 40 mdef: 40
spd: 130 spd: 130
xpCurve: Slow

View File

@ -11,7 +11,9 @@ package object stat {
type Stat = Statistic.Value type Stat = Statistic.Value
type MoveType = MoveType.Value type MoveType = MoveType.Value
type Gender = Gender.Value type Gender = Gender.Value
type Nature = Nature.Val
type Target = Target.Value type Target = Target.Value
type XpCurve = XpCurve.Val
implicit val formats = DefaultFormats + new EnumNameSerializer(MoveType) + new EnumNameSerializer(Gender) implicit val formats = DefaultFormats + new EnumNameSerializer(MoveType) + new EnumNameSerializer(Gender)
implicit def rngDice(rng : Random) = new Dice(rng) implicit def rngDice(rng : Random) = new Dice(rng)