feat(game): implement the Kanto story from Pallet Town through the Pokedex (#127)

* feat(game): implement Kanto story through the Pokedex

* fix(game): stop the rival walking into the player in the pokedex scene

* fix(game): stop oak teleporting to his desk in the starter scene

* fix(game): make a scripted warp arrive the way a walked one does

* fix(game): finish the oaks lab rival scene whether the player wins or loses

* chore(game): tidy the kanto script and item codegen comments

* docs: point the script guides at MapEntryScripts and trainerBattle

* fix(codegen): send item ids in the region whose table matches the decomp
This commit is contained in:
Fiereu authored and GitHub committed 2026-08-09 10:45:24 +02:00
1 parent 70c746fdc6
commit 9215a0862a
35 files changed
+1311 -508

No files matched your search

+10
View File
@@ -41,6 +41,16 @@ jteCodegen {
"$region|${rootProject.layout.projectDirectory.dir("decomp/$decomp").asFile.absolutePath}" "$region|${rootProject.layout.projectDirectory.dir("decomp/$decomp").asFile.absolutePath}"
}) })
} }
// Item ids scripts hand to giveItem. Both GBA games number items the same, so one decomp is
// enough, like moves and species. The client holds one item table per region, so the region
// decides what a number means. Checked against a real client: region 0 reads 3, 4 and 13 as
// Great Ball, Poke Ball and Potion, matching the decomp, while region 1 and region 5 read the
// same numbers as unrelated items.
register("item") {
mainClass.set("de.fiereu.openmmo.codegen.item.Main")
inputDirs.from(sourceDecompDir)
extraArgs.set(listOf("kanto|${sourceDecompDir.asFile.absolutePath}"))
}
register("moves") { register("moves") {
mainClass.set("de.fiereu.openmmo.codegen.move.Main") mainClass.set("de.fiereu.openmmo.codegen.move.Main")
templatesSubdir.set("move") templatesSubdir.set("move")
+15
View File
@@ -0,0 +1,15 @@
@import java.util.List
@import de.fiereu.openmmo.codegen.item.ParsedItem
@param List<ParsedItem> items
package de.fiereu.openmmo.items.generated
/**
* Item ids the client uses, already carrying the region prefix of the decomp they were read from.
* Generated from the GBA decomp item header, do not edit by hand.
*/
object Items {
@for(ParsedItem item : items)
const val ${item.getName()} = ${item.getId()}
@endfor
}
@@ -13,7 +13,14 @@ class TextParser(private val decompDir: File) {
private val labelLine = Regex("^(\\w+):+\\s*$") private val labelLine = Regex("^(\\w+):+\\s*$")
fun parseAll(): List<DecompText> { fun parseAll(): List<DecompText> {
val roots = listOf(File(decompDir, "data/maps"), File(decompDir, "data/scripts")) // Emerald keeps its shared text next to the scripts that use it, FireRed keeps it in its own
// data/text folder. Reading all three roots covers both.
val roots =
listOf(
File(decompDir, "data/maps"),
File(decompDir, "data/scripts"),
File(decompDir, "data/text"),
)
val out = LinkedHashMap<String, String>() val out = LinkedHashMap<String, String>()
for (root in roots) { for (root in roots) {
if (!root.isDirectory) continue if (!root.isDirectory) continue
@@ -0,0 +1,30 @@
package de.fiereu.openmmo.codegen.item
import java.io.File
/**
* Reads the item constants out of a GBA decomp header. The two GBA decomps use the same item
* numbering, so one decomp is the single source of truth, the same way moves and species are.
*
* The client keys an item by `regionId * 1000 + itemId` and holds one item table per region.
* [regionId] picks the table that matches the decomp's own numbering, which leaves the Poke Ball at
* its decomp 4.
*/
class ItemParser(private val decompDir: File, private val regionId: Int) {
fun parseAll(): List<ParsedItem> {
val header = File(decompDir, "include/constants/items.h")
require(header.exists()) { "Missing ${header.path}" }
val define = Regex("""^#define\s+ITEM_([A-Z0-9_]+)\s+(\d+)\s*$""")
// ITEMS_COUNT closes the item list. Everything after it reuses the ITEM_ prefix for unrelated
// constants like the bag usage types, so parsing stops there.
return header
.readLines()
.takeWhile { !it.trimStart().startsWith("#define ITEMS_COUNT") }
.mapNotNull { define.find(it.trim()) }
.map { ParsedItem(it.groupValues[1], regionId * 1000 + it.groupValues[2].toInt()) }
// Placeholder slots are named after their hex index, for example ITEM_15C.
.filterNot { it.name.first().isDigit() }
.distinctBy(ParsedItem::name)
}
}
@@ -0,0 +1,36 @@
package de.fiereu.openmmo.codegen.item
import gg.jte.ContentType
import gg.jte.TemplateEngine
import gg.jte.output.FileOutput
import gg.jte.resolve.DirectoryCodeResolver
import java.io.File
class ItemsRenderer(
private val templatesDir: File,
private val outputDir: File,
private val classCacheDir: File,
) {
fun render(items: List<ParsedItem>) {
classCacheDir.mkdirs()
val engine =
TemplateEngine.create(
DirectoryCodeResolver(templatesDir.toPath()),
classCacheDir.toPath(),
ContentType.Plain,
)
val packageRoot = File(outputDir, BASE_PACKAGE.replace('.', '/'))
if (packageRoot.exists()) packageRoot.deleteRecursively()
packageRoot.mkdirs()
FileOutput(File(packageRoot, "Items.kt").toPath()).use { out ->
engine.render("Items.jte", mapOf("items" to items), out)
}
}
private companion object {
const val BASE_PACKAGE = "de.fiereu.openmmo.items.generated"
}
}
@@ -0,0 +1,24 @@
@file:JvmName("Main")
package de.fiereu.openmmo.codegen.item
import de.fiereu.openmmo.common.enums.Region
import java.io.File
fun main(args: Array<String>) {
require(args.size >= 4) {
"Usage: <output-dir> <templates-dir> <class-cache-dir> <region|decomp> got ${args.toList()}"
}
val outputDir = File(args[0])
val templatesDir = File(args[1])
val classCacheDir = File(args[2])
val (region, decomp) = args[3].split("|")
val decompDir = File(decomp)
val regionId = Region.valueOf(region.uppercase()).wireValue.toInt()
println("[item] parsing $region items from $decompDir")
val items = ItemParser(decompDir, regionId).parseAll()
println("[item] parsed ${items.size} items. writing to $outputDir")
ItemsRenderer(templatesDir, outputDir, classCacheDir).render(items)
println("[item] done")
}
@@ -0,0 +1,4 @@
package de.fiereu.openmmo.codegen.item
/** One item constant: the decomp name without its ITEM_ prefix and the id the client uses. */
data class ParsedItem(val name: String, val id: Int)
@@ -308,8 +308,9 @@ class PretGbaParser(
.find(text) .find(text)
?.groupValues ?.groupValues
?.get(1) ?: return emptyList() ?.get(1) ?: return emptyList()
// Emerald writes the table label with one colon, FireRed with two.
val block = val block =
Regex("""(?m)^$tableLabel:\s*\n(.*?)(?=\n\s*\.2byte)""", RegexOption.DOT_MATCHES_ALL) Regex("""(?m)^$tableLabel:+[^\n]*\n(.*?)(?=\n\s*\.2byte)""", RegexOption.DOT_MATCHES_ALL)
.find(text) .find(text)
?.groupValues ?.groupValues
?.get(1) ?: return emptyList() ?.get(1) ?: return emptyList()
@@ -18,32 +18,27 @@ object FlagVarParser {
fun vars(decompDir: File): List<StoryConstant> = fun vars(decompDir: File): List<StoryConstant> =
constants(decompDir, "include/constants/vars.h", "VAR_") constants(decompDir, "include/constants/vars.h", "VAR_")
/** Emerald new-game reset flags. */ /** Flags the source game's new-game reset sets. */
fun initialFlags(decompDir: File): List<String> = fun initialFlags(decompDir: File): List<String> =
scriptFlags( scriptFlags(decompDir, "EventScript_ResetAllMapFlags")
decompDir,
"data/scripts/new_game.inc",
"EventScript_ResetAllMapFlags",
)
/** Gender-specific flags normally established by InsideOfTruck's intro script. */ /**
* Gender-specific flags the source game establishes during its intro. Emerald sets them in the
* moving truck. A game without such a script contributes nothing.
*/
fun maleIntroFlags(decompDir: File): List<String> = fun maleIntroFlags(decompDir: File): List<String> =
scriptFlags( scriptFlags(decompDir, "InsideOfTruck_EventScript_SetIntroFlagsMale")
decompDir,
"data/maps/InsideOfTruck/scripts.inc",
"InsideOfTruck_EventScript_SetIntroFlagsMale",
)
fun femaleIntroFlags(decompDir: File): List<String> = fun femaleIntroFlags(decompDir: File): List<String> =
scriptFlags( scriptFlags(decompDir, "InsideOfTruck_EventScript_SetIntroFlagsFemale")
decompDir,
"data/maps/InsideOfTruck/scripts.inc",
"InsideOfTruck_EventScript_SetIntroFlagsFemale",
)
private fun scriptFlags(decompDir: File, relativePath: String, label: String): List<String> { /**
val file = File(decompDir, relativePath) * The flags one decomp script sets, found by its label. Each game keeps these scripts in a
if (!file.exists()) return emptyList() * different file (Emerald in data/scripts/new_game.inc, FireRed in data/event_scripts.s), so the
* label is looked up across the data folder instead of at a fixed path.
*/
private fun scriptFlags(decompDir: File, label: String): List<String> {
val file = findScriptFile(decompDir, label) ?: return emptyList()
val result = mutableListOf<String>() val result = mutableListOf<String>()
var inBlock = false var inBlock = false
for (rawLine in file.readLines()) { for (rawLine in file.readLines()) {
@@ -63,6 +58,15 @@ object FlagVarParser {
return result.distinct() return result.distinct()
} }
private fun findScriptFile(decompDir: File, label: String): File? {
val definition = "$label::"
return File(decompDir, "data")
.walkTopDown()
.filter { it.isFile && it.extension in SCRIPT_EXTENSIONS }
.sortedBy(File::getPath)
.firstOrNull { file -> file.useLines { lines -> lines.any { it.trim() == definition } } }
}
private fun constants( private fun constants(
decompDir: File, decompDir: File,
relativePath: String, relativePath: String,
@@ -309,4 +313,6 @@ object FlagVarParser {
private fun parseNumber(value: String): Int = private fun parseNumber(value: String): Int =
if (value.startsWith("0x", ignoreCase = true)) value.drop(2).toInt(16) else value.toInt() if (value.startsWith("0x", ignoreCase = true)) value.drop(2).toInt(16) else value.toInt()
private val SCRIPT_EXTENSIONS = setOf("inc", "s")
} }
@@ -0,0 +1,41 @@
package de.fiereu.openmmo.codegen.item
import de.fiereu.openmmo.common.enums.Region
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
class ItemParserTest :
FunSpec({
test("prefixes decomp item ids with their region and stops at the list end") {
val decomp = kotlin.io.path.createTempDirectory("items").toFile()
decomp.resolve("include/constants").mkdirs()
decomp
.resolve("include/constants/items.h")
.writeText(
"""
#define ITEM_NONE 0
#define ITEM_GREAT_BALL 3
#define ITEM_POKE_BALL 4
#define ITEM_15C 348
#define ITEM_LIST_END 0xFFFF
#define ITEMS_COUNT 377
#define ITEM_USE_MAIL 0
#define ITEM_HAS_EFFECT(item) ((item) >= ITEM_POTION)
"""
.trimIndent())
ItemParser(decomp, Region.KANTO.wireValue.toInt()).parseAll() shouldBe
listOf(
ParsedItem("NONE", 0),
ParsedItem("GREAT_BALL", 3),
ParsedItem("POKE_BALL", 4),
)
ItemParser(decomp, Region.HOENN.wireValue.toInt()).parseAll() shouldBe
listOf(
ParsedItem("NONE", 1000),
ParsedItem("GREAT_BALL", 1003),
ParsedItem("POKE_BALL", 1004),
)
}
})
@@ -76,4 +76,23 @@ class FlagVarParserTest :
FlagVarParser.maleIntroFlags(decomp) shouldBe listOf("FLAG_MALE") FlagVarParser.maleIntroFlags(decomp) shouldBe listOf("FLAG_MALE")
FlagVarParser.femaleIntroFlags(decomp) shouldBe listOf("FLAG_FEMALE") FlagVarParser.femaleIntroFlags(decomp) shouldBe listOf("FLAG_FEMALE")
} }
// FireRed keeps the reset script in data/event_scripts.s and has no moving truck intro.
test("finds the reset script wherever the decomp keeps it") {
val decomp = kotlin.io.path.createTempDirectory("story-script-flags-alt").toFile()
decomp.resolve("data").mkdirs()
decomp
.resolve("data/event_scripts.s")
.writeText(
"""
EventScript_ResetAllMapFlags::
setflag FLAG_HIDE_OAK_IN_HIS_LAB
setvar VAR_SOMETHING, 500
end
"""
.trimIndent())
FlagVarParser.initialFlags(decomp) shouldBe listOf("FLAG_HIDE_OAK_IN_HIS_LAB")
FlagVarParser.maleIntroFlags(decomp) shouldBe emptyList()
}
}) })
+6 -2
View File
@@ -85,8 +85,8 @@ Scripts triggered this way get `entityId = -1`.
### Entering a map ### Entering a map
`MapScriptService.onMapEnter` runs on every entry, however the player got there: `MapScriptService.onMapEnter` runs on every entry, however the player got there:
login, a warp, or walking across a map connection. It builds a list of up to two login, a warp, or walking across a map connection. `MapEntryScripts.onEntry`
scripts and runs them in order: builds the list and `MapScriptService` runs it in order:
1. `map.onTransitionScript`, unconditionally. 1. `map.onTransitionScript`, unconditionally.
2. The **first** entry in `map.onFrameScripts` whose story var currently equals 2. The **first** entry in `map.onFrameScripts` whose story var currently equals
@@ -94,6 +94,10 @@ scripts and runs them in order:
Both go through `ScriptRunner.runAll` on one coroutine, so an on-transition Both go through `ScriptRunner.runAll` on one coroutine, so an on-transition
script and the cutscene it enables share a single dialog lock instead of racing. script and the cutscene it enables share a single dialog lock instead of racing.
A script that warps is the exception: `ctx.warp` runs the destination map's
entry scripts inline on the coroutine it is already on, the way the decomp's
warp continues into the destination's scripts, rather than starting a new one.
The conditional `ON_WARP` table is not wired up yet. The conditional `ON_WARP` table is not wired up yet.
## Why scripts are coroutines ## Why scripts are coroutines
@@ -100,7 +100,7 @@ value it already has, is a no-op and does not dirty the character.
## Reading story state outside a script ## Reading story state outside a script
`MapScriptService` reads vars directly to pick which `ON_FRAME` script to run on `MapEntryScripts` reads vars directly to pick which `ON_FRAME` script to run on
map entry, comparing `storyService.getVar(charId, it.varKey)` against each map entry, comparing `storyService.getVar(charId, it.varKey)` against each
entry's value. Any other service can do the same: inject `StoryService` and pass entry's value. Any other service can do the same: inject `StoryService` and pass
the character id. `ScriptContext` is only a convenience wrapper for the common the character id. `ScriptContext` is only a convenience wrapper for the common
+29 -14
View File
@@ -56,9 +56,28 @@ end of your function.
| `goto_if_ne VAR_X, n, Label` | `if (ctx.getVar(HoennVars.VAR_X) != n) { ... }` | | `goto_if_ne VAR_X, n, Label` | `if (ctx.getVar(HoennVars.VAR_X) != n) { ... }` |
| `applymovement id, M` + `waitmovement 0` | `ctx.moveNpc(LOCALID_X, WALK_UP, ...)` | | `applymovement id, M` + `waitmovement 0` | `ctx.moveNpc(LOCALID_X, WALK_UP, ...)` |
| `applymovement OBJ_EVENT_ID_PLAYER, M` + `waitmovement 0` | `ctx.moveSelf(WALK_UP, ...)` | | `applymovement OBJ_EVENT_ID_PLAYER, M` + `waitmovement 0` | `ctx.moveSelf(WALK_UP, ...)` |
| Two `applymovement` lines then one `waitmovement 0` | `ctx.moveSelfAndNpcs(selfSteps, LOCALID_X to steps)` |
| `addobject id` | `ctx.showNpc(LOCALID_X)` | | `addobject id` | `ctx.showNpc(LOCALID_X)` |
| `setobjectxyperm id, x, y` | `ctx.repositionNpc(LOCALID_X, x, y)` |
| `removeobject id` | `ctx.removeNpc(LOCALID_X)` |
| `msgbox TEXT, MSGBOX_YESNO` + `goto_if_eq VAR_RESULT, YES` | `if (ctx.askYesNo(Map.Text)) { ... }` |
| `givemon SPECIES, level` | `ctx.givePokemon(dexId, level, ...moveIds)` |
| `giveitem`, `additem` / `removeitem` | `ctx.giveItem(Items.X, n)` / `ctx.takeItem(Items.X, n)` |
| `special HealPlayerParty` | `ctx.healParty()` |
| `warp MAP, x, y` | `ctx.warp(region, bank, map, x, y, facing)` |
| `setdynamicwarp ...` | `ctx.setDynamicWarp(region, bank, map, x, y, facing)` | | `setdynamicwarp ...` | `ctx.setDynamicWarp(region, bank, map, x, y, facing)` |
Item ids come from the generated `Items` object, never a raw number:
`ctx.giveItem(Items.POKE_BALL, 5)`. It is generated from the decomp item header,
so every item the games know about is in it. The client keys an item by
`regionId * 1000 + itemId` and holds one item table per region, so the ids in
`Items` sit in the region whose table matches the decomp numbering. Sending the
same number under another region reaches a different item entirely.
`ctx.warp` continues into the destination map's ON_TRANSITION and ON_FRAME
scripts on the same coroutine, exactly the way the decomp's `warp` does, so a
cutscene that walks the player into a building keeps running on the other side.
`ctx.say` and `ctx.sign` both **wait** for the player to close the box, so `ctx.say` and `ctx.sign` both **wait** for the player to close the box, so
consecutive calls show consecutive boxes with no extra plumbing. `moveNpc` and consecutive calls show consecutive boxes with no extra plumbing. `moveNpc` and
`moveSelf` likewise cover `applymovement` *and* its following `waitmovement`, so `moveSelf` likewise cover `applymovement` *and* its following `waitmovement`, so
@@ -116,22 +135,18 @@ private const val LOCALID_MOM = 3
There is no verb for these. Do not fake them: There is no verb for these. Do not fake them:
- **Choices.** `MSGBOX_YESNO`, `multichoice` and anything reading `VAR_RESULT` - **More than two answers.** `multichoice`. Yes/no works, a longer menu does not.
from a prompt. `DialogService` can see a choice packet come back, but
`ScriptContext` has no way to ask a question and branch on the answer.
- **Doors.** `opendoor`, `closedoor`, `waitdooranim`. - **Doors.** `opendoor`, `closedoor`, `waitdooranim`.
- **Warping from a script.** `warp`, `warpsilent`, `warphole`. Only - **Shops.** `pokemart` and its item list.
`setDynamicWarp`, which changes where an existing `MAP_DYNAMIC` warp tile - **Hiding the player.** `hideplayer`/`showplayer`. Npcs can be hidden with
sends the player, exists. `removeNpc` or by ending a movement with `SET_INVISIBLE`, the player cannot.
- **Hiding things.** `hideobjectat`, `hideplayer`/`showplayer`. `showNpc` exists, - **Money.** Buying and selling.
its inverse does not, beyond ending a movement with `SET_INVISIBLE`. - **Temporary state.** `VAR_TEMP_*` and `FLAG_TEMP_*` reset when the player
- **Items, money, party.** `giveitem`, `takeitem`, `checkitemspace`, leaves the map in the source game. Story flags and vars here are persistent,
`givemon`, `addvar` on money, and so on. so a script that leans on a temp value needs another way to say the same thing.
- **Battles.** `trainerbattle` in all its forms.
- **Player identity.** `checkplayergender`, and the `VAR_RESULT` branch that
usually follows it.
- **Presentation.** `playse`, `playfanfare`, `waitfanfare`, `fadescreen`, - **Presentation.** `playse`, `playfanfare`, `waitfanfare`, `fadescreen`,
`delay`, and `special` calls into engine C code generally. `delay`, `showmonpic`, emotes like the exclamation mark, and `special` calls
into engine C code generally.
When a script needs one of these, port the part you can and leave a scoped `TODO` When a script needs one of these, port the part you can and leave a scoped `TODO`
comment naming what is missing, the way the Littleroot intro does: comment naming what is missing, the way the Littleroot intro does:
@@ -74,17 +74,26 @@ Everything goes through `ctx`, the `ScriptContext`:
| Call | What it does | | Call | What it does |
| --- | --- | | --- | --- |
| `ctx.say(line)` | An npc box from the entity the player talked to. Waits. | | `ctx.say(line)` | An npc box from the entity the player talked to. Waits. |
| `ctx.sayNpc(localId, line)` | A box from a cutscene npc that the player did not talk to. Waits. |
| `ctx.sign(line)` | A sign or object box, no speaker. Waits. | | `ctx.sign(line)` | A sign or object box, no speaker. Waits. |
| `ctx.askYesNo(line)` / `ctx.askYesNoNpc(localId, line)` | A yes/no box. Waits and returns the answer. |
| `ctx.isFlagSet(f)` / `ctx.setFlag(f)` / `ctx.clearFlag(f)` | Read and write a story flag. | | `ctx.isFlagSet(f)` / `ctx.setFlag(f)` / `ctx.clearFlag(f)` | Read and write a story flag. |
| `ctx.getVar(k)` / `ctx.setVar(k, n)` | Read and write a story var. | | `ctx.getVar(k)` / `ctx.setVar(k, n)` | Read and write a story var. |
| `ctx.moveNpc(localId, ...steps)` | Walk a map npc through a path. Waits for it to finish. | | `ctx.moveNpc(localId, ...steps)` | Walk a map npc through a path. Waits for it to finish. |
| `ctx.moveSelf(...steps)` | Walk the player's own avatar. Waits. | | `ctx.moveSelf(...steps)` | Walk the player's own avatar. Waits. |
| `ctx.showNpc(localId)` | Reveal a normally hidden npc for a cutscene. | | `ctx.moveSelfAndNpcs(selfSteps, ...paths)` | Walk the player and npcs together. Waits for all of them. |
| `ctx.showNpc(localId)` / `ctx.showNpcAt(localId, x, y)` | Reveal a normally hidden npc for a cutscene. |
| `ctx.repositionNpc(localId, x, y)` / `ctx.removeNpc(localId)` | Move or delete an npc for this player. |
| `ctx.givePokemon(dexId, level, ...moveIds)` / `ctx.healParty()` | Party changes. |
| `ctx.giveItem(itemId, n)` / `ctx.takeItem(itemId, n)` | Bag changes. Ids come from the generated `Items`. |
| `ctx.battle(dexId, level, ...moveIds)` | A story battle against one monster. Waits and returns the result. |
| `ctx.trainerBattle(trainerId)` | A decomp trainer and its whole party, in the region the player is standing in. |
| `ctx.warp(...)` | Move the player to another map, then run that map's entry scripts. |
| `ctx.setDynamicWarp(...)` | Point this player's `MAP_DYNAMIC` warp somewhere. | | `ctx.setDynamicWarp(...)` | Point this player's `MAP_DYNAMIC` warp somewhere. |
| `ctx.entityId` | The npc that was talked to, or `-1` for a sign or map script. | | `ctx.isFemale` / `ctx.facingDirection` / `ctx.entityId` | The player's gender, their facing, and the npc that was talked to (`-1` for a sign or map script). |
That is the whole api. Plenty of decomp commands have no equivalent in it yet, That is the whole api. Plenty of decomp commands still have no equivalent in it,
choices, doors, giving items, trainer battles, doors, shops and sound effects among them,
[which the porting guide lists](../porting-scripts/#commands-with-no-equivalent-yet). [which the porting guide lists](../porting-scripts/#commands-with-no-equivalent-yet).
The calls that say "waits" suspend until the player acts, so you can write boxes The calls that say "waits" suspend until the player acts, so you can write boxes
@@ -5,11 +5,13 @@ import de.fiereu.openmmo.common.DynamicWarp
import de.fiereu.openmmo.common.dialog.DialogLine import de.fiereu.openmmo.common.dialog.DialogLine
import de.fiereu.openmmo.common.enums.Direction import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.Region import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.maps.MapManager
import de.fiereu.openmmo.net.game.packets.dialog.TextPokemonSpeciesArg import de.fiereu.openmmo.net.game.packets.dialog.TextPokemonSpeciesArg
import de.fiereu.openmmo.server.game.battle.BattleResult import de.fiereu.openmmo.server.game.battle.BattleResult
import de.fiereu.openmmo.server.game.services.BattleService import de.fiereu.openmmo.server.game.services.BattleService
import de.fiereu.openmmo.server.game.services.DialogPresentation import de.fiereu.openmmo.server.game.services.DialogPresentation
import de.fiereu.openmmo.server.game.services.DialogService import de.fiereu.openmmo.server.game.services.DialogService
import de.fiereu.openmmo.server.game.services.MapEntryScripts
import de.fiereu.openmmo.server.game.services.ScriptMovementService import de.fiereu.openmmo.server.game.services.ScriptMovementService
import de.fiereu.openmmo.server.game.services.ScriptWarpService import de.fiereu.openmmo.server.game.services.ScriptWarpService
import de.fiereu.openmmo.server.game.services.StoryClientState import de.fiereu.openmmo.server.game.services.StoryClientState
@@ -32,6 +34,8 @@ internal constructor(
internal val player: StoryPlayerService? = null, internal val player: StoryPlayerService? = null,
private val battles: BattleService? = null, private val battles: BattleService? = null,
internal val characters: CharacterStore? = null, internal val characters: CharacterStore? = null,
private val maps: MapManager? = null,
private val entryScripts: MapEntryScripts? = null,
) { ) {
private val characterId: Long? private val characterId: Long?
get() = state.characterId get() = state.characterId
@@ -134,6 +138,9 @@ internal constructor(
fun giveItem(itemId: Int, quantity: Int = 1): Boolean = fun giveItem(itemId: Int, quantity: Int = 1): Boolean =
checkNotNull(player) { STORY_PLAYER_UNAVAILABLE }.giveItem(session, state, itemId, quantity) checkNotNull(player) { STORY_PLAYER_UNAVAILABLE }.giveItem(session, state, itemId, quantity)
/** Take an item back out of the bag, the decomp removeitem. False when the bag lacks it. */
fun takeItem(itemId: Int, quantity: Int = 1): Boolean = giveItem(itemId, -quantity)
/** Run a non-catchable, non-escapable story battle and wait for its result. */ /** Run a non-catchable, non-escapable story battle and wait for its result. */
suspend fun battle(dexId: Int, level: Int, vararg moveIds: Int): BattleResult = suspend fun battle(dexId: Int, level: Int, vararg moveIds: Int): BattleResult =
checkNotNull(battles) { "Battle service is unavailable" } checkNotNull(battles) { "Battle service is unavailable" }
@@ -194,21 +201,35 @@ internal constructor(
DynamicWarp( DynamicWarp(
regionId.toByte(), bankId.toByte(), mapId.toByte(), x.toShort(), y.toShort(), facing)) regionId.toByte(), bankId.toByte(), mapId.toByte(), x.toShort(), y.toShort(), facing))
/** Warps the player without door movement. */ /**
* Warps the player without door movement, then runs the destination map's entry scripts on this
* same coroutine, the way the decomp's warp continues into the new map's scripts.
*/
suspend fun warp(regionId: Int, bankId: Int, mapId: Int, x: Int, y: Int, facing: Direction) { suspend fun warp(regionId: Int, bankId: Int, mapId: Int, x: Int, y: Int, facing: Direction) {
checkNotNull(warp) { "Script warp service is unavailable" } val warpService = checkNotNull(warp) { "Script warp service is unavailable" }
.warp( state.scriptOwnsMapEntry = true
session, try {
state, warpService.warp(
DynamicWarp( session,
regionId.toByte(), state,
bankId.toByte(), DynamicWarp(
mapId.toByte(), regionId.toByte(),
x.toShort(), bankId.toByte(),
y.toShort(), mapId.toByte(),
facing, x.toShort(),
), y.toShort(),
) facing,
),
)
val destination = maps?.getMap(regionId, bankId, mapId) ?: return
val scripts = entryScripts ?: return
scripts.onEntry(state, destination).forEach { it.run(this) }
state.characterId?.let { charId ->
scripts.atCoordinate(charId, destination, state.x.toInt(), state.y.toInt())?.run(this)
}
} finally {
state.scriptOwnsMapEntry = false
}
} }
private companion object { private companion object {
@@ -1,8 +1,10 @@
package de.fiereu.openmmo.server.game.script package de.fiereu.openmmo.server.game.script
import de.fiereu.network.SessionContext import de.fiereu.network.SessionContext
import de.fiereu.openmmo.maps.MapManager
import de.fiereu.openmmo.server.game.services.BattleService import de.fiereu.openmmo.server.game.services.BattleService
import de.fiereu.openmmo.server.game.services.DialogService import de.fiereu.openmmo.server.game.services.DialogService
import de.fiereu.openmmo.server.game.services.MapEntryScripts
import de.fiereu.openmmo.server.game.services.ScriptMovementService import de.fiereu.openmmo.server.game.services.ScriptMovementService
import de.fiereu.openmmo.server.game.services.ScriptWarpService import de.fiereu.openmmo.server.game.services.ScriptWarpService
import de.fiereu.openmmo.server.game.services.StoryPlayerService import de.fiereu.openmmo.server.game.services.StoryPlayerService
@@ -38,6 +40,8 @@ constructor(
private val storyPlayerService: StoryPlayerService, private val storyPlayerService: StoryPlayerService,
private val battleService: BattleService, private val battleService: BattleService,
private val characterStore: CharacterStore, private val characterStore: CharacterStore,
private val mapManager: MapManager,
private val entryScripts: MapEntryScripts,
) { ) {
fun run(session: SessionContext, state: PlayerState, script: Script, entityId: Long) = fun run(session: SessionContext, state: PlayerState, script: Script, entityId: Long) =
runAll(session, state, listOf(script), entityId) runAll(session, state, listOf(script), entityId)
@@ -70,6 +74,8 @@ constructor(
storyPlayerService, storyPlayerService,
battleService, battleService,
characterStore, characterStore,
mapManager,
entryScripts,
) )
scope.launch { scope.launch {
try { try {
@@ -1,6 +1,7 @@
package de.fiereu.openmmo.server.game.script.generated.hoenn package de.fiereu.openmmo.server.game.script.generated.hoenn
import de.fiereu.openmmo.dialog.generated.hoenn.LittlerootTown_ProfessorBirchsLab import de.fiereu.openmmo.dialog.generated.hoenn.LittlerootTown_ProfessorBirchsLab
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_LEFT import de.fiereu.openmmo.server.game.script.MovementStep.FACE_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
@@ -12,7 +13,6 @@ import de.fiereu.openmmo.story.generated.hoenn.HoennVars
private const val LOCALID_BIRCH = 1 private const val LOCALID_BIRCH = 1
private const val LOCALID_RIVAL = 2 private const val LOCALID_RIVAL = 2
private const val POKE_BALL_ITEM = 5004
private const val TREECKO = 252 private const val TREECKO = 252
private val HOENN_STARTERS = listOf(TREECKO, 255, 258) private val HOENN_STARTERS = listOf(TREECKO, 255, 258)
@@ -68,7 +68,7 @@ internal object LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent :
} else { } else {
ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.MayGotPokedexTooTakeThese) ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.MayGotPokedexTooTakeThese)
} }
ctx.giveItem(POKE_BALL_ITEM, 5) ctx.giveItem(Items.POKE_BALL, 5)
if (ctx.isFemale) { if (ctx.isFemale) {
ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.CatchCoolPokemonWithPokeBalls) ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.CatchCoolPokemonWithPokeBalls)
} else { } else {
@@ -1,6 +1,7 @@
package de.fiereu.openmmo.server.game.script.generated.hoenn package de.fiereu.openmmo.server.game.script.generated.hoenn
import de.fiereu.openmmo.dialog.generated.hoenn.PetalburgWoods import de.fiereu.openmmo.dialog.generated.hoenn.PetalburgWoods
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.battle.BattleResult import de.fiereu.openmmo.server.game.battle.BattleResult
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_UP import de.fiereu.openmmo.server.game.script.MovementStep.FACE_UP
import de.fiereu.openmmo.server.game.script.MovementStep.SET_INVISIBLE import de.fiereu.openmmo.server.game.script.MovementStep.SET_INVISIBLE
@@ -14,7 +15,6 @@ import de.fiereu.openmmo.story.generated.hoenn.HoennVars
private const val LOCALID_AQUA_GRUNT = 2 private const val LOCALID_AQUA_GRUNT = 2
private const val LOCALID_DEVON_RESEARCHER = 3 private const val LOCALID_DEVON_RESEARCHER = 3
private const val POOCHYENA = 261 private const val POOCHYENA = 261
private const val GREAT_BALL_ITEM = 5003
internal object PetalburgWoods_EventScript_DevonResearcherLeft : Script { internal object PetalburgWoods_EventScript_DevonResearcherLeft : Script {
override suspend fun run(ctx: ScriptContext) = devonResearcherEvent(ctx) override suspend fun run(ctx: ScriptContext) = devonResearcherEvent(ctx)
@@ -51,7 +51,7 @@ private suspend fun devonResearcherEvent(ctx: ScriptContext) {
) )
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_WOODS_AQUA_GRUNT) ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_WOODS_AQUA_GRUNT)
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ThatWasAwfullyClose) ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ThatWasAwfullyClose)
ctx.giveItem(GREAT_BALL_ITEM) ctx.giveItem(Items.GREAT_BALL)
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.TeamAquaAfterSomethingInRustboro) ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.TeamAquaAfterSomethingInRustboro)
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ICantBeWastingTime) ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ICantBeWastingTime)
ctx.moveNpc( ctx.moveNpc(
@@ -1,55 +1,163 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.dialog.generated.kanto.PalletTown import de.fiereu.openmmo.dialog.generated.kanto.PalletTown
import de.fiereu.openmmo.server.game.script.MovementStep
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_UP
import de.fiereu.openmmo.server.game.script.MovementStep.SET_INVISIBLE
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_UP
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
import de.fiereu.openmmo.story.generated.kanto.KantoVars
private const val LOCALID_SIGN_LADY = 0
private const val LOCALID_PROF_OAK = 2
private const val OAKS_LAB_BANK = 4
private const val OAKS_LAB_MAP = 3
private const val OAKS_LAB_ENTRY_X = 6
private const val OAKS_LAB_ENTRY_Y = 12
// The shared tail of every walk down to the lab door (the decomp walk_to_lab macro).
private val WALK_TO_LAB = listOf(WALK_LEFT) + List(11) { WALK_DOWN } + List(4) { WALK_RIGHT }
internal object PalletTown_OnTransition : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.setFlag(KantoFlags.FLAG_WORLD_MAP_PALLET_TOWN)
val notBlocking = ctx.isFlagSet(KantoFlags.FLAG_PALLET_LADY_NOT_BLOCKING_SIGN)
// Once the player has a starter she stops blocking the sign, and once they have opened the
// start menu on their own she has nothing left to teach.
if (notBlocking &&
ctx.isFlagSet(KantoFlags.FLAG_OPENED_START_MENU) &&
ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY) < 1) {
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1)
}
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY) == 0) {
if (notBlocking) ctx.repositionNpc(LOCALID_SIGN_LADY, 12, 2)
else ctx.repositionNpc(LOCALID_SIGN_LADY, 5, 15)
}
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY) == 1) {
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 2)
}
}
}
internal object PalletTown_EventScript_OakTriggerLeft : Script {
override suspend fun run(ctx: ScriptContext) = oakTrigger(ctx, fromLeft = true)
}
internal object PalletTown_EventScript_OakTriggerRight : Script {
override suspend fun run(ctx: ScriptContext) = oakTrigger(ctx, fromLeft = false)
}
/** /**
* Not ported yet. Decomp body: * Oak stops the player from walking into the tall grass and walks them back to his lab. The player
* ``` * enters from one of two tiles, which decides where Oak comes from and which way both of them walk.
* lock
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 2, PalletTown_EventScript_SignLadyDone
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1, PalletTown_EventScript_SignLadyJustShowedSign
* goto_if_eq SIGN_LADY_READY, TRUE, PalletTown_EventScript_SignLadyStartShowSign
* goto_if_set FLAG_TEMP_2, PalletTown_EventScript_SignLadyGoReadSign
* msgbox PalletTown_Text_HmmIsThatRight
* applymovement LOCALID_PALLET_SIGN_LADY, Common_Movement_FacePlayer
* waitmovement 0
* playse SE_PIN
* applymovement LOCALID_PALLET_SIGN_LADY, Common_Movement_ExclamationMark
* waitmovement 0
* applymovement LOCALID_PALLET_SIGN_LADY, Common_Movement_Delay48
* waitmovement 0
* msgbox PalletTown_Text_OhLookLook
* closemessage
* call_if_eq VAR_FACING, DIR_EAST, PalletTown_EventScript_SignLadyMoveOutOfWayRight
* call_if_ne VAR_FACING, DIR_EAST, PalletTown_EventScript_SignLadyMoveOutOfWayLeft
* copyobjectxytoperm LOCALID_PALLET_SIGN_LADY
* setflag FLAG_TEMP_2
* release
* end
* ```
*/ */
private suspend fun oakTrigger(ctx: ScriptContext, fromLeft: Boolean) {
ctx.sign(PalletTown.OakDontGoOut)
ctx.moveSelf(FACE_DOWN)
ctx.showNpc(LOCALID_PROF_OAK)
ctx.moveNpc(LOCALID_PROF_OAK, *oakApproach(fromLeft))
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown.OakGrassUnsafeNeedMon)
val playerWalk =
if (fromLeft) listOf(WALK_DOWN, WALK_DOWN) + WALK_TO_LAB
else listOf(WALK_DOWN, WALK_DOWN, WALK_LEFT) + WALK_TO_LAB
val oakWalk =
(if (fromLeft) listOf(WALK_DOWN) else listOf(WALK_DOWN, WALK_LEFT)) +
WALK_TO_LAB +
listOf(WALK_RIGHT, FACE_UP)
ctx.moveSelfAndNpcs(playerWalk, LOCALID_PROF_OAK to oakWalk)
// TODO Animate the lab door during the Oak trigger
// The decomp opens and closes the door at (16, 13) around both of them stepping in. Doors need
// opendoor, closedoor and waitdooranim script verbs.
ctx.moveNpc(LOCALID_PROF_OAK, WALK_UP, SET_INVISIBLE)
ctx.moveSelf(WALK_RIGHT, WALK_UP)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 1)
ctx.clearFlag(KantoFlags.FLAG_HIDE_OAK_IN_HIS_LAB)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_OAK, 1)
ctx.setFlag(KantoFlags.FLAG_HIDE_OAK_IN_PALLET_TOWN)
ctx.setFlag(KantoFlags.FLAG_DONT_TRANSITION_MUSIC)
ctx.warp(
Region.KANTO.wireValue.toInt(),
OAKS_LAB_BANK,
OAKS_LAB_MAP,
OAKS_LAB_ENTRY_X,
OAKS_LAB_ENTRY_Y,
Direction.UP,
)
}
private fun oakApproach(fromLeft: Boolean): Array<MovementStep> =
if (fromLeft) {
arrayOf(WALK_UP, WALK_UP, WALK_RIGHT, WALK_UP, WALK_UP, WALK_RIGHT, WALK_UP, WALK_UP)
} else {
arrayOf(
WALK_RIGHT,
WALK_UP,
WALK_UP,
WALK_RIGHT,
WALK_UP,
WALK_UP,
WALK_RIGHT,
WALK_UP,
WALK_UP,
)
}
internal object PalletTown_EventScript_SignLady : Script { internal object PalletTown_EventScript_SignLady : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port PalletTown_EventScript_SignLady") override suspend fun run(ctx: ScriptContext) {
when (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY)) {
2 -> return ctx.say(PalletTown.RaisingMonsToo)
1 -> return ctx.say(PalletTown.SignsAreUsefulArentThey)
}
// She only starts the sign lesson once she has moved to the route entrance.
if (ctx.isFlagSet(KantoFlags.FLAG_PALLET_LADY_NOT_BLOCKING_SIGN)) {
return signLadyShowSign(ctx)
}
// TODO Port the sign lady stepping aside
// The decomp shows an exclamation mark, then walks her one tile left or right out of the
// player's way and remembers it in FLAG_TEMP_2. Neither the emote nor per visit temp flags
// exist yet, so she only says her lines.
ctx.say(PalletTown.HmmIsThatRight)
ctx.say(PalletTown.OhLookLook)
}
}
internal object PalletTown_EventScript_SignLadyTrigger : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_SIGN_LADY, FACE_RIGHT)
ctx.moveSelf(FACE_LEFT)
signLadyShowSign(ctx)
}
}
/** She copies the trainer tips sign, which is how the game teaches the start menu. */
private suspend fun signLadyShowSign(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_SIGN_LADY, FACE_DOWN)
ctx.say(PalletTown.LookCopiedTrainerTipsSign)
ctx.setFlag(KantoFlags.FLAG_OPENED_START_MENU)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1)
ctx.sign(PalletTown.PressStartToOpenMenuCopy)
} }
internal object PalletTown_EventScript_FatMan : Script { internal object PalletTown_EventScript_FatMan : Script {
override suspend fun run(ctx: ScriptContext) = ctx.say(PalletTown.CanStoreItemsAndMonsInPC) override suspend fun run(ctx: ScriptContext) = ctx.say(PalletTown.CanStoreItemsAndMonsInPC)
} }
/**
* Not ported yet. Decomp body:
* ```
* lockall
* famechecker FAMECHECKER_OAK, 0
* msgbox PalletTown_Text_OakPokemonResearchLab
* releaseall
* end
* ```
*/
internal object PalletTown_EventScript_OaksLabSign : Script { internal object PalletTown_EventScript_OaksLabSign : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port PalletTown_EventScript_OaksLabSign") override suspend fun run(ctx: ScriptContext) = ctx.sign(PalletTown.OakPokemonResearchLab)
} }
internal object PalletTown_EventScript_PlayersHouseSign : Script { internal object PalletTown_EventScript_PlayersHouseSign : Script {
@@ -64,23 +172,20 @@ internal object PalletTown_EventScript_TownSign : Script {
override suspend fun run(ctx: ScriptContext) = ctx.sign(PalletTown.TownSign) override suspend fun run(ctx: ScriptContext) = ctx.sign(PalletTown.TownSign)
} }
/**
* Not ported yet. Decomp body:
* ```
* lockall
* msgbox PalletTown_Text_PressStartToOpenMenu
* setvar VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1
* releaseall
* end
* ```
*/
internal object PalletTown_EventScript_TrainerTips : Script { internal object PalletTown_EventScript_TrainerTips : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port PalletTown_EventScript_TrainerTips") override suspend fun run(ctx: ScriptContext) {
ctx.sign(PalletTown.PressStartToOpenMenu)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1)
}
} }
internal val PalletTownScripts: Map<String, Script> = internal val PalletTownScripts: Map<String, Script> =
mapOf( mapOf(
"PalletTown_OnTransition" to PalletTown_OnTransition,
"PalletTown_EventScript_OakTriggerLeft" to PalletTown_EventScript_OakTriggerLeft,
"PalletTown_EventScript_OakTriggerRight" to PalletTown_EventScript_OakTriggerRight,
"PalletTown_EventScript_SignLady" to PalletTown_EventScript_SignLady, "PalletTown_EventScript_SignLady" to PalletTown_EventScript_SignLady,
"PalletTown_EventScript_SignLadyTrigger" to PalletTown_EventScript_SignLadyTrigger,
"PalletTown_EventScript_FatMan" to PalletTown_EventScript_FatMan, "PalletTown_EventScript_FatMan" to PalletTown_EventScript_FatMan,
"PalletTown_EventScript_OaksLabSign" to PalletTown_EventScript_OaksLabSign, "PalletTown_EventScript_OaksLabSign" to PalletTown_EventScript_OaksLabSign,
"PalletTown_EventScript_PlayersHouseSign" to PalletTown_EventScript_PlayersHouseSign, "PalletTown_EventScript_PlayersHouseSign" to PalletTown_EventScript_PlayersHouseSign,
@@ -1,42 +1,38 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.dialog.generated.kanto.PalletTown_PlayersHouse_1F
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_set FLAG_BEAT_RIVAL_IN_OAKS_LAB, PalletTown_PlayersHouse_1F_EventScript_MomHeal
* checkplayergender
* call_if_eq VAR_RESULT, MALE, PalletTown_PlayersHouse_1F_EventScript_MomOakLookingForYouMale
* call_if_eq VAR_RESULT, FEMALE, PalletTown_PlayersHouse_1F_EventScript_MomOakLookingForYouFemale
* closemessage
* applymovement LOCALID_MOM, Common_Movement_FaceOriginalDirection
* waitmovement 0
* release
* end
* ```
*/
internal object PalletTown_PlayersHouse_1F_EventScript_Mom : Script { internal object PalletTown_PlayersHouse_1F_EventScript_Mom : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) {
TODO("port PalletTown_PlayersHouse_1F_EventScript_Mom") if (ctx.isFlagSet(KantoFlags.FLAG_BEAT_RIVAL_IN_OAKS_LAB)) {
ctx.say(PalletTown_PlayersHouse_1F.YouShouldTakeQuickRest)
ctx.healParty()
ctx.say(PalletTown_PlayersHouse_1F.LookingGreatTakeCare)
return
}
if (ctx.isFemale) {
ctx.say(PalletTown_PlayersHouse_1F.AllGirlsLeaveOakLookingForYou)
} else {
ctx.say(PalletTown_PlayersHouse_1F.AllBoysLeaveOakLookingForYou)
}
}
} }
/**
* Not ported yet. Decomp body:
* ```
* lockall
* goto_if_eq VAR_FACING, DIR_NORTH, PalletTown_PlayersHouse_1F_EventScript_TVScreen
* msgbox PalletTown_PlayersHouse_1F_Text_OopsWrongSide
* releaseall
* end
* ```
*/
internal object PalletTown_PlayersHouse_1F_EventScript_TV : Script { internal object PalletTown_PlayersHouse_1F_EventScript_TV : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) {
TODO("port PalletTown_PlayersHouse_1F_EventScript_TV") if (ctx.facingDirection != Direction.UP) {
return ctx.sign(PalletTown_PlayersHouse_1F.OopsWrongSide)
}
if (ctx.isFemale) {
ctx.sign(PalletTown_PlayersHouse_1F.MovieOnTVGirlOnBrickRoad)
} else {
ctx.sign(PalletTown_PlayersHouse_1F.MovieOnTVFourBoysOnRailroad)
}
}
} }
internal val PalletTown_PlayersHouse_1FScripts: Map<String, Script> = internal val PalletTown_PlayersHouse_1FScripts: Map<String, Script> =
@@ -1,159 +1,332 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.dialog.generated.kanto.PalletTown_ProfessorOaksLab import de.fiereu.openmmo.dialog.generated.kanto.PalletTown_ProfessorOaksLab
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.battle.BattleResult
import de.fiereu.openmmo.server.game.script.MovementStep
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_UP
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_UP
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
import de.fiereu.openmmo.story.generated.kanto.KantoVars
private const val LOCALID_PROF_OAK = 3
private const val LOCALID_BULBASAUR_BALL = 4
private const val LOCALID_SQUIRTLE_BALL = 5
private const val LOCALID_CHARMANDER_BALL = 6
private const val LOCALID_RIVAL = 7
private const val LOCALID_POKEDEX_1 = 8
private const val LOCALID_POKEDEX_2 = 9
private const val BULBASAUR = 1
private const val CHARMANDER = 4
private const val SQUIRTLE = 7
private const val MOVE_SCRATCH = 10
private const val MOVE_TACKLE = 33
private const val MOVE_TAIL_WHIP = 39
private const val MOVE_GROWL = 45
private const val STARTER_LEVEL = 5
// Bulbasaur's ball on Oak's table. The other two sit one tile further right each, in starter order.
private const val FIRST_BALL_X = 8
// The three tiles the player can be standing on when the rival stops them on the way out.
private const val EXIT_X_LEFT = 5
private const val EXIT_X_MID = 6
private const val EXIT_X_RIGHT = 7
/** /**
* Not ported yet. Decomp body: * One of the three balls on Oak's table. [starterNumber] is what VAR_STARTER_MON ends up holding,
* ``` * and the rival always takes the starter that beats the player's.
* lock
* faceplayer
* goto_if_set FLAG_SYS_GAME_CLEAR, PalletTown_ProfessorOaksLab_EventScript_Aide1GameClear
* msgbox PalletTown_ProfessorOaksLab_Text_StudyAsOaksAide
* release
* end
* ```
*/ */
private enum class Starter(
val starterNumber: Int,
val localId: Int,
val species: Int,
val confirmLine: PalletTown_ProfessorOaksLab,
) {
BULBASAUR_BALL(
0,
LOCALID_BULBASAUR_BALL,
BULBASAUR,
PalletTown_ProfessorOaksLab.OakChoosingBulbasaur,
),
SQUIRTLE_BALL(
1,
LOCALID_SQUIRTLE_BALL,
SQUIRTLE,
PalletTown_ProfessorOaksLab.OakChoosingSquirtle,
),
CHARMANDER_BALL(
2,
LOCALID_CHARMANDER_BALL,
CHARMANDER,
PalletTown_ProfessorOaksLab.OakChoosingCharmander,
);
/** The ball the rival walks over to once the player has taken theirs. */
val rival: Starter
get() =
when (this) {
BULBASAUR_BALL -> CHARMANDER_BALL
SQUIRTLE_BALL -> BULBASAUR_BALL
CHARMANDER_BALL -> SQUIRTLE_BALL
}
/** The path the rival walks from his spot to this ball. */
val rivalWalk: List<MovementStep>
get() =
when (this) {
BULBASAUR_BALL -> listOf(WALK_DOWN, WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, FACE_UP)
SQUIRTLE_BALL ->
listOf(WALK_DOWN, WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, FACE_UP)
CHARMANDER_BALL ->
listOf(
WALK_DOWN,
WALK_DOWN,
WALK_RIGHT,
WALK_RIGHT,
WALK_RIGHT,
WALK_RIGHT,
WALK_RIGHT,
WALK_UP,
)
}
/** The moves the species knows at level 5, for the rival battle. */
val moves: IntArray
get() =
when (species) {
BULBASAUR -> intArrayOf(MOVE_TACKLE, MOVE_GROWL)
CHARMANDER -> intArrayOf(MOVE_SCRATCH, MOVE_GROWL)
else -> intArrayOf(MOVE_TACKLE, MOVE_TAIL_WHIP)
}
companion object {
fun byStarterNumber(number: Int): Starter? = entries.firstOrNull { it.starterNumber == number }
}
}
internal object PalletTown_ProfessorOaksLab_OnTransition : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.setFlag(KantoFlags.FLAG_VISITED_OAKS_LAB)
// Oak follows the player in and starts the scene just inside the door.
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB) == 1) {
ctx.repositionNpc(LOCALID_PROF_OAK, 6, 11)
}
}
}
internal object PalletTown_ProfessorOaksLab_ChooseStarterScene : Script {
override suspend fun run(ctx: ScriptContext) {
// Oak leads, then goes away and comes back behind his desk while the player is still far
// enough down the room not to see it. Moving him there in view would read as a teleport.
ctx.moveNpc(LOCALID_PROF_OAK, *List(6) { WALK_UP }.toTypedArray())
ctx.removeNpc(LOCALID_PROF_OAK)
ctx.showNpcAt(LOCALID_PROF_OAK, 6, 3)
ctx.moveNpc(LOCALID_PROF_OAK, FACE_DOWN)
ctx.moveSelf(*List(8) { WALK_UP }.toTypedArray())
ctx.moveNpc(LOCALID_RIVAL, FACE_UP)
ctx.clearFlag(KantoFlags.FLAG_DONT_TRANSITION_MUSIC)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalFedUpWithWaiting)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakThreeMonsChooseOne)
ctx.moveNpc(LOCALID_RIVAL, FACE_UP)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalNoFairWhatAboutMe)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakBePatientRival)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 2)
}
}
internal object PalletTown_ProfessorOaksLab_EventScript_LeaveStarterSceneTrigger : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_PROF_OAK, FACE_DOWN)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakHeyDontGoAwayYet)
ctx.moveSelf(WALK_UP)
}
}
internal object PalletTown_ProfessorOaksLab_EventScript_BulbasaurBall : Script {
override suspend fun run(ctx: ScriptContext) = starterBall(ctx, Starter.BULBASAUR_BALL)
}
internal object PalletTown_ProfessorOaksLab_EventScript_SquirtleBall : Script {
override suspend fun run(ctx: ScriptContext) = starterBall(ctx, Starter.SQUIRTLE_BALL)
}
internal object PalletTown_ProfessorOaksLab_EventScript_CharmanderBall : Script {
override suspend fun run(ctx: ScriptContext) = starterBall(ctx, Starter.CHARMANDER_BALL)
}
private suspend fun starterBall(ctx: ScriptContext, starter: Starter) {
val scene = ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB)
if (scene >= 3) return ctx.sign(PalletTown_ProfessorOaksLab.OaksLastMon)
if (scene != 2) return ctx.sign(PalletTown_ProfessorOaksLab.ThoseArePokeBalls)
ctx.moveNpc(LOCALID_PROF_OAK, FACE_RIGHT)
// TODO Show the starter's picture while Oak asks
// The decomp opens a showmonpic window over the yes/no box. There is no verb for it yet.
if (!ctx.askYesNoNpc(LOCALID_PROF_OAK, starter.confirmLine)) return
ctx.removeNpc(starter.localId)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakThisMonIsEnergetic)
ctx.setFlag(KantoFlags.FLAG_SYS_POKEMON_GET)
ctx.setFlag(KantoFlags.FLAG_PALLET_LADY_NOT_BLOCKING_SIGN)
ctx.givePokemon(starter.species, STARTER_LEVEL, *starter.moves)
ctx.setVar(KantoVars.VAR_STARTER_MON, starter.starterNumber)
ctx.sign(PalletTown_ProfessorOaksLab.ReceivedMonFromOak)
val rivalStarter = starter.rival
ctx.moveNpc(LOCALID_RIVAL, *rivalStarter.rivalWalk.toTypedArray())
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalIllTakeThisOneThen)
ctx.removeNpc(rivalStarter.localId)
ctx.sign(PalletTown_ProfessorOaksLab.RivalReceivedMonFromOak)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3)
if (ctx.isFlagSet(KantoFlags.FLAG_OPENED_START_MENU)) {
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1)
}
}
internal object PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerLeft : Script {
override suspend fun run(ctx: ScriptContext) = rivalBattle(ctx, playerX = EXIT_X_LEFT)
}
internal object PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerMid : Script {
override suspend fun run(ctx: ScriptContext) = rivalBattle(ctx, playerX = EXIT_X_MID)
}
internal object PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerRight : Script {
override suspend fun run(ctx: ScriptContext) = rivalBattle(ctx, playerX = EXIT_X_RIGHT)
}
/**
* The rival stops the player on the way out for the tutorial battle. He is still standing at his
* own ball, so he walks left until he is above the player's exit tile [playerX], then two down to
* block the way.
*/
private suspend fun rivalBattle(ctx: ScriptContext, playerX: Int) {
val playerStarter = Starter.byStarterNumber(ctx.getVar(KantoVars.VAR_STARTER_MON)) ?: return
val rivalStarter = playerStarter.rival
ctx.moveNpc(LOCALID_RIVAL, FACE_DOWN)
ctx.moveSelf(FACE_UP)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalLetsCheckOutMons)
ctx.moveNpc(LOCALID_PROF_OAK, FACE_DOWN)
val stepsLeft = FIRST_BALL_X + rivalStarter.starterNumber - playerX
val approach = List(stepsLeft) { WALK_LEFT } + listOf(WALK_DOWN, WALK_DOWN)
ctx.moveNpc(LOCALID_RIVAL, *approach.toTypedArray())
// The decomp ends this scene the same way whether the player won or lost, so a loss must not
// leave the rival standing on the exit tile with the trigger still armed.
val result = ctx.battle(rivalStarter.species, STARTER_LEVEL, *rivalStarter.moves)
if (result == BattleResult.DISCONNECTED || result == BattleResult.FAILED) return
ctx.healParty()
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalGoToughenMyMon)
// The rival leaves around whichever side the player blocked, so each exit tile has its own path.
val exit =
when (playerX) {
EXIT_X_LEFT -> listOf(WALK_RIGHT, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_DOWN)
EXIT_X_MID ->
listOf(WALK_RIGHT, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_LEFT, WALK_DOWN, WALK_DOWN)
else -> listOf(WALK_LEFT, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_DOWN)
}
ctx.moveNpc(LOCALID_RIVAL, *exit.toTypedArray())
ctx.removeNpc(LOCALID_RIVAL)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 4)
ctx.setFlag(KantoFlags.FLAG_BEAT_RIVAL_IN_OAKS_LAB)
}
internal object PalletTown_ProfessorOaksLab_EventScript_ProfOak : Script {
override suspend fun run(ctx: ScriptContext) {
val scene = ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB)
when {
scene >= 8 -> ctx.say(PalletTown_ProfessorOaksLab.OakMonsAroundWorldWait)
scene == 6 -> ctx.say(PalletTown_ProfessorOaksLab.OakComeSeeMeSometime)
ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_MART) >= 1 -> receiveDexScene(ctx)
scene == 4 -> ctx.say(PalletTown_ProfessorOaksLab.OakBattleMonForItToGrow)
scene == 3 -> ctx.say(PalletTown_ProfessorOaksLab.OakCanReachNextTownWithMon)
else -> ctx.say(PalletTown_ProfessorOaksLab.OakWhichOneWillYouChoose)
}
}
}
/** Handing over Oak's parcel is what earns the Pokedex and the first five Poke Balls. */
private suspend fun receiveDexScene(ctx: ScriptContext) {
ctx.say(PalletTown_ProfessorOaksLab.OakHaveSomethingForMe)
ctx.sign(PalletTown_ProfessorOaksLab.DeliveredOaksParcel)
ctx.takeItem(Items.OAKS_PARCEL)
ctx.say(PalletTown_ProfessorOaksLab.OakCustomBallIOrdered)
ctx.sign(PalletTown_ProfessorOaksLab.RivalGramps)
// A player facing Oak stands in the middle column, so the rival comes up the one beside it.
val facing = ctx.facingDirection
ctx.showNpcAt(LOCALID_RIVAL, if (facing == Direction.UP) 5 else 6, 10)
ctx.moveNpc(LOCALID_RIVAL, *List(6) { WALK_UP }.toTypedArray())
if (facing != Direction.DOWN) ctx.moveSelf(FACE_DOWN)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalWhatDidYouCallMeFor)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakHaveRequestForYouTwo)
ctx.moveNpc(LOCALID_PROF_OAK, WALK_UP, WALK_LEFT, FACE_DOWN)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakPokedexOnDesk)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakTakeTheseWithYou)
ctx.removeNpc(LOCALID_POKEDEX_1)
ctx.removeNpc(LOCALID_POKEDEX_2)
ctx.moveNpc(LOCALID_PROF_OAK, WALK_RIGHT, WALK_DOWN)
ctx.sign(PalletTown_ProfessorOaksLab.ReceivedPokedexFromOak)
ctx.setFlag(KantoFlags.FLAG_SYS_POKEDEX_GET)
ctx.setVar(KantoVars.VAR_MAP_SCENE_POKEMON_CENTER_TEALA, 1)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakCatchMonsForDataTakeThese)
ctx.giveItem(Items.POKE_BALL, 5)
ctx.sign(PalletTown_ProfessorOaksLab.ReceivedFivePokeBalls)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakExplainCatching)
ctx.sayNpc(LOCALID_PROF_OAK, PalletTown_ProfessorOaksLab.OakCompleteMonGuideWasMyDream)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalLeaveItToMeGramps)
ctx.sayNpc(LOCALID_RIVAL, PalletTown_ProfessorOaksLab.RivalTellSisNotToGiveYouMap)
ctx.moveNpc(LOCALID_RIVAL, *List(6) { WALK_DOWN }.toTypedArray())
ctx.removeNpc(LOCALID_RIVAL)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 6)
ctx.setVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_MART, 2)
ctx.setVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 1)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE, 1)
ctx.setVar(KantoVars.VAR_MAP_SCENE_ROUTE22, 1)
}
internal object PalletTown_ProfessorOaksLab_EventScript_Rival : Script {
override suspend fun run(ctx: ScriptContext) {
when (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB)) {
3 -> ctx.say(PalletTown_ProfessorOaksLab.RivalMyMonLooksTougher)
2 -> ctx.say(PalletTown_ProfessorOaksLab.RivalGoChoosePlayer)
else -> ctx.say(PalletTown_ProfessorOaksLab.RivalGrampsIsntAround)
}
}
}
internal object PalletTown_ProfessorOaksLab_EventScript_Aide1 : Script { internal object PalletTown_ProfessorOaksLab_EventScript_Aide1 : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_Aide1") ctx.say(PalletTown_ProfessorOaksLab.StudyAsOaksAide)
} }
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* famechecker FAMECHECKER_OAK, 2
* msgbox PalletTown_ProfessorOaksLab_Text_OakIsAuthorityOnMons
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_Aide3 : Script {
override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_Aide3")
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_set FLAG_SYS_GAME_CLEAR, PalletTown_ProfessorOaksLab_EventScript_Aide2GameClear
* msgbox PalletTown_ProfessorOaksLab_Text_StudyAsOaksAide
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_Aide2 : Script { internal object PalletTown_ProfessorOaksLab_EventScript_Aide2 : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_Aide2") ctx.say(PalletTown_ProfessorOaksLab.StudyAsOaksAide)
} }
/** internal object PalletTown_ProfessorOaksLab_EventScript_Aide3 : Script {
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_set SHOWED_OAK_COMPLETE_DEX, PalletTown_ProfessorOaksLab_EventScript_OakJustShownCompleteDex
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 9, PalletTown_ProfessorOaksLab_EventScript_RatePokedex
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 8, PalletTown_ProfessorOaksLab_EventScript_MonsAroundWorldWait
* goto_if_set FLAG_SYS_GAME_CLEAR, PalletTown_ProfessorOaksLab_EventScript_TryStartNationalDexScene
* goto_if_eq VAR_MAP_SCENE_CERULEAN_CITY_RIVAL, 1, PalletTown_ProfessorOaksLab_EventScript_RatePokedex
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 6, PalletTown_ProfessorOaksLab_EventScript_RatePokedexOrTryGiveBalls
* goto_if_ge VAR_MAP_SCENE_VIRIDIAN_CITY_MART, 1, PalletTown_ProfessorOaksLab_EventScript_ReceiveDexScene
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 4, PalletTown_ProfessorOaksLab_EventScript_OakBattleMonForItToGrow
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3, PalletTown_ProfessorOaksLab_EventScript_OakCanReachNextTownWithMon
* msgbox PalletTown_ProfessorOaksLab_Text_OakWhichOneWillYouChoose
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_ProfOak : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_ProfOak") ctx.say(PalletTown_ProfessorOaksLab.OakIsAuthorityOnMons)
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* setvar PLAYER_STARTER_NUM, 0
* setvar PLAYER_STARTER_SPECIES, SPECIES_BULBASAUR
* setvar RIVAL_STARTER_SPECIES, SPECIES_CHARMANDER
* setvar RIVAL_STARTER_ID, LOCALID_CHARMANDER_BALL
* goto_if_ge VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3, PalletTown_ProfessorOaksLab_EventScript_LastPokeBall
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 2, PalletTown_ProfessorOaksLab_EventScript_ConfirmStarterChoice
* msgbox PalletTown_ProfessorOaksLab_Text_ThoseArePokeBalls
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_BulbasaurBall : Script {
override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_BulbasaurBall")
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* setvar PLAYER_STARTER_NUM, 1
* setvar PLAYER_STARTER_SPECIES, SPECIES_SQUIRTLE
* setvar RIVAL_STARTER_SPECIES, SPECIES_BULBASAUR
* setvar RIVAL_STARTER_ID, LOCALID_BULBASAUR_BALL
* goto_if_ge VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3, PalletTown_ProfessorOaksLab_EventScript_LastPokeBall
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 2, PalletTown_ProfessorOaksLab_EventScript_ConfirmStarterChoice
* msgbox PalletTown_ProfessorOaksLab_Text_ThoseArePokeBalls
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_SquirtleBall : Script {
override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_SquirtleBall")
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* setvar PLAYER_STARTER_NUM, 2
* setvar PLAYER_STARTER_SPECIES, SPECIES_CHARMANDER
* setvar RIVAL_STARTER_SPECIES, SPECIES_SQUIRTLE
* setvar RIVAL_STARTER_ID, LOCALID_SQUIRTLE_BALL
* goto_if_ge VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3, PalletTown_ProfessorOaksLab_EventScript_LastPokeBall
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 2, PalletTown_ProfessorOaksLab_EventScript_ConfirmStarterChoice
* msgbox PalletTown_ProfessorOaksLab_Text_ThoseArePokeBalls
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_CharmanderBall : Script {
override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_CharmanderBall")
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 3, PalletTown_ProfessorOaksLab_EventScript_RivalChoseStarter
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 2, PalletTown_ProfessorOaksLab_EventScript_RivalWaitingForStarter
* msgbox PalletTown_ProfessorOaksLab_Text_RivalGrampsIsntAround
* release
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_Rival : Script {
override suspend fun run(ctx: ScriptContext) =
TODO("port PalletTown_ProfessorOaksLab_EventScript_Rival")
} }
internal object PalletTown_ProfessorOaksLab_EventScript_Pokedex : Script { internal object PalletTown_ProfessorOaksLab_EventScript_Pokedex : Script {
@@ -170,23 +343,29 @@ internal object PalletTown_ProfessorOaksLab_EventScript_LeftSign : Script {
ctx.sign(PalletTown_ProfessorOaksLab.PressStartToOpenMenu) ctx.sign(PalletTown_ProfessorOaksLab.PressStartToOpenMenu)
} }
/**
* Not ported yet. Decomp body:
* ```
* lockall
* goto_if_ge VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 6, PalletTown_ProfessorOaksLab_EventScript_RightSignAlt
* msgbox PalletTown_ProfessorOaksLab_Text_SaveOptionInMenu
* releaseall
* end
* ```
*/
internal object PalletTown_ProfessorOaksLab_EventScript_RightSign : Script { internal object PalletTown_ProfessorOaksLab_EventScript_RightSign : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) {
TODO("port PalletTown_ProfessorOaksLab_EventScript_RightSign") if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB) >= 6) {
ctx.sign(PalletTown_ProfessorOaksLab.AllMonTypesHaveStrongAndWeakPoints)
} else {
ctx.sign(PalletTown_ProfessorOaksLab.SaveOptionInMenu)
}
}
} }
internal val PalletTown_ProfessorOaksLabScripts: Map<String, Script> = internal val PalletTown_ProfessorOaksLabScripts: Map<String, Script> =
mapOf( mapOf(
"PalletTown_ProfessorOaksLab_OnTransition" to PalletTown_ProfessorOaksLab_OnTransition,
"PalletTown_ProfessorOaksLab_ChooseStarterScene" to
PalletTown_ProfessorOaksLab_ChooseStarterScene,
"PalletTown_ProfessorOaksLab_EventScript_LeaveStarterSceneTrigger" to
PalletTown_ProfessorOaksLab_EventScript_LeaveStarterSceneTrigger,
"PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerLeft" to
PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerLeft,
"PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerMid" to
PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerMid,
"PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerRight" to
PalletTown_ProfessorOaksLab_EventScript_RivalBattleTriggerRight,
"PalletTown_ProfessorOaksLab_EventScript_Aide1" to "PalletTown_ProfessorOaksLab_EventScript_Aide1" to
PalletTown_ProfessorOaksLab_EventScript_Aide1, PalletTown_ProfessorOaksLab_EventScript_Aide1,
"PalletTown_ProfessorOaksLab_EventScript_Aide3" to "PalletTown_ProfessorOaksLab_EventScript_Aide3" to
@@ -1,31 +1,47 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.dialog.generated.kanto.PalletTown_RivalsHouse import de.fiereu.openmmo.dialog.generated.kanto.PalletTown_RivalsHouse
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoVars
private const val LOCALID_DAISY = 0
private const val LOCALID_TOWN_MAP = 1
internal object PalletTown_RivalsHouse_OnTransition : Script {
override suspend fun run(ctx: ScriptContext) {
// Daisy sits at the table until the town map is handed over.
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE) < 2) {
ctx.repositionNpc(LOCALID_DAISY, 5, 4)
}
}
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* famechecker FAMECHECKER_DAISY, FCPICKSTATE_COLORED, UpdatePickStateFromSpecialVar8005
* goto_if_set FLAG_SYS_GAME_CLEAR, PalletTown_RivalsHouse_EventScript_GroomMon
* goto_if_eq RECEIVED_TOWN_MAP, TRUE, PalletTown_RivalsHouse_EventScript_PleaseGiveMonsRest
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE, 2, PalletTown_RivalsHouse_EventScript_ExplainTownMap
* goto_if_eq VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE, 1, PalletTown_RivalsHouse_EventScript_GiveTownMap
* goto_if_ge VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 1, PalletTown_RivalsHouse_EventScript_HeardBattledRival
* msgbox PalletTown_RivalsHouse_Text_HiBrothersAtLab
* closemessage
* applymovement LOCALID_DAISY, Common_Movement_FaceOriginalDirection
* waitmovement 0
* release
* end
* ```
*/
internal object PalletTown_RivalsHouse_EventScript_Daisy : Script { internal object PalletTown_RivalsHouse_EventScript_Daisy : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) {
TODO("port PalletTown_RivalsHouse_EventScript_Daisy") when (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE)) {
2 -> return ctx.say(PalletTown_RivalsHouse.ExplainTownMap)
1 -> return giveTownMap(ctx)
}
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB) >= 1) {
return ctx.say(PalletTown_RivalsHouse.HeardYouBattledRival)
}
ctx.say(PalletTown_RivalsHouse.HiBrothersAtLab)
}
}
/** Oak's errand is what makes Daisy hand over her brother's town map. */
private suspend fun giveTownMap(ctx: ScriptContext) {
ctx.say(PalletTown_RivalsHouse.ErrandForGrandpaThisWillHelp)
ctx.moveNpc(LOCALID_DAISY, FACE_RIGHT)
ctx.removeNpc(LOCALID_TOWN_MAP)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE, 2)
if (!ctx.giveItem(Items.TOWN_MAP)) {
return ctx.say(PalletTown_RivalsHouse.DontHaveSpaceForThis)
}
ctx.sign(PalletTown_RivalsHouse.ReceivedTownMapFromDaisy)
} }
internal object PalletTown_RivalsHouse_EventScript_TownMap : Script { internal object PalletTown_RivalsHouse_EventScript_TownMap : Script {
@@ -44,6 +60,7 @@ internal object PalletTown_RivalsHouse_EventScript_Picture : Script {
internal val PalletTown_RivalsHouseScripts: Map<String, Script> = internal val PalletTown_RivalsHouseScripts: Map<String, Script> =
mapOf( mapOf(
"PalletTown_RivalsHouse_OnTransition" to PalletTown_RivalsHouse_OnTransition,
"PalletTown_RivalsHouse_EventScript_Daisy" to PalletTown_RivalsHouse_EventScript_Daisy, "PalletTown_RivalsHouse_EventScript_Daisy" to PalletTown_RivalsHouse_EventScript_Daisy,
"PalletTown_RivalsHouse_EventScript_TownMap" to PalletTown_RivalsHouse_EventScript_TownMap, "PalletTown_RivalsHouse_EventScript_TownMap" to PalletTown_RivalsHouse_EventScript_TownMap,
"PalletTown_RivalsHouse_EventScript_Bookshelf" to "PalletTown_RivalsHouse_EventScript_Bookshelf" to
@@ -1,34 +1,21 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.dialog.generated.kanto.Route1 import de.fiereu.openmmo.dialog.generated.kanto.Route1
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_set FLAG_GOT_POTION_ON_ROUTE_1, Route1_EventScript_AlreadyGotPotion
* msgbox Route1_Text_WorkAtPokeMartTakeSample
* textcolor NPC_TEXT_COLOR_NEUTRAL
* checkitemspace ITEM_POTION
* goto_if_eq VAR_RESULT, FALSE, EventScript_BagIsFull
* bufferitemname STR_VAR_2, ITEM_POTION
* playfanfare MUS_LEVEL_UP
* message Text_ObtainedTheX
* waitmessage
* waitfanfare
* additem ITEM_POTION
* msgbox Route1_Text_PutPotionAway
* call EventScript_RestorePrevTextColor
* setflag FLAG_GOT_POTION_ON_ROUTE_1
* release
* end
* ```
*/
internal object Route1_EventScript_MartClerk : Script { internal object Route1_EventScript_MartClerk : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port Route1_EventScript_MartClerk") override suspend fun run(ctx: ScriptContext) {
if (ctx.isFlagSet(KantoFlags.FLAG_GOT_POTION_ON_ROUTE_1)) {
return ctx.say(Route1.ComeSeeUsIfYouNeedPokeBalls)
}
ctx.say(Route1.WorkAtPokeMartTakeSample)
ctx.giveItem(Items.POTION)
ctx.say(Route1.PutPotionAway)
ctx.setFlag(KantoFlags.FLAG_GOT_POTION_ON_ROUTE_1)
}
} }
internal object Route1_EventScript_Boy : Script { internal object Route1_EventScript_Boy : Script {
@@ -1,8 +1,77 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.dialog.generated.kanto.ViridianCity import de.fiereu.openmmo.dialog.generated.kanto.ViridianCity
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_UP
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
import de.fiereu.openmmo.story.generated.kanto.KantoVars
private const val LOCALID_TUTORIAL_MAN = 3
private const val LOCALID_POTION_BALL = 8
internal object ViridianCity_OnTransition : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.setFlag(KantoFlags.FLAG_WORLD_MAP_VIRIDIAN_CITY)
// He naps across the road north until Oak's parcel is delivered, then stands beside it.
when (ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN)) {
0 -> ctx.repositionNpc(LOCALID_TUTORIAL_MAN, 21, 11)
1 -> ctx.repositionNpc(LOCALID_TUTORIAL_MAN, 21, 8)
}
// TODO Unlock the Viridian gym once seven badges are in
// The decomp checks FLAG_BADGE02_GET through FLAG_BADGE07_GET here. Badges are not tracked
// yet, so the gym door stays locked.
}
}
internal object ViridianCity_EventScript_RoadBlocked : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.sign(ViridianCity.ThisIsPrivateProperty)
ctx.moveSelf(WALK_DOWN)
}
}
internal object ViridianCity_EventScript_GymDoorLocked : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveSelf(FACE_UP)
ctx.sign(ViridianCity.GymDoorsAreLocked)
// The decomp hops the player back down the ledge, and a plain step down is the closest we have.
ctx.moveSelf(WALK_DOWN)
}
}
internal object ViridianCity_EventScript_TutorialTriggerLeft : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_TUTORIAL_MAN, FACE_LEFT)
ctx.moveSelf(FACE_RIGHT)
tutorialBattle(ctx)
}
}
internal object ViridianCity_EventScript_TutorialTriggerRight : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_TUTORIAL_MAN, FACE_RIGHT)
ctx.moveSelf(FACE_LEFT)
tutorialBattle(ctx)
}
}
/** The old man's catching demonstration, which ends with him handing over the Teachy TV. */
private suspend fun tutorialBattle(ctx: ScriptContext) {
ctx.sayNpc(LOCALID_TUTORIAL_MAN, ViridianCity.ShowYouHowToCatchMons)
// TODO Play the catching tutorial battle
// The decomp runs StartOldManTutorialBattle, a scripted battle the old man fights for the
// player. Scripted battles always use the player's own party today, so the demonstration is
// skipped and only its reward is given.
ctx.sayNpc(LOCALID_TUTORIAL_MAN, ViridianCity.ThatWasEducationalTakeThis)
ctx.setVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 2)
ctx.giveItem(Items.TEACHY_TV)
ctx.sayNpc(LOCALID_TUTORIAL_MAN, ViridianCity.WatchThatToLearnBasics)
}
/** /**
* Not ported yet. Decomp body: * Not ported yet. Decomp body:
@@ -16,84 +85,62 @@ internal object ViridianCity_EventScript_DreamEaterTutor : Script {
TODO("port ViridianCity_EventScript_DreamEaterTutor") TODO("port ViridianCity_EventScript_DreamEaterTutor")
} }
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_eq VAR_MAP_SCENE_VIRIDIAN_CITY_GYM_DOOR, 1, ViridianCity_EventScript_OldManGymLeaderReturned
* msgbox ViridianCity_Text_GymClosedWonderWhoLeaderIs
* closemessage
* applymovement LOCALID_VIRIDIAN_OLD_MAN, Common_Movement_FaceOriginalDirection
* waitmovement 0
* release
* end
* ```
*/
internal object ViridianCity_EventScript_OldMan : Script { internal object ViridianCity_EventScript_OldMan : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port ViridianCity_EventScript_OldMan") override suspend fun run(ctx: ScriptContext) {
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_GYM_DOOR) == 1) {
return ctx.say(ViridianCity.ViridiansGymLeaderReturned)
}
ctx.say(ViridianCity.GymClosedWonderWhoLeaderIs)
}
} }
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_set FLAG_BADGE01_GET, ViridianCity_EventScript_AskIfTeachyTVHelpful
* goto_if_ge VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 2, ViridianCity_EventScript_TutorialCompleted
* goto_if_eq VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 1, ViridianCity_EventScript_TutorialStart
* goto_if_eq VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 0, ViridianCity_EventScript_TutorialNotReady
* end
* ```
*/
internal object ViridianCity_EventScript_TutorialOldMan : Script { internal object ViridianCity_EventScript_TutorialOldMan : Script {
override suspend fun run(ctx: ScriptContext) = override suspend fun run(ctx: ScriptContext) {
TODO("port ViridianCity_EventScript_TutorialOldMan") when {
ctx.isFlagSet(KantoFlags.FLAG_BADGE01_GET) -> {
if (ctx.askYesNo(ViridianCity.HowsTeachyTVHelping)) {
ctx.say(ViridianCity.MyGrandsonOnTheShow)
} else {
ctx.say(ViridianCity.TooBusyForTeachyTV)
}
}
ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN) >= 2 ->
ctx.say(ViridianCity.WeakenMonsFirstToCatch)
ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN) == 1 -> tutorialBattle(ctx)
else -> ctx.say(ViridianCity.ThisIsPrivateProperty)
}
}
} }
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_eq VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 0, ViridianCity_EventScript_WomanRoadBlocked
* msgbox ViridianCity_Text_GoShoppingInPewterOccasionally
* release
* end
* ```
*/
internal object ViridianCity_EventScript_Woman : Script { internal object ViridianCity_EventScript_Woman : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port ViridianCity_EventScript_Woman") override suspend fun run(ctx: ScriptContext) {
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN) == 0) {
return ctx.say(ViridianCity.GrandpaHasntHadCoffeeYet)
}
ctx.say(ViridianCity.GoShoppingInPewterOccasionally)
}
} }
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* msgbox ViridianCity_Text_WantToKnowAboutCaterpillarMons, MSGBOX_YESNO
* goto_if_eq VAR_RESULT, YES, ViridianCity_EventScript_YoungsterExplainCaterpillars
* goto_if_eq VAR_RESULT, NO, ViridianCity_EventScript_YoungsterDeclineExplanation
* end
* ```
*/
internal object ViridianCity_EventScript_Youngster : Script { internal object ViridianCity_EventScript_Youngster : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port ViridianCity_EventScript_Youngster") override suspend fun run(ctx: ScriptContext) {
if (ctx.askYesNo(ViridianCity.WantToKnowAboutCaterpillarMons)) {
ctx.say(ViridianCity.ExplainCaterpieWeedle)
} else {
ctx.say(ViridianCity.OhOkayThen)
}
}
} }
internal object ViridianCity_EventScript_Boy : Script { internal object ViridianCity_EventScript_Boy : Script {
override suspend fun run(ctx: ScriptContext) = ctx.say(ViridianCity.CanCarryMonsAnywhere) override suspend fun run(ctx: ScriptContext) = ctx.say(ViridianCity.CanCarryMonsAnywhere)
} }
/**
* Not ported yet. Decomp body:
* ```
* finditem ITEM_POTION
* end
* ```
*/
internal object ViridianCity_EventScript_ItemPotion : Script { internal object ViridianCity_EventScript_ItemPotion : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port ViridianCity_EventScript_ItemPotion") override suspend fun run(ctx: ScriptContext) {
if (!ctx.giveItem(Items.POTION)) return
ctx.removeNpc(LOCALID_POTION_BALL)
ctx.setFlag(KantoFlags.FLAG_HIDE_VIRIDIAN_CITY_POTION)
}
} }
internal object ViridianCity_EventScript_TrainerTips1 : Script { internal object ViridianCity_EventScript_TrainerTips1 : Script {
@@ -118,6 +165,13 @@ internal object ViridianCity_EventScript_GymDoor : Script {
internal val ViridianCityScripts: Map<String, Script> = internal val ViridianCityScripts: Map<String, Script> =
mapOf( mapOf(
"ViridianCity_OnTransition" to ViridianCity_OnTransition,
"ViridianCity_EventScript_RoadBlocked" to ViridianCity_EventScript_RoadBlocked,
"ViridianCity_EventScript_GymDoorLocked" to ViridianCity_EventScript_GymDoorLocked,
"ViridianCity_EventScript_TutorialTriggerLeft" to
ViridianCity_EventScript_TutorialTriggerLeft,
"ViridianCity_EventScript_TutorialTriggerRight" to
ViridianCity_EventScript_TutorialTriggerRight,
"ViridianCity_EventScript_DreamEaterTutor" to ViridianCity_EventScript_DreamEaterTutor, "ViridianCity_EventScript_DreamEaterTutor" to ViridianCity_EventScript_DreamEaterTutor,
"ViridianCity_EventScript_OldMan" to ViridianCity_EventScript_OldMan, "ViridianCity_EventScript_OldMan" to ViridianCity_EventScript_OldMan,
"ViridianCity_EventScript_TutorialOldMan" to ViridianCity_EventScript_TutorialOldMan, "ViridianCity_EventScript_TutorialOldMan" to ViridianCity_EventScript_TutorialOldMan,
@@ -1,26 +1,42 @@
package de.fiereu.openmmo.server.game.script.generated.kanto package de.fiereu.openmmo.server.game.script.generated.kanto
import de.fiereu.openmmo.dialog.generated.kanto.ViridianCity_Mart import de.fiereu.openmmo.dialog.generated.kanto.ViridianCity_Mart
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_LEFT
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_RIGHT
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_UP
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptContext import de.fiereu.openmmo.server.game.script.ScriptContext
import de.fiereu.openmmo.story.generated.kanto.KantoVars
private const val LOCALID_MART_CLERK = 0
/** The clerk calls the player over the moment they walk in, and hands them Oak's parcel. */
internal object ViridianCity_Mart_EventScript_ParcelScene : Script {
override suspend fun run(ctx: ScriptContext) {
ctx.moveNpc(LOCALID_MART_CLERK, FACE_DOWN)
ctx.sayNpc(LOCALID_MART_CLERK, ViridianCity_Mart.YouCameFromPallet)
ctx.moveSelfAndNpcs(
listOf(WALK_UP, WALK_UP, WALK_UP, WALK_UP, FACE_LEFT),
LOCALID_MART_CLERK to listOf(FACE_RIGHT),
)
ctx.sayNpc(LOCALID_MART_CLERK, ViridianCity_Mart.TakeThisToProfOak)
ctx.setVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_MART, 1)
ctx.giveItem(Items.OAKS_PARCEL)
ctx.sign(ViridianCity_Mart.ReceivedOaksParcelFromClerk)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_PROFESSOR_OAKS_LAB, 5)
}
}
/**
* Not ported yet. Decomp body:
* ```
* lock
* faceplayer
* goto_if_eq VAR_MAP_SCENE_VIRIDIAN_CITY_MART, 1, ViridianCity_Mart_EventScript_SayHiToOak
* goto_if_questlog EventScript_ReleaseEnd
* message Text_MayIHelpYou
* waitmessage
* pokemart ViridianCity_Mart_Items
* msgbox Text_PleaseComeAgain
* release
* end
* ```
*/
internal object ViridianCity_Mart_EventScript_Clerk : Script { internal object ViridianCity_Mart_EventScript_Clerk : Script {
override suspend fun run(ctx: ScriptContext) = TODO("port ViridianCity_Mart_EventScript_Clerk") override suspend fun run(ctx: ScriptContext) {
if (ctx.getVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_MART) == 1) {
return ctx.say(ViridianCity_Mart.SayHiToOakForMe)
}
// TODO Open the mart shop
// The decomp runs pokemart with the shop's item list. Buying and selling needs a shop verb.
}
} }
internal object ViridianCity_Mart_EventScript_Youngster : Script { internal object ViridianCity_Mart_EventScript_Youngster : Script {
@@ -34,6 +50,7 @@ internal object ViridianCity_Mart_EventScript_Woman : Script {
internal val ViridianCity_MartScripts: Map<String, Script> = internal val ViridianCity_MartScripts: Map<String, Script> =
mapOf( mapOf(
"ViridianCity_Mart_EventScript_ParcelScene" to ViridianCity_Mart_EventScript_ParcelScene,
"ViridianCity_Mart_EventScript_Clerk" to ViridianCity_Mart_EventScript_Clerk, "ViridianCity_Mart_EventScript_Clerk" to ViridianCity_Mart_EventScript_Clerk,
"ViridianCity_Mart_EventScript_Youngster" to ViridianCity_Mart_EventScript_Youngster, "ViridianCity_Mart_EventScript_Youngster" to ViridianCity_Mart_EventScript_Youngster,
"ViridianCity_Mart_EventScript_Woman" to ViridianCity_Mart_EventScript_Woman, "ViridianCity_Mart_EventScript_Woman" to ViridianCity_Mart_EventScript_Woman,
@@ -7,6 +7,7 @@ import de.fiereu.openmmo.common.enums.BattleAction
import de.fiereu.openmmo.common.enums.IVs import de.fiereu.openmmo.common.enums.IVs
import de.fiereu.openmmo.common.enums.PokemonContainer import de.fiereu.openmmo.common.enums.PokemonContainer
import de.fiereu.openmmo.common.enums.Region import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.items.generated.Items
import de.fiereu.openmmo.moves.MoveRegistry import de.fiereu.openmmo.moves.MoveRegistry
import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket
import de.fiereu.openmmo.net.game.packets.SocialListEntryAddPacket import de.fiereu.openmmo.net.game.packets.SocialListEntryAddPacket
@@ -42,7 +43,7 @@ import javax.inject.Singleton
private val log = KotlinLogging.logger {} private val log = KotlinLogging.logger {}
private const val POKE_BALL_ITEM: Short = 5004 private val POKE_BALL_ITEM: Short = Items.POKE_BALL.toShort()
/** /**
* A prompt waiting for its answer, kept after the battle ends. A trainer battle can raise one * A prompt waiting for its answer, kept after the battle ends. A trainer battle can raise one
@@ -0,0 +1,59 @@
package de.fiereu.openmmo.server.game.services
import de.fiereu.openmmo.maps.MapDef
import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptRegistry
import de.fiereu.openmmo.server.game.session.PlayerState
import io.github.oshai.kotlinlogging.KotlinLogging
import javax.inject.Inject
import javax.inject.Singleton
private val log = KotlinLogging.logger {}
/**
* Works out which scripts a map runs when a player arrives on it: the ON_TRANSITION script, then
* the first ON_FRAME entry whose story var matches, then the coordinate trigger the player landed
* on. [MapScriptService] runs these on a fresh script coroutine when the player walks or logs in,
* and a script that warps runs them inline on its own coroutine, the way the decomp's warp
* continues into the destination map's scripts.
*/
@Singleton
class MapEntryScripts
@Inject
constructor(
private val scriptRegistry: ScriptRegistry,
private val storyService: StoryService,
) {
fun onEntry(state: PlayerState, map: MapDef): List<Script> {
val charId = state.characterId
return buildList {
resolve(map.onTransitionScript)?.let { add(it) }
if (charId != null) {
map.onFrameScripts
.firstOrNull { storyService.getVar(charId, it.varKey) == it.value }
?.let { resolve(it.script) }
?.let { add(it) }
}
}
}
/** The conditional coordinate trigger on one tile, the decomp coord_events table. */
fun atCoordinate(charId: Long, map: MapDef, x: Int, y: Int): Script? {
val trigger =
map.coordScripts.firstOrNull {
it.x == x && it.y == y && storyService.getVar(charId, it.varKey) == it.value
} ?: return null
return resolve(trigger.script)
}
/** True when the tile has a trigger at all, whatever its var currently says. */
fun hasCoordinate(map: MapDef, x: Int, y: Int): Boolean =
map.coordScripts.any { it.x == x && it.y == y }
private fun resolve(label: String): Script? {
if (label.isEmpty()) return null
val script = scriptRegistry.forLabel(label)
if (script == null) log.debug { "Map script $label is not ported yet" }
return script
}
}
@@ -3,15 +3,11 @@ package de.fiereu.openmmo.server.game.services
import de.fiereu.network.SessionContext import de.fiereu.network.SessionContext
import de.fiereu.openmmo.maps.MapDef import de.fiereu.openmmo.maps.MapDef
import de.fiereu.openmmo.server.game.script.Script import de.fiereu.openmmo.server.game.script.Script
import de.fiereu.openmmo.server.game.script.ScriptRegistry
import de.fiereu.openmmo.server.game.script.ScriptRunner import de.fiereu.openmmo.server.game.script.ScriptRunner
import de.fiereu.openmmo.server.game.session.PlayerState import de.fiereu.openmmo.server.game.session.PlayerState
import io.github.oshai.kotlinlogging.KotlinLogging
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
private val log = KotlinLogging.logger {}
/** /**
* Runs a map's scripts when a player enters it. The decomp ON_TRANSITION script fires on every * Runs a map's scripts when a player enters it. The decomp ON_TRANSITION script fires on every
* entry however the player got there (login, a warp, or walking across a map connection), followed * entry however the player got there (login, a warp, or walking across a map connection), followed
@@ -22,33 +18,22 @@ private val log = KotlinLogging.logger {}
class MapScriptService class MapScriptService
@Inject @Inject
constructor( constructor(
private val scriptRegistry: ScriptRegistry, private val entryScripts: MapEntryScripts,
private val scriptRunner: ScriptRunner, private val scriptRunner: ScriptRunner,
private val storyService: StoryService,
) { ) {
fun onMapEnter(session: SessionContext, state: PlayerState, map: MapDef) { fun onMapEnter(session: SessionContext, state: PlayerState, map: MapDef) {
// A script is already running for this player, do not start a second one on top of it. // A script is already running for this player, do not start a second one on top of it.
if (state.inDialog) return if (state.scriptOwnsMapEntry || state.inDialog) return
val charId = state.characterId val charId = state.characterId
// The on-transition script runs on every entry, then the one on-frame script whose var matches. val entry = entryScripts.onEntry(state, map)
val entryScripts = buildList { val hasArrivalTrigger = entryScripts.hasCoordinate(map, state.x.toInt(), state.y.toInt())
resolve(map.onTransitionScript)?.let { add(it) } if (entry.isEmpty() && !hasArrivalTrigger) return
if (charId != null) {
map.onFrameScripts
.firstOrNull { storyService.getVar(charId, it.varKey) == it.value }
?.let { resolve(it.script) }
?.let { add(it) }
}
}
val hasArrivalTrigger =
map.coordScripts.any { it.x == state.x.toInt() && it.y == state.y.toInt() }
if (entryScripts.isEmpty() && !hasArrivalTrigger) return
// Entry scripts may trigger their landing coordinate. // Entry scripts may trigger their landing coordinate.
val entrySequence = Script { ctx -> val entrySequence = Script { ctx ->
entryScripts.forEach { it.run(ctx) } entry.forEach { it.run(ctx) }
if (charId != null) { if (charId != null) {
matchingCoordScript(map, charId, state.x.toInt(), state.y.toInt())?.run(ctx) entryScripts.atCoordinate(charId, map, state.x.toInt(), state.y.toInt())?.run(ctx)
} }
} }
scriptRunner.run(session, state, entrySequence, entityId = -1) scriptRunner.run(session, state, entrySequence, entityId = -1)
@@ -64,23 +49,8 @@ constructor(
): Boolean { ): Boolean {
if (state.inDialog) return false if (state.inDialog) return false
val charId = state.characterId ?: return false val charId = state.characterId ?: return false
val script = matchingCoordScript(map, charId, x, y) ?: return false val script = entryScripts.atCoordinate(charId, map, x, y) ?: return false
scriptRunner.run(session, state, script, entityId = -1) scriptRunner.run(session, state, script, entityId = -1)
return true return true
} }
private fun matchingCoordScript(map: MapDef, charId: Long, x: Int, y: Int): Script? {
val trigger =
map.coordScripts.firstOrNull {
it.x == x && it.y == y && storyService.getVar(charId, it.varKey) == it.value
} ?: return null
return resolve(trigger.script)
}
private fun resolve(label: String): Script? {
if (label.isEmpty()) return null
val script = scriptRegistry.forLabel(label)
if (script == null) log.debug { "Map script $label is not ported yet" }
return script
}
} }
@@ -23,6 +23,12 @@ data class PlayerState(
@field:Volatile var elevation: Int = 0, @field:Volatile var elevation: Int = 0,
/** Trusts one source tile after scripted movement. */ /** Trusts one source tile after scripted movement. */
@field:Volatile var acceptNextMoveSource: Boolean = false, @field:Volatile var acceptNextMoveSource: Boolean = false,
/**
* A script is warping and will run the destination's entry scripts itself. The arrival must not
* start a second copy, which [inDialog] alone cannot prevent because a stray dialog packet
* clears it while the script is parked on the map load.
*/
@field:Volatile var scriptOwnsMapEntry: Boolean = false,
/** Maps the client already holds. A warp sends deleteCache, which empties this. */ /** Maps the client already holds. A warp sends deleteCache, which empties this. */
val loadedMaps: MutableSet<Int> = ConcurrentHashMap.newKeySet(), val loadedMaps: MutableSet<Int> = ConcurrentHashMap.newKeySet(),
) )
@@ -4,10 +4,7 @@ import de.fiereu.openmmo.common.CharacterInfo
import de.fiereu.openmmo.common.DynamicWarp import de.fiereu.openmmo.common.DynamicWarp
import de.fiereu.openmmo.common.Pokemon import de.fiereu.openmmo.common.Pokemon
import de.fiereu.openmmo.common.enums.CharacterGender import de.fiereu.openmmo.common.enums.CharacterGender
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.Region import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.KotlinLogging
import java.time.LocalDateTime import java.time.LocalDateTime
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@@ -28,19 +25,6 @@ private val log = KotlinLogging.logger {}
private val FLUSH_TICK = 5.seconds private val FLUSH_TICK = 5.seconds
private val FLUSH_DEBOUNCE = 10.seconds private val FLUSH_DEBOUNCE = 10.seconds
private data class StartingPosition(
val bankId: Byte,
val mapId: Byte,
val x: Short,
val y: Short,
)
private val SHOWCASE_STARTS =
mapOf(
Region.KANTO to StartingPosition(4, 1, 6, 6),
Region.HOENN to StartingPosition(75, 40, 2, 2),
)
data class StoredCharacter( data class StoredCharacter(
val info: CharacterInfo, val info: CharacterInfo,
val pokemon: MutableList<Pokemon>, val pokemon: MutableList<Pokemon>,
@@ -86,8 +70,7 @@ constructor(
startingRegion: Region, startingRegion: Region,
): StoredCharacter { ): StoredCharacter {
val female = gender == CharacterGender.FEMALE val female = gender == CharacterGender.FEMALE
val startingPosition = SHOWCASE_STARTS.getValue(startingRegion) val start = NewGameStarts.forRegion(startingRegion, female)
val isHoenn = startingRegion == Region.HOENN
val id = entityIds.newCharacterId() val id = entityIds.newCharacterId()
val now = LocalDateTime.now() val now = LocalDateTime.now()
val info = val info =
@@ -107,54 +90,25 @@ constructor(
pcExtraSlots = 0, pcExtraSlots = 0,
battleBoxExtraSlots = 0, battleBoxExtraSlots = 0,
templateAmount = 0, templateAmount = 0,
// Hoenn starts inside the moving truck.
positionRegionId = startingRegion.wireValue, positionRegionId = startingRegion.wireValue,
positionBankId = startingPosition.bankId, positionBankId = start.bankId,
positionMapId = startingPosition.mapId, positionMapId = start.mapId,
positionX = startingPosition.x, positionX = start.x,
positionY = startingPosition.y, positionY = start.y,
repelLeft = 0, repelLeft = 0,
repelItemId = 0, repelItemId = 0,
lureLeft = 0, lureLeft = 0,
lureItemId = 0, lureItemId = 0,
// The truck exit uses the player's dynamic warp. dynamicWarp = start.dynamicWarp,
dynamicWarp =
if (!isHoenn) null
else
DynamicWarp(
1,
50,
9,
if (female) 12 else 3,
10,
Direction.RIGHT,
),
) )
val storyFlags =
if (!isHoenn) mutableSetOf<String>()
else
(HoennFlags.initiallySet +
(if (female) HoennFlags.femaleIntro else HoennFlags.maleIntro) +
HoennFlags.FLAG_HIDE_MAP_NAME_POPUP)
.toMutableSet()
val housesState =
if (female) HoennVars.VAR_LITTLEROOT_HOUSES_STATE_MAY
else HoennVars.VAR_LITTLEROOT_HOUSES_STATE_BRENDAN
val storyVars =
if (!isHoenn) mutableMapOf<String, Int>()
else
mutableMapOf(
HoennVars.VAR_LITTLEROOT_INTRO_STATE to if (female) 2 else 1,
housesState to 1,
)
val stored = val stored =
StoredCharacter( StoredCharacter(
info, info,
mutableListOf(), mutableListOf(),
mutableListOf(), mutableListOf(),
mutableMapOf(), mutableMapOf(),
storyFlags = storyFlags, storyFlags = start.storyFlags.toMutableSet(),
storyVars = storyVars, storyVars = start.storyVars.toMutableMap(),
) )
repository.insertAggregate(stored) repository.insertAggregate(stored)
characters[id] = stored characters[id] = stored
@@ -0,0 +1,73 @@
package de.fiereu.openmmo.server.game.storage
import de.fiereu.openmmo.common.DynamicWarp
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
/**
* Where a fresh character starts and the story state its source game would already have set. Every
* region needs its own entry, so a new region is one function here rather than another branch in
* [CharacterStore].
*/
internal data class NewGameStart(
val bankId: Byte,
val mapId: Byte,
val x: Short,
val y: Short,
val dynamicWarp: DynamicWarp? = null,
val storyFlags: Set<String> = emptySet(),
val storyVars: Map<String, Int> = emptyMap(),
)
internal object NewGameStarts {
fun forRegion(region: Region, female: Boolean): NewGameStart =
when (region) {
Region.HOENN -> hoenn(female)
Region.KANTO -> kanto()
}
/** Emerald opens in the moving truck, whose exit goes through the player's dynamic warp. */
private fun hoenn(female: Boolean): NewGameStart =
NewGameStart(
bankId = 75,
mapId = 40,
x = 2,
y = 2,
dynamicWarp =
DynamicWarp(
Region.HOENN.wireValue,
50,
9,
if (female) 12 else 3,
10,
Direction.RIGHT,
),
storyFlags =
HoennFlags.initiallySet +
(if (female) HoennFlags.femaleIntro else HoennFlags.maleIntro) +
HoennFlags.FLAG_HIDE_MAP_NAME_POPUP,
storyVars =
mapOf(
HoennVars.VAR_LITTLEROOT_INTRO_STATE to if (female) 2 else 1,
(if (female) HoennVars.VAR_LITTLEROOT_HOUSES_STATE_MAY
else HoennVars.VAR_LITTLEROOT_HOUSES_STATE_BRENDAN) to 1,
),
)
/**
* FireRed opens in the player's bedroom above their house in Pallet Town, at the coordinates its
* new game code warps to. Nothing about the opening depends on the player's gender.
*/
private fun kanto(): NewGameStart =
NewGameStart(
bankId = 4,
mapId = 1,
x = 6,
y = 6,
storyFlags = KantoFlags.initiallySet,
)
}
@@ -0,0 +1,127 @@
package de.fiereu.openmmo.server.game.script
import de.fiereu.openmmo.common.enums.CharacterGender
import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.maps.MapManager
import de.fiereu.openmmo.net.game.packets.NpcUpdatePacket
import de.fiereu.openmmo.server.game.script.generated.kanto.PalletTown_OnTransition
import de.fiereu.openmmo.server.game.script.generated.kanto.PalletTown_ProfessorOaksLab_OnTransition
import de.fiereu.openmmo.server.game.script.generated.kanto.PalletTown_RivalsHouse_OnTransition
import de.fiereu.openmmo.server.game.script.generated.kanto.ViridianCity_OnTransition
import de.fiereu.openmmo.server.game.services.DialogService
import de.fiereu.openmmo.server.game.services.NpcService
import de.fiereu.openmmo.server.game.services.ScriptMovementService
import de.fiereu.openmmo.server.game.services.StoryService
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
import de.fiereu.openmmo.server.game.storage.CharacterStore
import de.fiereu.openmmo.server.game.storage.EntityIdService
import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository
import de.fiereu.openmmo.server.game.testsupport.FakeSession
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
import de.fiereu.openmmo.story.generated.kanto.KantoVars
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
private const val KANTO = 0
private const val PALLET_TOWN_BANK = 3
private const val PALLET_TOWN_MAP = 0
private const val INDOOR_PALLET_BANK = 4
private const val OAKS_LAB_MAP = 3
private const val RIVALS_HOUSE_MAP = 2
private const val VIRIDIAN_CITY_MAP = 1
@OptIn(ExperimentalCoroutinesApi::class)
class KantoStoryScriptTest :
FunSpec({
/** Builds a context for a fresh Kanto character standing on one map. */
suspend fun context(
store: CharacterStore,
story: StoryService,
bankId: Int,
mapId: Int,
): Pair<FakeSession, ScriptContext> {
val charId = store.createCharacter(1, "Red", CharacterGender.MALE, Region.KANTO).info.id
store.updatePosition(charId, 0, 0, bankId.toByte(), mapId.toByte())
val session =
FakeSession(characterId = charId, regionId = KANTO, bankId = bankId, mapId = mapId)
val state = session.attributes[PLAYER_STATE]!!
val mapManager = MapManager()
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
return session to
ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
}
test("entering Oak's lab records the visit") {
runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
val story = StoryService(store)
val (_, ctx) = context(store, story, INDOOR_PALLET_BANK, OAKS_LAB_MAP)
PalletTown_ProfessorOaksLab_OnTransition.run(ctx)
ctx.isFlagSet(KantoFlags.FLAG_VISITED_OAKS_LAB) shouldBe true
}
}
test("Pallet Town marks the sign lady done once she has shown her sign") {
runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
val story = StoryService(store)
val (_, ctx) = context(store, story, PALLET_TOWN_BANK, PALLET_TOWN_MAP)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY, 1)
PalletTown_OnTransition.run(ctx)
ctx.isFlagSet(KantoFlags.FLAG_WORLD_MAP_PALLET_TOWN) shouldBe true
ctx.getVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_SIGN_LADY) shouldBe 2
}
}
test("Pallet Town keeps the sign lady in front of the sign before the starter") {
runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
val story = StoryService(store)
val (session, ctx) = context(store, story, PALLET_TOWN_BANK, PALLET_TOWN_MAP)
PalletTown_OnTransition.run(ctx)
val moves = session.sent.filterIsInstance<NpcUpdatePacket>()
moves.map { it.x to it.y } shouldBe listOf(5 to 15)
moves.map { it.regionId } shouldBe listOf(KANTO)
}
}
test("Daisy sits at the table until she has handed over the town map") {
runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
val story = StoryService(store)
val (session, ctx) = context(store, story, INDOOR_PALLET_BANK, RIVALS_HOUSE_MAP)
PalletTown_RivalsHouse_OnTransition.run(ctx)
ctx.setVar(KantoVars.VAR_MAP_SCENE_PALLET_TOWN_RIVALS_HOUSE, 2)
PalletTown_RivalsHouse_OnTransition.run(ctx)
session.sent.filterIsInstance<NpcUpdatePacket>().map { it.x to it.y } shouldBe
listOf(5 to 4)
}
}
test("the Viridian tutorial man steps aside once Oak's errand is running") {
runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
val story = StoryService(store)
val (session, ctx) = context(store, story, PALLET_TOWN_BANK, VIRIDIAN_CITY_MAP)
ViridianCity_OnTransition.run(ctx)
ctx.setVar(KantoVars.VAR_MAP_SCENE_VIRIDIAN_CITY_OLD_MAN, 1)
ViridianCity_OnTransition.run(ctx)
ctx.isFlagSet(KantoFlags.FLAG_WORLD_MAP_VIRIDIAN_CITY) shouldBe true
session.sent.filterIsInstance<NpcUpdatePacket>().map { it.x to it.y } shouldBe
listOf(21 to 11, 21 to 8)
}
}
})
@@ -5,6 +5,7 @@ import de.fiereu.openmmo.common.enums.Region
import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
import de.fiereu.openmmo.story.generated.hoenn.HoennVars import de.fiereu.openmmo.story.generated.hoenn.HoennVars
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -47,7 +48,7 @@ class CharacterIntroTest :
} }
} }
test("Kanto characters use the captured Pallet bedroom start") { test("Kanto characters start in the Pallet bedroom with FireRed's new game flags") {
runTest { runTest {
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope) val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
@@ -64,9 +65,15 @@ class CharacterIntroTest :
character.info.positionMapId shouldBe 1 character.info.positionMapId shouldBe 1
character.info.positionX shouldBe 6 character.info.positionX shouldBe 6
character.info.positionY shouldBe 6 character.info.positionY shouldBe 6
// Kanto has no truck ride, so nothing depends on the player's dynamic warp yet.
character.info.dynamicWarp shouldBe null character.info.dynamicWarp shouldBe null
character.storyFlags shouldBe emptySet()
character.storyVars shouldBe emptyMap() character.storyVars shouldBe emptyMap()
// Oak waits in the grass rather than in his lab or in town.
(KantoFlags.FLAG_HIDE_OAK_IN_HIS_LAB in character.storyFlags) shouldBe true
(KantoFlags.FLAG_HIDE_OAK_IN_PALLET_TOWN in character.storyFlags) shouldBe true
// The rival and the three starter balls are there from the start.
(KantoFlags.FLAG_HIDE_RIVAL_IN_LAB in character.storyFlags) shouldBe false
(KantoFlags.FLAG_HIDE_BULBASAUR_BALL in character.storyFlags) shouldBe false
} }
} }
@@ -15,6 +15,7 @@ import de.fiereu.openmmo.server.game.script.ScriptRunner
import de.fiereu.openmmo.server.game.services.BattleService import de.fiereu.openmmo.server.game.services.BattleService
import de.fiereu.openmmo.server.game.services.DialogService import de.fiereu.openmmo.server.game.services.DialogService
import de.fiereu.openmmo.server.game.services.EncounterService import de.fiereu.openmmo.server.game.services.EncounterService
import de.fiereu.openmmo.server.game.services.MapEntryScripts
import de.fiereu.openmmo.server.game.services.MapLoadService import de.fiereu.openmmo.server.game.services.MapLoadService
import de.fiereu.openmmo.server.game.services.MapScriptService import de.fiereu.openmmo.server.game.services.MapScriptService
import de.fiereu.openmmo.server.game.services.MovementService import de.fiereu.openmmo.server.game.services.MovementService
@@ -62,7 +63,7 @@ fun movementService(
moveRegistry = moves, moveRegistry = moves,
trainers = TrainerRegistry(), trainers = TrainerRegistry(),
) )
val registry = ScriptRegistry(emptyMap()) val entryScripts = MapEntryScripts(ScriptRegistry(emptyMap()), story)
val runner = val runner =
ScriptRunner( ScriptRunner(
DialogService(), DialogService(),
@@ -72,6 +73,8 @@ fun movementService(
StoryPlayerService(store, wildMons, species, moves), StoryPlayerService(store, wildMons, species, moves),
battles, battles,
store, store,
mapManager,
entryScripts,
) )
return MovementService( return MovementService(
WarpService(mapLoad, mapManager, store, presence), WarpService(mapLoad, mapManager, store, presence),
@@ -81,6 +84,6 @@ fun movementService(
mapManager, mapManager,
store, store,
EncounterService(store, battles), EncounterService(store, battles),
MapScriptService(registry, runner, story), MapScriptService(entryScripts, runner),
) )
} }