feat(game): give monsters their real level up moveset (#85)
* feat(codegen): generate the level up learnsets from the decomp * feat(game): give monsters their real level up moveset
This commit is contained in:
1 parent
e24bc5518d
commit
1ecfabaed5
22 files changed
+485
-39
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package de.fiereu.openmmo.server.game.battle
|
||||
|
||||
import de.fiereu.openmmo.common.MAX_MOVE_SLOTS
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.pokemon.LearnsetRegistry
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** A move learned on level up, ready to be announced to the player. */
|
||||
data class LearnedMove(val level: Int, val moveId: Int, val name: String)
|
||||
|
||||
/** Teaches the level up moves a monster gained from a level range. */
|
||||
@Singleton
|
||||
class MoveLearner
|
||||
@Inject
|
||||
constructor(
|
||||
private val learnsets: LearnsetRegistry,
|
||||
private val moves: MoveRegistry,
|
||||
) {
|
||||
|
||||
/**
|
||||
* Adds every move learned above [fromLevel] up to [toLevel] that fits a free slot and returns
|
||||
* them. A monster that already knows four moves learns nothing.
|
||||
*/
|
||||
// TODO Let the player replace a move when the moveset is full
|
||||
// A monster with four moves silently skips every move it would learn on level up. The client's
|
||||
// move learn prompt packets are unknown, ByteDex holds no capture of them. Capture the prompt
|
||||
// and the answer, then apply the chosen slot here.
|
||||
fun learn(known: MutableList<PokemonMove>, dexId: Int, fromLevel: Int, toLevel: Int) = buildList {
|
||||
for (level in fromLevel + 1..toLevel) {
|
||||
for (moveId in learnsets.movesAt(dexId, level)) {
|
||||
if (known.any { it.id.toInt() == moveId }) continue
|
||||
val def = moves.get(moveId) ?: continue
|
||||
val slot = known.indexOfFirst { it.id.toInt() == 0 }
|
||||
if (slot < 0 && known.size >= MAX_MOVE_SLOTS) continue
|
||||
val learned = PokemonMove(moveId.toShort(), def.pp.toByte())
|
||||
if (slot < 0) known += learned else known[slot] = learned
|
||||
add(LearnedMove(level, moveId, def.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
package de.fiereu.openmmo.server.game.battle
|
||||
|
||||
import de.fiereu.openmmo.common.MAX_MOVE_SLOTS
|
||||
import de.fiereu.openmmo.common.Pokemon
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.common.enums.EVs
|
||||
import de.fiereu.openmmo.common.enums.IVs
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.pokemon.LearnsetRegistry
|
||||
import de.fiereu.openmmo.pokemon.SpeciesRegistry
|
||||
import de.fiereu.openmmo.server.game.storage.EntityIdService
|
||||
import java.time.LocalDateTime
|
||||
@@ -22,6 +24,7 @@ class WildMonFactory
|
||||
constructor(
|
||||
private val species: SpeciesRegistry,
|
||||
private val moves: MoveRegistry,
|
||||
private val learnsets: LearnsetRegistry,
|
||||
private val entityIds: EntityIdService,
|
||||
) {
|
||||
|
||||
@@ -36,10 +39,11 @@ constructor(
|
||||
spDef = rng.ivRoll()
|
||||
spd = rng.ivRoll()
|
||||
}
|
||||
// TODO Give wild monsters their real level up moveset
|
||||
// Parse level_up_learnsets.h in a new codegen generator, use it here for wild movesets and
|
||||
// for learning moves on level up, and capture the client's move learn prompt packets.
|
||||
val tacklePp = (moves.get(TACKLE_ID)?.pp ?: FALLBACK_PP).toByte()
|
||||
// Species without a learnset fall back to Tackle so the monster can still attack.
|
||||
val moveIds = learnsets.initialMoveset(dexId, level).ifEmpty { listOf(TACKLE_ID) }
|
||||
val moveset =
|
||||
moveIds.map { PokemonMove(it.toShort(), (moves.get(it)?.pp ?: FALLBACK_PP).toByte()) } +
|
||||
List(MAX_MOVE_SLOTS - moveIds.size) { PokemonMove(0, 0) }
|
||||
val mon =
|
||||
Pokemon(
|
||||
id = entityIds.newMonsterId(),
|
||||
@@ -55,13 +59,7 @@ constructor(
|
||||
xp = ExpCurves.totalXpFor(def.growthRate, level),
|
||||
eVs = EVs(),
|
||||
iVs = ivs,
|
||||
moves =
|
||||
listOf(
|
||||
PokemonMove(TACKLE_ID.toShort(), tacklePp),
|
||||
PokemonMove(0, 0),
|
||||
PokemonMove(0, 0),
|
||||
PokemonMove(0, 0),
|
||||
),
|
||||
moves = moveset,
|
||||
isShiny = false,
|
||||
hasHiddenAbility = false,
|
||||
isAlpha = false,
|
||||
|
||||
@@ -20,6 +20,7 @@ import de.fiereu.openmmo.server.game.battle.BattleRegistry
|
||||
import de.fiereu.openmmo.server.game.battle.BattleResult
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRewards
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRng
|
||||
import de.fiereu.openmmo.server.game.battle.MoveLearner
|
||||
import de.fiereu.openmmo.server.game.battle.StatCalculator
|
||||
import de.fiereu.openmmo.server.game.battle.TurnEngine
|
||||
import de.fiereu.openmmo.server.game.battle.WildMonFactory
|
||||
@@ -61,6 +62,7 @@ constructor(
|
||||
private val wildMons: WildMonFactory,
|
||||
private val emitter: BattlePacketEmitter,
|
||||
private val rewards: BattleRewards,
|
||||
private val moveLearner: MoveLearner,
|
||||
private val interestManager: InterestManager,
|
||||
private val speciesRegistry: SpeciesRegistry,
|
||||
private val moveRegistry: MoveRegistry,
|
||||
@@ -326,7 +328,12 @@ constructor(
|
||||
"char=${battle.charId} won: +${reward.xpGained} xp, level ${winner.level} -> ${reward.newLevel}"
|
||||
}
|
||||
winner.currentHp = reward.newCurrentHp
|
||||
val learned =
|
||||
moveLearner.learn(winner.moves, winner.source.dexId, winner.level, reward.newLevel)
|
||||
emitter.sendVictoryDelta(battle, winner.entityId, reward)
|
||||
for (move in learned) {
|
||||
emitter.sendNotice(battle, "${winner.species.name} learned ${move.name}!")
|
||||
}
|
||||
characterStore.updatePokemon(
|
||||
battle.charId,
|
||||
winner.source.copy(
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.fiereu.openmmo.server.game.battle
|
||||
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.pokemon.LearnsetRegistry
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.collections.shouldBeEmpty
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
private const val BULBASAUR = 1
|
||||
private const val TACKLE: Short = 33
|
||||
private const val GROWL: Short = 45
|
||||
private const val LEECH_SEED: Short = 73
|
||||
private const val VINE_WHIP: Short = 22
|
||||
private const val POISON_POWDER: Short = 77
|
||||
|
||||
private fun slots(vararg ids: Short) = ids.map { PokemonMove(it, 0) }.toMutableList()
|
||||
|
||||
class MoveLearnerTest :
|
||||
FunSpec({
|
||||
val moves = MoveRegistry()
|
||||
val learner = MoveLearner(LearnsetRegistry(), moves)
|
||||
|
||||
test("a move learned at the new level goes into a free slot") {
|
||||
val known = slots(TACKLE, 0, 0, 0)
|
||||
val learned = learner.learn(known, BULBASAUR, 3, 4)
|
||||
learned.map { it.moveId } shouldBe listOf(GROWL.toInt())
|
||||
known.map { it.id } shouldBe listOf(TACKLE, GROWL, 0, 0)
|
||||
}
|
||||
|
||||
test("the new move gets its registry pp") {
|
||||
val known = slots(TACKLE, 0, 0, 0)
|
||||
learner.learn(known, BULBASAUR, 3, 4)
|
||||
known[1].pp shouldBe moves.get(GROWL.toInt())!!.pp.toByte()
|
||||
}
|
||||
|
||||
test("skipping levels learns every move in between") {
|
||||
val known = slots(TACKLE, 0, 0, 0)
|
||||
val learned = learner.learn(known, BULBASAUR, 1, 10)
|
||||
learned.map { it.moveId.toShort() } shouldBe listOf(GROWL, LEECH_SEED, VINE_WHIP)
|
||||
known.map { it.id } shouldBe listOf(TACKLE, GROWL, LEECH_SEED, VINE_WHIP)
|
||||
}
|
||||
|
||||
test("a full moveset keeps its moves") {
|
||||
val known = slots(TACKLE, GROWL, LEECH_SEED, VINE_WHIP)
|
||||
learner.learn(known, BULBASAUR, 14, 15).shouldBeEmpty()
|
||||
known.map { it.id } shouldBe listOf(TACKLE, GROWL, LEECH_SEED, VINE_WHIP)
|
||||
}
|
||||
|
||||
// Bulbasaur learns Poison Powder and Sleep Powder at 15, only the first one fits.
|
||||
test("a partly full moveset learns until it runs out of slots") {
|
||||
val known = slots(TACKLE, GROWL, LEECH_SEED, 0)
|
||||
val learned = learner.learn(known, BULBASAUR, 14, 15)
|
||||
learned.map { it.moveId.toShort() } shouldBe listOf(POISON_POWDER)
|
||||
known.map { it.id } shouldBe listOf(TACKLE, GROWL, LEECH_SEED, POISON_POWDER)
|
||||
}
|
||||
|
||||
test("a known move is not learned twice") {
|
||||
val known = slots(GROWL, 0, 0, 0)
|
||||
learner.learn(known, BULBASAUR, 3, 4).shouldBeEmpty()
|
||||
known.map { it.id } shouldBe listOf(GROWL, 0, 0, 0)
|
||||
}
|
||||
|
||||
test("no level up learns nothing") {
|
||||
val known = slots(TACKLE, 0, 0, 0)
|
||||
learner.learn(known, BULBASAUR, 5, 5).shouldBeEmpty()
|
||||
}
|
||||
|
||||
test("an unknown species learns nothing") {
|
||||
val known = slots(TACKLE, 0, 0, 0)
|
||||
learner.learn(known, 9999, 1, 100).shouldBeEmpty()
|
||||
}
|
||||
|
||||
test("a moveset shorter than four slots grows") {
|
||||
val known = slots(TACKLE)
|
||||
learner.learn(known, BULBASAUR, 3, 4)
|
||||
known.map { it.id } shouldBe listOf(TACKLE, GROWL)
|
||||
}
|
||||
})
|
||||
+12
-4
@@ -1,6 +1,7 @@
|
||||
package de.fiereu.openmmo.server.game.battle
|
||||
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.pokemon.LearnsetRegistry
|
||||
import de.fiereu.openmmo.pokemon.SpeciesRegistry
|
||||
import de.fiereu.openmmo.server.game.storage.EntityIdService
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
@@ -11,7 +12,8 @@ import io.kotest.matchers.shouldBe
|
||||
|
||||
class WildMonFactoryTest :
|
||||
FunSpec({
|
||||
val factory = WildMonFactory(SpeciesRegistry(), MoveRegistry(), EntityIdService())
|
||||
val factory =
|
||||
WildMonFactory(SpeciesRegistry(), MoveRegistry(), LearnsetRegistry(), EntityIdService())
|
||||
|
||||
test("the same seed rolls the same monster") {
|
||||
val a = factory.create(19, 3, BattleRng(seed = 42))!!
|
||||
@@ -31,11 +33,17 @@ class WildMonFactoryTest :
|
||||
}
|
||||
}
|
||||
|
||||
test("the moveset is Tackle with its registry pp") {
|
||||
test("the moveset is the level up moveset with registry pp") {
|
||||
// Bulbasaur knows Tackle at level 1 and Growl at level 4.
|
||||
val mon = factory.create(1, 5, BattleRng(seed = 7))!!
|
||||
mon.moves[0].id shouldBe 33.toShort()
|
||||
mon.moves.map { it.id.toInt() } shouldBe listOf(33, 45, 0, 0)
|
||||
mon.moves[0].pp shouldBe MoveRegistry().get(33)!!.pp.toByte()
|
||||
mon.moves.drop(1).all { it.id == 0.toShort() } shouldBe true
|
||||
mon.moves[1].pp shouldBe MoveRegistry().get(45)!!.pp.toByte()
|
||||
}
|
||||
|
||||
test("a high level monster keeps only the last four moves") {
|
||||
val mon = factory.create(1, 100, BattleRng(seed = 7))!!
|
||||
mon.moves.map { it.id.toInt() } shouldBe listOf(230, 74, 235, 76)
|
||||
}
|
||||
|
||||
test("xp matches the species growth curve at the rolled level") {
|
||||
|
||||
+6
-1
@@ -21,10 +21,12 @@ import de.fiereu.openmmo.net.game.packets.battle.BattleFieldStatePacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleQueuedEventPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleSidePacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleTileMapPacket
|
||||
import de.fiereu.openmmo.pokemon.LearnsetRegistry
|
||||
import de.fiereu.openmmo.pokemon.SpeciesRegistry
|
||||
import de.fiereu.openmmo.server.game.battle.BattlePacketEmitter
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRegistry
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRewards
|
||||
import de.fiereu.openmmo.server.game.battle.MoveLearner
|
||||
import de.fiereu.openmmo.server.game.battle.TurnEngine
|
||||
import de.fiereu.openmmo.server.game.battle.WildMonFactory
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
@@ -84,9 +86,12 @@ private class Fixture(scope: CoroutineScope) {
|
||||
characterStore = store,
|
||||
battles = registry,
|
||||
engine = TurnEngine(MoveRegistry(), TypeChart()),
|
||||
wildMons = WildMonFactory(SpeciesRegistry(), MoveRegistry(), EntityIdService()),
|
||||
wildMons =
|
||||
WildMonFactory(
|
||||
SpeciesRegistry(), MoveRegistry(), LearnsetRegistry(), EntityIdService()),
|
||||
emitter = BattlePacketEmitter(interestManager),
|
||||
rewards = BattleRewards(),
|
||||
moveLearner = MoveLearner(LearnsetRegistry(), MoveRegistry()),
|
||||
interestManager = interestManager,
|
||||
speciesRegistry = SpeciesRegistry(),
|
||||
moveRegistry = MoveRegistry(),
|
||||
|
||||
Reference in new issue
Block a user