feat(game): fight the decomp trainers for experience and prize money (#122)
* fix(protocol): decode the trainer form of the battle field state * refactor(game): model the battle opponent as a party instead of one monster * feat(game): let a script fight one of the decomp trainers * fix(protocol): stop writing moves the opposing side's battle block leaves out * feat(game): pay experience and prize money for a won trainer battle * fix(game): send battle outcomes the way the client reads them * fix(game): correct the reward and stat change defects the review found * chore(game): tidy the battle comments * fix(game): send real party slots on a switch and handle a double faint
This commit is contained in:
1 parent
299886ae19
commit
abce0d6eb4
28 files changed
+878
-167
No files matched your search
@@ -14,5 +14,6 @@ data class ParsedTrainer(
|
||||
val name: String,
|
||||
val trainerClass: Int,
|
||||
val doubleBattle: Boolean,
|
||||
val prizeRate: Int,
|
||||
val party: List<ParsedTrainerMon>,
|
||||
)
|
||||
@@ -5,7 +5,7 @@ object RenderUtil {
|
||||
fun trainer(region: String, t: ParsedTrainer): String {
|
||||
val party = t.party.joinToString(", ", "listOf(", ")") { mon(it) }
|
||||
return "reg.register(Region.${region.uppercase()}, TrainerDef(${t.id}, \"${escape(t.name)}\", " +
|
||||
"${t.trainerClass}, ${t.doubleBattle}, $party))"
|
||||
"${t.trainerClass}, ${t.doubleBattle}, ${t.prizeRate}, $party))"
|
||||
}
|
||||
|
||||
private fun mon(m: ParsedTrainerMon): String {
|
||||
|
||||
@@ -18,6 +18,7 @@ class TrainerParser(private val rootDir: File) {
|
||||
|
||||
fun parseAll(): List<ParsedTrainer> {
|
||||
val parties = readParties()
|
||||
val (prizeRates, defaultPrizeRate) = readPrizeRates()
|
||||
return readTrainers()
|
||||
.mapNotNull { entry ->
|
||||
val id = trainerIds[entry.constant]
|
||||
@@ -37,6 +38,7 @@ class TrainerParser(private val rootDir: File) {
|
||||
name = entry.name,
|
||||
trainerClass = classIds[entry.trainerClass] ?: 0,
|
||||
doubleBattle = entry.doubleBattle,
|
||||
prizeRate = prizeRates[entry.trainerClass] ?: defaultPrizeRate,
|
||||
party = party,
|
||||
)
|
||||
}
|
||||
@@ -103,6 +105,18 @@ class TrainerParser(private val rootDir: File) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gTrainerMoneyTable, which pays a trainer class this much per level of its last monster. The
|
||||
* table ends with a 0xFF row that every class it does not list falls through to.
|
||||
*/
|
||||
private fun readPrizeRates(): Pair<Map<String, Int>, Int> {
|
||||
val table = MONEY_TABLE.find(read("src/battle_main.c"))?.groupValues?.get(1).orEmpty()
|
||||
val byClass =
|
||||
MONEY_ENTRY.findAll(table).associate { it.groupValues[1] to it.groupValues[2].toInt() }
|
||||
val fallback = MONEY_FALLBACK.find(table)?.groupValues?.get(1)?.toInt() ?: 0
|
||||
return byClass to fallback
|
||||
}
|
||||
|
||||
private fun fields(body: String): Map<String, String> =
|
||||
FIELD.findAll(body).associate { it.groupValues[1] to it.groupValues[2].trim() }
|
||||
|
||||
@@ -133,5 +147,9 @@ class TrainerParser(private val rootDir: File) {
|
||||
val MEMBER = Regex("""\{((?:[^{}]|\{[^{}]*})*)}""", RegexOption.DOT_MATCHES_ALL)
|
||||
val FIELD = Regex("""\.(\w+)\s*=\s*(\{[^}]*}|[^,}]+)""")
|
||||
val MOVE = Regex("""MOVE_\w+""")
|
||||
val MONEY_TABLE =
|
||||
Regex("""gTrainerMoneyTable\[]\s*=\s*\{(.*?)};""", RegexOption.DOT_MATCHES_ALL)
|
||||
val MONEY_ENTRY = Regex("""\{\s*(TRAINER_CLASS_\w+)\s*,\s*(\d+)\s*}""")
|
||||
val MONEY_FALLBACK = Regex("""\{\s*0xFF\s*,\s*(\d+)\s*}""")
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ data class TrainerDef(
|
||||
val name: String,
|
||||
val trainerClass: Int,
|
||||
val doubleBattle: Boolean,
|
||||
/** What the class pays per level of its last monster. */
|
||||
val prizeRate: Int,
|
||||
val party: List<TrainerMon>,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user