diff --git a/codegen/build.gradle.kts b/codegen/build.gradle.kts index c730804..d56f35d 100644 --- a/codegen/build.gradle.kts +++ b/codegen/build.gradle.kts @@ -41,6 +41,16 @@ jteCodegen { "$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") { mainClass.set("de.fiereu.openmmo.codegen.move.Main") templatesSubdir.set("move") diff --git a/codegen/src/generator/jte/item/Items.jte b/codegen/src/generator/jte/item/Items.jte new file mode 100644 index 0000000..d3a2740 --- /dev/null +++ b/codegen/src/generator/jte/item/Items.jte @@ -0,0 +1,15 @@ +@import java.util.List +@import de.fiereu.openmmo.codegen.item.ParsedItem + +@param List 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 +} diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/dialog/TextParser.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/dialog/TextParser.kt index 88a9a3e..644cb74 100644 --- a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/dialog/TextParser.kt +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/dialog/TextParser.kt @@ -13,7 +13,14 @@ class TextParser(private val decompDir: File) { private val labelLine = Regex("^(\\w+):+\\s*$") fun parseAll(): List { - 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() for (root in roots) { if (!root.isDirectory) continue diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemParser.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemParser.kt new file mode 100644 index 0000000..9a2e745 --- /dev/null +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemParser.kt @@ -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 { + 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) + } +} diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemsRenderer.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemsRenderer.kt new file mode 100644 index 0000000..e9a4e2f --- /dev/null +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ItemsRenderer.kt @@ -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) { + 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" + } +} diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/Main.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/Main.kt new file mode 100644 index 0000000..40c8e8e --- /dev/null +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/Main.kt @@ -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) { + require(args.size >= 4) { + "Usage: 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") +} diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ParsedModel.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ParsedModel.kt new file mode 100644 index 0000000..a2d262f --- /dev/null +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/item/ParsedModel.kt @@ -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) diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/maps/PretGbaParser.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/maps/PretGbaParser.kt index b5ae9ef..7796051 100644 --- a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/maps/PretGbaParser.kt +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/maps/PretGbaParser.kt @@ -308,8 +308,9 @@ class PretGbaParser( .find(text) ?.groupValues ?.get(1) ?: return emptyList() + // Emerald writes the table label with one colon, FireRed with two. 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) ?.groupValues ?.get(1) ?: return emptyList() diff --git a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParser.kt b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParser.kt index c7ca2cf..38ff783 100644 --- a/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParser.kt +++ b/codegen/src/generator/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParser.kt @@ -18,32 +18,27 @@ object FlagVarParser { fun vars(decompDir: File): List = 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 = - scriptFlags( - decompDir, - "data/scripts/new_game.inc", - "EventScript_ResetAllMapFlags", - ) + scriptFlags(decompDir, "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 = - scriptFlags( - decompDir, - "data/maps/InsideOfTruck/scripts.inc", - "InsideOfTruck_EventScript_SetIntroFlagsMale", - ) + scriptFlags(decompDir, "InsideOfTruck_EventScript_SetIntroFlagsMale") fun femaleIntroFlags(decompDir: File): List = - scriptFlags( - decompDir, - "data/maps/InsideOfTruck/scripts.inc", - "InsideOfTruck_EventScript_SetIntroFlagsFemale", - ) + scriptFlags(decompDir, "InsideOfTruck_EventScript_SetIntroFlagsFemale") - private fun scriptFlags(decompDir: File, relativePath: String, label: String): List { - val file = File(decompDir, relativePath) - if (!file.exists()) return emptyList() + /** + * The flags one decomp script sets, found by its label. Each game keeps these scripts in a + * 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 { + val file = findScriptFile(decompDir, label) ?: return emptyList() val result = mutableListOf() var inBlock = false for (rawLine in file.readLines()) { @@ -63,6 +58,15 @@ object FlagVarParser { 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( decompDir: File, relativePath: String, @@ -309,4 +313,6 @@ object FlagVarParser { private fun parseNumber(value: String): Int = if (value.startsWith("0x", ignoreCase = true)) value.drop(2).toInt(16) else value.toInt() + + private val SCRIPT_EXTENSIONS = setOf("inc", "s") } diff --git a/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/item/ItemParserTest.kt b/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/item/ItemParserTest.kt new file mode 100644 index 0000000..8a4cf70 --- /dev/null +++ b/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/item/ItemParserTest.kt @@ -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), + ) + } + }) diff --git a/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParserTest.kt b/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParserTest.kt index b593760..22b5934 100644 --- a/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParserTest.kt +++ b/codegen/src/test/kotlin/de/fiereu/openmmo/codegen/story/FlagVarParserTest.kt @@ -76,4 +76,23 @@ class FlagVarParserTest : FlagVarParser.maleIntroFlags(decomp) shouldBe listOf("FLAG_MALE") 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() + } }) diff --git a/docs/src/content/docs/concepts/scripts.md b/docs/src/content/docs/concepts/scripts.md index 24777b6..785d344 100644 --- a/docs/src/content/docs/concepts/scripts.md +++ b/docs/src/content/docs/concepts/scripts.md @@ -85,8 +85,8 @@ Scripts triggered this way get `entityId = -1`. ### Entering a map `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 -scripts and runs them in order: +login, a warp, or walking across a map connection. `MapEntryScripts.onEntry` +builds the list and `MapScriptService` runs it in order: 1. `map.onTransitionScript`, unconditionally. 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 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. ## Why scripts are coroutines diff --git a/docs/src/content/docs/concepts/story-state.md b/docs/src/content/docs/concepts/story-state.md index 9f99ff8..41e284d 100644 --- a/docs/src/content/docs/concepts/story-state.md +++ b/docs/src/content/docs/concepts/story-state.md @@ -100,7 +100,7 @@ value it already has, is a no-op and does not dirty the character. ## 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 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 diff --git a/docs/src/content/docs/guides/porting-scripts.md b/docs/src/content/docs/guides/porting-scripts.md index 019445f..1fe0757 100644 --- a/docs/src/content/docs/guides/porting-scripts.md +++ b/docs/src/content/docs/guides/porting-scripts.md @@ -56,9 +56,28 @@ end of your function. | `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 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)` | +| `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)` | +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 consecutive calls show consecutive boxes with no extra plumbing. `moveNpc` and `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: -- **Choices.** `MSGBOX_YESNO`, `multichoice` and anything reading `VAR_RESULT` - 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. +- **More than two answers.** `multichoice`. Yes/no works, a longer menu does not. - **Doors.** `opendoor`, `closedoor`, `waitdooranim`. -- **Warping from a script.** `warp`, `warpsilent`, `warphole`. Only - `setDynamicWarp`, which changes where an existing `MAP_DYNAMIC` warp tile - sends the player, exists. -- **Hiding things.** `hideobjectat`, `hideplayer`/`showplayer`. `showNpc` exists, - its inverse does not, beyond ending a movement with `SET_INVISIBLE`. -- **Items, money, party.** `giveitem`, `takeitem`, `checkitemspace`, - `givemon`, `addvar` on money, and so on. -- **Battles.** `trainerbattle` in all its forms. -- **Player identity.** `checkplayergender`, and the `VAR_RESULT` branch that - usually follows it. +- **Shops.** `pokemart` and its item list. +- **Hiding the player.** `hideplayer`/`showplayer`. Npcs can be hidden with + `removeNpc` or by ending a movement with `SET_INVISIBLE`, the player cannot. +- **Money.** Buying and selling. +- **Temporary state.** `VAR_TEMP_*` and `FLAG_TEMP_*` reset when the player + leaves the map in the source game. Story flags and vars here are persistent, + so a script that leans on a temp value needs another way to say the same thing. - **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` comment naming what is missing, the way the Littleroot intro does: diff --git a/docs/src/content/docs/guides/writing-scripts.md b/docs/src/content/docs/guides/writing-scripts.md index 2c733f5..b4b4eff 100644 --- a/docs/src/content/docs/guides/writing-scripts.md +++ b/docs/src/content/docs/guides/writing-scripts.md @@ -74,17 +74,26 @@ Everything goes through `ctx`, the `ScriptContext`: | Call | What it does | | --- | --- | | `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.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.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.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.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, -choices, doors, giving items, trainer battles, +That is the whole api. Plenty of decomp commands still have no equivalent in it, +doors, shops and sound effects among them, [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 diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptContext.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptContext.kt index 02b19db..48e1bd2 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptContext.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptContext.kt @@ -5,11 +5,13 @@ import de.fiereu.openmmo.common.DynamicWarp import de.fiereu.openmmo.common.dialog.DialogLine import de.fiereu.openmmo.common.enums.Direction 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.server.game.battle.BattleResult import de.fiereu.openmmo.server.game.services.BattleService import de.fiereu.openmmo.server.game.services.DialogPresentation 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.ScriptWarpService import de.fiereu.openmmo.server.game.services.StoryClientState @@ -32,6 +34,8 @@ internal constructor( internal val player: StoryPlayerService? = null, private val battles: BattleService? = null, internal val characters: CharacterStore? = null, + private val maps: MapManager? = null, + private val entryScripts: MapEntryScripts? = null, ) { private val characterId: Long? get() = state.characterId @@ -134,6 +138,9 @@ internal constructor( fun giveItem(itemId: Int, quantity: Int = 1): Boolean = 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. */ suspend fun battle(dexId: Int, level: Int, vararg moveIds: Int): BattleResult = checkNotNull(battles) { "Battle service is unavailable" } @@ -194,21 +201,35 @@ internal constructor( DynamicWarp( 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) { - checkNotNull(warp) { "Script warp service is unavailable" } - .warp( - session, - state, - DynamicWarp( - regionId.toByte(), - bankId.toByte(), - mapId.toByte(), - x.toShort(), - y.toShort(), - facing, - ), - ) + val warpService = checkNotNull(warp) { "Script warp service is unavailable" } + state.scriptOwnsMapEntry = true + try { + warpService.warp( + session, + state, + DynamicWarp( + regionId.toByte(), + bankId.toByte(), + mapId.toByte(), + 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 { diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptRunner.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptRunner.kt index 8d33d34..c0b02ab 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptRunner.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/ScriptRunner.kt @@ -1,8 +1,10 @@ package de.fiereu.openmmo.server.game.script 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.DialogService +import de.fiereu.openmmo.server.game.services.MapEntryScripts import de.fiereu.openmmo.server.game.services.ScriptMovementService import de.fiereu.openmmo.server.game.services.ScriptWarpService import de.fiereu.openmmo.server.game.services.StoryPlayerService @@ -38,6 +40,8 @@ constructor( private val storyPlayerService: StoryPlayerService, private val battleService: BattleService, private val characterStore: CharacterStore, + private val mapManager: MapManager, + private val entryScripts: MapEntryScripts, ) { fun run(session: SessionContext, state: PlayerState, script: Script, entityId: Long) = runAll(session, state, listOf(script), entityId) @@ -70,6 +74,8 @@ constructor( storyPlayerService, battleService, characterStore, + mapManager, + entryScripts, ) scope.launch { try { diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/LittlerootTown_ProfessorBirchsLab.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/LittlerootTown_ProfessorBirchsLab.kt index deb691e..458cb74 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/LittlerootTown_ProfessorBirchsLab.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/LittlerootTown_ProfessorBirchsLab.kt @@ -1,6 +1,7 @@ package de.fiereu.openmmo.server.game.script.generated.hoenn 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_RIGHT 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_RIVAL = 2 -private const val POKE_BALL_ITEM = 5004 private const val TREECKO = 252 private val HOENN_STARTERS = listOf(TREECKO, 255, 258) @@ -68,7 +68,7 @@ internal object LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent : } else { ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.MayGotPokedexTooTakeThese) } - ctx.giveItem(POKE_BALL_ITEM, 5) + ctx.giveItem(Items.POKE_BALL, 5) if (ctx.isFemale) { ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.CatchCoolPokemonWithPokeBalls) } else { diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/PetalburgWoods.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/PetalburgWoods.kt index 88767d5..5c53e42 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/PetalburgWoods.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/hoenn/PetalburgWoods.kt @@ -1,6 +1,7 @@ package de.fiereu.openmmo.server.game.script.generated.hoenn 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.script.MovementStep.FACE_UP 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_DEVON_RESEARCHER = 3 private const val POOCHYENA = 261 -private const val GREAT_BALL_ITEM = 5003 internal object PetalburgWoods_EventScript_DevonResearcherLeft : Script { 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.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.ICantBeWastingTime) ctx.moveNpc( diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown.kt index f931b2d..9cfab43 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown.kt @@ -1,55 +1,163 @@ 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.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.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: - * ``` - * 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 - * ``` + * 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. */ +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 = + 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 { - 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 { 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 { - 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 { @@ -64,23 +172,20 @@ internal object PalletTown_EventScript_TownSign : Script { 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 { - 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 = 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_SignLadyTrigger" to PalletTown_EventScript_SignLadyTrigger, "PalletTown_EventScript_FatMan" to PalletTown_EventScript_FatMan, "PalletTown_EventScript_OaksLabSign" to PalletTown_EventScript_OaksLabSign, "PalletTown_EventScript_PlayersHouseSign" to PalletTown_EventScript_PlayersHouseSign, diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_PlayersHouse_1F.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_PlayersHouse_1F.kt index 2df4a92..6de5114 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_PlayersHouse_1F.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_PlayersHouse_1F.kt @@ -1,42 +1,38 @@ 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.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 { - override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_PlayersHouse_1F_EventScript_Mom") + override suspend fun run(ctx: ScriptContext) { + 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 { - override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_PlayersHouse_1F_EventScript_TV") + override suspend fun run(ctx: ScriptContext) { + 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 = diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_ProfessorOaksLab.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_ProfessorOaksLab.kt index 0c1e8d7..2a222bb 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_ProfessorOaksLab.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_ProfessorOaksLab.kt @@ -1,159 +1,332 @@ 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.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.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: - * ``` - * lock - * faceplayer - * goto_if_set FLAG_SYS_GAME_CLEAR, PalletTown_ProfessorOaksLab_EventScript_Aide1GameClear - * msgbox PalletTown_ProfessorOaksLab_Text_StudyAsOaksAide - * release - * end - * ``` + * 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. */ +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 + 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 { 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 { override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_ProfessorOaksLab_EventScript_Aide2") + ctx.say(PalletTown_ProfessorOaksLab.StudyAsOaksAide) } -/** - * 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 { +internal object PalletTown_ProfessorOaksLab_EventScript_Aide3 : Script { override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_ProfessorOaksLab_EventScript_ProfOak") -} - -/** - * 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") + ctx.say(PalletTown_ProfessorOaksLab.OakIsAuthorityOnMons) } internal object PalletTown_ProfessorOaksLab_EventScript_Pokedex : Script { @@ -170,23 +343,29 @@ internal object PalletTown_ProfessorOaksLab_EventScript_LeftSign : Script { 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 { - override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_ProfessorOaksLab_EventScript_RightSign") + override suspend fun run(ctx: ScriptContext) { + 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 = 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, "PalletTown_ProfessorOaksLab_EventScript_Aide3" to diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_RivalsHouse.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_RivalsHouse.kt index 7ab8c8a..2cb9fc4 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_RivalsHouse.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/PalletTown_RivalsHouse.kt @@ -1,31 +1,47 @@ package de.fiereu.openmmo.server.game.script.generated.kanto 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.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 { - override suspend fun run(ctx: ScriptContext) = - TODO("port PalletTown_RivalsHouse_EventScript_Daisy") + override suspend fun run(ctx: ScriptContext) { + 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 { @@ -44,6 +60,7 @@ internal object PalletTown_RivalsHouse_EventScript_Picture : Script { internal val PalletTown_RivalsHouseScripts: Map = mapOf( + "PalletTown_RivalsHouse_OnTransition" to PalletTown_RivalsHouse_OnTransition, "PalletTown_RivalsHouse_EventScript_Daisy" to PalletTown_RivalsHouse_EventScript_Daisy, "PalletTown_RivalsHouse_EventScript_TownMap" to PalletTown_RivalsHouse_EventScript_TownMap, "PalletTown_RivalsHouse_EventScript_Bookshelf" to diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/Route1.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/Route1.kt index e0afea4..1adf116 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/Route1.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/Route1.kt @@ -1,34 +1,21 @@ package de.fiereu.openmmo.server.game.script.generated.kanto 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.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 { - 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 { diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity.kt index 369a77e..35019bb 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity.kt @@ -1,8 +1,77 @@ package de.fiereu.openmmo.server.game.script.generated.kanto 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.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: @@ -16,84 +85,62 @@ internal object ViridianCity_EventScript_DreamEaterTutor : Script { 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 { - 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 { - override suspend fun run(ctx: ScriptContext) = - TODO("port ViridianCity_EventScript_TutorialOldMan") + override suspend fun run(ctx: ScriptContext) { + 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 { - 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 { - 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 { 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 { - 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 { @@ -118,6 +165,13 @@ internal object ViridianCity_EventScript_GymDoor : Script { internal val ViridianCityScripts: Map = 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_OldMan" to ViridianCity_EventScript_OldMan, "ViridianCity_EventScript_TutorialOldMan" to ViridianCity_EventScript_TutorialOldMan, diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity_Mart.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity_Mart.kt index 4ee8466..464a2c4 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity_Mart.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/script/generated/kanto/ViridianCity_Mart.kt @@ -1,26 +1,42 @@ package de.fiereu.openmmo.server.game.script.generated.kanto 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.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 { - 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 { @@ -34,6 +50,7 @@ internal object ViridianCity_Mart_EventScript_Woman : Script { internal val ViridianCity_MartScripts: Map = mapOf( + "ViridianCity_Mart_EventScript_ParcelScene" to ViridianCity_Mart_EventScript_ParcelScene, "ViridianCity_Mart_EventScript_Clerk" to ViridianCity_Mart_EventScript_Clerk, "ViridianCity_Mart_EventScript_Youngster" to ViridianCity_Mart_EventScript_Youngster, "ViridianCity_Mart_EventScript_Woman" to ViridianCity_Mart_EventScript_Woman, diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/BattleService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/BattleService.kt index 0f9e55c..c55a9dc 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/BattleService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/BattleService.kt @@ -7,6 +7,7 @@ import de.fiereu.openmmo.common.enums.BattleAction import de.fiereu.openmmo.common.enums.IVs import de.fiereu.openmmo.common.enums.PokemonContainer import de.fiereu.openmmo.common.enums.Region +import de.fiereu.openmmo.items.generated.Items import de.fiereu.openmmo.moves.MoveRegistry import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket import de.fiereu.openmmo.net.game.packets.SocialListEntryAddPacket @@ -42,7 +43,7 @@ import javax.inject.Singleton 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 diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapEntryScripts.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapEntryScripts.kt new file mode 100644 index 0000000..f82c096 --- /dev/null +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/MapEntryScripts.kt @@ -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