feat(game): implement Hoenn story through Rustboro (#77)
* feat(game): implement Hoenn story through Rustboro * fix(game): group dialog presentation options * fix(game): address review feedback and running movement
This commit is contained in:
1 parent
f57149eae3
commit
3b19a81201
85 files changed
+4044
-338
No files matched your search
@@ -12,12 +12,11 @@ dependencies {
|
||||
"generatorImplementation"(project(":common"))
|
||||
"generatorImplementation"(libs.jte)
|
||||
"generatorImplementation"(libs.kotlinx.serialization.json)
|
||||
testImplementation(sourceSets["generator"].output)
|
||||
testImplementation(libs.bundles.kotest)
|
||||
}
|
||||
|
||||
// Region name -> source decomp. Only non-NDS (GBA, 2D) decomps that share the pret
|
||||
// map format are listed. The NDS decomps (pokeblack, pokeheartgold, pokeplatinum) use
|
||||
// 3D maps and are not parsed here. Region ids live in the per-region constants.
|
||||
// GBA regions sharing the pret map format.
|
||||
val regionSources =
|
||||
mapOf(
|
||||
"hoenn" to "pokeemerald",
|
||||
|
||||
@@ -15,6 +15,7 @@ import de.fiereu.openmmo.common.enums.MapType
|
||||
import de.fiereu.openmmo.common.enums.MovementType
|
||||
import de.fiereu.openmmo.common.enums.Weather
|
||||
import de.fiereu.openmmo.maps.BgEventDef
|
||||
import de.fiereu.openmmo.maps.MapCoordScript
|
||||
import de.fiereu.openmmo.maps.MapDef
|
||||
import de.fiereu.openmmo.maps.MapFrameScript
|
||||
import de.fiereu.openmmo.maps.NpcDef
|
||||
@@ -25,9 +26,9 @@ import de.fiereu.openmmo.net.game.packets.MapData
|
||||
|
||||
internal val ${objectName}: MapDef =
|
||||
MapDef(
|
||||
regionId = ${map.getRegion()},
|
||||
bankId = ${map.getBank()},
|
||||
mapId = ${map.getIndex()},
|
||||
regionId = ${map.getRegion()}.toByte(),
|
||||
bankId = ${map.getBank()}.toByte(),
|
||||
mapId = ${map.getIndex()}.toByte(),
|
||||
width = ${map.getWidth()},
|
||||
height = ${map.getHeight()},
|
||||
paletteIdx1 = ${map.getPaletteIdx1()},
|
||||
@@ -48,4 +49,5 @@ internal val ${objectName}: MapDef =
|
||||
bgEvents = ${RenderUtil.INSTANCE.bgEvents(map.getBgEvents())},
|
||||
onTransitionScript = "${map.getOnTransitionScript()}",
|
||||
onFrameScripts = ${RenderUtil.INSTANCE.frameScripts(map.getOnFrameScripts())},
|
||||
coordScripts = ${RenderUtil.INSTANCE.coordScripts(map.getCoordScripts())},
|
||||
)
|
||||
@@ -1,9 +1,14 @@
|
||||
@import java.util.List
|
||||
@import de.fiereu.openmmo.codegen.story.StoryConstant
|
||||
|
||||
@param String pkg
|
||||
@param String objectName
|
||||
@param String namespace
|
||||
@param List<String> names
|
||||
@param List<StoryConstant> constants
|
||||
@param List<List<StoryConstant>> idChunks
|
||||
@param List<StoryConstant> initialFlags
|
||||
@param List<StoryConstant> maleIntroFlags
|
||||
@param List<StoryConstant> femaleIntroFlags
|
||||
package ${pkg}
|
||||
|
||||
/**
|
||||
@@ -11,7 +16,52 @@ package ${pkg}
|
||||
* to ScriptContext (setFlag/isFlagSet, setVar/getVar). Generated, do not edit by hand.
|
||||
*/
|
||||
object ${objectName} {
|
||||
@for(String name : names)
|
||||
const val ${name} = "${namespace}/${name}"
|
||||
@for(StoryConstant constant : constants)
|
||||
const val ${constant.getName()} = "${namespace}/${constant.getName()}"
|
||||
@endfor
|
||||
|
||||
@if(!initialFlags.isEmpty())
|
||||
/** Flags set by the source game's new-game map reset. */
|
||||
val initiallySet: Set<String> =
|
||||
setOf(
|
||||
@for(StoryConstant constant : initialFlags)
|
||||
${constant.getName()},
|
||||
@endfor
|
||||
)
|
||||
|
||||
/** Additional flags established in the moving truck for the male player path. */
|
||||
val maleIntro: Set<String> =
|
||||
setOf(
|
||||
@for(StoryConstant constant : maleIntroFlags)
|
||||
${constant.getName()},
|
||||
@endfor
|
||||
)
|
||||
|
||||
/** Additional flags established in the moving truck for the female player path. */
|
||||
val femaleIntro: Set<String> =
|
||||
setOf(
|
||||
@for(StoryConstant constant : femaleIntroFlags)
|
||||
${constant.getName()},
|
||||
@endfor
|
||||
)
|
||||
|
||||
@endif
|
||||
/** Numeric id assigned by the source game's constants header. */
|
||||
fun numericId(key: String): Int? {
|
||||
@for(int index = 0; index < idChunks.size(); index++)
|
||||
numericId${index}(key)?.let { return it }
|
||||
@endfor
|
||||
return null
|
||||
}
|
||||
|
||||
@for(int index = 0; index < idChunks.size(); index++)
|
||||
private fun numericId${index}(key: String): Int? =
|
||||
when (key) {
|
||||
@for(StoryConstant constant : idChunks.get(index))
|
||||
${constant.getName()} -> ${constant.getNumericId()}
|
||||
@endfor
|
||||
else -> null
|
||||
}
|
||||
|
||||
@endfor
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.fiereu.openmmo.codegen.maps
|
||||
|
||||
internal const val BANK_GROUP_OFFSET = 50
|
||||
|
||||
internal val COMMON_DIR_MAP =
|
||||
mapOf(
|
||||
"down" to "Direction.DOWN",
|
||||
|
||||
@@ -4,6 +4,9 @@ object HoennConstants :
|
||||
RegionConstants(
|
||||
name = "hoenn",
|
||||
regionId = 1,
|
||||
// Emerald uses offset map and tileset namespaces.
|
||||
gbaBankOffset = 50,
|
||||
gbaPaletteOffset = 100,
|
||||
defaultVisibleNpcs =
|
||||
mapOf(
|
||||
"LittlerootTown_MaysHouse_1F" to listOf(0),
|
||||
|
||||
@@ -88,6 +88,10 @@ private constructor(
|
||||
when (name) {
|
||||
"MB_TALL_GRASS" -> TileBehavior.TALL_GRASS
|
||||
"MB_LONG_GRASS" -> TileBehavior.LONG_GRASS
|
||||
"MB_JUMP_EAST" -> TileBehavior.JUMP_EAST
|
||||
"MB_JUMP_WEST" -> TileBehavior.JUMP_WEST
|
||||
"MB_JUMP_NORTH" -> TileBehavior.JUMP_NORTH
|
||||
"MB_JUMP_SOUTH" -> TileBehavior.JUMP_SOUTH
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ data class ParsedMap(
|
||||
val onTransitionScript: String,
|
||||
// The map's ON_FRAME table: run the script once its var equals the value, on map entry.
|
||||
val onFrameScripts: List<ParsedFrameScript>,
|
||||
// Tile triggers from map.json coord_events.
|
||||
val coordScripts: List<ParsedCoordScript>,
|
||||
)
|
||||
|
||||
data class ParsedFrameScript(
|
||||
@@ -38,6 +40,15 @@ data class ParsedFrameScript(
|
||||
val script: String,
|
||||
)
|
||||
|
||||
data class ParsedCoordScript(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val elevation: Int,
|
||||
val varKey: String,
|
||||
val value: Int,
|
||||
val script: String,
|
||||
)
|
||||
|
||||
data class ParsedConnection(
|
||||
val direction: String,
|
||||
val offset: Int,
|
||||
|
||||
@@ -168,7 +168,7 @@ class PretGbaParser(
|
||||
groupName = groupName,
|
||||
mapId = mapJson["id"]?.jsonPrimitive?.contentOrNull ?: mapDirName,
|
||||
region = region.regionId,
|
||||
bank = groupIndex + BANK_GROUP_OFFSET,
|
||||
bank = wireBank(groupIndex),
|
||||
index = mapIndex,
|
||||
width = layout["width"]?.jsonPrimitive?.intOrNull ?: 20,
|
||||
height = layout["height"]?.jsonPrimitive?.intOrNull ?: 15,
|
||||
@@ -194,6 +194,7 @@ class PretGbaParser(
|
||||
bgEvents = parseBgEvents(mapJson),
|
||||
onTransitionScript = parseOnTransitionScript(mapDirName),
|
||||
onFrameScripts = parseOnFrameScripts(mapDirName),
|
||||
coordScripts = parseCoordScripts(mapJson),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -217,7 +218,7 @@ class PretGbaParser(
|
||||
ParsedConnection(
|
||||
direction = dir,
|
||||
offset = obj["offset"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
targetBank = addr.groupIndex + BANK_GROUP_OFFSET,
|
||||
targetBank = wireBank(addr.groupIndex),
|
||||
targetMap = addr.mapIndex,
|
||||
)
|
||||
} ?: emptyList()
|
||||
@@ -257,7 +258,7 @@ class PretGbaParser(
|
||||
y = y,
|
||||
elevation = (srcElevation - 1).coerceAtLeast(0),
|
||||
targetRegion = region.regionId,
|
||||
targetBank = destAddr.groupIndex + BANK_GROUP_OFFSET,
|
||||
targetBank = wireBank(destAddr.groupIndex),
|
||||
targetMap = destAddr.mapIndex,
|
||||
targetX = target?.get("x")?.jsonPrimitive?.intOrNull ?: x,
|
||||
targetY = target?.get("y")?.jsonPrimitive?.intOrNull ?: y,
|
||||
@@ -338,6 +339,25 @@ class PretGbaParser(
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
/** Scripts fired on map trigger coordinates. */
|
||||
private fun parseCoordScripts(mapJson: JsonObject): List<ParsedCoordScript> =
|
||||
mapJson["coord_events"]?.jsonArrayOrNull()?.mapNotNull { event ->
|
||||
val obj = event.jsonObject
|
||||
if (obj["type"]?.jsonPrimitive?.contentOrNull != "trigger") return@mapNotNull null
|
||||
val varName = obj["var"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
|
||||
val value =
|
||||
obj["var_value"]?.jsonPrimitive?.contentOrNull?.toIntOrNull() ?: return@mapNotNull null
|
||||
val script = obj["script"]?.jsonPrimitive?.contentOrNull ?: return@mapNotNull null
|
||||
ParsedCoordScript(
|
||||
x = obj["x"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
y = obj["y"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
elevation = obj["elevation"]?.jsonPrimitive?.intOrNull ?: 0,
|
||||
varKey = "${region.name}/$varName",
|
||||
value = value,
|
||||
script = script,
|
||||
)
|
||||
} ?: emptyList()
|
||||
|
||||
private fun parseBorderTiles(layout: JsonObject): List<Int> =
|
||||
layout["border_filepath"]?.jsonPrimitive?.contentOrNull?.let {
|
||||
readBorderTiles(File(rootDir, it))
|
||||
@@ -435,11 +455,11 @@ class PretGbaParser(
|
||||
val file = File(rootDir, "src/data/tilesets/headers.h")
|
||||
if (!file.exists()) return emptyMap()
|
||||
val pattern = Regex("""^const struct Tileset\s+(gTileset_\w+)\s*=""")
|
||||
var index = 0
|
||||
var index = region.gbaPaletteOffset
|
||||
val out = mutableMapOf<String, Int>()
|
||||
file.forEachLine { line ->
|
||||
val m = pattern.find(line.trim()) ?: return@forEachLine
|
||||
out[m.groupValues[1]] = 100 + index
|
||||
out[m.groupValues[1]] = index
|
||||
index++
|
||||
}
|
||||
return out
|
||||
@@ -454,5 +474,7 @@ class PretGbaParser(
|
||||
return out
|
||||
}
|
||||
|
||||
private fun wireBank(groupIndex: Int): Int = groupIndex + region.gbaBankOffset
|
||||
|
||||
private fun JsonElement.jsonArrayOrNull() = (this as? JsonArray)
|
||||
}
|
||||
@@ -3,6 +3,10 @@ package de.fiereu.openmmo.codegen.maps
|
||||
open class RegionConstants(
|
||||
val name: String,
|
||||
val regionId: Int,
|
||||
/** Client map-group offset. */
|
||||
val gbaBankOffset: Int = 0,
|
||||
/** Client tileset offset. */
|
||||
val gbaPaletteOffset: Int = 0,
|
||||
val defaultVisibleNpcs: Map<String, List<Int>> = emptyMap(),
|
||||
val dirMap: Map<String, String> = COMMON_DIR_MAP,
|
||||
val weatherMap: Map<String, String> = COMMON_WEATHER_MAP,
|
||||
|
||||
@@ -29,8 +29,8 @@ object RenderUtil {
|
||||
if (warps.isEmpty()) return EMPTY_LIST
|
||||
return warps.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"WarpTile(x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
|
||||
" targetRegionId = ${it.targetRegion}, targetBankId = ${it.targetBank}," +
|
||||
" targetMapId = ${it.targetMap}," +
|
||||
" targetRegionId = ${it.targetRegion}.toByte(), targetBankId = ${it.targetBank}.toByte()," +
|
||||
" targetMapId = ${it.targetMap}.toByte()," +
|
||||
" targetX = ${it.targetX}, targetY = ${it.targetY}, targetElevation = ${it.targetElevation}," +
|
||||
" dynamic = ${it.dynamic})"
|
||||
}
|
||||
@@ -56,6 +56,15 @@ object RenderUtil {
|
||||
}
|
||||
}
|
||||
|
||||
fun coordScripts(scripts: List<ParsedCoordScript>): String {
|
||||
if (scripts.isEmpty()) return EMPTY_LIST
|
||||
return scripts.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
"MapCoordScript(x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," +
|
||||
" varKey = ${escapeString(it.varKey)}, value = ${it.value}," +
|
||||
" script = ${escapeString(it.script)})"
|
||||
}
|
||||
}
|
||||
|
||||
fun bgEvents(events: List<ParsedBgEvent>): String {
|
||||
if (events.isEmpty()) return EMPTY_LIST
|
||||
return events.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) {
|
||||
|
||||
@@ -2,22 +2,311 @@ package de.fiereu.openmmo.codegen.story
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Pulls the flag and var names out of a GBA decomp. Only the names matter here, the numeric values
|
||||
* are the client's concern and are not needed to key the game agnostic story store. The FLAG_/VAR_
|
||||
* prefix match skips the range markers like TEMP_FLAGS_START and FLAGS_COUNT on its own.
|
||||
*/
|
||||
data class StoryConstant(val name: String, val numericId: Int)
|
||||
|
||||
/** Reads GBA ids from pret headers. */
|
||||
object FlagVarParser {
|
||||
private data class Macro(
|
||||
val parameters: List<String>?,
|
||||
val expression: String,
|
||||
val numericHint: Int?,
|
||||
)
|
||||
|
||||
fun flags(decompDir: File): List<String> =
|
||||
names(File(decompDir, "include/constants/flags.h"), "FLAG_")
|
||||
fun flags(decompDir: File): List<StoryConstant> =
|
||||
constants(decompDir, "include/constants/flags.h", "FLAG_")
|
||||
|
||||
fun vars(decompDir: File): List<String> =
|
||||
names(File(decompDir, "include/constants/vars.h"), "VAR_")
|
||||
fun vars(decompDir: File): List<StoryConstant> =
|
||||
constants(decompDir, "include/constants/vars.h", "VAR_")
|
||||
|
||||
private fun names(file: File, prefix: String): List<String> {
|
||||
require(file.exists()) { "Missing ${file.path}" }
|
||||
val re = Regex("""^#define\s+($prefix\w+)\b""")
|
||||
return file.readLines().mapNotNull { re.find(it.trim())?.groupValues?.get(1) }.distinct()
|
||||
/** Emerald new-game reset flags. */
|
||||
fun initialFlags(decompDir: File): List<String> =
|
||||
scriptFlags(
|
||||
decompDir,
|
||||
"data/scripts/new_game.inc",
|
||||
"EventScript_ResetAllMapFlags",
|
||||
)
|
||||
|
||||
/** Gender-specific flags normally established by InsideOfTruck's intro script. */
|
||||
fun maleIntroFlags(decompDir: File): List<String> =
|
||||
scriptFlags(
|
||||
decompDir,
|
||||
"data/maps/InsideOfTruck/scripts.inc",
|
||||
"InsideOfTruck_EventScript_SetIntroFlagsMale",
|
||||
)
|
||||
|
||||
fun femaleIntroFlags(decompDir: File): List<String> =
|
||||
scriptFlags(
|
||||
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)
|
||||
if (!file.exists()) return emptyList()
|
||||
val result = mutableListOf<String>()
|
||||
var inBlock = false
|
||||
for (rawLine in file.readLines()) {
|
||||
val line = rawLine.substringBefore('@').trim()
|
||||
if (!inBlock) {
|
||||
if (line == "$label::") inBlock = true
|
||||
continue
|
||||
}
|
||||
if (line.endsWith("::")) break
|
||||
Regex("""^setflag\s+(FLAG_[A-Za-z0-9_]+)\b""")
|
||||
.find(line)
|
||||
?.groupValues
|
||||
?.get(1)
|
||||
?.let(result::add)
|
||||
if (line == "end" || line == "return") break
|
||||
}
|
||||
return result.distinct()
|
||||
}
|
||||
|
||||
private fun constants(
|
||||
decompDir: File,
|
||||
relativePath: String,
|
||||
prefix: String,
|
||||
): List<StoryConstant> {
|
||||
val target = File(decompDir, relativePath)
|
||||
require(target.exists()) { "Missing ${target.path}" }
|
||||
|
||||
// Load sibling constants before the target header.
|
||||
val targetConstants = parseConstants(target)
|
||||
val macros = linkedMapOf<String, Macro>()
|
||||
targetConstants.forEach { (name, macro) -> macros[name] = macro }
|
||||
File(decompDir, "include/constants")
|
||||
.walkTopDown()
|
||||
.filter { it.isFile && it.extension == "h" && it != target }
|
||||
.sortedBy(File::getPath)
|
||||
.forEach { file ->
|
||||
parseConstants(file).forEach { (name, macro) -> macros.putIfAbsent(name, macro) }
|
||||
}
|
||||
|
||||
val wanted =
|
||||
targetConstants
|
||||
.filter { (name, macro) -> name.startsWith(prefix) && macro.parameters == null }
|
||||
.keys
|
||||
val evaluator = MacroEvaluator(macros)
|
||||
val unresolved = mutableListOf<String>()
|
||||
val result =
|
||||
wanted.mapNotNull { name ->
|
||||
evaluator.resolve(name)?.let { StoryConstant(name, it) }
|
||||
?: run {
|
||||
unresolved += name
|
||||
null
|
||||
}
|
||||
}
|
||||
check(unresolved.isEmpty()) {
|
||||
"Could not resolve ${unresolved.size} $prefix constants in ${target.path}: " +
|
||||
unresolved.take(12).joinToString()
|
||||
}
|
||||
return result.distinctBy(StoryConstant::name)
|
||||
}
|
||||
|
||||
private fun parseMacros(file: File): LinkedHashMap<String, Macro> {
|
||||
val result = linkedMapOf<String, Macro>()
|
||||
val define = Regex("""^#define\s+([A-Za-z_]\w*)(?:\(([^)]*)\))?\s+(.+)$""")
|
||||
val blockComment = Regex("""/\*.*?\*/""")
|
||||
for (line in file.readLines()) {
|
||||
val match = define.find(line.trim()) ?: continue
|
||||
val name = match.groupValues[1]
|
||||
val parameters =
|
||||
match.groupValues[2].takeIf(String::isNotEmpty)?.split(',')?.map(String::trim)
|
||||
val raw = match.groupValues[3]
|
||||
val comment = raw.substringAfter("//", "")
|
||||
val expression = raw.substringBefore("//").replace(blockComment, "").trim()
|
||||
if (expression.isEmpty()) continue
|
||||
val hint = Regex("""(?:0x[0-9A-Fa-f]+|\b\d+\b)""").find(comment)?.value?.let(::parseNumber)
|
||||
result[name] = Macro(parameters, expression, hint)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun parseConstants(file: File): LinkedHashMap<String, Macro> =
|
||||
linkedMapOf<String, Macro>().apply {
|
||||
putAll(parseMacros(file))
|
||||
putAll(parseEnumConstants(file))
|
||||
}
|
||||
|
||||
/** Treat C enum members as ordinary integer macros, including implicit incrementing values. */
|
||||
private fun parseEnumConstants(file: File): LinkedHashMap<String, Macro> {
|
||||
val result = linkedMapOf<String, Macro>()
|
||||
var inEnum = false
|
||||
var previous: String? = null
|
||||
for (rawLine in file.readLines()) {
|
||||
val line = rawLine.substringBefore("//").replace(Regex("""/\*.*?\*/"""), "").trim()
|
||||
if (!inEnum) {
|
||||
if (line.startsWith("enum") && line.contains('{')) {
|
||||
inEnum = true
|
||||
previous = null
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (line.startsWith("}")) {
|
||||
inEnum = false
|
||||
previous = null
|
||||
continue
|
||||
}
|
||||
val member = line.removeSuffix(",").trim()
|
||||
val match = Regex("""^([A-Za-z_]\w*)(?:\s*=\s*(.+))?$""").matchEntire(member) ?: continue
|
||||
val name = match.groupValues[1]
|
||||
val explicit = match.groupValues[2].takeIf(String::isNotEmpty)
|
||||
val expression = explicit ?: previous?.let { "($it + 1)" } ?: "0"
|
||||
result[name] = Macro(parameters = null, expression = expression, numericHint = null)
|
||||
previous = name
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private class MacroEvaluator(private val macros: Map<String, Macro>) {
|
||||
private val memo = mutableMapOf<String, Int>()
|
||||
private val resolving = mutableSetOf<String>()
|
||||
|
||||
fun resolve(name: String): Int? {
|
||||
memo[name]?.let {
|
||||
return it
|
||||
}
|
||||
if (!resolving.add(name)) return null
|
||||
val macro = macros[name]
|
||||
val value =
|
||||
if (macro == null || macro.parameters != null) null
|
||||
else ExpressionParser(macro.expression, this, emptyMap()).parse() ?: macro.numericHint
|
||||
resolving.remove(name)
|
||||
if (value != null) memo[name] = value
|
||||
return value
|
||||
}
|
||||
|
||||
fun resolve(name: String, arguments: List<Int>, locals: Map<String, Int>): Int? {
|
||||
locals[name]?.let {
|
||||
return it
|
||||
}
|
||||
val macro = macros[name] ?: return null
|
||||
val parameters = macro.parameters ?: return if (arguments.isEmpty()) resolve(name) else null
|
||||
if (parameters.size != arguments.size) return null
|
||||
val callLocals = locals + parameters.zip(arguments)
|
||||
return ExpressionParser(macro.expression, this, callLocals).parse() ?: macro.numericHint
|
||||
}
|
||||
}
|
||||
|
||||
private class ExpressionParser(
|
||||
expression: String,
|
||||
private val evaluator: MacroEvaluator,
|
||||
private val locals: Map<String, Int>,
|
||||
) {
|
||||
private val tokens =
|
||||
Regex("""0x[0-9A-Fa-f]+|\d+|[A-Za-z_]\w*|<<|>>|[(),+\-*/%|&~]""")
|
||||
.findAll(expression)
|
||||
.map { it.value }
|
||||
.toList()
|
||||
private val compactExpression = expression.filterNot(Char::isWhitespace)
|
||||
private var position = 0
|
||||
|
||||
fun parse(): Int? {
|
||||
if (tokens.joinToString("") != compactExpression) return null
|
||||
val value = parseBitwiseOr() ?: return null
|
||||
return value.takeIf { position == tokens.size }
|
||||
}
|
||||
|
||||
private fun parseBitwiseOr(): Int? = binary(::parseBitwiseAnd, "|") { a, b -> a or b }
|
||||
|
||||
private fun parseBitwiseAnd(): Int? = binary(::parseShift, "&") { a, b -> a and b }
|
||||
|
||||
private fun parseShift(): Int? {
|
||||
var value = parseAdditive() ?: return null
|
||||
while (peek() == "<<" || peek() == ">>") {
|
||||
val operator = take()
|
||||
val right = parseAdditive() ?: return null
|
||||
value = if (operator == "<<") value shl right else value shr right
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun parseAdditive(): Int? {
|
||||
var value = parseMultiplicative() ?: return null
|
||||
while (peek() == "+" || peek() == "-") {
|
||||
val operator = take()
|
||||
val right = parseMultiplicative() ?: return null
|
||||
value = if (operator == "+") value + right else value - right
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun parseMultiplicative(): Int? {
|
||||
var value = parseUnary() ?: return null
|
||||
while (peek() == "*" || peek() == "/" || peek() == "%") {
|
||||
val operator = take()
|
||||
val right = parseUnary() ?: return null
|
||||
if ((operator == "/" || operator == "%") && right == 0) return null
|
||||
value =
|
||||
when (operator) {
|
||||
"*" -> value * right
|
||||
"/" -> value / right
|
||||
else -> value % right
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun parseUnary(): Int? =
|
||||
when (peek()) {
|
||||
"+" -> {
|
||||
take()
|
||||
parseUnary()
|
||||
}
|
||||
"-" -> {
|
||||
take()
|
||||
parseUnary()?.let { -it }
|
||||
}
|
||||
"~" -> {
|
||||
take()
|
||||
parseUnary()?.inv()
|
||||
}
|
||||
else -> parsePrimary()
|
||||
}
|
||||
|
||||
private fun parsePrimary(): Int? {
|
||||
val token = take() ?: return null
|
||||
if (token == "(") {
|
||||
val value = parseBitwiseOr() ?: return null
|
||||
if (take() != ")") return null
|
||||
return value
|
||||
}
|
||||
if (token.firstOrNull()?.isDigit() == true) return parseNumber(token)
|
||||
if (token.firstOrNull()?.isLetter() != true && token.firstOrNull() != '_') return null
|
||||
if (peek() != "(") return evaluator.resolve(token, emptyList(), locals)
|
||||
|
||||
take()
|
||||
val arguments = mutableListOf<Int>()
|
||||
if (peek() != ")") {
|
||||
while (true) {
|
||||
arguments += parseBitwiseOr() ?: return null
|
||||
if (peek() != ",") break
|
||||
take()
|
||||
}
|
||||
}
|
||||
if (take() != ")") return null
|
||||
return evaluator.resolve(token, arguments, locals)
|
||||
}
|
||||
|
||||
private fun binary(
|
||||
operand: () -> Int?,
|
||||
operator: String,
|
||||
combine: (Int, Int) -> Int,
|
||||
): Int? {
|
||||
var value = operand() ?: return null
|
||||
while (peek() == operator) {
|
||||
take()
|
||||
value = combine(value, operand() ?: return null)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
private fun peek(): String? = tokens.getOrNull(position)
|
||||
|
||||
private fun take(): String? = tokens.getOrNull(position++)
|
||||
}
|
||||
|
||||
private fun parseNumber(value: String): Int =
|
||||
if (value.startsWith("0x", ignoreCase = true)) value.drop(2).toInt(16) else value.toInt()
|
||||
}
|
||||
@@ -18,6 +18,13 @@ fun main(args: Array<String>) {
|
||||
val flags = FlagVarParser.flags(decompDir)
|
||||
val vars = FlagVarParser.vars(decompDir)
|
||||
println("[story] $region: parsed ${flags.size} flags, ${vars.size} vars from $decompDir")
|
||||
StoryConstantsRenderer(region, templatesDir, outputDir, classCacheDir).render(flags, vars)
|
||||
StoryConstantsRenderer(region, templatesDir, outputDir, classCacheDir)
|
||||
.render(
|
||||
flags,
|
||||
vars,
|
||||
FlagVarParser.initialFlags(decompDir),
|
||||
FlagVarParser.maleIntroFlags(decompDir),
|
||||
FlagVarParser.femaleIntroFlags(decompDir),
|
||||
)
|
||||
}
|
||||
}
|
||||
+27
-4
@@ -22,7 +22,13 @@ class StoryConstantsRenderer(
|
||||
private val basePackage = "de.fiereu.openmmo.story.generated.$region"
|
||||
private val objectPrefix = region.replaceFirstChar { it.uppercase() }
|
||||
|
||||
fun render(flags: List<String>, vars: List<String>) {
|
||||
fun render(
|
||||
flags: List<StoryConstant>,
|
||||
vars: List<StoryConstant>,
|
||||
initialFlags: List<String>,
|
||||
maleIntroFlags: List<String>,
|
||||
femaleIntroFlags: List<String>,
|
||||
) {
|
||||
classCacheDir.mkdirs()
|
||||
val engine =
|
||||
TemplateEngine.create(
|
||||
@@ -35,7 +41,16 @@ class StoryConstantsRenderer(
|
||||
if (packageRoot.exists()) packageRoot.deleteRecursively()
|
||||
packageRoot.mkdirs()
|
||||
|
||||
write(engine, packageRoot, "${objectPrefix}Flags", flags)
|
||||
val knownFlags = flags.associateBy(StoryConstant::name)
|
||||
write(
|
||||
engine,
|
||||
packageRoot,
|
||||
"${objectPrefix}Flags",
|
||||
flags,
|
||||
initialFlags.mapNotNull(knownFlags::get),
|
||||
maleIntroFlags.mapNotNull(knownFlags::get),
|
||||
femaleIntroFlags.mapNotNull(knownFlags::get),
|
||||
)
|
||||
write(engine, packageRoot, "${objectPrefix}Vars", vars)
|
||||
}
|
||||
|
||||
@@ -43,7 +58,10 @@ class StoryConstantsRenderer(
|
||||
engine: TemplateEngine,
|
||||
packageRoot: File,
|
||||
objectName: String,
|
||||
names: List<String>,
|
||||
constants: List<StoryConstant>,
|
||||
initialFlags: List<StoryConstant> = emptyList(),
|
||||
maleIntroFlags: List<StoryConstant> = emptyList(),
|
||||
femaleIntroFlags: List<StoryConstant> = emptyList(),
|
||||
) {
|
||||
FileOutput(File(packageRoot, "$objectName.kt").toPath()).use { out ->
|
||||
engine.render(
|
||||
@@ -52,7 +70,12 @@ class StoryConstantsRenderer(
|
||||
"pkg" to basePackage,
|
||||
"objectName" to objectName,
|
||||
"namespace" to namespace,
|
||||
"names" to names,
|
||||
"constants" to constants,
|
||||
// Keep lookup methods comfortably below the JVM's per-method bytecode limit.
|
||||
"idChunks" to constants.chunked(128),
|
||||
"initialFlags" to initialFlags,
|
||||
"maleIntroFlags" to maleIntroFlags,
|
||||
"femaleIntroFlags" to femaleIntroFlags,
|
||||
),
|
||||
out,
|
||||
)
|
||||
|
||||
@@ -36,6 +36,8 @@ class MapDef(
|
||||
val onTransitionScript: String = "",
|
||||
/** Conditional entry scripts: run [MapFrameScript.script] when its var equals its value. */
|
||||
val onFrameScripts: List<MapFrameScript> = emptyList(),
|
||||
/** Conditional tile scripts checked after the player completes a step. */
|
||||
val coordScripts: List<MapCoordScript> = emptyList(),
|
||||
private val blockData: String = "",
|
||||
private val behaviorData: String = "",
|
||||
) {
|
||||
@@ -57,6 +59,16 @@ data class MapFrameScript(
|
||||
val script: String,
|
||||
)
|
||||
|
||||
/** One map coordinate trigger, corresponding to a decomp map.json `coord_events` entry. */
|
||||
data class MapCoordScript(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val elevation: Int,
|
||||
val varKey: String,
|
||||
val value: Int,
|
||||
val script: String,
|
||||
)
|
||||
|
||||
private fun decodeBlockData(blockData: String, behaviorData: String): List<Tile2D> {
|
||||
if (blockData.isEmpty()) return emptyList()
|
||||
val bytes = Base64.getDecoder().decode(blockData)
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.fiereu.openmmo.codegen.story
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
class FlagVarParserTest :
|
||||
FunSpec({
|
||||
test("resolves literals, aliases, expressions, hints, and function macros") {
|
||||
val decomp = kotlin.io.path.createTempDirectory("story-constants").toFile()
|
||||
val constants = decomp.resolve("include/constants").also { it.mkdirs() }
|
||||
constants.resolve("support.h").writeText("#define EXTERNAL_COUNT 0x20\n")
|
||||
constants
|
||||
.resolve("flags.h")
|
||||
.writeText(
|
||||
"""
|
||||
#define FLAGS_START 0x100
|
||||
#define FLAGS_END (FLAGS_START + EXTERNAL_COUNT - 1) // 0x11F
|
||||
#define FLAG_FACTORY(index) (FLAGS_END + 1 + (index * 2))
|
||||
#define FLAG_LITERAL 0x42
|
||||
#define FLAG_ALIAS FLAG_LITERAL
|
||||
#define FLAG_EXPRESSION (FLAGS_START + 0x0F)
|
||||
#define FLAG_HINT (UNKNOWN_VALUE + 1) // FLAG_0x234
|
||||
#define FLAG_FUNCTION FLAG_FACTORY(3)
|
||||
"""
|
||||
.trimIndent())
|
||||
constants
|
||||
.resolve("vars.h")
|
||||
.writeText(
|
||||
"""
|
||||
#define VARS_START 0x4000
|
||||
#define VAR_FIRST (VARS_START + 1)
|
||||
"""
|
||||
.trimIndent())
|
||||
|
||||
FlagVarParser.flags(decomp) shouldBe
|
||||
listOf(
|
||||
StoryConstant("FLAG_LITERAL", 0x42),
|
||||
StoryConstant("FLAG_ALIAS", 0x42),
|
||||
StoryConstant("FLAG_EXPRESSION", 0x10F),
|
||||
StoryConstant("FLAG_HINT", 0x234),
|
||||
StoryConstant("FLAG_FUNCTION", 0x126),
|
||||
)
|
||||
FlagVarParser.vars(decomp) shouldBe listOf(StoryConstant("VAR_FIRST", 0x4001))
|
||||
}
|
||||
|
||||
test("extracts initial and gender-specific flags from script blocks") {
|
||||
val decomp = kotlin.io.path.createTempDirectory("story-script-flags").toFile()
|
||||
decomp.resolve("data/scripts").mkdirs()
|
||||
decomp.resolve("data/maps/InsideOfTruck").mkdirs()
|
||||
decomp
|
||||
.resolve("data/scripts/new_game.inc")
|
||||
.writeText(
|
||||
"""
|
||||
EventScript_ResetAllMapFlags::
|
||||
setflag FLAG_INITIAL
|
||||
setflag FLAG_INITIAL
|
||||
end
|
||||
AnotherScript::
|
||||
setflag FLAG_NOT_INCLUDED
|
||||
"""
|
||||
.trimIndent())
|
||||
decomp
|
||||
.resolve("data/maps/InsideOfTruck/scripts.inc")
|
||||
.writeText(
|
||||
"""
|
||||
InsideOfTruck_EventScript_SetIntroFlagsMale::
|
||||
setflag FLAG_MALE
|
||||
end
|
||||
InsideOfTruck_EventScript_SetIntroFlagsFemale::
|
||||
setflag FLAG_FEMALE
|
||||
end
|
||||
"""
|
||||
.trimIndent())
|
||||
|
||||
FlagVarParser.initialFlags(decomp) shouldBe listOf("FLAG_INITIAL")
|
||||
FlagVarParser.maleIntroFlags(decomp) shouldBe listOf("FLAG_MALE")
|
||||
FlagVarParser.femaleIntroFlags(decomp) shouldBe listOf("FLAG_FEMALE")
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
package de.fiereu.openmmo.maps
|
||||
|
||||
import de.fiereu.openmmo.common.enums.TileBehavior
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
class HoennMapBehaviorTest :
|
||||
FunSpec({
|
||||
test("generated Hoenn maps retain the ledge behaviors used by Emerald") {
|
||||
val maps = MapManager()
|
||||
val behaviors = buildSet {
|
||||
for (bank in 50..83) {
|
||||
for (mapId in 0..255) {
|
||||
maps.getMap(1, bank, mapId)?.tiles?.forEach { add(it.behavior) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
behaviors shouldContainAll
|
||||
listOf(
|
||||
TileBehavior.JUMP_EAST,
|
||||
TileBehavior.JUMP_WEST,
|
||||
TileBehavior.JUMP_SOUTH,
|
||||
)
|
||||
|
||||
maps.getMap(1, 50, 26)!!.tiles.any { it.behavior == TileBehavior.JUMP_SOUTH } shouldBe true
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.fiereu.openmmo.common.enums
|
||||
|
||||
enum class CharacterGender(val wireValue: Byte) {
|
||||
MALE(0),
|
||||
FEMALE(1);
|
||||
|
||||
companion object {
|
||||
fun byWireValue(wireValue: Byte): CharacterGender? = entries.find { it.wireValue == wireValue }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.fiereu.openmmo.common.enums
|
||||
|
||||
enum class Region(val id: Int) {
|
||||
enum class Region(val wireValue: Byte) {
|
||||
KANTO(0),
|
||||
HOENN(1);
|
||||
|
||||
companion object {
|
||||
fun byId(id: Int): Region? = entries.find { it.id == id }
|
||||
fun byId(id: Int): Region? = entries.find { it.wireValue.toInt() == id }
|
||||
|
||||
fun byWireValue(wireValue: Byte): Region? = entries.find { it.wireValue == wireValue }
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,8 @@ enum class TileBehavior {
|
||||
NORMAL,
|
||||
TALL_GRASS,
|
||||
LONG_GRASS,
|
||||
JUMP_EAST,
|
||||
JUMP_WEST,
|
||||
JUMP_NORTH,
|
||||
JUMP_SOUTH,
|
||||
}
|
||||
@@ -123,7 +123,7 @@ object GameProtocol : Protocol() {
|
||||
s2c<ShopPriceTablePacket>(0x29u, ShopPriceTablePacketCodec)
|
||||
|
||||
c2s<TeamNameChangePacket>(0x2Au, TeamNameChangePacketCodec)
|
||||
s2c<BattleStatusFlagPacket>(0x2Au, BattleStatusFlagPacketCodec)
|
||||
s2c<StoryFlagUpdatePacket>(0x2Au, StoryFlagUpdatePacketCodec)
|
||||
|
||||
c2s<SetCharacterNamePacket>(0x2Bu, SetCharacterNamePacketCodec)
|
||||
s2c<FollowerAdvancePacket>(0x2Bu, FollowerAdvancePacketCodec)
|
||||
@@ -276,12 +276,12 @@ object GameProtocol : Protocol() {
|
||||
s2c<EntityCoordSyncPacket>(0x61u, EntityCoordSyncPacketCodec)
|
||||
|
||||
c2s<AddFriendPacket>(0x62u, AddFriendPacketCodec)
|
||||
s2c<SocialActionOutcomePacket>(0x62u, SocialActionOutcomePacketCodec)
|
||||
s2c<DeleteCharacterResultPacket>(0x62u, DeleteCharacterResultPacketCodec)
|
||||
|
||||
c2s<RemoveFriendPacket>(0x63u, RemoveFriendPacketCodec)
|
||||
s2c<FriendListPacket>(0x63u, FriendListPacketCodec)
|
||||
|
||||
c2s<FriendProfileRequestPacket>(0x64u, FriendProfileRequestPacketCodec)
|
||||
c2s<DeleteCharacterPacket>(0x64u, DeleteCharacterPacketCodec)
|
||||
s2c<ContactInsertPacket>(0x64u, ContactInsertPacketCodec)
|
||||
|
||||
s2c<ContactDeletePacket>(0x65u, ContactDeletePacketCodec)
|
||||
@@ -567,6 +567,8 @@ object GameProtocol : Protocol() {
|
||||
c2s<BattleChallengeRequestPacket>(0xE4u, BattleChallengeRequestPacketCodec)
|
||||
s2c<EntityMovePacket>(0xE4u, EntityMovePacketCodec)
|
||||
|
||||
s2c<GbaEntityMovePacket>(0xEAu, GbaEntityMovePacketCodec)
|
||||
|
||||
s2c<QueuePositionPacket>(0xF0u, QueuePositionPacketCodec)
|
||||
|
||||
c2s<ChunkedTransferDataPacket>(0xF1u, ChunkedTransferDataPacketCodec)
|
||||
|
||||
+8
-5
@@ -41,16 +41,19 @@ class CharacterInfoCodec(private val withExtraLong: Boolean) : PacketCodec<Chara
|
||||
val battleBoxExtraSlots = field(S8, CharacterInfo::battleBoxExtraSlots)
|
||||
val templateAmount = field(S8, CharacterInfo::templateAmount)
|
||||
field(S8) { 0 }
|
||||
field(S8) { 0 }
|
||||
field(S8) { 0 }
|
||||
// Captured markers precede the complete position block.
|
||||
field(S8, CharacterInfo::positionRegionId)
|
||||
field(S8) { -1 }
|
||||
field(S8) { 2 }
|
||||
val positionRegionId = field(S8, CharacterInfo::positionRegionId)
|
||||
val positionBankId = field(S8, CharacterInfo::positionBankId)
|
||||
val positionMapId = field(S8, CharacterInfo::positionMapId)
|
||||
field(S8) { 0 }
|
||||
val positionMapId =
|
||||
field(
|
||||
S16LE.imap(decode = { it.toByte() }, encode = { it.toShort() }),
|
||||
CharacterInfo::positionMapId)
|
||||
val positionX = field(S16LE, CharacterInfo::positionX)
|
||||
val positionY = field(S16LE, CharacterInfo::positionY)
|
||||
field(S8) { 0 }
|
||||
field(S8) { 0 }
|
||||
val repelLeft = field(S16LE, CharacterInfo::repelLeft)
|
||||
val repelItemId = field(S16LE, CharacterInfo::repelItemId)
|
||||
field(S8) { 0 }
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.*
|
||||
|
||||
data class Skin(val slot: SkinSlot, val type: UShort?, val color: UByte?)
|
||||
|
||||
class SkinSet : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
class SkinSet(var regionSelectionIndex: Int = 0) : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
fun put(skin: Skin) {
|
||||
this[skin.slot] = skin
|
||||
}
|
||||
@@ -22,9 +22,12 @@ class SkinSetCodec(
|
||||
private val withLeadingByte: Boolean = true,
|
||||
) : PacketCodec<SkinSet>() {
|
||||
override fun CodecScope<SkinSet>.body(): SkinSet {
|
||||
if (withLeadingByte) field(U8) { 0 }
|
||||
val mask = field(U16LE) { slots.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) } }
|
||||
val skins = SkinSet()
|
||||
val regionSelectionIndex = if (withLeadingByte) field(U8) { it.regionSelectionIndex } else 0
|
||||
val mask =
|
||||
field(U16LE) { skins ->
|
||||
skins.keys.filter { it in slots }.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) }
|
||||
}
|
||||
val skins = SkinSet(regionSelectionIndex)
|
||||
slots.forEach { slot ->
|
||||
if ((mask and (1 shl slot.ordinal)) != 0) {
|
||||
val compressed =
|
||||
|
||||
+14
-2
@@ -2,13 +2,25 @@ package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S8
|
||||
import de.fiereu.bytecodec.Utf16LeNullTerminated
|
||||
import de.fiereu.openmmo.net.game.codecs.DefaultSkinSetCodec
|
||||
import de.fiereu.openmmo.net.game.codecs.SkinSet
|
||||
|
||||
data class CreateCharacterPacket(val name: String)
|
||||
/** The choices submitted by the client's character creator. */
|
||||
data class CreateCharacterPacket(
|
||||
val name: String,
|
||||
val gender: Byte,
|
||||
val startingRegion: Byte,
|
||||
val appearance: SkinSet,
|
||||
)
|
||||
|
||||
object CreateCharacterPacketCodec : PacketCodec<CreateCharacterPacket>() {
|
||||
override fun CodecScope<CreateCharacterPacket>.body(): CreateCharacterPacket {
|
||||
val name = field(Utf16LeNullTerminated) { it.name }
|
||||
return CreateCharacterPacket(name)
|
||||
val gender = field(S8) { it.gender }
|
||||
val startingRegion = field(S8) { it.startingRegion }
|
||||
val appearance = field(DefaultSkinSetCodec) { it.appearance }
|
||||
return CreateCharacterPacket(name, gender, startingRegion, appearance)
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S64LE
|
||||
import de.fiereu.bytecodec.U8
|
||||
|
||||
/** Character-selection deletion request, captured as opcode 0x64 followed by the character id. */
|
||||
data class DeleteCharacterPacket(val characterId: Long)
|
||||
|
||||
object DeleteCharacterPacketCodec : PacketCodec<DeleteCharacterPacket>() {
|
||||
override fun CodecScope<DeleteCharacterPacket>.body(): DeleteCharacterPacket =
|
||||
DeleteCharacterPacket(field(S64LE) { it.characterId })
|
||||
}
|
||||
|
||||
/** Captured character deletion result. */
|
||||
data class DeleteCharacterResultPacket(val result: Int, val characterId: Long)
|
||||
|
||||
object DeleteCharacterResultPacketCodec : PacketCodec<DeleteCharacterResultPacket>() {
|
||||
override fun CodecScope<DeleteCharacterResultPacket>.body(): DeleteCharacterResultPacket {
|
||||
val result = field(U8) { it.result }
|
||||
val characterId = field(S64LE) { it.characterId }
|
||||
return DeleteCharacterResultPacket(result, characterId)
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S64LE
|
||||
import de.fiereu.bytecodec.U8
|
||||
import de.fiereu.bytecodec.enumByOrdinalByte
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
|
||||
/** Opcode 0xEA (s2c). A GBA-map entity's new tile after one step. */
|
||||
data class GbaEntityMovePacket(
|
||||
val entityId: Long,
|
||||
val bankId: Int,
|
||||
val mapId: Int,
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val movementMode: Int = 2,
|
||||
val direction: Direction,
|
||||
)
|
||||
|
||||
object GbaEntityMovePacketCodec : PacketCodec<GbaEntityMovePacket>() {
|
||||
private val DirectionCodec = enumByOrdinalByte<Direction>()
|
||||
|
||||
override fun CodecScope<GbaEntityMovePacket>.body(): GbaEntityMovePacket {
|
||||
val entityId = field(S64LE) { it.entityId }
|
||||
val bankId = field(U8) { it.bankId }
|
||||
val mapId = field(U8) { it.mapId }
|
||||
val x = field(U8) { it.x }
|
||||
val y = field(U8) { it.y }
|
||||
val movementMode = field(U8) { it.movementMode }
|
||||
val direction = field(DirectionCodec) { it.direction }
|
||||
return GbaEntityMovePacket(entityId, bankId, mapId, x, y, movementMode, direction)
|
||||
}
|
||||
}
|
||||
+22
-4
@@ -1,12 +1,30 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.*
|
||||
|
||||
class MapLoadedAckPacket
|
||||
/** Empty payload means the client is ready. */
|
||||
data class MapLoadedAckPacket(val data: ByteArray = byteArrayOf()) {
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is MapLoadedAckPacket && data.contentEquals(other.data)
|
||||
|
||||
override fun hashCode(): Int = data.contentHashCode()
|
||||
}
|
||||
|
||||
private val MapLoadedAckBytes: Codec<ByteArray> =
|
||||
object : Codec<ByteArray> {
|
||||
override fun read(buf: ReadBuffer): ByteArray {
|
||||
val data = ByteArray(buf.remaining())
|
||||
if (data.isNotEmpty()) buf.readBytes(data)
|
||||
return data
|
||||
}
|
||||
|
||||
override fun write(buf: WriteBuffer, value: ByteArray) {
|
||||
if (value.isNotEmpty()) buf.writeBytes(value)
|
||||
}
|
||||
}
|
||||
|
||||
object MapLoadedAckPacketCodec : PacketCodec<MapLoadedAckPacket>() {
|
||||
override fun CodecScope<MapLoadedAckPacket>.body(): MapLoadedAckPacket {
|
||||
return MapLoadedAckPacket()
|
||||
return MapLoadedAckPacket(field(MapLoadedAckBytes, MapLoadedAckPacket::data))
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -3,18 +3,23 @@ package de.fiereu.openmmo.net.game.packets
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S16LE
|
||||
import de.fiereu.bytecodec.enumByOrdinalByte
|
||||
import de.fiereu.bytecodec.U8
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
|
||||
data class MovementPacket(val x: Int, val y: Int, val direction: Direction)
|
||||
data class MovementPacket(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val direction: Direction,
|
||||
val running: Boolean = false,
|
||||
)
|
||||
|
||||
object MovementPacketCodec : PacketCodec<MovementPacket>() {
|
||||
private val DirectionCodec = enumByOrdinalByte<Direction>()
|
||||
|
||||
override fun CodecScope<MovementPacket>.body(): MovementPacket {
|
||||
val x = field(S16LE) { it.x.toShort() }
|
||||
val y = field(S16LE) { it.y.toShort() }
|
||||
val direction = field(DirectionCodec) { it.direction }
|
||||
return MovementPacket(x.toInt(), y.toInt(), direction)
|
||||
val state = field(U8) { it.direction.ordinal or (if (it.running) 0x80 else 0) }
|
||||
val direction = Direction.entries[state and 0x03]
|
||||
val running = state and 0x80 != 0
|
||||
return MovementPacket(x.toInt(), y.toInt(), direction, running)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S16LE
|
||||
import de.fiereu.bytecodec.S8
|
||||
|
||||
/** Opcode 0x2A (s2c). Sets or clears one region-specific GBA story flag. */
|
||||
data class StoryFlagUpdatePacket(
|
||||
val regionId: Byte,
|
||||
val flagId: Int,
|
||||
val enabled: Boolean,
|
||||
)
|
||||
|
||||
object StoryFlagUpdatePacketCodec : PacketCodec<StoryFlagUpdatePacket>() {
|
||||
override fun CodecScope<StoryFlagUpdatePacket>.body(): StoryFlagUpdatePacket {
|
||||
val regionId = field(S8) { it.regionId }
|
||||
val flagId = field(S16LE) { it.flagId.toShort() }.toInt() and 0xffff
|
||||
val enabled = field(S16LE) { if (it.enabled) 1 else 0 }.toInt() != 0
|
||||
return StoryFlagUpdatePacket(regionId, flagId, enabled)
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -10,8 +10,12 @@ data class CreatureDataArg(val value: Int, val args: List<DialogMessageArg>) : D
|
||||
|
||||
data class CreatureMovesArg(val team: Byte, val moveIds: List<Short>) : DialogMessageArg()
|
||||
|
||||
data class MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) :
|
||||
DialogMessageArg()
|
||||
/** Fills a ROM string variable with a species name. */
|
||||
data class TextPokemonSpeciesArg(
|
||||
val partySlot: Byte,
|
||||
val stringVariable: Byte,
|
||||
val speciesId: Short,
|
||||
) : DialogMessageArg()
|
||||
|
||||
data class TextCreatureArg(
|
||||
val slot: Byte,
|
||||
@@ -38,8 +42,7 @@ private val DialogMessageArgCodec: Codec<DialogMessageArg> =
|
||||
}
|
||||
|
||||
2 -> {
|
||||
val moveId = S16LE.read(buf)
|
||||
MoveAnimationArg(buf.readByte(), buf.readByte(), moveId)
|
||||
TextPokemonSpeciesArg(buf.readByte(), buf.readByte(), S16LE.read(buf))
|
||||
}
|
||||
|
||||
3 -> TextCreatureArg(buf.readByte(), buf.readByte(), S16LE.read(buf), S16LE.read(buf))
|
||||
@@ -63,11 +66,11 @@ private val DialogMessageArgCodec: Codec<DialogMessageArg> =
|
||||
value.moveIds.forEach { S16LE.write(buf, it) }
|
||||
}
|
||||
|
||||
is MoveAnimationArg -> {
|
||||
is TextPokemonSpeciesArg -> {
|
||||
buf.writeByte(2)
|
||||
S16LE.write(buf, value.moveId)
|
||||
buf.writeByte(value.sourceSlot)
|
||||
buf.writeByte(value.targetSlot)
|
||||
buf.writeByte(value.partySlot)
|
||||
buf.writeByte(value.stringVariable)
|
||||
S16LE.write(buf, value.speciesId)
|
||||
}
|
||||
|
||||
is TextCreatureArg -> {
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package de.fiereu.openmmo.net.game
|
||||
|
||||
import de.fiereu.bytecodec.test.decodeBytes
|
||||
import de.fiereu.bytecodec.test.encodeToBytes
|
||||
import de.fiereu.openmmo.common.enums.SkinSlot
|
||||
import de.fiereu.openmmo.common.utils.hexToBytes
|
||||
import de.fiereu.openmmo.common.utils.toHex
|
||||
import de.fiereu.openmmo.net.game.packets.CreateCharacterPacketCodec
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
class CreateCharacterPacketTest :
|
||||
FunSpec({
|
||||
test("decodes the captured female Hoenn character creation") {
|
||||
val bytes =
|
||||
"4c0061006e0061006e0061005400650073007400540077006f0000000101014c0304600f00030800680084"
|
||||
.hexToBytes()
|
||||
|
||||
val packet = CreateCharacterPacketCodec.decodeBytes(bytes)
|
||||
|
||||
packet.name shouldBe "LananaTestTwo"
|
||||
packet.gender shouldBe 1
|
||||
packet.startingRegion shouldBe 1
|
||||
packet.appearance.keys shouldBe
|
||||
setOf(
|
||||
SkinSlot.HAIR,
|
||||
SkinSlot.EYES,
|
||||
SkinSlot.TOP,
|
||||
SkinSlot.FOOTWEAR,
|
||||
SkinSlot.LEGGINGS,
|
||||
)
|
||||
CreateCharacterPacketCodec.encodeToBytes(packet).toHex() shouldBe bytes.toHex()
|
||||
}
|
||||
|
||||
test("roundtrips the new male Hoenn character creation capture") {
|
||||
val bytes =
|
||||
"4d006100630068006500720044006500720000000001034c031e280a00025400700020".hexToBytes()
|
||||
|
||||
val packet = CreateCharacterPacketCodec.decodeBytes(bytes)
|
||||
|
||||
packet.name shouldBe "MacherDer"
|
||||
packet.gender shouldBe 0
|
||||
packet.startingRegion shouldBe 1
|
||||
packet.appearance.regionSelectionIndex shouldBe 3
|
||||
CreateCharacterPacketCodec.encodeToBytes(packet).toHex() shouldBe bytes.toHex()
|
||||
}
|
||||
|
||||
test("roundtrips the independent female Kanto character creation capture") {
|
||||
val bytes =
|
||||
"4d0061006300680065007200520069006e0000000100004c030bb80e0003180030029c".hexToBytes()
|
||||
|
||||
val packet = CreateCharacterPacketCodec.decodeBytes(bytes)
|
||||
|
||||
packet.name shouldBe "MacherRin"
|
||||
packet.gender shouldBe 1
|
||||
packet.startingRegion shouldBe 0
|
||||
packet.appearance.regionSelectionIndex shouldBe 0
|
||||
CreateCharacterPacketCodec.encodeToBytes(packet).toHex() shouldBe bytes.toHex()
|
||||
}
|
||||
})
|
||||
@@ -6,6 +6,7 @@ import de.fiereu.openmmo.common.utils.hexToBytes
|
||||
import de.fiereu.openmmo.common.utils.toHex
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.CreatureDataArg
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacketCodec
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.TextPokemonSpeciesArg
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
@@ -38,4 +39,12 @@ class DialogActionPacketTest :
|
||||
packet.contextValue shouldBe 0x04b0
|
||||
packet.messageArgs shouldBe listOf(CreatureDataArg(0x03d09209, emptyList()))
|
||||
}
|
||||
|
||||
test("species-name argument uses the captured party slot variable and species order") {
|
||||
val bytes = "000400000000ffffffffffffffff0000000001020101ff0000".hexToBytes()
|
||||
val packet = DialogActionPacketCodec.decodeBytes(bytes)
|
||||
|
||||
packet.messageArgs shouldBe listOf(TextPokemonSpeciesArg(1, 1, 255))
|
||||
DialogActionPacketCodec.encodeToBytes(packet) shouldBe bytes
|
||||
}
|
||||
})
|
||||
@@ -39,6 +39,12 @@ class GameCodecRoundtripTest :
|
||||
MovementPacketCodec.decodeBytes(MovementPacketCodec.encodeToBytes(pkt)) shouldBe pkt
|
||||
}
|
||||
|
||||
test("MovementPacket decodes the running flag") {
|
||||
val pkt = MovementPacket(x = 100, y = 250, direction = Direction.UP, running = true)
|
||||
MovementPacketCodec.encodeToBytes(pkt) shouldBe byteArrayOf(100, 0, -6, 0, -127)
|
||||
MovementPacketCodec.decodeBytes(byteArrayOf(100, 0, -6, 0, -127)) shouldBe pkt
|
||||
}
|
||||
|
||||
test("DialogStatePacket roundtrip") {
|
||||
DialogStatePacketCodec.encodeToBytes(DialogStatePacket(true)) shouldBe byteArrayOf(1)
|
||||
DialogStatePacketCodec.decodeBytes(byteArrayOf(0)) shouldBe DialogStatePacket(false)
|
||||
|
||||
@@ -3,12 +3,16 @@ package de.fiereu.openmmo.net.game
|
||||
import de.fiereu.network.Direction
|
||||
import de.fiereu.network.Side
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterResultPacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityMovePacket
|
||||
import de.fiereu.openmmo.net.game.packets.GbaEntityMovePacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinResponsePacket
|
||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||
import de.fiereu.openmmo.net.game.packets.LoadMapPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NullPacket
|
||||
import de.fiereu.openmmo.net.game.packets.StoryFlagUpdatePacket
|
||||
import de.fiereu.openmmo.net.game.packets.TokenPayloadPacket
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.collections.shouldContainAll
|
||||
@@ -46,6 +50,7 @@ class GameProtocolTest :
|
||||
0xB9u.toUByte(),
|
||||
0xC2u.toUByte(),
|
||||
0xE4u.toUByte(),
|
||||
0xEAu.toUByte(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -63,12 +68,28 @@ class GameProtocolTest :
|
||||
GameProtocol.outgoingRegistration(Side.CLIENT, EntityMovePacket::class) shouldBe null
|
||||
}
|
||||
|
||||
test("capture-backed story and GBA movement packets are S2C only") {
|
||||
GameProtocol.outgoingRegistration(Side.SERVER, StoryFlagUpdatePacket::class)
|
||||
?.opcode shouldBe 0x2Au
|
||||
GameProtocol.outgoingRegistration(Side.CLIENT, StoryFlagUpdatePacket::class) shouldBe null
|
||||
GameProtocol.outgoingRegistration(Side.SERVER, GbaEntityMovePacket::class)?.opcode shouldBe
|
||||
0xEAu
|
||||
GameProtocol.outgoingRegistration(Side.CLIENT, GbaEntityMovePacket::class) shouldBe null
|
||||
}
|
||||
|
||||
test("0x20 split: NullPacket C2S, TokenPayloadPacket S2C") {
|
||||
GameProtocol.incomingRegistration(Side.SERVER, 0x20u)?.type shouldBe NullPacket::class
|
||||
GameProtocol.incomingRegistration(Side.CLIENT, 0x20u)?.type shouldBe
|
||||
TokenPayloadPacket::class
|
||||
}
|
||||
|
||||
test("captured character deletion opcodes are direction-specific") {
|
||||
GameProtocol.outgoingRegistration(Side.CLIENT, DeleteCharacterPacket::class)
|
||||
?.opcode shouldBe 0x64u
|
||||
GameProtocol.outgoingRegistration(Side.SERVER, DeleteCharacterResultPacket::class)
|
||||
?.opcode shouldBe 0x62u
|
||||
}
|
||||
|
||||
test("bidi packets are registered both directions") {
|
||||
val bidi =
|
||||
listOf(
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package de.fiereu.openmmo.net.game.codecs
|
||||
|
||||
import de.fiereu.bytecodec.test.decodeBytes
|
||||
import de.fiereu.bytecodec.test.encodeToBytes
|
||||
import de.fiereu.openmmo.common.CharacterInfo
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import java.time.LocalDateTime
|
||||
|
||||
class CharacterInfoCodecTest :
|
||||
FunSpec({
|
||||
test("encodes the captured position block alignment and NDS global coordinates") {
|
||||
val timestamp = LocalDateTime.of(2024, 1, 2, 3, 4, 5)
|
||||
val info =
|
||||
CharacterInfo(
|
||||
id = 123,
|
||||
name = "Uno",
|
||||
userId = 2,
|
||||
rivalSex = 1,
|
||||
lastLogin = timestamp,
|
||||
createdAt = timestamp,
|
||||
money = 30000,
|
||||
permissions = 8,
|
||||
remainingSafariSteps = 0,
|
||||
remainingSafariBalls = 0,
|
||||
pcExtraSlots = 0,
|
||||
battleBoxExtraSlots = 0,
|
||||
templateAmount = 0,
|
||||
positionRegionId = 2,
|
||||
positionBankId = 133.toByte(),
|
||||
positionMapId = 1,
|
||||
positionX = 782,
|
||||
positionY = 749,
|
||||
repelLeft = 0,
|
||||
repelItemId = 0,
|
||||
lureLeft = 0,
|
||||
lureItemId = 0,
|
||||
)
|
||||
|
||||
val bytes = CharacterInfoCodecShort.encodeToBytes(info)
|
||||
val tail = bytes.copyOfRange(bytes.size - 68, bytes.size)
|
||||
|
||||
tail.copyOfRange(45, 56) shouldBe
|
||||
byteArrayOf(
|
||||
0x02,
|
||||
0xff.toByte(),
|
||||
0x02,
|
||||
0x02,
|
||||
0x85.toByte(),
|
||||
0x01,
|
||||
0x00,
|
||||
0x0e,
|
||||
0x03,
|
||||
0xed.toByte(),
|
||||
0x02,
|
||||
)
|
||||
CharacterInfoCodecShort.decodeBytes(bytes) shouldBe info
|
||||
}
|
||||
})
|
||||
@@ -29,6 +29,7 @@ dependencies {
|
||||
implementation(libs.kotlinx.coroutines)
|
||||
implementation(libs.kotlin.logging)
|
||||
implementation(libs.logback)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
testImplementation(libs.bundles.kotest)
|
||||
testImplementation(libs.kotlinx.coroutines.test)
|
||||
|
||||
@@ -2,6 +2,16 @@ package de.fiereu.openmmo.server.game.battle
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.server.game.world.interest.BattleInterestKey
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
|
||||
enum class BattleResult {
|
||||
VICTORY,
|
||||
DEFEAT,
|
||||
FLED,
|
||||
CAUGHT,
|
||||
DISCONNECTED,
|
||||
FAILED,
|
||||
}
|
||||
|
||||
/** One running wild battle. Trainer battles later add more participants to the same key. */
|
||||
class BattleInstance(
|
||||
@@ -11,6 +21,8 @@ class BattleInstance(
|
||||
val party: List<BattleMonState>,
|
||||
val wild: BattleMonState,
|
||||
val rng: BattleRng,
|
||||
val catchable: Boolean = true,
|
||||
val escapable: Boolean = true,
|
||||
) {
|
||||
val key: BattleInterestKey = BattleInterestKey(battleId)
|
||||
var turn: Int = 1
|
||||
@@ -20,5 +32,11 @@ class BattleInstance(
|
||||
// full block, a return only its active detail.
|
||||
val seenActive: MutableSet<Int> = mutableSetOf(0)
|
||||
|
||||
/** Completes when the battle leaves the registry. */
|
||||
val completion = CompletableDeferred<BattleResult>()
|
||||
|
||||
/** Result held until the client confirms that its battle-to-map transition has finished. */
|
||||
var pendingResult: BattleResult? = null
|
||||
|
||||
fun activeMon(): BattleMonState = party[activeSlot]
|
||||
}
|
||||
@@ -19,8 +19,20 @@ class BattleRegistry @Inject constructor() {
|
||||
party: List<BattleMonState>,
|
||||
wild: BattleMonState,
|
||||
rng: BattleRng,
|
||||
catchable: Boolean = true,
|
||||
escapable: Boolean = true,
|
||||
): BattleInstance {
|
||||
val battle = BattleInstance(ids.getAndIncrement(), charId, session, party, wild, rng)
|
||||
val battle =
|
||||
BattleInstance(
|
||||
ids.getAndIncrement(),
|
||||
charId,
|
||||
session,
|
||||
party,
|
||||
wild,
|
||||
rng,
|
||||
catchable,
|
||||
escapable,
|
||||
)
|
||||
byChar[charId] = battle
|
||||
return battle
|
||||
}
|
||||
|
||||
@@ -12,13 +12,15 @@ import de.fiereu.openmmo.net.game.packets.CancelSocialInteractionPacket
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessageSendPacket
|
||||
import de.fiereu.openmmo.net.game.packets.CreateCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
|
||||
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
||||
import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||
import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket
|
||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NullPacket
|
||||
import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket
|
||||
import de.fiereu.openmmo.net.game.packets.RequestCharactersPacket
|
||||
import de.fiereu.openmmo.net.game.packets.RequestPlayerPacket
|
||||
@@ -101,6 +103,7 @@ constructor(
|
||||
onSuspend<CreateCharacterPacket> { event -> loginService.onCreateCharacter(event) }
|
||||
onSuspend<RequestCharactersPacket> { event -> loginService.onCharacterRequest(event) }
|
||||
onSuspend<SelectCharacterPacket> { event -> loginService.onCharacterSelected(event) }
|
||||
onSuspend<DeleteCharacterPacket> { event -> loginService.onDeleteCharacter(event) }
|
||||
onSuspend<RequestPlayerPacket> { event -> loginService.onRequestPlayer(event) }
|
||||
|
||||
onSuspend<MovementPacket> { event -> movementService.onMovement(event) }
|
||||
@@ -115,7 +118,6 @@ constructor(
|
||||
on<RemoveFriendPacket> { event -> socialService.onRemoveFriend(event) }
|
||||
on<BlockPlayerPacket> { event -> socialService.onBlockPlayer(event) }
|
||||
on<UnblockPlayerPacket> { event -> socialService.onUnblockPlayer(event) }
|
||||
on<FriendProfileRequestPacket> { event -> socialService.onFriendProfileRequest(event) }
|
||||
on<RequestSocialProfilePacket> { event -> socialService.onRequestSocialProfile(event) }
|
||||
on<CancelSocialInteractionPacket> { event -> socialService.onCancelSocialInteraction(event) }
|
||||
|
||||
@@ -152,7 +154,10 @@ constructor(
|
||||
on<BattleTeamPreviewConfirmPacket> { event -> battleService.onBattlePacket(event) }
|
||||
on<BattleRewardSelectPacket> { event -> battleService.onBattlePacket(event) }
|
||||
on<BattleChallengeRequestPacket> { event -> battleService.onBattlePacket(event) }
|
||||
on<MapLoadedAckPacket> { event -> battleService.onClientReady(event) }
|
||||
|
||||
// The client sends an empty heartbeat packet.
|
||||
on<NullPacket> {}
|
||||
on<KeepAlivePacket> { event -> event.session.send(event.packet) }
|
||||
on<ChatMessagePacket> { event -> onChatMessage(event) }
|
||||
on<ChatMessageSendPacket> { event -> battleService.onChatSend(event) }
|
||||
|
||||
@@ -8,7 +8,13 @@ import de.fiereu.openmmo.common.enums.Direction
|
||||
* 0x00-0x03, walk 0x10-0x13); a whole sequence of these is sent in one movement packet. This is the
|
||||
* small game agnostic vocabulary scripts use.
|
||||
*/
|
||||
enum class MovementStep(val direction: Direction, val walks: Boolean, val action: Int) {
|
||||
enum class MovementStep(
|
||||
val direction: Direction,
|
||||
val walks: Boolean,
|
||||
val action: Int,
|
||||
val changesFacing: Boolean = true,
|
||||
val fast: Boolean = false,
|
||||
) {
|
||||
FACE_DOWN(Direction.DOWN, false, 0x00),
|
||||
FACE_UP(Direction.UP, false, 0x01),
|
||||
FACE_LEFT(Direction.LEFT, false, 0x02),
|
||||
@@ -17,6 +23,15 @@ enum class MovementStep(val direction: Direction, val walks: Boolean, val action
|
||||
WALK_UP(Direction.UP, true, 0x11),
|
||||
WALK_LEFT(Direction.LEFT, true, 0x12),
|
||||
WALK_RIGHT(Direction.RIGHT, true, 0x13),
|
||||
FAST_DOWN(Direction.DOWN, true, 0x1D, fast = true),
|
||||
FAST_UP(Direction.UP, true, 0x1E, fast = true),
|
||||
FAST_LEFT(Direction.LEFT, true, 0x1F, fast = true),
|
||||
FAST_RIGHT(Direction.RIGHT, true, 0x20, fast = true),
|
||||
WALK_IN_PLACE_FAST_LEFT(Direction.LEFT, false, 0x23, fast = true),
|
||||
WALK_IN_PLACE_FAST_RIGHT(Direction.RIGHT, false, 0x24, fast = true),
|
||||
// Captured delay actions use Emerald ids plus eight.
|
||||
DELAY_8(Direction.DOWN, false, 0x1B, changesFacing = false),
|
||||
DELAY_16(Direction.DOWN, false, 0x1C, changesFacing = false),
|
||||
// Hides the entity in place, used at the end of a walk into a door (decomp set_invisible).
|
||||
SET_INVISIBLE(Direction.DOWN, false, 0x60),
|
||||
SET_INVISIBLE(Direction.DOWN, false, 0x60, changesFacing = false),
|
||||
}
|
||||
@@ -4,40 +4,117 @@ import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.DynamicWarp
|
||||
import de.fiereu.openmmo.common.dialog.DialogLine
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
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.ScriptMovementService
|
||||
import de.fiereu.openmmo.server.game.services.ScriptWarpService
|
||||
import de.fiereu.openmmo.server.game.services.StoryClientState
|
||||
import de.fiereu.openmmo.server.game.services.StoryPlayerService
|
||||
import de.fiereu.openmmo.server.game.services.StoryService
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
|
||||
/** What a [Script] uses to talk to the player it interacted with and read or write story state. */
|
||||
class ScriptContext
|
||||
internal constructor(
|
||||
private val session: SessionContext,
|
||||
private val state: PlayerState,
|
||||
internal val session: SessionContext,
|
||||
internal val state: PlayerState,
|
||||
/** The npc the player talked to, or -1 for a sign. */
|
||||
val entityId: Long,
|
||||
private val dialog: DialogService,
|
||||
private val story: StoryService,
|
||||
internal val dialog: DialogService,
|
||||
internal val story: StoryService,
|
||||
private val movement: ScriptMovementService,
|
||||
private val warp: ScriptWarpService? = null,
|
||||
internal val player: StoryPlayerService? = null,
|
||||
private val battles: BattleService? = null,
|
||||
internal val characters: CharacterStore? = null,
|
||||
) {
|
||||
private val characterId: Long?
|
||||
get() = state.characterId
|
||||
|
||||
val facingDirection: Direction
|
||||
get() = state.facingDirection
|
||||
|
||||
val isFemale: Boolean
|
||||
get() = movement.playerGender(state) == FEMALE
|
||||
|
||||
internal val playerEntityId: Long
|
||||
get() = checkNotNull(state.characterId) { "Scene has no selected character" }
|
||||
|
||||
internal val playerName: String
|
||||
get() = state.characterId?.let { characters?.getCharacter(it)?.info?.name }.orEmpty()
|
||||
|
||||
internal fun send(packet: Any) = session.send(packet)
|
||||
|
||||
/** Show [line] as a sign and wait for the player to close it. */
|
||||
suspend fun sign(line: DialogLine) = dialog.showAndWait(session, state, line.textId, SIGN, -1)
|
||||
|
||||
/** Show [line] from the interacted entity and wait for the player to go on. */
|
||||
suspend fun say(line: DialogLine) = dialog.showAndWait(session, state, line.textId, NPC, entityId)
|
||||
|
||||
/** Show [line] from a cutscene npc addressed by its decomp local id. */
|
||||
suspend fun sayNpc(localId: Int, line: DialogLine) =
|
||||
dialog.showAndWait(
|
||||
session,
|
||||
state,
|
||||
line.textId,
|
||||
NPC,
|
||||
movement.npcEntityId(state, localId) ?: -1,
|
||||
)
|
||||
|
||||
/** Shows dialog with a species-name variable. */
|
||||
suspend fun sayNpcWithSpeciesName(localId: Int, line: DialogLine, speciesId: Int) =
|
||||
dialog.showAndWait(
|
||||
session,
|
||||
state,
|
||||
line.textId,
|
||||
NPC,
|
||||
movement.npcEntityId(state, localId) ?: -1,
|
||||
DialogPresentation(
|
||||
messageArgs =
|
||||
listOf(
|
||||
TextPokemonSpeciesArg(
|
||||
partySlot = 1,
|
||||
stringVariable = 1,
|
||||
speciesId = speciesId.toShort(),
|
||||
))),
|
||||
)
|
||||
|
||||
/** Opens the Emerald starter picker. */
|
||||
suspend fun chooseHoennStarter(): Int = dialog.chooseHoennStarter(session, state)
|
||||
|
||||
/** Ask a ROM-backed yes/no question from the interacted entity. */
|
||||
suspend fun askYesNo(line: DialogLine): Boolean =
|
||||
dialog.askYesNo(session, state, line.textId, entityId)
|
||||
|
||||
/** Ask a ROM-backed yes/no question from a cutscene npc. */
|
||||
suspend fun askYesNoNpc(localId: Int, line: DialogLine): Boolean =
|
||||
dialog.askYesNo(
|
||||
session,
|
||||
state,
|
||||
line.textId,
|
||||
movement.npcEntityId(state, localId) ?: -1,
|
||||
)
|
||||
|
||||
/** True if the story [flag] is set. Keys come from the content layer, for example HoennFlags. */
|
||||
fun isFlagSet(flag: String): Boolean = characterId?.let { story.isFlagSet(it, flag) } ?: false
|
||||
|
||||
fun setFlag(flag: String) {
|
||||
characterId?.let { story.setFlag(it, flag) }
|
||||
characterId?.let {
|
||||
story.setFlag(it, flag)
|
||||
StoryClientState.flagUpdate(state.regionId.toByte(), flag, enabled = true)?.let(session::send)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearFlag(flag: String) {
|
||||
characterId?.let { story.clearFlag(it, flag) }
|
||||
characterId?.let {
|
||||
story.clearFlag(it, flag)
|
||||
StoryClientState.flagUpdate(state.regionId.toByte(), flag, enabled = false)
|
||||
?.let(session::send)
|
||||
}
|
||||
}
|
||||
|
||||
/** The story var [key], or 0 if it was never set. */
|
||||
@@ -47,6 +124,20 @@ internal constructor(
|
||||
characterId?.let { story.setVar(it, key, value) }
|
||||
}
|
||||
|
||||
fun givePokemon(dexId: Int, level: Int, vararg moveIds: Int) =
|
||||
checkNotNull(player) { STORY_PLAYER_UNAVAILABLE }
|
||||
.givePokemon(session, state, dexId, level, moveIds.toList())
|
||||
|
||||
fun healParty() = checkNotNull(player) { STORY_PLAYER_UNAVAILABLE }.healParty(session, state)
|
||||
|
||||
fun giveItem(itemId: Int, quantity: Int = 1): Boolean =
|
||||
checkNotNull(player) { STORY_PLAYER_UNAVAILABLE }.giveItem(session, state, 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" }
|
||||
.startScriptedBattle(session, dexId, level, moveIds.toList())
|
||||
|
||||
/**
|
||||
* Walk the map npc with decomp local id [localId] (its entityIdx) through [steps] and wait for
|
||||
* the whole path to finish. This is applymovement plus waitmovement for an npc.
|
||||
@@ -54,6 +145,16 @@ internal constructor(
|
||||
suspend fun moveNpc(localId: Int, vararg steps: MovementStep) =
|
||||
movement.moveNpc(session, state, localId, steps.toList())
|
||||
|
||||
/** Starts concurrent NPC movement paths. */
|
||||
suspend fun moveNpcs(vararg paths: Pair<Int, List<MovementStep>>) =
|
||||
movement.moveNpcs(session, state, paths.toList())
|
||||
|
||||
/** Starts player and NPC paths together. */
|
||||
suspend fun moveSelfAndNpcs(
|
||||
selfSteps: List<MovementStep>,
|
||||
vararg paths: Pair<Int, List<MovementStep>>,
|
||||
) = movement.moveSelfAndNpcs(session, state, selfSteps, paths.toList())
|
||||
|
||||
/** Walk the player's own avatar through [steps] and wait for it to finish. */
|
||||
suspend fun moveSelf(vararg steps: MovementStep) =
|
||||
movement.moveSelf(session, state, steps.toList())
|
||||
@@ -61,6 +162,20 @@ internal constructor(
|
||||
/** Show a normally hidden map npc (its decomp local id) to this player, the decomp addobject. */
|
||||
fun showNpc(localId: Int) = movement.showNpc(session, state, localId)
|
||||
|
||||
/** Shows a hidden NPC at a new position. */
|
||||
fun showNpcAt(localId: Int, x: Int, y: Int) = movement.showNpcAt(session, state, localId, x, y)
|
||||
|
||||
/** Repositions an existing NPC. */
|
||||
fun repositionNpc(localId: Int, x: Int, y: Int) =
|
||||
movement.repositionNpc(session, state, localId, x, y)
|
||||
|
||||
/** Relocate the player's overworld entity as part of a cutscene. */
|
||||
fun repositionSelf(x: Int, y: Int, facing: Direction) =
|
||||
movement.repositionSelf(session, state, x, y, facing)
|
||||
|
||||
/** Remove a cutscene npc and its collision (`removeobject`). */
|
||||
fun removeNpc(localId: Int) = movement.removeNpc(session, state, localId)
|
||||
|
||||
/** Set where a MAP_DYNAMIC warp sends this player (the decomp setdynamicwarp). */
|
||||
fun setDynamicWarp(regionId: Int, bankId: Int, mapId: Int, x: Int, y: Int, facing: Direction) =
|
||||
movement.setDynamicWarp(
|
||||
@@ -68,9 +183,28 @@ internal constructor(
|
||||
DynamicWarp(
|
||||
regionId.toByte(), bankId.toByte(), mapId.toByte(), x.toShort(), y.toShort(), facing))
|
||||
|
||||
/** Warps the player without door movement. */
|
||||
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,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
// Sign boxes have no speaker, npc boxes point at the entity.
|
||||
const val SIGN = 3
|
||||
const val NPC = 4
|
||||
const val FEMALE: Byte = 1
|
||||
const val STORY_PLAYER_UNAVAILABLE = "Story player service is unavailable"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package de.fiereu.openmmo.server.game.script
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.server.game.services.BattleService
|
||||
import de.fiereu.openmmo.server.game.services.DialogService
|
||||
import de.fiereu.openmmo.server.game.services.ScriptMovementService
|
||||
import de.fiereu.openmmo.server.game.services.ScriptWarpService
|
||||
import de.fiereu.openmmo.server.game.services.StoryPlayerService
|
||||
import de.fiereu.openmmo.server.game.services.StoryService
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.session.SCRIPT_SCOPE
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -30,6 +34,10 @@ constructor(
|
||||
private val dialogService: DialogService,
|
||||
private val storyService: StoryService,
|
||||
private val movementService: ScriptMovementService,
|
||||
private val warpService: ScriptWarpService,
|
||||
private val storyPlayerService: StoryPlayerService,
|
||||
private val battleService: BattleService,
|
||||
private val characterStore: CharacterStore,
|
||||
) {
|
||||
fun run(session: SessionContext, state: PlayerState, script: Script, entityId: Long) =
|
||||
runAll(session, state, listOf(script), entityId)
|
||||
@@ -50,7 +58,19 @@ constructor(
|
||||
session.attributes.getOrPut(SCRIPT_SCOPE) {
|
||||
CoroutineScope(SupervisorJob() + Dispatchers.Default)
|
||||
}
|
||||
val ctx = ScriptContext(session, state, entityId, dialogService, storyService, movementService)
|
||||
val ctx =
|
||||
ScriptContext(
|
||||
session,
|
||||
state,
|
||||
entityId,
|
||||
dialogService,
|
||||
storyService,
|
||||
movementService,
|
||||
warpService,
|
||||
storyPlayerService,
|
||||
battleService,
|
||||
characterStore,
|
||||
)
|
||||
scope.launch {
|
||||
try {
|
||||
for (script in scripts) script.run(ctx)
|
||||
|
||||
+115
-20
@@ -1,10 +1,12 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.LittlerootTown
|
||||
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
|
||||
@@ -14,6 +16,7 @@ import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
// Decomp local id of mom in this map's object events (LOCALID_LITTLEROOT_MOM).
|
||||
private const val LOCALID_MOM = 3
|
||||
private const val LOCALID_TWIN = 0
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -29,7 +32,18 @@ private const val LOCALID_MOM = 3
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_EventScript_Twin : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port LittlerootTown_EventScript_Twin")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
when {
|
||||
ctx.isFlagSet(HoennFlags.FLAG_ADVENTURE_STARTED) ->
|
||||
ctx.say(LittlerootTown.GoodLuckCatchingPokemon)
|
||||
ctx.isFlagSet(HoennFlags.FLAG_RESCUED_BIRCH) -> ctx.say(LittlerootTown.YouSavedBirch)
|
||||
ctx.getVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE) != 0 -> {
|
||||
ctx.say(LittlerootTown.CanYouGoSeeWhatsHappening)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 2)
|
||||
}
|
||||
else -> ctx.say(LittlerootTown.IfYouGoInGrassPokemonWillJumpOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,33 +54,51 @@ internal object LittlerootTown_EventScript_Twin : Script {
|
||||
* call_if_eq VAR_LITTLEROOT_INTRO_STATE, 2, LittlerootTown_EventScript_MoveMomToMaysDoor
|
||||
* ```
|
||||
*
|
||||
* The two calls set the rival's sprite and move mom for the intro, which need object and movement
|
||||
* scripting that does not exist yet, so only the flag is ported for now.
|
||||
* Female-path positions are applied during spawning.
|
||||
*/
|
||||
internal object LittlerootTown_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.setFlag(HoennFlags.FLAG_VISITED_LITTLEROOT_TOWN)
|
||||
if (ctx.getVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE) == 3 &&
|
||||
!ctx.isFlagSet(HoennFlags.FLAG_RECEIVED_RUNNING_SHOES)) {
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE)
|
||||
ctx.showNpcAt(LOCALID_MOM, if (ctx.isFemale) 14 else 5, 9)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The intro cutscene, run from the on-frame table when VAR_LITTLEROOT_INTRO_STATE is 1 (the player
|
||||
* just stepped off the truck). Lean port of LittlerootTown_EventScript_StepOffTruckMale plus
|
||||
* GoInsideWithMom: mom comes out and greets the player, then the intro advances so it plays once.
|
||||
*/
|
||||
/** Runs the male moving-truck cutscene. */
|
||||
internal object LittlerootTown_EventScript_StepOffTruckMale : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.showNpc(LOCALID_MOM)
|
||||
ctx.moveNpc(LOCALID_MOM, WALK_DOWN, WALK_DOWN, WALK_LEFT, FACE_LEFT)
|
||||
override suspend fun run(ctx: ScriptContext) = stepOffTruck(ctx, female = false)
|
||||
}
|
||||
|
||||
/** Female half of the moving-truck cutscene (intro state 2). */
|
||||
internal object LittlerootTown_EventScript_StepOffTruckFemale : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = stepOffTruck(ctx, female = true)
|
||||
}
|
||||
|
||||
private suspend fun stepOffTruck(ctx: ScriptContext, female: Boolean) {
|
||||
val doorX = if (female) 14 else 5
|
||||
val houseMap = if (female) 2 else 0
|
||||
val houseX = if (female) 2 else 8
|
||||
|
||||
// Approximate the scripted hop with ordinary movement.
|
||||
ctx.moveSelf(WALK_RIGHT)
|
||||
ctx.showNpcAt(LOCALID_MOM, doorX, 8)
|
||||
ctx.moveNpc(LOCALID_MOM, WALK_DOWN, WALK_DOWN, FACE_LEFT)
|
||||
ctx.say(LittlerootTown.OurNewHomeLetsGoInside)
|
||||
// Mom walks back to her door and steps inside (goes invisible).
|
||||
ctx.moveNpc(LOCALID_MOM, WALK_RIGHT, WALK_UP, WALK_UP, SET_INVISIBLE)
|
||||
ctx.moveNpc(LOCALID_MOM, WALK_UP, WALK_UP, SET_INVISIBLE)
|
||||
ctx.moveSelf(WALK_RIGHT, FACE_UP, WALK_UP, WALK_UP)
|
||||
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE)
|
||||
ctx.setFlag(
|
||||
if (female) HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_TRUCK
|
||||
else HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_TRUCK)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_FAT_MAN)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_MAP_NAME_POPUP)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 3)
|
||||
// TODO Finish the Littleroot intro cutscene
|
||||
// Port the rest of GoInsideWithMom: the player jumping off the truck, the door open/close
|
||||
// animations, the player following mom into the house, and the warpsilent inside. These need
|
||||
// door, hideplayer, warpsilent and sound-effect script verbs.
|
||||
}
|
||||
ctx.warp(
|
||||
regionId = 1, bankId = 51, mapId = houseMap, x = houseX, y = 8, facing = FACE_UP.direction)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_EventScript_FatMan : Script {
|
||||
@@ -77,6 +109,31 @@ internal object LittlerootTown_EventScript_Boy : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(LittlerootTown.BirchSpendsDaysInLab)
|
||||
}
|
||||
|
||||
/** Starts Birch's rescue after meeting the rival. */
|
||||
internal object LittlerootTown_EventScript_GoSaveBirchTrigger : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.moveNpc(LOCALID_TWIN, FACE_RIGHT)
|
||||
ctx.moveSelf(FACE_LEFT)
|
||||
ctx.sayNpc(LOCALID_TWIN, LittlerootTown.CanYouGoSeeWhatsHappening)
|
||||
ctx.moveNpc(LOCALID_TWIN, FACE_DOWN)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 2)
|
||||
}
|
||||
}
|
||||
|
||||
internal object LittlerootTown_EventScript_NeedPokemonTriggerLeft : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = preventLeavingWithoutPokemon(ctx)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_EventScript_NeedPokemonTriggerRight : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = preventLeavingWithoutPokemon(ctx)
|
||||
}
|
||||
|
||||
private suspend fun preventLeavingWithoutPokemon(ctx: ScriptContext) {
|
||||
ctx.sayNpc(LOCALID_TWIN, LittlerootTown.IfYouGoInGrassPokemonWillJumpOut)
|
||||
ctx.moveSelf(WALK_DOWN)
|
||||
ctx.sayNpc(LOCALID_TWIN, LittlerootTown.DangerousIfYouDontHavePokemon)
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
@@ -100,7 +157,25 @@ internal object LittlerootTown_EventScript_Boy : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_EventScript_Mom : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port LittlerootTown_EventScript_Mom")
|
||||
override suspend fun run(ctx: ScriptContext) = giveRunningShoes(ctx)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_EventScript_GiveRunningShoes : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = giveRunningShoes(ctx)
|
||||
}
|
||||
|
||||
private suspend fun giveRunningShoes(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_RECEIVED_RUNNING_SHOES)) return
|
||||
ctx.sayNpc(LOCALID_MOM, LittlerootTown.WaitPlayer)
|
||||
ctx.sayNpc(LOCALID_MOM, LittlerootTown.WearTheseRunningShoes)
|
||||
ctx.sayNpc(LOCALID_MOM, LittlerootTown.SwitchShoesWithRunningShoes)
|
||||
ctx.setFlag(HoennFlags.FLAG_RECEIVED_RUNNING_SHOES)
|
||||
ctx.setFlag(HoennFlags.FLAG_SYS_B_DASH)
|
||||
ctx.sayNpc(LOCALID_MOM, LittlerootTown.ExplainRunningShoes)
|
||||
ctx.sayNpc(LOCALID_MOM, LittlerootTown.ComeHomeIfAnythingHappens)
|
||||
ctx.moveNpc(LOCALID_MOM, WALK_UP, SET_INVISIBLE)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 4)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_EventScript_TownSign : Script {
|
||||
@@ -148,9 +223,29 @@ internal val LittlerootTownScripts: Map<String, Script> =
|
||||
"LittlerootTown_OnTransition" to LittlerootTown_OnTransition,
|
||||
"LittlerootTown_EventScript_StepOffTruckMale" to
|
||||
LittlerootTown_EventScript_StepOffTruckMale,
|
||||
"LittlerootTown_EventScript_StepOffTruckFemale" to
|
||||
LittlerootTown_EventScript_StepOffTruckFemale,
|
||||
"LittlerootTown_EventScript_Twin" to LittlerootTown_EventScript_Twin,
|
||||
"LittlerootTown_EventScript_FatMan" to LittlerootTown_EventScript_FatMan,
|
||||
"LittlerootTown_EventScript_Boy" to LittlerootTown_EventScript_Boy,
|
||||
"LittlerootTown_EventScript_GoSaveBirchTrigger" to
|
||||
LittlerootTown_EventScript_GoSaveBirchTrigger,
|
||||
"LittlerootTown_EventScript_NeedPokemonTriggerLeft" to
|
||||
LittlerootTown_EventScript_NeedPokemonTriggerLeft,
|
||||
"LittlerootTown_EventScript_NeedPokemonTriggerRight" to
|
||||
LittlerootTown_EventScript_NeedPokemonTriggerRight,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger0" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger1" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger2" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger3" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger4" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_GiveRunningShoesTrigger5" to
|
||||
LittlerootTown_EventScript_GiveRunningShoes,
|
||||
"LittlerootTown_EventScript_Mom" to LittlerootTown_EventScript_Mom,
|
||||
"LittlerootTown_EventScript_TownSign" to LittlerootTown_EventScript_TownSign,
|
||||
"LittlerootTown_EventScript_BirchsLabSign" to LittlerootTown_EventScript_BirchsLabSign,
|
||||
|
||||
+102
@@ -1,7 +1,94 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.PlayersHouse_1F
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_HOUSE_MOM = 0
|
||||
|
||||
internal object LittlerootTown_BrendansHouse_1F_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = positionMom(ctx, female = false)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_MaysHouse_1F_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = positionMom(ctx, female = true)
|
||||
}
|
||||
|
||||
private fun positionMom(ctx: ScriptContext, female: Boolean) {
|
||||
val position =
|
||||
when (ctx.getVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE)) {
|
||||
3 -> if (female) 1 to 8 else 9 to 8
|
||||
5 -> if (female) 2 to 4 else 8 to 4
|
||||
6 -> if (female) 6 to 5 else 4 to 5
|
||||
else -> return
|
||||
}
|
||||
ctx.showNpcAt(LOCALID_HOUSE_MOM, position.first, position.second)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_BrendansHouse_1F_EventScript_EnterHouseMovingIn : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = enterHouseMovingIn(ctx, female = false)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_MaysHouse_1F_EventScript_EnterHouseMovingIn : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = enterHouseMovingIn(ctx, female = true)
|
||||
}
|
||||
|
||||
private suspend fun enterHouseMovingIn(ctx: ScriptContext, female: Boolean) {
|
||||
positionMom(ctx, female)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.IsntItNiceInHere)
|
||||
ctx.moveNpc(LOCALID_HOUSE_MOM, if (female) FACE_RIGHT else FACE_LEFT)
|
||||
ctx.moveSelf(if (female) FACE_LEFT else FACE_RIGHT)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.MoversPokemonGoSetClock)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 4)
|
||||
ctx.moveSelf(WALK_UP)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_BrendansHouse_1F_EventScript_GoUpstairsToSetClock : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = goUpstairsToSetClock(ctx, female = false)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_MaysHouse_1F_EventScript_GoUpstairsToSetClock : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = goUpstairsToSetClock(ctx, female = true)
|
||||
}
|
||||
|
||||
private suspend fun goUpstairsToSetClock(ctx: ScriptContext, female: Boolean) {
|
||||
positionMom(ctx, female)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.GoSetTheClock)
|
||||
ctx.moveSelf(WALK_UP)
|
||||
ctx.warp(
|
||||
regionId = 1,
|
||||
bankId = 51,
|
||||
mapId = if (female) 3 else 1,
|
||||
x = if (female) 1 else 7,
|
||||
y = 1,
|
||||
facing = Direction.DOWN,
|
||||
)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_BrendansHouse_1F_EventScript_PetalburgGymReport : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = watchPetalburgReport(ctx, female = false)
|
||||
}
|
||||
|
||||
internal object LittlerootTown_MaysHouse_1F_EventScript_PetalburgGymReport : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = watchPetalburgReport(ctx, female = true)
|
||||
}
|
||||
|
||||
private suspend fun watchPetalburgReport(ctx: ScriptContext, female: Boolean) {
|
||||
positionMom(ctx, female)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.OhComeQuickly)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.MaybeDadWillBeOn)
|
||||
ctx.sign(PlayersHouse_1F.ReportFromPetalburgGym)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.ItsOverWeMissedHim)
|
||||
ctx.sayNpc(LOCALID_HOUSE_MOM, PlayersHouse_1F.GoIntroduceYourselfNextDoor)
|
||||
ctx.setFlag(HoennFlags.FLAG_SYS_TV_HOME)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 7)
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -93,6 +180,21 @@ internal object RivalsHouse_1F_EventScript_RivalSibling : Script {
|
||||
|
||||
internal val LittlerootTown_BrendansHouse_1FScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"LittlerootTown_BrendansHouse_1F_OnTransition" to
|
||||
LittlerootTown_BrendansHouse_1F_OnTransition,
|
||||
"LittlerootTown_MaysHouse_1F_OnTransition" to LittlerootTown_MaysHouse_1F_OnTransition,
|
||||
"LittlerootTown_BrendansHouse_1F_EventScript_EnterHouseMovingIn" to
|
||||
LittlerootTown_BrendansHouse_1F_EventScript_EnterHouseMovingIn,
|
||||
"LittlerootTown_MaysHouse_1F_EventScript_EnterHouseMovingIn" to
|
||||
LittlerootTown_MaysHouse_1F_EventScript_EnterHouseMovingIn,
|
||||
"LittlerootTown_BrendansHouse_1F_EventScript_GoUpstairsToSetClock" to
|
||||
LittlerootTown_BrendansHouse_1F_EventScript_GoUpstairsToSetClock,
|
||||
"LittlerootTown_MaysHouse_1F_EventScript_GoUpstairsToSetClock" to
|
||||
LittlerootTown_MaysHouse_1F_EventScript_GoUpstairsToSetClock,
|
||||
"LittlerootTown_BrendansHouse_1F_EventScript_PetalburgGymReport" to
|
||||
LittlerootTown_BrendansHouse_1F_EventScript_PetalburgGymReport,
|
||||
"LittlerootTown_MaysHouse_1F_EventScript_PetalburgGymReport" to
|
||||
LittlerootTown_MaysHouse_1F_EventScript_PetalburgGymReport,
|
||||
"PlayersHouse_1F_EventScript_Mom" to PlayersHouse_1F_EventScript_Mom,
|
||||
"PlayersHouse_1F_EventScript_Vigoroth2" to PlayersHouse_1F_EventScript_Vigoroth2,
|
||||
"PlayersHouse_1F_EventScript_Vigoroth1" to PlayersHouse_1F_EventScript_Vigoroth1,
|
||||
|
||||
+143
-26
@@ -1,37 +1,123 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.PlayersHouse_2F
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.RivalsHouse_2F
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.DELAY_16
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.DELAY_8
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
* lockall
|
||||
* goto_if_set FLAG_MET_RIVAL_LILYCOVE, RivalsHouse_2F_EventScript_RivalPostLilycove
|
||||
* checkplayergender
|
||||
* goto_if_eq VAR_RESULT, MALE, RivalsHouse_2F_EventScript_May
|
||||
* goto_if_eq VAR_RESULT, FEMALE, RivalsHouse_2F_EventScript_Brendan
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
private const val LOCALID_BEDROOM_MOM = 13
|
||||
private const val LOCALID_RIVAL = 0
|
||||
private const val LOCALID_RIVALS_POKE_BALL = 14
|
||||
|
||||
internal object LittlerootTown_BrendansHouse_2F_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFemale && ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) < 2) {
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 2)
|
||||
}
|
||||
if (ctx.isFemale &&
|
||||
ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) >= 3 &&
|
||||
ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) < 2) {
|
||||
// Keep Brendan at his post-cutscene position.
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_RIVAL_BEDROOM)
|
||||
ctx.removeNpc(LOCALID_RIVAL)
|
||||
ctx.showNpcAt(LOCALID_RIVAL, 0, 2)
|
||||
}
|
||||
if (ctx.getVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE) == 4) {
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal object RivalsHouse_2F_EventScript_Rival : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port RivalsHouse_2F_EventScript_Rival")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.sayNpc(
|
||||
LOCALID_RIVAL,
|
||||
if (ctx.isFemale) RivalsHouse_2F.BrendanGettingReady else RivalsHouse_2F.MayGettingReady,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
* lockall
|
||||
* goto_if_eq VAR_LITTLEROOT_RIVAL_STATE, 2, LittlerootTown_BrendansHouse_2F_EventScript_MeetBrendan
|
||||
* msgbox RivalsHouse_2F_Text_ItsRivalsPokeBall, MSGBOX_DEFAULT
|
||||
* releaseall
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) != 2) {
|
||||
ctx.say(RivalsHouse_2F.ItsRivalsPokeBall)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.showNpc(LOCALID_RIVAL)
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_DOWN, WALK_DOWN, FACE_LEFT)
|
||||
when (ctx.facingDirection) {
|
||||
Direction.UP -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT, WALK_LEFT, WALK_DOWN, WALK_DOWN, WALK_LEFT)
|
||||
ctx.moveSelf(FACE_RIGHT)
|
||||
ctx.sayNpc(LOCALID_RIVAL, RivalsHouse_2F.BrendanWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_LEFT)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
FACE_UP,
|
||||
)
|
||||
}
|
||||
Direction.DOWN,
|
||||
Direction.DIVE,
|
||||
Direction.EMERGE -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT, WALK_LEFT, WALK_LEFT)
|
||||
ctx.moveSelf(FACE_RIGHT)
|
||||
ctx.sayNpc(LOCALID_RIVAL, RivalsHouse_2F.BrendanWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_LEFT)
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_UP, WALK_LEFT, WALK_LEFT, WALK_LEFT, WALK_LEFT, FACE_UP)
|
||||
}
|
||||
Direction.LEFT -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT, WALK_LEFT, WALK_DOWN, FACE_LEFT)
|
||||
ctx.moveSelf(FACE_RIGHT)
|
||||
ctx.sayNpc(LOCALID_RIVAL, RivalsHouse_2F.BrendanWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_LEFT)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
WALK_LEFT,
|
||||
FACE_UP,
|
||||
)
|
||||
}
|
||||
Direction.RIGHT -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT, WALK_LEFT, WALK_LEFT, WALK_LEFT, WALK_LEFT, FACE_DOWN)
|
||||
ctx.moveSelf(FACE_UP)
|
||||
ctx.sayNpc(LOCALID_RIVAL, RivalsHouse_2F.BrendanWhoAreYou)
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_UP, WALK_LEFT, WALK_LEFT, FACE_UP)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.moveNpc(LOCALID_RIVALS_POKE_BALL, SET_INVISIBLE)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 3)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F_POKE_BALL)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_RIVAL_BEDROOM)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,8 +149,37 @@ internal object PlayersHouse_2F_EventScript_Notebook : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_BrendansHouse_2F_EventScript_WallClock : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_BrendansHouse_2F_EventScript_WallClock")
|
||||
override suspend fun run(ctx: ScriptContext) = setWallClock(ctx, female = false)
|
||||
}
|
||||
|
||||
internal suspend fun setWallClock(ctx: ScriptContext, female: Boolean) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_SET_WALL_CLOCK)) return
|
||||
ctx.sign(PlayersHouse_2F.ClockIsStopped)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 6)
|
||||
ctx.setFlag(HoennFlags.FLAG_SET_WALL_CLOCK)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_PLAYERS_HOUSE_VIGOROTH_1)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_PLAYERS_HOUSE_VIGOROTH_2)
|
||||
|
||||
ctx.showNpcAt(LOCALID_BEDROOM_MOM, if (female) 1 else 7, 1)
|
||||
ctx.moveNpc(
|
||||
LOCALID_BEDROOM_MOM,
|
||||
DELAY_8,
|
||||
WALK_DOWN,
|
||||
if (female) FACE_RIGHT else FACE_LEFT,
|
||||
DELAY_16,
|
||||
DELAY_8,
|
||||
if (female) WALK_RIGHT else WALK_LEFT,
|
||||
)
|
||||
ctx.moveSelf(if (female) FACE_LEFT else FACE_RIGHT)
|
||||
ctx.sayNpc(LOCALID_BEDROOM_MOM, PlayersHouse_2F.HowDoYouLikeYourRoom)
|
||||
ctx.moveNpc(
|
||||
LOCALID_BEDROOM_MOM,
|
||||
if (female) WALK_LEFT else WALK_RIGHT,
|
||||
WALK_UP,
|
||||
DELAY_8,
|
||||
)
|
||||
// Removing Mom clears her stair collision.
|
||||
ctx.removeNpc(LOCALID_BEDROOM_MOM)
|
||||
}
|
||||
|
||||
internal object PlayersHouse_2F_EventScript_GameCube : Script {
|
||||
@@ -73,6 +188,8 @@ internal object PlayersHouse_2F_EventScript_GameCube : Script {
|
||||
|
||||
internal val LittlerootTown_BrendansHouse_2FScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"LittlerootTown_BrendansHouse_2F_OnTransition" to
|
||||
LittlerootTown_BrendansHouse_2F_OnTransition,
|
||||
"RivalsHouse_2F_EventScript_Rival" to RivalsHouse_2F_EventScript_Rival,
|
||||
"LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall" to
|
||||
LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall,
|
||||
|
||||
+119
-4
@@ -1,7 +1,40 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.RivalsHouse_2F
|
||||
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_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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_RIVAL_MAY = 0
|
||||
private const val LOCALID_RIVALS_POKE_BALL_MAY = 15
|
||||
|
||||
internal object LittlerootTown_MaysHouse_2F_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (!ctx.isFemale && ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) < 2) {
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 2)
|
||||
}
|
||||
if (!ctx.isFemale &&
|
||||
ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) >= 3 &&
|
||||
ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) < 2) {
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_RIVAL_BEDROOM)
|
||||
ctx.removeNpc(LOCALID_RIVAL_MAY)
|
||||
ctx.showNpcAt(LOCALID_RIVAL_MAY, 8, 2)
|
||||
}
|
||||
if (ctx.getVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE) == 4) {
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_INTRO_STATE, 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -14,8 +47,90 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_MaysHouse_2F_EventScript_RivalsPokeBall : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_MaysHouse_2F_EventScript_RivalsPokeBall")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE) != 2) {
|
||||
ctx.say(RivalsHouse_2F.ItsRivalsPokeBall)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.showNpc(LOCALID_RIVAL_MAY)
|
||||
ctx.moveNpc(LOCALID_RIVAL_MAY, WALK_DOWN, WALK_DOWN, FACE_RIGHT)
|
||||
when (ctx.facingDirection) {
|
||||
Direction.UP -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL_MAY, WALK_RIGHT, WALK_RIGHT, WALK_DOWN, WALK_DOWN, WALK_RIGHT)
|
||||
ctx.moveSelf(FACE_LEFT)
|
||||
ctx.sayNpc(LOCALID_RIVAL_MAY, RivalsHouse_2F.MayWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_RIGHT)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL_MAY,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
FACE_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
FACE_UP,
|
||||
)
|
||||
}
|
||||
Direction.DOWN,
|
||||
Direction.DIVE,
|
||||
Direction.EMERGE -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL_MAY, WALK_RIGHT, WALK_RIGHT, WALK_RIGHT)
|
||||
ctx.moveSelf(FACE_LEFT)
|
||||
ctx.sayNpc(LOCALID_RIVAL_MAY, RivalsHouse_2F.MayWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_RIGHT)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL_MAY,
|
||||
WALK_UP,
|
||||
FACE_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
FACE_UP,
|
||||
)
|
||||
}
|
||||
Direction.LEFT -> {
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL_MAY,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
FACE_DOWN,
|
||||
)
|
||||
ctx.moveSelf(FACE_UP)
|
||||
ctx.sayNpc(LOCALID_RIVAL_MAY, RivalsHouse_2F.MayWhoAreYou)
|
||||
ctx.moveNpc(LOCALID_RIVAL_MAY, WALK_UP, WALK_RIGHT, WALK_RIGHT, FACE_UP)
|
||||
}
|
||||
Direction.RIGHT -> {
|
||||
ctx.moveNpc(LOCALID_RIVAL_MAY, WALK_RIGHT, WALK_RIGHT, WALK_DOWN, FACE_RIGHT)
|
||||
ctx.moveSelf(FACE_LEFT)
|
||||
ctx.sayNpc(LOCALID_RIVAL_MAY, RivalsHouse_2F.MayWhoAreYou)
|
||||
ctx.moveSelf(FACE_UP, FACE_RIGHT)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL_MAY,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
WALK_RIGHT,
|
||||
FACE_UP,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.moveNpc(LOCALID_RIVALS_POKE_BALL_MAY, SET_INVISIBLE)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 3)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_2F_POKE_BALL)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_RIVAL_BEDROOM)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,8 +143,7 @@ internal object LittlerootTown_MaysHouse_2F_EventScript_RivalsPokeBall : Script
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_MaysHouse_2F_EventScript_WallClock : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_MaysHouse_2F_EventScript_WallClock")
|
||||
override suspend fun run(ctx: ScriptContext) = setWallClock(ctx, female = true)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +163,7 @@ internal object LittlerootTown_MaysHouse_2F_EventScript_PC : Script {
|
||||
|
||||
internal val LittlerootTown_MaysHouse_2FScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"LittlerootTown_MaysHouse_2F_OnTransition" to LittlerootTown_MaysHouse_2F_OnTransition,
|
||||
"LittlerootTown_MaysHouse_2F_EventScript_RivalsPokeBall" to
|
||||
LittlerootTown_MaysHouse_2F_EventScript_RivalsPokeBall,
|
||||
"LittlerootTown_MaysHouse_2F_EventScript_WallClock" to
|
||||
|
||||
+101
-4
@@ -1,8 +1,86 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.LittlerootTown_ProfessorBirchsLab
|
||||
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
|
||||
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.hoenn.HoennFlags
|
||||
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)
|
||||
|
||||
internal object LittlerootTown_ProfessorBirchsLab_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = Unit
|
||||
}
|
||||
|
||||
internal object LittlerootTown_ProfessorBirchsLab_EventScript_GiveStarterEvent : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) != 2) return
|
||||
val starter = HOENN_STARTERS.getOrElse(ctx.getVar(HoennVars.VAR_STARTER_MON)) { TREECKO }
|
||||
ctx.sayNpcWithSpeciesName(
|
||||
LOCALID_BIRCH,
|
||||
LittlerootTown_ProfessorBirchsLab.LikeYouToHavePokemon,
|
||||
starter,
|
||||
)
|
||||
|
||||
// The captured client skips the nickname screen.
|
||||
var agreed =
|
||||
ctx.askYesNoNpc(
|
||||
LOCALID_BIRCH,
|
||||
LittlerootTown_ProfessorBirchsLab.MightBeGoodIdeaToGoSeeRival,
|
||||
)
|
||||
while (!agreed) {
|
||||
agreed =
|
||||
ctx.askYesNoNpc(
|
||||
LOCALID_BIRCH,
|
||||
LittlerootTown_ProfessorBirchsLab.DontBeThatWay,
|
||||
)
|
||||
}
|
||||
ctx.sayNpc(LOCALID_BIRCH, LittlerootTown_ProfessorBirchsLab.GetRivalToTeachYou)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_ROUTE_101_BOY)
|
||||
ctx.setVar(HoennVars.VAR_BIRCH_LAB_STATE, 3)
|
||||
}
|
||||
}
|
||||
|
||||
internal object LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) != 4) return
|
||||
repeat(7) { ctx.moveSelf(WALK_UP) }
|
||||
ctx.sayNpc(LOCALID_BIRCH, LittlerootTown_ProfessorBirchsLab.HeardYouBeatRivalTakePokedex)
|
||||
ctx.sayNpc(LOCALID_BIRCH, LittlerootTown_ProfessorBirchsLab.ReceivedPokedex)
|
||||
ctx.setFlag(HoennFlags.FLAG_SYS_POKEDEX_GET)
|
||||
ctx.setFlag(HoennFlags.FLAG_RECEIVED_POKEDEX_FROM_BIRCH)
|
||||
ctx.sayNpc(LOCALID_BIRCH, LittlerootTown_ProfessorBirchsLab.ExplainPokedex)
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_DOWN, FACE_LEFT)
|
||||
ctx.moveSelf(FACE_RIGHT)
|
||||
if (ctx.isFemale) {
|
||||
ctx.sayNpc(
|
||||
LOCALID_RIVAL,
|
||||
LittlerootTown_ProfessorBirchsLab.BrendanGotPokedexTooTakeThese,
|
||||
)
|
||||
} else {
|
||||
ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.MayGotPokedexTooTakeThese)
|
||||
}
|
||||
ctx.giveItem(POKE_BALL_ITEM, 5)
|
||||
if (ctx.isFemale) {
|
||||
ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.CatchCoolPokemonWithPokeBalls)
|
||||
} else {
|
||||
ctx.sayNpc(LOCALID_RIVAL, LittlerootTown_ProfessorBirchsLab.CatchCutePokemonWithPokeBalls)
|
||||
}
|
||||
ctx.setVar(HoennVars.VAR_BIRCH_LAB_STATE, 5)
|
||||
ctx.setFlag(HoennFlags.FLAG_ADVENTURE_STARTED)
|
||||
ctx.setVar(HoennVars.VAR_OLDALE_TOWN_STATE, 1)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 4)
|
||||
ctx.setVar(HoennVars.VAR_LITTLEROOT_TOWN_STATE, 3)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -18,8 +96,16 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_ProfessorBirchsLab_EventScript_Aide : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_ProfessorBirchsLab_EventScript_Aide")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) >= 3) {
|
||||
ctx.say(LittlerootTown_ProfessorBirchsLab.BirchEnjoysRivalsHelpToo)
|
||||
} else if (ctx.isFlagSet(HoennFlags.FLAG_BIRCH_AIDE_MET)) {
|
||||
ctx.say(LittlerootTown_ProfessorBirchsLab.BirchIsntOneForDeskWork)
|
||||
} else {
|
||||
ctx.say(LittlerootTown_ProfessorBirchsLab.BirchAwayOnFieldwork)
|
||||
ctx.setFlag(HoennFlags.FLAG_BIRCH_AIDE_MET)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,8 +122,13 @@ internal object LittlerootTown_ProfessorBirchsLab_EventScript_Aide : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object LittlerootTown_ProfessorBirchsLab_EventScript_Birch : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port LittlerootTown_ProfessorBirchsLab_EventScript_Birch")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_BIRCH_LAB_STATE) >= 5) {
|
||||
ctx.say(LittlerootTown_ProfessorBirchsLab.CountlessPokemonAwait)
|
||||
} else {
|
||||
ctx.say(LittlerootTown_ProfessorBirchsLab.BirchRivalGoneHome)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +230,12 @@ internal object LittlerootTown_ProfessorBirchsLab_EventScript_PC : Script {
|
||||
|
||||
internal val LittlerootTown_ProfessorBirchsLabScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"LittlerootTown_ProfessorBirchsLab_OnTransition" to
|
||||
LittlerootTown_ProfessorBirchsLab_OnTransition,
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_GiveStarterEvent" to
|
||||
LittlerootTown_ProfessorBirchsLab_EventScript_GiveStarterEvent,
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent" to
|
||||
LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent,
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_Aide" to
|
||||
LittlerootTown_ProfessorBirchsLab_EventScript_Aide,
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_Birch" to
|
||||
|
||||
+79
-2
@@ -1,8 +1,28 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.OldaleTown
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
|
||||
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.Script
|
||||
import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_FOOTPRINTS_MAN = 2
|
||||
private const val LOCALID_RIVAL = 3
|
||||
|
||||
internal object OldaleTown_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.setFlag(HoennFlags.FLAG_VISITED_OLDALE_TOWN)
|
||||
if (!ctx.isFlagSet(HoennFlags.FLAG_ADVENTURE_STARTED)) {
|
||||
ctx.showNpcAt(LOCALID_FOOTPRINTS_MAN, 1, 11)
|
||||
} else {
|
||||
ctx.setVar(HoennVars.VAR_OLDALE_TOWN_STATE, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_Girl : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(OldaleTown.SavingMyProgress)
|
||||
@@ -45,7 +65,23 @@ internal object OldaleTown_EventScript_MartEmployee : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object OldaleTown_EventScript_FootprintsMan : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port OldaleTown_EventScript_FootprintsMan")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_ADVENTURE_STARTED)) {
|
||||
ctx.say(OldaleTown.FinishedSketchingFootprints)
|
||||
} else {
|
||||
ctx.say(OldaleTown.DiscoveredFootprints)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_BlockedPath : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_ADVENTURE_STARTED)) return
|
||||
ctx.moveSelf(WALK_RIGHT)
|
||||
ctx.moveNpc(LOCALID_FOOTPRINTS_MAN, WALK_RIGHT)
|
||||
ctx.sayNpc(LOCALID_FOOTPRINTS_MAN, OldaleTown.WaitDontComeInHere)
|
||||
ctx.moveNpc(LOCALID_FOOTPRINTS_MAN, WALK_LEFT)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +96,43 @@ internal object OldaleTown_EventScript_FootprintsMan : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object OldaleTown_EventScript_Rival : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port OldaleTown_EventScript_Rival")
|
||||
override suspend fun run(ctx: ScriptContext) = finishRivalReturn(ctx)
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_RivalTrigger1 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT, WALK_LEFT)
|
||||
finishRivalReturn(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_RivalTrigger2 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_LEFT)
|
||||
finishRivalReturn(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_RivalTrigger3 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = finishRivalReturn(ctx)
|
||||
}
|
||||
|
||||
private suspend fun finishRivalReturn(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_OLDALE_RIVAL_STATE) != 1) return
|
||||
if (ctx.isFemale) ctx.sayNpc(LOCALID_RIVAL, OldaleTown.BrendanLetsGoBack)
|
||||
else ctx.sayNpc(LOCALID_RIVAL, OldaleTown.MayLetsGoBack)
|
||||
ctx.moveNpc(
|
||||
LOCALID_RIVAL,
|
||||
WALK_DOWN,
|
||||
WALK_DOWN,
|
||||
WALK_DOWN,
|
||||
WALK_DOWN,
|
||||
WALK_DOWN,
|
||||
WALK_DOWN,
|
||||
FACE_DOWN,
|
||||
)
|
||||
ctx.setVar(HoennVars.VAR_OLDALE_RIVAL_STATE, 2)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_OLDALE_TOWN_RIVAL)
|
||||
}
|
||||
|
||||
internal object OldaleTown_EventScript_TownSign : Script {
|
||||
@@ -69,9 +141,14 @@ internal object OldaleTown_EventScript_TownSign : Script {
|
||||
|
||||
internal val OldaleTownScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"OldaleTown_OnTransition" to OldaleTown_OnTransition,
|
||||
"OldaleTown_EventScript_Girl" to OldaleTown_EventScript_Girl,
|
||||
"OldaleTown_EventScript_MartEmployee" to OldaleTown_EventScript_MartEmployee,
|
||||
"OldaleTown_EventScript_FootprintsMan" to OldaleTown_EventScript_FootprintsMan,
|
||||
"OldaleTown_EventScript_BlockedPath" to OldaleTown_EventScript_BlockedPath,
|
||||
"OldaleTown_EventScript_Rival" to OldaleTown_EventScript_Rival,
|
||||
"OldaleTown_EventScript_RivalTrigger1" to OldaleTown_EventScript_RivalTrigger1,
|
||||
"OldaleTown_EventScript_RivalTrigger2" to OldaleTown_EventScript_RivalTrigger2,
|
||||
"OldaleTown_EventScript_RivalTrigger3" to OldaleTown_EventScript_RivalTrigger3,
|
||||
"OldaleTown_EventScript_TownSign" to OldaleTown_EventScript_TownSign,
|
||||
)
|
||||
+1
-2
@@ -16,8 +16,7 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object OldaleTown_PokemonCenter_1F_EventScript_Nurse : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port OldaleTown_PokemonCenter_1F_EventScript_Nurse")
|
||||
override suspend fun run(ctx: ScriptContext) = healAtPokemonCenter(ctx)
|
||||
}
|
||||
|
||||
internal object OldaleTown_PokemonCenter_1F_EventScript_Gentleman : Script {
|
||||
|
||||
+76
@@ -1,8 +1,27 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.PetalburgCity
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_GYM_BOY = 7
|
||||
|
||||
internal object PetalburgCity_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.setFlag(HoennFlags.FLAG_VISITED_PETALBURG_CITY)
|
||||
if (ctx.getVar(HoennVars.VAR_PETALBURG_CITY_STATE) == 0) {
|
||||
ctx.showNpcAt(LOCALID_GYM_BOY, 5, 11)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_WallysMom : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(PetalburgCity.WhereIsWally)
|
||||
@@ -56,6 +75,58 @@ internal object PetalburgCity_EventScript_GymBoy : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(PetalburgCity.AreYouRookieTrainer)
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_ShowGymToPlayer0 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = showGymToPlayer(ctx, 0)
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_ShowGymToPlayer1 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = showGymToPlayer(ctx, 1)
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_ShowGymToPlayer2 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = showGymToPlayer(ctx, 2)
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_ShowGymToPlayer3 : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = showGymToPlayer(ctx, 3)
|
||||
}
|
||||
|
||||
private suspend fun showGymToPlayer(ctx: ScriptContext, entranceRow: Int) {
|
||||
val approach =
|
||||
when (entranceRow) {
|
||||
0 -> listOf(WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, FACE_UP)
|
||||
1 -> listOf(WALK_RIGHT, WALK_RIGHT)
|
||||
2 -> listOf(WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, FACE_DOWN)
|
||||
else -> listOf(WALK_DOWN, WALK_RIGHT, WALK_RIGHT, WALK_RIGHT, FACE_DOWN)
|
||||
}
|
||||
ctx.moveNpc(LOCALID_GYM_BOY, *approach.toTypedArray())
|
||||
ctx.sayNpc(LOCALID_GYM_BOY, PetalburgCity.AreYouRookieTrainer)
|
||||
|
||||
val boyToGym =
|
||||
when (entranceRow) {
|
||||
0 -> List(7) { WALK_RIGHT } + listOf(WALK_UP, WALK_RIGHT, FACE_UP)
|
||||
1 ->
|
||||
listOf(WALK_DOWN) +
|
||||
List(8) { WALK_RIGHT } +
|
||||
listOf(WALK_UP, WALK_UP, WALK_RIGHT, FACE_UP)
|
||||
2 -> List(7) { WALK_RIGHT } + listOf(WALK_UP, WALK_RIGHT, FACE_UP)
|
||||
else -> List(7) { WALK_RIGHT } + listOf(WALK_UP, WALK_UP, WALK_RIGHT, FACE_UP)
|
||||
}
|
||||
val playerToGym =
|
||||
when (entranceRow) {
|
||||
0 -> listOf(WALK_DOWN) + List(7) { WALK_RIGHT } + WALK_UP
|
||||
1 -> listOf(WALK_DOWN) + List(7) { WALK_RIGHT } + listOf(WALK_UP, WALK_UP)
|
||||
2 -> listOf(WALK_UP) + List(7) { WALK_RIGHT } + WALK_UP
|
||||
else -> listOf(WALK_UP) + List(7) { WALK_RIGHT } + listOf(WALK_UP, WALK_UP)
|
||||
}
|
||||
// Run Wally and Norman's paths before dialog.
|
||||
ctx.moveNpc(LOCALID_GYM_BOY, *boyToGym.toTypedArray())
|
||||
ctx.moveSelf(*playerToGym.toTypedArray())
|
||||
ctx.sayNpc(LOCALID_GYM_BOY, PetalburgCity.ThisIsPetalburgGym)
|
||||
ctx.sayNpc(LOCALID_GYM_BOY, PetalburgCity.ThisIsGymSign)
|
||||
ctx.moveNpc(LOCALID_GYM_BOY, WALK_DOWN, *Array(11) { WALK_LEFT })
|
||||
}
|
||||
|
||||
internal object PetalburgCity_EventScript_GymSign : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.sign(PetalburgCity.GymSign)
|
||||
}
|
||||
@@ -70,12 +141,17 @@ internal object PetalburgCity_EventScript_WallyHouseSign : Script {
|
||||
|
||||
internal val PetalburgCityScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"PetalburgCity_OnTransition" to PetalburgCity_OnTransition,
|
||||
"PetalburgCity_EventScript_WallysMom" to PetalburgCity_EventScript_WallysMom,
|
||||
"PetalburgCity_EventScript_Boy" to PetalburgCity_EventScript_Boy,
|
||||
"PetalburgCity_EventScript_Gentleman" to PetalburgCity_EventScript_Gentleman,
|
||||
"PetalburgCity_EventScript_ItemMaxRevive" to PetalburgCity_EventScript_ItemMaxRevive,
|
||||
"PetalburgCity_EventScript_ItemEther" to PetalburgCity_EventScript_ItemEther,
|
||||
"PetalburgCity_EventScript_GymBoy" to PetalburgCity_EventScript_GymBoy,
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer0" to PetalburgCity_EventScript_ShowGymToPlayer0,
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer1" to PetalburgCity_EventScript_ShowGymToPlayer1,
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer2" to PetalburgCity_EventScript_ShowGymToPlayer2,
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer3" to PetalburgCity_EventScript_ShowGymToPlayer3,
|
||||
"PetalburgCity_EventScript_GymSign" to PetalburgCity_EventScript_GymSign,
|
||||
"PetalburgCity_EventScript_CitySign" to PetalburgCity_EventScript_CitySign,
|
||||
"PetalburgCity_EventScript_WallyHouseSign" to PetalburgCity_EventScript_WallyHouseSign,
|
||||
|
||||
+63
-1
@@ -1,7 +1,36 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.PetalburgCity_Gym
|
||||
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.Script
|
||||
import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_NORMAN = 0
|
||||
private const val LOCALID_WALLY = 9
|
||||
|
||||
internal object PetalburgCity_Gym_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
val state = ctx.getVar(HoennVars.VAR_PETALBURG_GYM_STATE)
|
||||
if (state < 6) ctx.showNpcAt(LOCALID_NORMAN, 4, 107)
|
||||
if (state == 1) ctx.showNpcAt(LOCALID_WALLY, 5, 108)
|
||||
}
|
||||
}
|
||||
|
||||
internal object PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_PETALBURG_GYM_STATE) != 1) return
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadSoDidItWorkOut)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WallyThankYouBye)
|
||||
ctx.moveNpc(LOCALID_WALLY, WALK_DOWN, WALK_DOWN, WALK_DOWN, SET_INVISIBLE)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_CITY_WALLY)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_GYM_WALLY)
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadGoCollectBadges)
|
||||
ctx.setVar(HoennVars.VAR_PETALBURG_GYM_STATE, 2)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -27,7 +56,37 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object PetalburgCity_Gym_EventScript_Norman : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port PetalburgCity_Gym_EventScript_Norman")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
when (ctx.getVar(HoennVars.VAR_PETALBURG_GYM_STATE)) {
|
||||
0 -> beginWallyTutorial(ctx)
|
||||
1 -> PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial.run(ctx)
|
||||
2 -> ctx.say(PetalburgCity_Gym.NormanGoToRustboro)
|
||||
else -> ctx.say(PetalburgCity_Gym.NormanGoToRustboro)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun beginWallyTutorial(ctx: ScriptContext) {
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadYoureHereWithYourPokemon)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_PETALBURG_GYM_WALLY)
|
||||
ctx.showNpcAt(LOCALID_WALLY, 4, 111)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WallyIdLikeAPokemon)
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadOhYoureWallyRight)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WallyIveNeverCaughtAPokemon)
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadHmISee)
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.DadPlayerGoWithWally)
|
||||
ctx.sayNpc(LOCALID_NORMAN, PetalburgCity_Gym.IllLoanYouMyZigzagoon)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WallyThankYouAndDadGivesPokeBall)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WallyOhWowThankYou)
|
||||
ctx.sayNpc(LOCALID_WALLY, PetalburgCity_Gym.WouldYouReallyComeWithMe)
|
||||
|
||||
// PokeMMO intentionally skips the GBA catching demonstration. Retain its ROM-backed
|
||||
// conversation and advance directly to the post-tutorial state without modifying the party.
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_CITY_WALLYS_MOM)
|
||||
ctx.setVar(HoennVars.VAR_PETALBURG_CITY_STATE, 3)
|
||||
ctx.setVar(HoennVars.VAR_PETALBURG_GYM_STATE, 1)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BIRCHS_LAB_RIVAL)
|
||||
PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial.run(ctx)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -382,6 +441,9 @@ internal object PetalburgCity_Gym_EventScript_RightGymStatue : Script {
|
||||
|
||||
internal val PetalburgCity_GymScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"PetalburgCity_Gym_OnTransition" to PetalburgCity_Gym_OnTransition,
|
||||
"PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial" to
|
||||
PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial,
|
||||
"PetalburgCity_Gym_EventScript_Norman" to PetalburgCity_Gym_EventScript_Norman,
|
||||
"PetalburgCity_Gym_EventScript_Mary" to PetalburgCity_Gym_EventScript_Mary,
|
||||
"PetalburgCity_Gym_EventScript_Randall" to PetalburgCity_Gym_EventScript_Randall,
|
||||
|
||||
+1
-2
@@ -16,8 +16,7 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object PetalburgCity_PokemonCenter_1F_EventScript_Nurse : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port PetalburgCity_PokemonCenter_1F_EventScript_Nurse")
|
||||
override suspend fun run(ctx: ScriptContext) = healAtPokemonCenter(ctx)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+67
@@ -1,8 +1,71 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.PetalburgWoods
|
||||
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
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
|
||||
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.hoenn.HoennFlags
|
||||
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)
|
||||
}
|
||||
|
||||
internal object PetalburgWoods_EventScript_DevonResearcherRight : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = devonResearcherEvent(ctx)
|
||||
}
|
||||
|
||||
private suspend fun devonResearcherEvent(ctx: ScriptContext) {
|
||||
if (ctx.getVar(HoennVars.VAR_PETALBURG_WOODS_STATE) != 0) return
|
||||
ctx.moveNpc(LOCALID_DEVON_RESEARCHER, FACE_UP)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.NotAOneToBeFound)
|
||||
ctx.moveNpc(LOCALID_DEVON_RESEARCHER, WALK_DOWN, WALK_DOWN)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.HaveYouSeenShroomish)
|
||||
ctx.moveNpc(LOCALID_AQUA_GRUNT, WALK_DOWN, WALK_DOWN)
|
||||
ctx.sayNpc(LOCALID_AQUA_GRUNT, PetalburgWoods.IWasGoingToAmbushYou)
|
||||
ctx.moveNpc(LOCALID_AQUA_GRUNT, WALK_DOWN, WALK_DOWN)
|
||||
ctx.sayNpc(LOCALID_AQUA_GRUNT, PetalburgWoods.HandOverThosePapers)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.YouHaveToHelpMe)
|
||||
ctx.moveNpc(LOCALID_AQUA_GRUNT, WALK_DOWN)
|
||||
ctx.sayNpc(LOCALID_AQUA_GRUNT, PetalburgWoods.NoOneCrossesTeamAqua)
|
||||
if (ctx.battle(POOCHYENA, 9, 33, 336, 28) != BattleResult.VICTORY) return
|
||||
ctx.sayNpc(LOCALID_AQUA_GRUNT, PetalburgWoods.YoureKiddingMe)
|
||||
ctx.sayNpc(LOCALID_AQUA_GRUNT, PetalburgWoods.YouveGotSomeNerve)
|
||||
ctx.moveNpc(
|
||||
LOCALID_AQUA_GRUNT,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
SET_INVISIBLE,
|
||||
)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_WOODS_AQUA_GRUNT)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ThatWasAwfullyClose)
|
||||
ctx.giveItem(GREAT_BALL_ITEM)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.TeamAquaAfterSomethingInRustboro)
|
||||
ctx.sayNpc(LOCALID_DEVON_RESEARCHER, PetalburgWoods.ICantBeWastingTime)
|
||||
ctx.moveNpc(
|
||||
LOCALID_DEVON_RESEARCHER,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
WALK_UP,
|
||||
SET_INVISIBLE,
|
||||
)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_PETALBURG_WOODS_DEVON_EMPLOYEE)
|
||||
ctx.setVar(HoennVars.VAR_PETALBURG_WOODS_STATE, 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -140,6 +203,10 @@ internal object PetalburgWoods_EventScript_Sign2 : Script {
|
||||
|
||||
internal val PetalburgWoodsScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"PetalburgWoods_EventScript_DevonResearcherLeft" to
|
||||
PetalburgWoods_EventScript_DevonResearcherLeft,
|
||||
"PetalburgWoods_EventScript_DevonResearcherRight" to
|
||||
PetalburgWoods_EventScript_DevonResearcherRight,
|
||||
"EventScript_CutTree" to EventScript_CutTree,
|
||||
"PetalburgWoods_EventScript_ItemGreatBall" to PetalburgWoods_EventScript_ItemGreatBall,
|
||||
"PetalburgWoods_EventScript_ItemXAttack" to PetalburgWoods_EventScript_ItemXAttack,
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.common.dialog.DialogLine
|
||||
import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
|
||||
/** Shared Emerald nurse text, resolved directly against the configured retail ROM. */
|
||||
private enum class PokemonCenterNurseDialog(override val textId: Int) : DialogLine {
|
||||
WouldYouLikeToRestYourPokemon(0x102726EB),
|
||||
IllTakeYourPokemon(0x10272768),
|
||||
RestoredPokemonToFullHealth(0x10272798),
|
||||
WeHopeToSeeYouAgain(0x10272640),
|
||||
}
|
||||
|
||||
internal suspend fun healAtPokemonCenter(ctx: ScriptContext) {
|
||||
if (!ctx.askYesNo(PokemonCenterNurseDialog.WouldYouLikeToRestYourPokemon)) {
|
||||
ctx.say(PokemonCenterNurseDialog.WeHopeToSeeYouAgain)
|
||||
return
|
||||
}
|
||||
ctx.say(PokemonCenterNurseDialog.IllTakeYourPokemon)
|
||||
ctx.healParty()
|
||||
ctx.say(PokemonCenterNurseDialog.RestoredPokemonToFullHealth)
|
||||
ctx.say(PokemonCenterNurseDialog.WeHopeToSeeYouAgain)
|
||||
}
|
||||
+145
-33
@@ -1,49 +1,155 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.Route101
|
||||
import de.fiereu.openmmo.server.game.battle.BattleResult
|
||||
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.FAST_DOWN
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FAST_LEFT
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FAST_RIGHT
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FAST_UP
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_DOWN
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_IN_PLACE_FAST_LEFT
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.WALK_IN_PLACE_FAST_RIGHT
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_BIRCH = 1
|
||||
private const val LOCALID_ZIGZAGOON = 3
|
||||
|
||||
internal object Route101_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = Unit
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_HideMapNamePopup : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_MAP_NAME_POPUP)
|
||||
ctx.setVar(HoennVars.VAR_ROUTE101_STATE, 1)
|
||||
}
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_StartBirchRescue : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.say(Route101.HelpMe)
|
||||
ctx.repositionNpc(LOCALID_BIRCH, 0, 15)
|
||||
ctx.repositionNpc(LOCALID_ZIGZAGOON, 0, 16)
|
||||
ctx.moveSelfAndNpcs(
|
||||
listOf(FAST_UP, FAST_UP, FAST_UP, FAST_UP, FACE_LEFT),
|
||||
LOCALID_BIRCH to listOf(FAST_RIGHT, FAST_RIGHT, FAST_RIGHT, FAST_RIGHT, FAST_UP, FAST_UP),
|
||||
LOCALID_ZIGZAGOON to
|
||||
listOf(FAST_UP, FAST_RIGHT, FAST_RIGHT, FAST_RIGHT, FAST_RIGHT, FAST_UP),
|
||||
)
|
||||
ctx.moveNpcs(
|
||||
LOCALID_BIRCH to chaseInCircles(initialUpSteps = 2),
|
||||
LOCALID_ZIGZAGOON to chaseInCircles(initialUpSteps = 3, finalLeftSteps = 2),
|
||||
)
|
||||
ctx.moveNpc(LOCALID_BIRCH, FACE_RIGHT)
|
||||
ctx.moveNpcs(
|
||||
LOCALID_ZIGZAGOON to List(4) { WALK_IN_PLACE_FAST_LEFT },
|
||||
LOCALID_BIRCH to List(4) { WALK_IN_PLACE_FAST_RIGHT },
|
||||
)
|
||||
ctx.say(Route101.PleaseHelp)
|
||||
ctx.setVar(HoennVars.VAR_ROUTE101_STATE, 2)
|
||||
}
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_PreventExitSouth : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.say(Route101.DontLeaveMe)
|
||||
ctx.moveSelf(WALK_UP)
|
||||
}
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_PreventExitWest : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.say(Route101.DontLeaveMe)
|
||||
ctx.moveSelf(WALK_RIGHT)
|
||||
}
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_PreventExitNorth : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.say(Route101.DontLeaveMe)
|
||||
ctx.moveSelf(WALK_DOWN)
|
||||
}
|
||||
}
|
||||
|
||||
private fun chaseInCircles(initialUpSteps: Int, finalLeftSteps: Int = 3) = buildList {
|
||||
repeat(initialUpSteps) { add(FAST_UP) }
|
||||
repeat(3) { circuit ->
|
||||
repeat(3) { add(FAST_RIGHT) }
|
||||
repeat(2) { add(FAST_DOWN) }
|
||||
repeat(if (circuit == 2) finalLeftSteps else 3) { add(FAST_LEFT) }
|
||||
if (circuit < 2) repeat(2) { add(FAST_UP) }
|
||||
}
|
||||
}
|
||||
|
||||
internal object Route101_EventScript_Youngster : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(Route101.TakeTiredPokemonToPokeCenter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
* lock
|
||||
* faceplayer
|
||||
* setflag FLAG_SYS_POKEMON_GET
|
||||
* setflag FLAG_RESCUED_BIRCH
|
||||
* fadescreen FADE_TO_BLACK
|
||||
* removeobject LOCALID_ROUTE101_ZIGZAGOON
|
||||
* setobjectxy LOCALID_PLAYER, 6, 13
|
||||
* applymovement LOCALID_PLAYER, Common_Movement_WalkInPlaceFasterLeft
|
||||
* waitmovement 0
|
||||
* special ChooseStarter
|
||||
* applymovement LOCALID_ROUTE101_BIRCH, Route101_Movement_BirchApproachPlayer
|
||||
* waitmovement 0
|
||||
* msgbox Route101_Text_YouSavedMe, MSGBOX_DEFAULT
|
||||
* special HealPlayerParty
|
||||
* setflag FLAG_HIDE_ROUTE_101_BIRCH_ZIGZAGOON_BATTLE
|
||||
* clearflag FLAG_HIDE_LITTLEROOT_TOWN_BIRCHS_LAB_BIRCH
|
||||
* setflag FLAG_HIDE_ROUTE_101_BIRCH_STARTERS_BAG
|
||||
* setvar VAR_BIRCH_LAB_STATE, 2
|
||||
* setvar VAR_ROUTE101_STATE, 3
|
||||
* clearflag FLAG_HIDE_MAP_NAME_POPUP
|
||||
* checkplayergender
|
||||
* call_if_eq VAR_RESULT, MALE, Route101_EventScript_HideMayInBedroom
|
||||
* call_if_eq VAR_RESULT, FEMALE, Route101_EventScript_HideBrendanInBedroom
|
||||
* warp MAP_LITTLEROOT_TOWN_PROFESSOR_BIRCHS_LAB, 6, 5
|
||||
* waitstate
|
||||
* release
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
internal object Route101_EventScript_BirchsBag : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port Route101_EventScript_BirchsBag")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
// Grant the starter before opening battle.
|
||||
if (!ctx.isFlagSet(HoennFlags.FLAG_SYS_POKEMON_GET)) {
|
||||
val starter = ctx.chooseHoennStarter()
|
||||
val starterIndex = STARTERS.indexOf(starter).coerceAtLeast(0)
|
||||
ctx.setVar(HoennVars.VAR_STARTER_MON, starterIndex)
|
||||
val moves = STARTER_MOVES.getValue(starter)
|
||||
checkNotNull(ctx.givePokemon(starter, level = 5, *moves.toIntArray()))
|
||||
ctx.setFlag(HoennFlags.FLAG_SYS_POKEMON_GET)
|
||||
ctx.setFlag(HoennFlags.FLAG_RESCUED_BIRCH)
|
||||
}
|
||||
|
||||
val result = ctx.battle(ZIGZAGOON, 2, 33, 45)
|
||||
if (result != BattleResult.VICTORY) {
|
||||
// Restore the starter after this mandatory battle.
|
||||
ctx.healParty()
|
||||
return
|
||||
}
|
||||
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_ROUTE_101_ZIGZAGOON)
|
||||
ctx.removeNpc(LOCALID_ZIGZAGOON)
|
||||
ctx.repositionSelf(6, 13, Direction.UP)
|
||||
ctx.moveSelfAndNpcs(
|
||||
listOf(FACE_LEFT),
|
||||
LOCALID_BIRCH to listOf(WALK_RIGHT),
|
||||
)
|
||||
ctx.sayNpc(LOCALID_BIRCH, Route101.YouSavedMe)
|
||||
ctx.healParty()
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_ROUTE_101_BIRCH_ZIGZAGOON_BATTLE)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BIRCHS_LAB_BIRCH)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_ROUTE_101_BIRCH_STARTERS_BAG)
|
||||
ctx.setVar(HoennVars.VAR_BIRCH_LAB_STATE, 2)
|
||||
ctx.setVar(HoennVars.VAR_ROUTE101_STATE, 3)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_MAP_NAME_POPUP)
|
||||
if (ctx.isFemale) {
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_RIVAL_BEDROOM)
|
||||
} else {
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_RIVAL_BEDROOM)
|
||||
}
|
||||
ctx.warp(HOENN, LITTLEROOT_INDOOR_BANK, BIRCH_LAB_MAP, 6, 5, Direction.UP)
|
||||
LittlerootTown_ProfessorBirchsLab_EventScript_GiveStarterEvent.run(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
private val STARTERS = listOf(252, 255, 258)
|
||||
private val STARTER_MOVES =
|
||||
mapOf(
|
||||
252 to listOf(1, 43), // Treecko: Pound, Leer
|
||||
255 to listOf(10, 45), // Torchic: Scratch, Growl
|
||||
258 to listOf(33, 45), // Mudkip: Tackle, Growl
|
||||
)
|
||||
private const val ZIGZAGOON = 263
|
||||
private const val HOENN = 1
|
||||
private const val LITTLEROOT_INDOOR_BANK = 51
|
||||
private const val BIRCH_LAB_MAP = 4
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
@@ -68,6 +174,12 @@ internal object Route101_EventScript_RouteSign : Script {
|
||||
|
||||
internal val Route101Scripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"Route101_OnTransition" to Route101_OnTransition,
|
||||
"Route101_EventScript_HideMapNamePopup" to Route101_EventScript_HideMapNamePopup,
|
||||
"Route101_EventScript_StartBirchRescue" to Route101_EventScript_StartBirchRescue,
|
||||
"Route101_EventScript_PreventExitSouth" to Route101_EventScript_PreventExitSouth,
|
||||
"Route101_EventScript_PreventExitWest" to Route101_EventScript_PreventExitWest,
|
||||
"Route101_EventScript_PreventExitNorth" to Route101_EventScript_PreventExitNorth,
|
||||
"Route101_EventScript_Youngster" to Route101_EventScript_Youngster,
|
||||
"Route101_EventScript_BirchsBag" to Route101_EventScript_BirchsBag,
|
||||
"ProfBirch_EventScript_RatePokedexOrRegister" to
|
||||
|
||||
+47
-11
@@ -1,25 +1,61 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.Route103
|
||||
import de.fiereu.openmmo.server.game.battle.BattleResult
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep.FACE_DOWN
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val LOCALID_RIVAL = 1
|
||||
|
||||
internal object Route103_EventScript_Man : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(Route103.ShortcutToOldale)
|
||||
}
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
* ```
|
||||
* lockall
|
||||
* checkplayergender
|
||||
* goto_if_eq VAR_RESULT, MALE, Route103_EventScript_RivalMay
|
||||
* goto_if_eq VAR_RESULT, FEMALE, Route103_EventScript_RivalBrendan
|
||||
* end
|
||||
* ```
|
||||
*/
|
||||
internal object Route103_EventScript_Rival : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port Route103_EventScript_Rival")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_DEFEATED_RIVAL_ROUTE103)) return
|
||||
val femalePlayer = ctx.isFemale
|
||||
if (femalePlayer) {
|
||||
ctx.say(Route103.BrendanRoute103Pokemon)
|
||||
ctx.say(Route103.BrendanLetsBattle)
|
||||
} else {
|
||||
ctx.say(Route103.MayRoute103Pokemon)
|
||||
ctx.say(Route103.MayLetsBattle)
|
||||
}
|
||||
|
||||
val opponent =
|
||||
when (ctx.getVar(HoennVars.VAR_STARTER_MON)) {
|
||||
0 -> 255 // Treecko player -> Torchic rival
|
||||
1 -> 258 // Torchic player -> Mudkip rival
|
||||
else -> 252 // Mudkip player -> Treecko rival
|
||||
}
|
||||
val moves =
|
||||
when (opponent) {
|
||||
252 -> intArrayOf(1, 43)
|
||||
255 -> intArrayOf(10, 45)
|
||||
else -> intArrayOf(33, 45)
|
||||
}
|
||||
if (ctx.battle(opponent, 5, *moves) != BattleResult.VICTORY) return
|
||||
|
||||
if (femalePlayer) {
|
||||
ctx.say(Route103.BrendanDefeated)
|
||||
ctx.say(Route103.BrendanTimeToHeadBack)
|
||||
} else {
|
||||
ctx.say(Route103.MayDefeated)
|
||||
ctx.say(Route103.MayTimeToHeadBack)
|
||||
}
|
||||
ctx.moveNpc(LOCALID_RIVAL, WALK_DOWN, WALK_DOWN, WALK_DOWN, WALK_DOWN, FACE_DOWN)
|
||||
ctx.setFlag(HoennFlags.FLAG_HIDE_ROUTE_103_RIVAL)
|
||||
ctx.setVar(HoennVars.VAR_BIRCH_LAB_STATE, 4)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BIRCHS_LAB_RIVAL)
|
||||
ctx.setFlag(HoennFlags.FLAG_DEFEATED_RIVAL_ROUTE103)
|
||||
ctx.setVar(HoennVars.VAR_OLDALE_RIVAL_STATE, 1)
|
||||
ctx.clearFlag(HoennFlags.FLAG_HIDE_OLDALE_TOWN_RIVAL)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
@@ -3,6 +3,13 @@ package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.RustboroCity
|
||||
import de.fiereu.openmmo.server.game.script.Script
|
||||
import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
|
||||
internal object RustboroCity_OnTransition : Script {
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
ctx.setFlag(HoennFlags.FLAG_VISITED_RUSTBORO_CITY)
|
||||
}
|
||||
}
|
||||
|
||||
internal object RustboroCity_EventScript_Woman : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = ctx.say(RustboroCity.GymLeaderIsntEasyWithFire)
|
||||
@@ -173,6 +180,7 @@ internal object RustboroCity_EventScript_CuttersHouseSign : Script {
|
||||
|
||||
internal val RustboroCityScripts: Map<String, Script> =
|
||||
mapOf(
|
||||
"RustboroCity_OnTransition" to RustboroCity_OnTransition,
|
||||
"RustboroCity_EventScript_Woman" to RustboroCity_EventScript_Woman,
|
||||
"RustboroCity_EventScript_FatMan" to RustboroCity_EventScript_FatMan,
|
||||
"RustboroCity_EventScript_NinjaBoy" to RustboroCity_EventScript_NinjaBoy,
|
||||
|
||||
+54
-6
@@ -1,7 +1,15 @@
|
||||
package de.fiereu.openmmo.server.game.script.generated.hoenn
|
||||
|
||||
import de.fiereu.openmmo.dialog.generated.hoenn.RustboroCity_Gym
|
||||
import de.fiereu.openmmo.server.game.battle.BattleResult
|
||||
import de.fiereu.openmmo.server.game.script.Script
|
||||
import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
|
||||
private const val GEODUDE = 74
|
||||
private const val NOSEPASS = 299
|
||||
private const val TM39_ROCK_TOMB_ITEM = 5327
|
||||
|
||||
/**
|
||||
* Not ported yet. Decomp body:
|
||||
@@ -16,7 +24,38 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object RustboroCity_Gym_EventScript_Roxanne : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port RustboroCity_Gym_EventScript_Roxanne")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_DEFEATED_RUSTBORO_GYM)) {
|
||||
if (!ctx.isFlagSet(HoennFlags.FLAG_RECEIVED_TM_ROCK_TOMB)) giveRockTomb(ctx)
|
||||
else ctx.say(RustboroCity_Gym.RoxannePostBattle)
|
||||
return
|
||||
}
|
||||
ctx.say(RustboroCity_Gym.RoxanneIntro)
|
||||
|
||||
// Trainer switching uses consecutive battle rounds.
|
||||
if (ctx.battle(GEODUDE, 12, 33, 111, 88, 317) != BattleResult.VICTORY) return
|
||||
if (ctx.battle(GEODUDE, 12, 33, 111, 88, 317) != BattleResult.VICTORY) return
|
||||
if (ctx.battle(NOSEPASS, 15, 335, 106, 33, 317) != BattleResult.VICTORY) return
|
||||
|
||||
ctx.say(RustboroCity_Gym.RoxanneDefeat)
|
||||
ctx.say(RustboroCity_Gym.ReceivedStoneBadge)
|
||||
ctx.say(RustboroCity_Gym.StoneBadgeInfoTakeThis)
|
||||
ctx.setFlag(HoennFlags.FLAG_DEFEATED_RUSTBORO_GYM)
|
||||
ctx.setFlag(HoennFlags.FLAG_BADGE01_GET)
|
||||
ctx.setVar(HoennVars.VAR_RUSTBORO_CITY_STATE, 1)
|
||||
ctx.setVar(
|
||||
HoennVars.VAR_PETALBURG_GYM_STATE,
|
||||
ctx.getVar(HoennVars.VAR_PETALBURG_GYM_STATE) + 1,
|
||||
)
|
||||
giveRockTomb(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun giveRockTomb(ctx: ScriptContext) {
|
||||
if (ctx.giveItem(TM39_ROCK_TOMB_ITEM)) {
|
||||
ctx.setFlag(HoennFlags.FLAG_RECEIVED_TM_ROCK_TOMB)
|
||||
ctx.say(RustboroCity_Gym.ExplainRockTomb)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +94,13 @@ internal object RustboroCity_Gym_EventScript_Tommy : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object RustboroCity_Gym_EventScript_GymGuide : Script {
|
||||
override suspend fun run(ctx: ScriptContext) = TODO("port RustboroCity_Gym_EventScript_GymGuide")
|
||||
override suspend fun run(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_DEFEATED_RUSTBORO_GYM)) {
|
||||
ctx.say(RustboroCity_Gym.GymGuidePostVictory)
|
||||
} else {
|
||||
ctx.say(RustboroCity_Gym.GymGuideAdvice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,8 +125,7 @@ internal object RustboroCity_Gym_EventScript_Marc : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object RustboroCity_Gym_EventScript_LeftGymStatue : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port RustboroCity_Gym_EventScript_LeftGymStatue")
|
||||
override suspend fun run(ctx: ScriptContext) = showGymStatue(ctx)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,8 +138,12 @@ internal object RustboroCity_Gym_EventScript_LeftGymStatue : Script {
|
||||
* ```
|
||||
*/
|
||||
internal object RustboroCity_Gym_EventScript_RightGymStatue : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port RustboroCity_Gym_EventScript_RightGymStatue")
|
||||
override suspend fun run(ctx: ScriptContext) = showGymStatue(ctx)
|
||||
}
|
||||
|
||||
private suspend fun showGymStatue(ctx: ScriptContext) {
|
||||
if (ctx.isFlagSet(HoennFlags.FLAG_BADGE01_GET)) ctx.sign(RustboroCity_Gym.GymStatueCertified)
|
||||
else ctx.sign(RustboroCity_Gym.GymStatue)
|
||||
}
|
||||
|
||||
internal val RustboroCity_GymScripts: Map<String, Script> =
|
||||
|
||||
+1
-2
@@ -16,8 +16,7 @@ import de.fiereu.openmmo.server.game.script.ScriptContext
|
||||
* ```
|
||||
*/
|
||||
internal object RustboroCity_PokemonCenter_1F_EventScript_Nurse : Script {
|
||||
override suspend fun run(ctx: ScriptContext) =
|
||||
TODO("port RustboroCity_PokemonCenter_1F_EventScript_Nurse")
|
||||
override suspend fun run(ctx: ScriptContext) = healAtPokemonCenter(ctx)
|
||||
}
|
||||
|
||||
internal object RustboroCity_PokemonCenter_1F_EventScript_Man : Script {
|
||||
|
||||
+85
-17
@@ -5,7 +5,9 @@ import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.common.enums.BattleAction
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessageSendPacket
|
||||
import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket
|
||||
import de.fiereu.openmmo.net.game.packets.SocialListEntryAddPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleActionSelectPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleListEventDetail
|
||||
@@ -15,6 +17,7 @@ import de.fiereu.openmmo.server.game.battle.BattleInstance
|
||||
import de.fiereu.openmmo.server.game.battle.BattleMonState
|
||||
import de.fiereu.openmmo.server.game.battle.BattlePacketEmitter
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRegistry
|
||||
import de.fiereu.openmmo.server.game.battle.BattleResult
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRewards
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRng
|
||||
import de.fiereu.openmmo.server.game.battle.StatCalculator
|
||||
@@ -60,6 +63,7 @@ constructor(
|
||||
private val rewards: BattleRewards,
|
||||
private val interestManager: InterestManager,
|
||||
private val speciesRegistry: SpeciesRegistry,
|
||||
private val moveRegistry: MoveRegistry,
|
||||
) {
|
||||
|
||||
fun onBattlePacket(event: PacketEvent<*>) {
|
||||
@@ -69,6 +73,7 @@ constructor(
|
||||
fun onBattleAction(event: PacketEvent<BattleActionSelectPacket>) {
|
||||
val charId = event.session.attributes[PLAYER_STATE]?.characterId ?: return
|
||||
val battle = battles.byChar(charId) ?: return
|
||||
if (battle.pendingResult != null) return
|
||||
val action = event.packet
|
||||
log.info { "Battle action char=$charId: $action" }
|
||||
// While the active mon is fainted the player owes a replacement and may only switch.
|
||||
@@ -105,41 +110,88 @@ constructor(
|
||||
val charId = session.attributes[PLAYER_STATE]?.characterId ?: return
|
||||
val battle = battles.byChar(charId) ?: return
|
||||
persistParty(battle)
|
||||
finishBattle(battle)
|
||||
finishBattle(battle, BattleResult.DISCONNECTED)
|
||||
}
|
||||
|
||||
/** Resumes scripts after returning to the overworld. */
|
||||
fun onClientReady(event: PacketEvent<MapLoadedAckPacket>) {
|
||||
if (event.packet.data.isNotEmpty()) return
|
||||
val charId = event.session.attributes[PLAYER_STATE]?.characterId ?: return
|
||||
val battle = battles.byChar(charId) ?: return
|
||||
val result = battle.pendingResult ?: return
|
||||
finishBattle(battle, result)
|
||||
}
|
||||
|
||||
/** True while the character has a battle running, so callers can skip starting another. */
|
||||
fun inBattle(charId: Long): Boolean = battles.byChar(charId) != null
|
||||
|
||||
fun startWildBattle(session: SessionContext, dexId: Int, level: Int) {
|
||||
val charId = session.attributes[PLAYER_STATE]?.characterId ?: return
|
||||
createWildBattle(session, dexId, level, catchable = true, escapable = true)
|
||||
}
|
||||
|
||||
/** Runs a story battle and waits for its scene. */
|
||||
suspend fun startScriptedBattle(
|
||||
session: SessionContext,
|
||||
dexId: Int,
|
||||
level: Int,
|
||||
moveIds: List<Int> = emptyList(),
|
||||
): BattleResult {
|
||||
val battle =
|
||||
createWildBattle(
|
||||
session,
|
||||
dexId,
|
||||
level,
|
||||
catchable = false,
|
||||
escapable = false,
|
||||
moveIds = moveIds,
|
||||
) ?: return BattleResult.FAILED
|
||||
return battle.completion.await()
|
||||
}
|
||||
|
||||
private fun createWildBattle(
|
||||
session: SessionContext,
|
||||
dexId: Int,
|
||||
level: Int,
|
||||
catchable: Boolean,
|
||||
escapable: Boolean,
|
||||
moveIds: List<Int> = emptyList(),
|
||||
): BattleInstance? {
|
||||
val charId = session.attributes[PLAYER_STATE]?.characterId ?: return null
|
||||
if (battles.byChar(charId) != null) {
|
||||
session.send(notice("You are already in a battle."))
|
||||
return
|
||||
return null
|
||||
}
|
||||
val stored = characterStore.getCharacter(charId) ?: return
|
||||
val stored = characterStore.getCharacter(charId) ?: return null
|
||||
if (stored.pokemon.isEmpty()) {
|
||||
session.send(notice("You need a monster in your party to battle."))
|
||||
return
|
||||
return null
|
||||
}
|
||||
val party = mutableListOf<BattleMonState>()
|
||||
for ((index, mon) in stored.pokemon.withIndex()) {
|
||||
val def = speciesRegistry.get(mon.dexId)
|
||||
if (def == null) {
|
||||
session.send(notice("Your party has a species the battle data does not cover yet."))
|
||||
return
|
||||
return null
|
||||
}
|
||||
party += BattleMonState(mon.id, def, index, mon, StatCalculator.computeAll(def, mon))
|
||||
}
|
||||
if (party.all { it.fainted }) {
|
||||
session.send(notice("All of your monsters have fainted."))
|
||||
return
|
||||
return null
|
||||
}
|
||||
val rng = BattleRng()
|
||||
val wildPokemon = wildMons.create(dexId, level, rng)
|
||||
var wildPokemon = wildMons.create(dexId, level, rng)
|
||||
if (wildPokemon == null) {
|
||||
session.send(notice("Unknown species $dexId."))
|
||||
return
|
||||
return null
|
||||
}
|
||||
if (moveIds.isNotEmpty()) {
|
||||
wildPokemon =
|
||||
wildPokemon.copy(
|
||||
moves =
|
||||
moveIds.take(4).map { id ->
|
||||
PokemonMove(id.toShort(), (moveRegistry.get(id)?.pp ?: 0).toByte())
|
||||
} + List((4 - moveIds.size).coerceAtLeast(0)) { PokemonMove(0, 0) })
|
||||
}
|
||||
val wildDef = speciesRegistry.get(dexId)!!
|
||||
val wild =
|
||||
@@ -153,13 +205,14 @@ constructor(
|
||||
log.info {
|
||||
"Starting wild battle for char=$charId (${stored.info.name}): ${wildDef.name} level $level"
|
||||
}
|
||||
val battle = battles.create(charId, session, party, wild, rng)
|
||||
val battle = battles.create(charId, session, party, wild, rng, catchable, escapable)
|
||||
val firstAlive = party.indexOfFirst { !it.fainted }
|
||||
battle.activeSlot = firstAlive
|
||||
battle.seenActive.clear()
|
||||
battle.seenActive.add(firstAlive)
|
||||
interestManager.join(session, battle.key)
|
||||
emitter.sendStart(battle, stored.info.name)
|
||||
return battle
|
||||
}
|
||||
|
||||
private fun resolveTurn(battle: BattleInstance, moveId: Short) {
|
||||
@@ -221,12 +274,22 @@ constructor(
|
||||
}
|
||||
|
||||
private fun flee(battle: BattleInstance) {
|
||||
if (!battle.escapable) {
|
||||
emitter.sendNotice(battle, "You can't run from this battle.")
|
||||
emitter.sendPrompt(battle)
|
||||
return
|
||||
}
|
||||
emitter.sendFled(battle)
|
||||
persistParty(battle)
|
||||
finishBattle(battle)
|
||||
battle.pendingResult = BattleResult.FLED
|
||||
}
|
||||
|
||||
private fun catchWild(battle: BattleInstance) {
|
||||
if (!battle.catchable) {
|
||||
emitter.sendNotice(battle, "You can't catch this monster.")
|
||||
emitter.sendPrompt(battle)
|
||||
return
|
||||
}
|
||||
val stored = characterStore.getCharacter(battle.charId) ?: return
|
||||
val nextSlot = ((stored.pokemon.maxOfOrNull { it.containerSlot } ?: -1) + 1).toShort()
|
||||
val caught =
|
||||
@@ -253,7 +316,7 @@ constructor(
|
||||
),
|
||||
)
|
||||
characterStore.addPokemon(battle.charId, caught)
|
||||
endBattle(battle)
|
||||
endBattle(battle, BattleResult.CAUGHT)
|
||||
}
|
||||
|
||||
private fun endVictory(battle: BattleInstance) {
|
||||
@@ -274,19 +337,23 @@ constructor(
|
||||
moves = winner.moves.map { PokemonMove(it.id, it.pp) },
|
||||
),
|
||||
)
|
||||
endBattle(battle, skip = winner.entityId)
|
||||
endBattle(battle, BattleResult.VICTORY, skip = winner.entityId)
|
||||
}
|
||||
|
||||
private fun endDefeat(battle: BattleInstance) {
|
||||
endBattle(battle)
|
||||
endBattle(battle, BattleResult.DEFEAT)
|
||||
}
|
||||
|
||||
// Known issue: the caught monster does not show up in the party until the client reopens it.
|
||||
private fun endBattle(battle: BattleInstance, skip: Long? = null) {
|
||||
private fun endBattle(
|
||||
battle: BattleInstance,
|
||||
result: BattleResult,
|
||||
skip: Long? = null,
|
||||
) {
|
||||
persistParty(battle, skip)
|
||||
val party = characterStore.getCharacter(battle.charId)?.pokemon ?: emptyList()
|
||||
emitter.sendBattleEnd(battle, party)
|
||||
finishBattle(battle)
|
||||
battle.pendingResult = result
|
||||
}
|
||||
|
||||
/** Write the battle's live hp and pp back into the party and flush the character. */
|
||||
@@ -303,8 +370,9 @@ constructor(
|
||||
characterStore.flushCharacterAsync(battle.charId)
|
||||
}
|
||||
|
||||
private fun finishBattle(battle: BattleInstance) {
|
||||
private fun finishBattle(battle: BattleInstance, result: BattleResult) {
|
||||
interestManager.leave(battle.session, battle.key)
|
||||
battles.remove(battle.charId)
|
||||
battle.completion.complete(result)
|
||||
}
|
||||
}
|
||||
+155
-3
@@ -6,7 +6,9 @@ import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
||||
import de.fiereu.openmmo.net.game.packets.DialogStatePacket
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacket
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.DialogMessageArg
|
||||
import de.fiereu.openmmo.server.game.session.PENDING_DIALOG
|
||||
import de.fiereu.openmmo.server.game.session.PENDING_DIALOG_RESPONSE
|
||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
@@ -16,9 +18,74 @@ import kotlinx.coroutines.CompletableDeferred
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
internal val CLOSE_DIALOG_ACTION =
|
||||
DialogActionPacket(
|
||||
flags = 0,
|
||||
actionType = 0x64,
|
||||
textId = 0,
|
||||
entityId = -1,
|
||||
contextValue = 0,
|
||||
messageArgs = emptyList(),
|
||||
detail = ByteArray(0),
|
||||
)
|
||||
|
||||
data class DialogPresentation(
|
||||
val messageArgs: List<DialogMessageArg> = emptyList(),
|
||||
val contextValue: Int = 0,
|
||||
val detail: ByteArray = byteArrayOf(0),
|
||||
)
|
||||
|
||||
@Singleton
|
||||
class DialogService @Inject constructor() {
|
||||
|
||||
/** Emerald starter picker ROM ids. */
|
||||
suspend fun chooseHoennStarter(session: SessionContext, state: PlayerState): Int {
|
||||
while (true) {
|
||||
val choice =
|
||||
showChoiceAndWait(
|
||||
session = session,
|
||||
state = state,
|
||||
textId = HOENN_STARTER_PICK_TEXT,
|
||||
actionType = STARTER_PICK,
|
||||
entityId = NO_ENTITY,
|
||||
contextValue = STARTER_CONTEXT,
|
||||
detail =
|
||||
byteArrayOf(
|
||||
3,
|
||||
(TREECKO and 0xFF).toByte(),
|
||||
(TREECKO shr 8).toByte(),
|
||||
(TORCHIC and 0xFF).toByte(),
|
||||
(TORCHIC shr 8).toByte(),
|
||||
(MUDKIP and 0xFF).toByte(),
|
||||
(MUDKIP shr 8).toByte(),
|
||||
),
|
||||
)
|
||||
.unk
|
||||
if (choice !in 1..3) continue
|
||||
|
||||
val accepted =
|
||||
showChoiceAndWait(
|
||||
session = session,
|
||||
state = state,
|
||||
textId = HOENN_STARTER_CONFIRM_TEXT,
|
||||
actionType = YES_NO,
|
||||
entityId = NO_ENTITY,
|
||||
contextValue = STARTER_CONTEXT,
|
||||
)
|
||||
.unk != 0
|
||||
if (accepted) return listOf(TREECKO, TORCHIC, MUDKIP)[choice - 1]
|
||||
}
|
||||
}
|
||||
|
||||
/** Show a ROM-backed yes/no box and return true for YES. */
|
||||
suspend fun askYesNo(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
textId: Int,
|
||||
entityId: Long,
|
||||
): Boolean =
|
||||
showChoiceAndWait(session, state, textId, YES_NO, entityId, contextValue = 0).unk != 0
|
||||
|
||||
/**
|
||||
* Shows a dialog box and waits for the player to advance or close it. [actionType] is 3 for a
|
||||
* sign and 4 for an npc box, [entityId] is the speaking npc or -1. The flags byte counts up per
|
||||
@@ -30,6 +97,7 @@ class DialogService @Inject constructor() {
|
||||
textId: Int,
|
||||
actionType: Int,
|
||||
entityId: Long,
|
||||
presentation: DialogPresentation = DialogPresentation(),
|
||||
) {
|
||||
val advance = CompletableDeferred<Unit>()
|
||||
session.attributes[PENDING_DIALOG] = advance
|
||||
@@ -46,16 +114,52 @@ class DialogService @Inject constructor() {
|
||||
actionType = actionType.toByte(),
|
||||
textId = textId,
|
||||
entityId = entityId,
|
||||
contextValue = 0,
|
||||
messageArgs = emptyList(),
|
||||
detail = byteArrayOf(0),
|
||||
contextValue = presentation.contextValue,
|
||||
messageArgs = presentation.messageArgs,
|
||||
detail = presentation.detail,
|
||||
))
|
||||
advance.await()
|
||||
}
|
||||
|
||||
/** Show a scene page and wait for the client's 0x21 acknowledgement. */
|
||||
suspend fun showScenePageAndWait(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
textId: Int,
|
||||
actionType: Int,
|
||||
contextValue: Int,
|
||||
messageArgs: List<DialogMessageArg>,
|
||||
) =
|
||||
showAndWait(
|
||||
session,
|
||||
state,
|
||||
textId,
|
||||
actionType,
|
||||
NO_ENTITY,
|
||||
DialogPresentation(messageArgs, contextValue, ByteArray(0)),
|
||||
)
|
||||
|
||||
/** Show a scene menu and return its 1-based choice. */
|
||||
suspend fun showSceneMenuAndWait(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
detail: ByteArray,
|
||||
): Int =
|
||||
showChoiceAndWait(
|
||||
session,
|
||||
state,
|
||||
textId = 0,
|
||||
actionType = STARTER_PICK,
|
||||
entityId = NO_ENTITY,
|
||||
contextValue = 0,
|
||||
detail = detail,
|
||||
)
|
||||
.unk
|
||||
|
||||
/** Closes the dialog once a script has shown its last box. */
|
||||
fun close(session: SessionContext, state: PlayerState) {
|
||||
session.attributes.remove(PENDING_DIALOG)
|
||||
session.attributes.remove(PENDING_DIALOG_RESPONSE)
|
||||
if (state.inDialog) {
|
||||
session.send(DialogStatePacket(false))
|
||||
state.inDialog = false
|
||||
@@ -65,6 +169,11 @@ class DialogService @Inject constructor() {
|
||||
|
||||
fun onInteractive(event: PacketEvent<DialogActionResponsePacket>) {
|
||||
val session = event.session
|
||||
val response = session.attributes.remove(PENDING_DIALOG_RESPONSE)
|
||||
if (response != null) {
|
||||
response.complete(event.packet)
|
||||
return
|
||||
}
|
||||
val advance = session.attributes.remove(PENDING_DIALOG)
|
||||
log.debug { "Dialog response id=${event.packet.id} advancing=${advance != null}" }
|
||||
if (advance != null) {
|
||||
@@ -96,4 +205,47 @@ class DialogService @Inject constructor() {
|
||||
state.dialogNpcEntityId = 0
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun showChoiceAndWait(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
textId: Int,
|
||||
actionType: Int,
|
||||
entityId: Long,
|
||||
contextValue: Int,
|
||||
detail: ByteArray = byteArrayOf(0),
|
||||
): DialogActionResponsePacket {
|
||||
val response = CompletableDeferred<DialogActionResponsePacket>()
|
||||
session.attributes[PENDING_DIALOG_RESPONSE] = response
|
||||
val seq = state.dialogSeqId
|
||||
state.dialogSeqId = seq + 1
|
||||
state.inDialog = true
|
||||
state.dialogNpcEntityId = entityId
|
||||
session.send(
|
||||
DialogActionPacket(
|
||||
flags = seq.toByte(),
|
||||
actionType = actionType.toByte(),
|
||||
textId = textId,
|
||||
entityId = entityId,
|
||||
contextValue = contextValue,
|
||||
messageArgs = emptyList(),
|
||||
detail = detail,
|
||||
))
|
||||
return response.await()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val NO_ENTITY = -1L
|
||||
const val YES_NO = 0x05
|
||||
const val STARTER_PICK = 0x23
|
||||
const val STARTER_CONTEXT = 700
|
||||
|
||||
const val TREECKO = 252
|
||||
const val TORCHIC = 255
|
||||
const val MUDKIP = 258
|
||||
|
||||
// Verified against the captured Emerald dialog database.
|
||||
const val HOENN_STARTER_PICK_TEXT = 0x105E8C53
|
||||
const val HOENN_STARTER_CONFIRM_TEXT = 0x105E8C90
|
||||
}
|
||||
}
|
||||
+54
-28
@@ -3,9 +3,11 @@ package de.fiereu.openmmo.server.game.services
|
||||
import de.fiereu.network.PacketEvent
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.CharacterInfo
|
||||
import de.fiereu.openmmo.common.enums.CharacterGender
|
||||
import de.fiereu.openmmo.common.enums.ChatType
|
||||
import de.fiereu.openmmo.common.enums.Language
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.common.utils.hexToBytes
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.codecs.SkinSet
|
||||
@@ -13,6 +15,8 @@ import de.fiereu.openmmo.net.game.packets.CharacterEntry
|
||||
import de.fiereu.openmmo.net.game.packets.CharactersListPacket
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||
import de.fiereu.openmmo.net.game.packets.CreateCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterResultPacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinResponsePacket
|
||||
import de.fiereu.openmmo.net.game.packets.LocalPlayerStatePacket
|
||||
@@ -30,12 +34,11 @@ import de.fiereu.openmmo.net.game.packets.ViewScalePacket
|
||||
import de.fiereu.openmmo.net.game.packets.WorldFlagTableResetPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleRatingBulkPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleStateBytePacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.ItemStack
|
||||
import de.fiereu.openmmo.net.game.packets.battle.itemStacksPacket
|
||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.session.SessionRegistry
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import de.fiereu.openmmo.server.game.storage.StoredCharacter
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.time.LocalDateTime
|
||||
import javax.inject.Inject
|
||||
@@ -55,11 +58,8 @@ private val WORLD_FLAG_GROUPS =
|
||||
)
|
||||
.map(String::hexToBytes)
|
||||
|
||||
private const val POKE_BALL_ITEM_ID: Short = 5004
|
||||
private const val POKE_BALL_OBJECT_ID = 0x0000000000015000L
|
||||
private const val POKE_BALL_QUANTITY: Short = 10
|
||||
private val STARTING_BAG =
|
||||
listOf(ItemStack(POKE_BALL_OBJECT_ID, POKE_BALL_ITEM_ID, POKE_BALL_QUANTITY))
|
||||
private const val DELETE_SUCCESS = 0
|
||||
private const val DELETE_REJECTED = 1
|
||||
|
||||
@Singleton
|
||||
class LoginService
|
||||
@@ -111,7 +111,17 @@ constructor(
|
||||
return
|
||||
}
|
||||
log.info { "Creating character '$name' for userId=${state.userId}" }
|
||||
characterStore.createCharacter(state.userId, name)
|
||||
val gender = CharacterGender.byWireValue(event.packet.gender)
|
||||
val startingRegion = Region.byWireValue(event.packet.startingRegion)
|
||||
if (gender == null || startingRegion == null) {
|
||||
log.warn {
|
||||
"Rejected character options gender=${event.packet.gender} " +
|
||||
"region=${event.packet.startingRegion} for userId=${state.userId}"
|
||||
}
|
||||
ctx.send(buildCharacterList(state.userId))
|
||||
return
|
||||
}
|
||||
characterStore.createCharacter(state.userId, name, gender, startingRegion)
|
||||
ctx.send(buildCharacterList(state.userId))
|
||||
}
|
||||
|
||||
@@ -126,6 +136,24 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun onDeleteCharacter(event: PacketEvent<DeleteCharacterPacket>) {
|
||||
val ctx = event.session
|
||||
val state = ctx.attributes[PLAYER_STATE]
|
||||
val userId = state?.userId
|
||||
val characterId = event.packet.characterId
|
||||
val deleted =
|
||||
userId != null &&
|
||||
state.characterId == null &&
|
||||
characterStore.deleteCharacter(userId, characterId)
|
||||
if (deleted) {
|
||||
log.info { "Deleted character $characterId for userId=$userId" }
|
||||
} else {
|
||||
log.warn { "Rejected character deletion id=$characterId from ${ctx.remoteAddress}" }
|
||||
}
|
||||
ctx.send(
|
||||
DeleteCharacterResultPacket(if (deleted) DELETE_SUCCESS else DELETE_REJECTED, characterId))
|
||||
}
|
||||
|
||||
private suspend fun buildCharacterList(userId: Int): CharactersListPacket {
|
||||
val characters = characterStore.getCharactersByUser(userId)
|
||||
val entries =
|
||||
@@ -134,7 +162,7 @@ constructor(
|
||||
characterInfo = stored.info,
|
||||
skinSet = SkinSet(),
|
||||
guildId = null,
|
||||
// Show the whole party. A party over 6 is an illegal state and CharacterEntry rejects it.
|
||||
// Character selection shows the complete party.
|
||||
pokemon = stored.pokemon,
|
||||
)
|
||||
}
|
||||
@@ -161,8 +189,10 @@ constructor(
|
||||
|
||||
// Initialise the client world-flag table before any monster or follower is built. Without it
|
||||
// the table stays null and the client crashes constructing a party monster that reads a flag.
|
||||
// Restore persisted story state after resetting client flags.
|
||||
ctx.send(WorldFlagTableResetPacket(WORLD_FLAG_GROUPS))
|
||||
ctx.send(buildLocalPlayerState(stored.info, stored.pokemon.map { it.dexId.toShort() }))
|
||||
ctx.send(buildLocalPlayerState(stored))
|
||||
StoryClientState.flags(stored.info.positionRegionId, stored.storyFlags).forEach { ctx.send(it) }
|
||||
|
||||
val info = stored.info
|
||||
val now = LocalDateTime.now()
|
||||
@@ -199,7 +229,7 @@ constructor(
|
||||
|
||||
// The bag item stacks (opcode 0x40). The real server sends these during join, interleaved with
|
||||
// the container packets, so the client has the items before entering the world.
|
||||
ctx.send(itemStacksPacket(STARTING_BAG))
|
||||
ctx.send(storyItemStacksPacket(stored.items))
|
||||
|
||||
ctx.send(SelectedCharacterPacket(info))
|
||||
sendJoinState(ctx)
|
||||
@@ -214,22 +244,12 @@ constructor(
|
||||
preloadMapAndJoin(ctx, state, info)
|
||||
}
|
||||
|
||||
// TODO Sync persisted story flags and vars to the client
|
||||
// The server now owns per character story flags and vars (see StoryService), but the client
|
||||
// still
|
||||
// gets the hardcoded WORLD_FLAG_GROUPS blob and empty badges/variables below. Map the stored
|
||||
// flags into the world-flag table and the stored vars into LocalPlayerStatePacket.variables so
|
||||
// the
|
||||
// overworld (hidden or shown npcs, map states, badges) reflects real progress. This needs the
|
||||
// GBA
|
||||
// numeric flag/var ids, so extend the story codegen to also emit the name to id map per region.
|
||||
// The full local-player state snapshot the client loads on login. Missing it leaves player state
|
||||
// uninitialised and the client crashes reading it (for example when opening the battle bag).
|
||||
private fun buildLocalPlayerState(
|
||||
info: CharacterInfo,
|
||||
partyDex: List<Short>
|
||||
): LocalPlayerStatePacket =
|
||||
LocalPlayerStatePacket(
|
||||
private fun buildLocalPlayerState(stored: StoredCharacter): LocalPlayerStatePacket {
|
||||
val info = stored.info
|
||||
val partyDex = stored.pokemon.map { it.dexId.toShort() }
|
||||
return LocalPlayerStatePacket(
|
||||
region = info.positionRegionId,
|
||||
mapId = info.positionMapId.toShort(),
|
||||
moveSpeed = 0.05f,
|
||||
@@ -237,7 +257,7 @@ constructor(
|
||||
y = info.positionY,
|
||||
z = 0,
|
||||
money = info.money,
|
||||
gender = 0,
|
||||
gender = info.rivalSex,
|
||||
skinTone = 0,
|
||||
hairColor = 0,
|
||||
playtime = 0.0,
|
||||
@@ -247,8 +267,9 @@ constructor(
|
||||
pokedexSeen = emptyList(),
|
||||
pokedexCaught = emptyList(),
|
||||
badges = emptyList(),
|
||||
variables = emptyList(),
|
||||
variables = StoryClientState.variables(info.positionRegionId, stored.storyVars),
|
||||
)
|
||||
}
|
||||
|
||||
// Small state packets the real server sends in the join flow. The battle-state byte and menu
|
||||
// payloads initialise state the battle bag reads, so without them opening the bag crashes.
|
||||
@@ -316,7 +337,12 @@ constructor(
|
||||
val loadEntity = mapLoadService.createLoadEntity(info, facing, party = stored.pokemon)
|
||||
ctx.send(loadEntity)
|
||||
|
||||
npcService.spawnNpcsForMap(ctx, info.positionBankId.toInt(), info.positionMapId.toInt())
|
||||
npcService.spawnNpcsForMap(
|
||||
ctx,
|
||||
info.positionBankId.toInt(),
|
||||
info.positionMapId.toInt(),
|
||||
info.positionRegionId.toInt(),
|
||||
)
|
||||
|
||||
val bankId = info.positionBankId.toInt()
|
||||
val mapId = info.positionMapId.toInt()
|
||||
|
||||
+36
-2
@@ -30,7 +30,7 @@ constructor(
|
||||
if (state.inDialog) return
|
||||
val charId = state.characterId
|
||||
// The on-transition script runs on every entry, then the one on-frame script whose var matches.
|
||||
val scripts = buildList {
|
||||
val entryScripts = buildList {
|
||||
resolve(map.onTransitionScript)?.let { add(it) }
|
||||
if (charId != null) {
|
||||
map.onFrameScripts
|
||||
@@ -39,7 +39,41 @@ constructor(
|
||||
?.let { add(it) }
|
||||
}
|
||||
}
|
||||
if (scripts.isNotEmpty()) scriptRunner.runAll(session, state, scripts, entityId = -1)
|
||||
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.
|
||||
val entrySequence = Script { ctx ->
|
||||
entryScripts.forEach { it.run(ctx) }
|
||||
if (charId != null) {
|
||||
matchingCoordScript(map, charId, state.x.toInt(), state.y.toInt())?.run(ctx)
|
||||
}
|
||||
}
|
||||
scriptRunner.run(session, state, entrySequence, entityId = -1)
|
||||
}
|
||||
|
||||
/** Run the matching conditional coordinate script after a completed player step. */
|
||||
fun onStep(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
map: MapDef,
|
||||
x: Int,
|
||||
y: Int,
|
||||
): Boolean {
|
||||
if (state.inDialog) return false
|
||||
val charId = state.characterId ?: return false
|
||||
val script = matchingCoordScript(map, charId, x, y) ?: return false
|
||||
scriptRunner.run(session, state, script, entityId = -1)
|
||||
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? {
|
||||
|
||||
+105
-34
@@ -3,12 +3,13 @@ package de.fiereu.openmmo.server.game.services
|
||||
import de.fiereu.network.PacketEvent
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.common.enums.TileBehavior
|
||||
import de.fiereu.openmmo.maps.MapDef
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.maps.WarpTile
|
||||
import de.fiereu.openmmo.net.game.packets.EntityFaceTurnPacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityMovePacket
|
||||
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
||||
import de.fiereu.openmmo.net.game.packets.GbaEntityMovePacket
|
||||
import de.fiereu.openmmo.net.game.packets.MapData
|
||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||
@@ -20,6 +21,33 @@ import javax.inject.Singleton
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
/** Resolve a cardinal Gen-3 ledge hop to its tile two spaces away. */
|
||||
internal fun ledgeLanding(
|
||||
map: MapDef,
|
||||
fromX: Int,
|
||||
fromY: Int,
|
||||
direction: Direction,
|
||||
): Pair<Int, Int>? {
|
||||
val expectedBehavior =
|
||||
when (direction) {
|
||||
Direction.DOWN -> TileBehavior.JUMP_SOUTH
|
||||
Direction.UP -> TileBehavior.JUMP_NORTH
|
||||
Direction.LEFT -> TileBehavior.JUMP_WEST
|
||||
Direction.RIGHT -> TileBehavior.JUMP_EAST
|
||||
Direction.DIVE,
|
||||
Direction.EMERGE -> return null
|
||||
}
|
||||
val ledgeX = fromX + direction.dx
|
||||
val ledgeY = fromY + direction.dy
|
||||
if (map.tileAt(ledgeX, ledgeY)?.behavior != expectedBehavior) return null
|
||||
|
||||
val landingX = fromX + direction.dx * 2
|
||||
val landingY = fromY + direction.dy * 2
|
||||
if (landingX !in 0 until map.width || landingY !in 0 until map.height) return null
|
||||
if (map.tileAt(landingX, landingY)?.blocksMovement() == true) return null
|
||||
return landingX to landingY
|
||||
}
|
||||
|
||||
@Singleton
|
||||
class MovementService
|
||||
@Inject
|
||||
@@ -44,32 +72,58 @@ constructor(
|
||||
log.debug { "Movement: char=$charId from (${msg.x}, ${msg.y}) dir=${msg.direction}" }
|
||||
|
||||
val stored = characterStore.getCharacter(charId) ?: return
|
||||
val fromX = stored.info.positionX.toInt()
|
||||
val fromY = stored.info.positionY.toInt()
|
||||
val atServerTile = msg.x == fromX && msg.y == fromY
|
||||
|
||||
if (state.justWarped) {
|
||||
// Ignore steps until the client reports the warp destination, so a packet still in flight
|
||||
// from the old map is dropped rather than applied against the new one.
|
||||
if (!atServerTile) return
|
||||
state.justWarped = false
|
||||
} else if (!atServerTile) {
|
||||
log.debug {
|
||||
"DESYNC: char=$charId claims (${msg.x}, ${msg.y}), server has ($fromX, $fromY), resetting"
|
||||
}
|
||||
sendPositionReset(ctx, charId, fromX, fromY, state.facingDirection)
|
||||
return
|
||||
}
|
||||
|
||||
val currentMap =
|
||||
mapManager.getMap(
|
||||
stored.info.positionRegionId,
|
||||
stored.info.positionBankId,
|
||||
stored.info.positionMapId,
|
||||
) ?: return
|
||||
var fromX = stored.info.positionX.toInt()
|
||||
var fromY = stored.info.positionY.toInt()
|
||||
if (state.acceptNextMoveSource &&
|
||||
msg.x in 0 until currentMap.width &&
|
||||
msg.y in 0 until currentMap.height) {
|
||||
// Trust the client after scripted movement.
|
||||
fromX = msg.x
|
||||
fromY = msg.y
|
||||
characterStore.updatePosition(charId, fromX.toShort(), fromY.toShort())
|
||||
state.x = fromX.toShort()
|
||||
state.y = fromY.toShort()
|
||||
state.acceptNextMoveSource = false
|
||||
}
|
||||
|
||||
val toX = fromX + msg.direction.dx
|
||||
val toY = fromY + msg.direction.dy
|
||||
val atServerTile = msg.x == fromX && msg.y == fromY
|
||||
|
||||
if (state.justWarped) {
|
||||
// Drop movement packets sent before the warp completed.
|
||||
if (!atServerTile) return
|
||||
state.justWarped = false
|
||||
} else if (!atServerTile) {
|
||||
log.debug {
|
||||
"DESYNC: char=$charId claims (${msg.x}, ${msg.y}), server has ($fromX, $fromY), resetting"
|
||||
}
|
||||
sendPositionReset(ctx, charId, currentMap, fromX, fromY, state.facingDirection)
|
||||
return
|
||||
}
|
||||
|
||||
var toX = fromX + msg.direction.dx
|
||||
var toY = fromY + msg.direction.dy
|
||||
|
||||
// Ledge hops land two tiles away.
|
||||
ledgeLanding(currentMap, fromX, fromY, msg.direction)?.let { landing ->
|
||||
toX = landing.first
|
||||
toY = landing.second
|
||||
}
|
||||
|
||||
// Some warps trigger from their current tile.
|
||||
val onTileWarp =
|
||||
currentMap.warps.find { w ->
|
||||
w.x == fromX && w.y == fromY && w.facingDirection == msg.direction
|
||||
}
|
||||
if (onTileWarp != null) {
|
||||
warpService.executeWarp(ctx, charId, onTileWarp)
|
||||
return
|
||||
}
|
||||
|
||||
// Walking off the edge of a map hands the player to the neighbouring map, if there is one.
|
||||
if (toX !in 0 until currentMap.width || toY !in 0 until currentMap.height) {
|
||||
@@ -77,7 +131,7 @@ constructor(
|
||||
val targetMap =
|
||||
connection?.let { mapManager.getMap(1, it.targetBank.toByte(), it.targetMap.toByte()) }
|
||||
if (connection == null || targetMap == null) {
|
||||
sendPositionReset(ctx, charId, fromX, fromY, msg.direction)
|
||||
sendPositionReset(ctx, charId, currentMap, fromX, fromY, msg.direction)
|
||||
return
|
||||
}
|
||||
val entryX =
|
||||
@@ -96,7 +150,7 @@ constructor(
|
||||
return
|
||||
}
|
||||
|
||||
// A warp fires on the tile the player steps onto, not the one it left.
|
||||
// Warps fire on the destination tile.
|
||||
val warp =
|
||||
currentMap.warps.find { w ->
|
||||
w.x == toX &&
|
||||
@@ -106,14 +160,16 @@ constructor(
|
||||
if (warp != null) {
|
||||
log.info { "WARP at ($toX, $toY) facing ${msg.direction}" }
|
||||
// A MAP_DYNAMIC warp (the truck exit) resolves to the destination a script set on the player.
|
||||
val resolved = if (warp.dynamic) resolveDynamicWarp(stored) else warp
|
||||
val resolved =
|
||||
if (warp.dynamic) resolveDynamicWarp(characterStore.getCharacter(charId) ?: stored)
|
||||
else warp
|
||||
if (resolved != null) warpService.executeWarp(ctx, charId, resolved)
|
||||
return
|
||||
}
|
||||
|
||||
if (!isWalkable(currentMap, toX, toY)) {
|
||||
log.debug { "WALL: char=$charId blocked at ($toX, $toY)" }
|
||||
sendPositionReset(ctx, charId, fromX, fromY, msg.direction)
|
||||
sendPositionReset(ctx, charId, currentMap, fromX, fromY, msg.direction)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -124,11 +180,14 @@ constructor(
|
||||
// The client already walked itself there, so only the observers need telling.
|
||||
presenceService.broadcastToObservers(
|
||||
ctx,
|
||||
EntityMovePacket(entityId = charId, x = toX, y = toY, direction = msg.direction),
|
||||
gbaMovePacket(charId, currentMap, toX, toY, msg.direction),
|
||||
)
|
||||
|
||||
// Story coordinate events take precedence over random encounters on the same step.
|
||||
if (!mapScriptService.onStep(ctx, state, currentMap, toX, toY)) {
|
||||
encounterService.onStep(ctx, charId, currentMap, toX, toY)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the real warp for a MAP_DYNAMIC tile from the destination a script set on the player.
|
||||
@@ -155,13 +214,31 @@ constructor(
|
||||
private fun sendPositionReset(
|
||||
ctx: SessionContext,
|
||||
charId: Long,
|
||||
map: MapDef,
|
||||
x: Int,
|
||||
y: Int,
|
||||
direction: Direction,
|
||||
) {
|
||||
ctx.send(EntityMovePacket(entityId = charId, x = x, y = y, direction = direction))
|
||||
ctx.send(gbaMovePacket(charId, map, x, y, direction))
|
||||
}
|
||||
|
||||
private fun gbaMovePacket(
|
||||
charId: Long,
|
||||
map: MapDef,
|
||||
x: Int,
|
||||
y: Int,
|
||||
direction: Direction,
|
||||
): GbaEntityMovePacket =
|
||||
GbaEntityMovePacket(
|
||||
entityId = charId,
|
||||
bankId = map.bankId.toInt() and 0xff,
|
||||
mapId = map.mapId.toInt() and 0xff,
|
||||
x = x,
|
||||
y = y,
|
||||
movementMode = 2,
|
||||
direction = direction,
|
||||
)
|
||||
|
||||
/** Turning in place. Only observers need it, the client has already turned itself. */
|
||||
fun onFaceDirection(event: PacketEvent<FaceDirectionPacket>) {
|
||||
val ctx = event.session
|
||||
@@ -212,15 +289,9 @@ constructor(
|
||||
presenceService.refresh(ctx)
|
||||
|
||||
mapLoadService.preloadConnectedMaps(ctx, map, depth = 1)
|
||||
npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt())
|
||||
npcService.spawnNpcsForMap(ctx, targetBank.toInt(), targetMap.toInt(), state?.regionId ?: 1)
|
||||
|
||||
ctx.send(
|
||||
EntityMovePacket(
|
||||
entityId = charId,
|
||||
x = targetX.toInt(),
|
||||
y = targetY.toInt(),
|
||||
direction = direction,
|
||||
))
|
||||
ctx.send(gbaMovePacket(charId, map, targetX.toInt(), targetY.toInt(), direction))
|
||||
|
||||
if (state != null) mapScriptService.onMapEnter(ctx, state, map)
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.common.enums.MovementType
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.maps.NpcDef
|
||||
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcSpawnPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcUpdatePacket
|
||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import javax.inject.Inject
|
||||
@@ -17,6 +23,7 @@ class NpcService
|
||||
@Inject
|
||||
constructor(
|
||||
private val mapManager: MapManager,
|
||||
private val characterStore: CharacterStore,
|
||||
) {
|
||||
|
||||
private val npcEntityIdCounter = AtomicLong(0x1A69000000000000L)
|
||||
@@ -26,10 +33,14 @@ constructor(
|
||||
return npcEntityIds["$bankId:$mapId:$entityIdx"]
|
||||
}
|
||||
|
||||
fun spawnNpcsForMap(ctx: SessionContext, bankId: Int, mapId: Int) {
|
||||
val map = mapManager.getMap(1, bankId, mapId) ?: return
|
||||
fun spawnNpcsForMap(ctx: SessionContext, bankId: Int, mapId: Int, regionId: Int = 1) {
|
||||
val map = mapManager.getMap(regionId, bankId, mapId) ?: return
|
||||
val stored = ctx.attributes[PLAYER_STATE]?.characterId?.let(characterStore::getCharacter)
|
||||
val storyFlags = stored?.storyFlags.orEmpty()
|
||||
val storyVars = stored?.storyVars.orEmpty()
|
||||
|
||||
if (bankId == 74 && mapId == 11) {
|
||||
// Generated Petalburg data now supplies these NPCs.
|
||||
if (regionId == 1 && USE_LEGACY_PETALBURG_SPAWNS && bankId == 74 && mapId == 11) {
|
||||
data class NpcEntry(
|
||||
val entityIdx: Int,
|
||||
val x: Int,
|
||||
@@ -88,9 +99,15 @@ constructor(
|
||||
}
|
||||
|
||||
for (npc in map.npcs) {
|
||||
// Npcs hidden by a story flag stay out of the world until a script shows them.
|
||||
if (npc.hideFlag.isNotEmpty()) continue
|
||||
ctx.send(buildSpawnPacket(npc, entityIdFor(bankId, mapId, npc.entityIdx), bankId, mapId))
|
||||
// Decoration slots are not normal NPCs.
|
||||
if (npc.hideFlag.substringAfter('/').startsWith(DECORATION_FLAG_PREFIX)) continue
|
||||
|
||||
// Only set hide flags suppress NPCs.
|
||||
if (shouldHideNpc(bankId, mapId, npc, storyFlags)) continue
|
||||
val resolved =
|
||||
resolveDynamicGraphics(
|
||||
ctx, applyStoryPlacement(bankId, mapId, npc, storyFlags, storyVars))
|
||||
ctx.send(buildSpawnPacket(resolved, entityIdFor(bankId, mapId, npc.entityIdx), bankId, mapId))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +122,70 @@ constructor(
|
||||
log.warn { "spawnNpc: npc $localId not found on $bankId:$mapId" }
|
||||
return
|
||||
}
|
||||
ctx.send(buildSpawnPacket(npc, entityIdFor(bankId, mapId, localId), bankId, mapId))
|
||||
ctx.send(
|
||||
buildSpawnPacket(
|
||||
resolveDynamicGraphics(ctx, npc),
|
||||
entityIdFor(bankId, mapId, localId),
|
||||
bankId,
|
||||
mapId,
|
||||
))
|
||||
}
|
||||
|
||||
/** Spawns an NPC at a cutscene position. */
|
||||
fun spawnNpcAt(
|
||||
ctx: SessionContext,
|
||||
bankId: Int,
|
||||
mapId: Int,
|
||||
localId: Int,
|
||||
x: Int,
|
||||
y: Int,
|
||||
) {
|
||||
val npc = mapManager.getMap(1, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId }
|
||||
if (npc == null) {
|
||||
log.warn { "spawnNpcAt: npc $localId not found on $bankId:$mapId" }
|
||||
return
|
||||
}
|
||||
ctx.send(
|
||||
buildSpawnPacket(
|
||||
resolveDynamicGraphics(ctx, npc.copy(x = x, y = y)),
|
||||
entityIdFor(bankId, mapId, localId),
|
||||
bankId,
|
||||
mapId,
|
||||
))
|
||||
}
|
||||
|
||||
/** Repositions an existing NPC. */
|
||||
fun repositionNpc(
|
||||
ctx: SessionContext,
|
||||
bankId: Int,
|
||||
mapId: Int,
|
||||
localId: Int,
|
||||
x: Int,
|
||||
y: Int,
|
||||
) {
|
||||
val npc = mapManager.getMap(1, bankId, mapId)?.npcs?.firstOrNull { it.entityIdx == localId }
|
||||
if (npc == null) {
|
||||
log.warn { "repositionNpc: npc $localId not found on $bankId:$mapId" }
|
||||
return
|
||||
}
|
||||
ctx.send(
|
||||
NpcUpdatePacket(
|
||||
entityId = entityIdFor(bankId, mapId, localId),
|
||||
regionId = 1,
|
||||
bankId = bankId,
|
||||
mapId = mapId,
|
||||
x = x,
|
||||
y = y,
|
||||
// Captures use 0xF6 followed by the direction for this update packet.
|
||||
facing = 0xF6,
|
||||
unk = npc.facing.ordinal,
|
||||
))
|
||||
}
|
||||
|
||||
/** Removes a cutscene NPC. */
|
||||
fun despawnNpc(ctx: SessionContext, bankId: Int, mapId: Int, localId: Int) {
|
||||
val entityId = getNpcEntityId(bankId, mapId, localId) ?: return
|
||||
ctx.send(EntityLeavePacket(entityId))
|
||||
}
|
||||
|
||||
private fun buildSpawnPacket(
|
||||
@@ -138,4 +218,69 @@ constructor(
|
||||
unk6 = 8,
|
||||
)
|
||||
}
|
||||
|
||||
private fun resolveDynamicGraphics(ctx: SessionContext, npc: NpcDef): NpcDef {
|
||||
if (npc.graphicsId != DYNAMIC_GFX_VAR_0 ||
|
||||
!(npc.script.contains("Rival", ignoreCase = true) ||
|
||||
npc.hideFlag.contains("RIVAL", ignoreCase = true))) {
|
||||
return npc
|
||||
}
|
||||
val playerGender =
|
||||
ctx.attributes[PLAYER_STATE]?.characterId?.let(characterStore::getCharacter)?.info?.rivalSex
|
||||
// The rival is the opposite gender from the player.
|
||||
val graphicsId = if (playerGender == FEMALE) RIVAL_BRENDAN_NORMAL else RIVAL_MAY_NORMAL
|
||||
return npc.copy(graphicsId = graphicsId)
|
||||
}
|
||||
|
||||
private fun applyStoryPlacement(
|
||||
bankId: Int,
|
||||
mapId: Int,
|
||||
npc: NpcDef,
|
||||
storyFlags: Set<String>,
|
||||
storyVars: Map<String, Int>,
|
||||
): NpcDef {
|
||||
if (bankId != LITTLEROOT_BANK || mapId != LITTLEROOT_MAP || npc.entityIdx != LITTLEROOT_TWIN) {
|
||||
return npc
|
||||
}
|
||||
if (RESCUED_BIRCH_FLAG in storyFlags) return npc
|
||||
return if (storyVars[LITTLEROOT_STATE_VAR].orZero() == 0) {
|
||||
npc.copy(x = 7, y = 2, facing = Direction.DOWN, movementType = MovementType.FACE_DOWN)
|
||||
} else {
|
||||
npc.copy(x = 10, y = 1, facing = Direction.UP, movementType = MovementType.FACE_UP)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Int?.orZero(): Int = this ?: 0
|
||||
|
||||
private fun shouldHideNpc(
|
||||
bankId: Int,
|
||||
mapId: Int,
|
||||
npc: NpcDef,
|
||||
storyFlags: Set<String>,
|
||||
): Boolean {
|
||||
if (npc.hideFlag in storyFlags) return true
|
||||
// Completed rescues must not restore Zigzagoon.
|
||||
return bankId == ROUTE_101_BANK &&
|
||||
mapId == ROUTE_101_MAP &&
|
||||
npc.entityIdx == ROUTE_101_ZIGZAGOON &&
|
||||
(RESCUED_BIRCH_FLAG in storyFlags || ROUTE_101_RESCUE_HIDDEN_FLAG in storyFlags)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val DECORATION_FLAG_PREFIX = "FLAG_DECORATION_"
|
||||
const val USE_LEGACY_PETALBURG_SPAWNS = false
|
||||
const val DYNAMIC_GFX_VAR_0 = 240
|
||||
const val RIVAL_BRENDAN_NORMAL = 100
|
||||
const val RIVAL_MAY_NORMAL = 105
|
||||
const val FEMALE: Byte = 1
|
||||
const val LITTLEROOT_BANK = 50
|
||||
const val LITTLEROOT_MAP = 9
|
||||
const val LITTLEROOT_TWIN = 0
|
||||
const val RESCUED_BIRCH_FLAG = "hoenn/FLAG_RESCUED_BIRCH"
|
||||
const val LITTLEROOT_STATE_VAR = "hoenn/VAR_LITTLEROOT_TOWN_STATE"
|
||||
const val ROUTE_101_BANK = 50
|
||||
const val ROUTE_101_MAP = 16
|
||||
const val ROUTE_101_ZIGZAGOON = 3
|
||||
const val ROUTE_101_RESCUE_HIDDEN_FLAG = "hoenn/FLAG_HIDE_ROUTE_101_BIRCH_ZIGZAGOON_BATTLE"
|
||||
}
|
||||
}
|
||||
+137
-6
@@ -5,6 +5,7 @@ import de.fiereu.openmmo.common.DynamicWarp
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.DialogDataPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcUpdatePacket
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
@@ -48,6 +49,59 @@ constructor(
|
||||
drive(session, entityId, Pose(npc.x, npc.y, npc.facing), steps)
|
||||
}
|
||||
|
||||
/** Starts concurrent NPC movement paths. */
|
||||
suspend fun moveNpcs(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
paths: List<Pair<Int, List<MovementStep>>>,
|
||||
) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
val map =
|
||||
mapManager.getMap(info.positionRegionId, info.positionBankId, info.positionMapId) ?: return
|
||||
val resolved =
|
||||
paths.mapNotNull { (localId, steps) ->
|
||||
if (map.npcs.none { it.entityIdx == localId }) return@mapNotNull null
|
||||
npcService.entityIdFor(
|
||||
info.positionBankId.toInt(), info.positionMapId.toInt(), localId) to steps
|
||||
}
|
||||
resolved.forEach { (entityId, steps) -> sendActions(session, entityId, steps) }
|
||||
delay(resolved.maxOfOrNull { (_, steps) -> durationMs(steps) } ?: 0)
|
||||
}
|
||||
|
||||
/** Starts player and NPC movement together. */
|
||||
suspend fun moveSelfAndNpcs(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
selfSteps: List<MovementStep>,
|
||||
paths: List<Pair<Int, List<MovementStep>>>,
|
||||
) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
val map =
|
||||
mapManager.getMap(info.positionRegionId, info.positionBankId, info.positionMapId) ?: return
|
||||
val resolved =
|
||||
paths.mapNotNull { (localId, steps) ->
|
||||
if (map.npcs.none { it.entityIdx == localId }) return@mapNotNull null
|
||||
npcService.entityIdFor(
|
||||
info.positionBankId.toInt(), info.positionMapId.toInt(), localId) to steps
|
||||
}
|
||||
sendActions(session, info.id, selfSteps)
|
||||
resolved.forEach { (entityId, steps) -> sendActions(session, entityId, steps) }
|
||||
delay(
|
||||
maxOf(
|
||||
durationMs(selfSteps),
|
||||
resolved.maxOfOrNull { (_, steps) -> durationMs(steps) } ?: 0,
|
||||
))
|
||||
|
||||
val start = Pose(info.positionX.toInt(), info.positionY.toInt(), state.facingDirection)
|
||||
val end = applySteps(start, selfSteps)
|
||||
characterStore.updatePosition(charId, end.x.toShort(), end.y.toShort())
|
||||
state.x = end.x.toShort()
|
||||
state.y = end.y.toShort()
|
||||
state.facingDirection = end.facing
|
||||
}
|
||||
|
||||
/** Show a normally hidden map npc to the player for a cutscene (the decomp addobject). */
|
||||
fun showNpc(session: SessionContext, state: PlayerState, localId: Int) {
|
||||
val charId = state.characterId ?: return
|
||||
@@ -55,6 +109,67 @@ constructor(
|
||||
npcService.spawnNpc(session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId)
|
||||
}
|
||||
|
||||
/** Show a normally hidden map npc at an overridden cutscene position. */
|
||||
fun showNpcAt(session: SessionContext, state: PlayerState, localId: Int, x: Int, y: Int) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
npcService.spawnNpcAt(
|
||||
session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId, x, y)
|
||||
}
|
||||
|
||||
/** Relocate an npc that the normal map spawn already created. */
|
||||
fun repositionNpc(session: SessionContext, state: PlayerState, localId: Int, x: Int, y: Int) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
npcService.repositionNpc(
|
||||
session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId, x, y)
|
||||
}
|
||||
|
||||
/** Repositions the player and synchronizes server state. */
|
||||
fun repositionSelf(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
x: Int,
|
||||
y: Int,
|
||||
facing: Direction,
|
||||
) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
session.send(
|
||||
NpcUpdatePacket(
|
||||
entityId = info.id,
|
||||
regionId = info.positionRegionId.toInt(),
|
||||
bankId = info.positionBankId.toInt(),
|
||||
mapId = info.positionMapId.toInt(),
|
||||
x = x,
|
||||
y = y,
|
||||
facing = 0xF6,
|
||||
unk = facing.ordinal,
|
||||
))
|
||||
characterStore.updatePosition(charId, x.toShort(), y.toShort())
|
||||
state.x = x.toShort()
|
||||
state.y = y.toShort()
|
||||
state.facingDirection = facing
|
||||
}
|
||||
|
||||
/** Removes a cutscene NPC and its collision. */
|
||||
fun removeNpc(session: SessionContext, state: PlayerState, localId: Int) {
|
||||
val charId = state.characterId ?: return
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return
|
||||
npcService.despawnNpc(session, info.positionBankId.toInt(), info.positionMapId.toInt(), localId)
|
||||
}
|
||||
|
||||
/** Resolves local NPC ids to entity ids. */
|
||||
fun npcEntityId(state: PlayerState, localId: Int): Long? {
|
||||
val charId = state.characterId ?: return null
|
||||
val info = characterStore.getCharacter(charId)?.info ?: return null
|
||||
return npcService.entityIdFor(info.positionBankId.toInt(), info.positionMapId.toInt(), localId)
|
||||
}
|
||||
|
||||
/** Returns the created player's gender. */
|
||||
fun playerGender(state: PlayerState): Byte? =
|
||||
state.characterId?.let(characterStore::getCharacter)?.info?.rivalSex
|
||||
|
||||
/**
|
||||
* Set the destination a MAP_DYNAMIC warp resolves to for this player (the decomp setdynamicwarp).
|
||||
*/
|
||||
@@ -89,25 +204,41 @@ constructor(
|
||||
steps: List<MovementStep>,
|
||||
): Pose {
|
||||
if (steps.isEmpty()) return start
|
||||
// The whole sequence goes in one movement packet (entityId, startIndex 0, count, action bytes).
|
||||
// The client walks/turns the entity itself, so no coords are sent.
|
||||
val actions = ByteArray(steps.size) { steps[it].action.toByte() }
|
||||
session.send(DialogDataPacket(entityId, unk1 = 0, type = steps.size, data = actions))
|
||||
sendActions(session, entityId, steps)
|
||||
// waitmovement: hold until the client has had time to play the sequence.
|
||||
delay(steps.sumOf { if (it.walks) WALK_STEP_MS else FACE_STEP_MS })
|
||||
delay(durationMs(steps))
|
||||
return applySteps(start, steps)
|
||||
}
|
||||
|
||||
private fun applySteps(start: Pose, steps: List<MovementStep>): Pose {
|
||||
var pose = start
|
||||
for (step in steps) {
|
||||
pose =
|
||||
if (step.walks)
|
||||
Pose(pose.x + step.direction.dx, pose.y + step.direction.dy, step.direction)
|
||||
else pose.copy(facing = step.direction)
|
||||
else if (step.changesFacing) pose.copy(facing = step.direction) else pose
|
||||
}
|
||||
return pose
|
||||
}
|
||||
|
||||
private fun sendActions(
|
||||
session: SessionContext,
|
||||
entityId: Long,
|
||||
steps: List<MovementStep>,
|
||||
) {
|
||||
if (steps.isEmpty()) return
|
||||
// Send each movement sequence in one packet.
|
||||
val actions = ByteArray(steps.size) { steps[it].action.toByte() }
|
||||
session.send(DialogDataPacket(entityId, unk1 = 0, type = steps.size, data = actions))
|
||||
}
|
||||
|
||||
private fun durationMs(steps: List<MovementStep>): Long =
|
||||
steps.sumOf { if (it.fast) FAST_STEP_MS else if (it.walks) WALK_STEP_MS else FACE_STEP_MS }
|
||||
|
||||
private companion object {
|
||||
// Rough client step timings, tune if the animation and server drift apart.
|
||||
const val WALK_STEP_MS = 250L
|
||||
const val FAST_STEP_MS = 130L
|
||||
const val FACE_STEP_MS = 120L
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.DynamicWarp
|
||||
import de.fiereu.openmmo.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.MapTransitionAckPacket
|
||||
import de.fiereu.openmmo.net.game.packets.MapTransitionPacket
|
||||
import de.fiereu.openmmo.net.game.packets.RenderScreenPacket
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** A direct, no-auto-step warp for cutscenes (the decomp's `warpsilent`). */
|
||||
@Singleton
|
||||
class ScriptWarpService
|
||||
@Inject
|
||||
constructor(
|
||||
private val mapManager: MapManager,
|
||||
private val mapLoadService: MapLoadService,
|
||||
private val characterStore: CharacterStore,
|
||||
private val presenceService: PresenceService,
|
||||
private val npcService: NpcService,
|
||||
) {
|
||||
fun warp(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
destination: DynamicWarp,
|
||||
) {
|
||||
val characterId = state.characterId ?: return
|
||||
val stored = characterStore.getCharacter(characterId) ?: return
|
||||
val map =
|
||||
mapManager.getMap(destination.regionId, destination.bankId, destination.mapId) ?: return
|
||||
val info =
|
||||
stored.info.copy(
|
||||
positionRegionId = destination.regionId,
|
||||
positionBankId = destination.bankId,
|
||||
positionMapId = destination.mapId,
|
||||
positionX = destination.x,
|
||||
positionY = destination.y,
|
||||
)
|
||||
|
||||
characterStore.updateCharacter(info)
|
||||
characterStore.flushCharacterAsync(characterId)
|
||||
state.justWarped = true
|
||||
state.regionId = destination.regionId.toInt()
|
||||
state.bankId = destination.bankId.toInt()
|
||||
state.mapId = destination.mapId.toInt()
|
||||
state.x = destination.x
|
||||
state.y = destination.y
|
||||
state.facingDirection = destination.facing
|
||||
|
||||
session.send(MapTransitionPacket())
|
||||
session.send(RenderScreenPacket(false))
|
||||
session.send(MapTransitionAckPacket(2))
|
||||
session.send(mapManager.createLoadMapPacket(map, reloadPlayer = true, deleteCache = true))
|
||||
mapLoadService.preloadConnectedMaps(session, map, depth = 1, reloadPlayer = true)
|
||||
session.send(mapLoadService.createLoadEntity(info, destination.facing))
|
||||
npcService.spawnNpcsForMap(
|
||||
session,
|
||||
destination.bankId.toInt(),
|
||||
destination.mapId.toInt(),
|
||||
destination.regionId.toInt(),
|
||||
)
|
||||
presenceService.refresh(session)
|
||||
session.send(RenderScreenPacket(true))
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.openmmo.net.game.packets.PlayerVariableEntry
|
||||
import de.fiereu.openmmo.net.game.packets.StoryFlagUpdatePacket
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import de.fiereu.openmmo.story.generated.kanto.KantoFlags
|
||||
import de.fiereu.openmmo.story.generated.kanto.KantoVars
|
||||
|
||||
/** Converts persisted story keys to client ids. */
|
||||
internal object StoryClientState {
|
||||
fun flags(regionId: Byte, flags: Collection<String>): List<StoryFlagUpdatePacket> =
|
||||
flags.mapNotNull { flagUpdate(regionId, it, enabled = true) }.sortedBy { it.flagId }
|
||||
|
||||
fun flagUpdate(regionId: Byte, key: String, enabled: Boolean): StoryFlagUpdatePacket? {
|
||||
val id = flagId(regionId, key) ?: return null
|
||||
return StoryFlagUpdatePacket(regionId, id, enabled)
|
||||
}
|
||||
|
||||
fun variables(regionId: Byte, vars: Map<String, Int>): List<PlayerVariableEntry> =
|
||||
vars
|
||||
.mapNotNull { (key, value) ->
|
||||
val id = varId(regionId, key) ?: return@mapNotNull null
|
||||
if (id !in GBA_VARS_START..GBA_VARS_END) return@mapNotNull null
|
||||
PlayerVariableEntry((id - GBA_VARS_START).toByte(), value.toShort())
|
||||
}
|
||||
.sortedBy { it.key.toInt() and 0xff }
|
||||
|
||||
private fun flagId(regionId: Byte, key: String): Int? =
|
||||
when (regionId.toInt()) {
|
||||
KANTO_REGION -> KantoFlags.numericId(key)
|
||||
HOENN_REGION -> HoennFlags.numericId(key)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun varId(regionId: Byte, key: String): Int? =
|
||||
when (regionId.toInt()) {
|
||||
KANTO_REGION -> KantoVars.numericId(key)
|
||||
HOENN_REGION -> HoennVars.numericId(key)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private const val KANTO_REGION = 0
|
||||
private const val HOENN_REGION = 1
|
||||
private const val GBA_VARS_START = 0x4000
|
||||
private const val GBA_VARS_END = 0x40ff
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.network.SessionContext
|
||||
import de.fiereu.openmmo.common.Pokemon
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.net.game.packets.PokemonContainerPacket
|
||||
import de.fiereu.openmmo.net.game.packets.SocialListEntryAddPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.ItemStack
|
||||
import de.fiereu.openmmo.net.game.packets.battle.itemStacksPacket
|
||||
import de.fiereu.openmmo.pokemon.SpeciesRegistry
|
||||
import de.fiereu.openmmo.server.game.battle.BattleRng
|
||||
import de.fiereu.openmmo.server.game.battle.StatCalculator
|
||||
import de.fiereu.openmmo.server.game.battle.WildMonFactory
|
||||
import de.fiereu.openmmo.server.game.session.PlayerState
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** Party, healing, and bag operations used by ROM-derived overworld scripts. */
|
||||
@Singleton
|
||||
class StoryPlayerService
|
||||
@Inject
|
||||
constructor(
|
||||
private val characters: CharacterStore,
|
||||
private val pokemonFactory: WildMonFactory,
|
||||
private val species: SpeciesRegistry,
|
||||
private val moves: MoveRegistry,
|
||||
) {
|
||||
|
||||
/** Gives a story Pokemon and syncs it. */
|
||||
fun givePokemon(
|
||||
session: SessionContext,
|
||||
state: PlayerState,
|
||||
dexId: Int,
|
||||
level: Int,
|
||||
moveIds: List<Int>,
|
||||
): Pokemon? {
|
||||
val characterId = state.characterId ?: return null
|
||||
val stored = characters.getCharacter(characterId) ?: return null
|
||||
if (stored.pokemon.size >= MAX_PARTY_SIZE) return null
|
||||
val rolled = pokemonFactory.create(dexId, level, BattleRng()) ?: return null
|
||||
val pokemon =
|
||||
rolled.copy(
|
||||
ownerId = characterId,
|
||||
container = PokemonContainer.PARTY,
|
||||
containerSlot = stored.pokemon.size.toShort(),
|
||||
ot = stored.info.name,
|
||||
moves = paddedMoves(moveIds),
|
||||
)
|
||||
characters.addPokemon(characterId, pokemon)
|
||||
// Send the granted Pokemon's full record.
|
||||
session.send(SocialListEntryAddPacket(pokemon))
|
||||
return pokemon
|
||||
}
|
||||
|
||||
fun healParty(session: SessionContext, state: PlayerState) {
|
||||
val characterId = state.characterId ?: return
|
||||
val stored = characters.getCharacter(characterId) ?: return
|
||||
val healed =
|
||||
stored.pokemon.map { pokemon ->
|
||||
val definition = species.get(pokemon.dexId) ?: return@map pokemon
|
||||
pokemon.copy(
|
||||
hp = StatCalculator.computeAll(definition, pokemon).hp.toShort(),
|
||||
moves =
|
||||
pokemon.moves.map { move ->
|
||||
val maxPp = moves.get(move.id.toInt())?.pp ?: move.pp.toInt()
|
||||
PokemonMove(move.id, maxPp.toByte())
|
||||
},
|
||||
)
|
||||
}
|
||||
healed.forEach { characters.updatePokemon(characterId, it) }
|
||||
session.send(
|
||||
PokemonContainerPacket(
|
||||
container = PokemonContainer.PARTY,
|
||||
hasChange = true,
|
||||
delete = false,
|
||||
pokemon = healed,
|
||||
))
|
||||
}
|
||||
|
||||
fun giveItem(session: SessionContext, state: PlayerState, itemId: Int, quantity: Int): Boolean {
|
||||
val characterId = state.characterId ?: return false
|
||||
if (!characters.addItem(characterId, itemId, quantity)) return false
|
||||
val items = characters.getCharacter(characterId)?.items ?: return false
|
||||
session.send(storyItemStacksPacket(items))
|
||||
return true
|
||||
}
|
||||
|
||||
private fun paddedMoves(moveIds: List<Int>): List<PokemonMove> =
|
||||
moveIds.take(MAX_MOVES).map { id ->
|
||||
PokemonMove(id.toShort(), (moves.get(id)?.pp ?: 0).toByte())
|
||||
} + List((MAX_MOVES - moveIds.size).coerceAtLeast(0)) { PokemonMove(0, 0) }
|
||||
|
||||
private companion object {
|
||||
const val MAX_PARTY_SIZE = 6
|
||||
const val MAX_MOVES = 4
|
||||
}
|
||||
}
|
||||
|
||||
/** Builds a stable full bag snapshot. */
|
||||
fun storyItemStacksPacket(items: Map<Int, Int>) =
|
||||
itemStacksPacket(
|
||||
items.entries
|
||||
.sortedBy { it.key }
|
||||
.map { (itemId, quantity) ->
|
||||
ItemStack(
|
||||
objectId = (itemId.toLong() shl 16) or ITEM_ENTITY_TAG,
|
||||
itemId = itemId.toShort(),
|
||||
quantity = quantity.toShort(),
|
||||
)
|
||||
})
|
||||
|
||||
private const val ITEM_ENTITY_TAG = 0x5000L
|
||||
@@ -108,8 +108,7 @@ constructor(
|
||||
|
||||
ctx.send(MapTransitionPacket())
|
||||
ctx.send(RenderScreenPacket(false))
|
||||
ctx.send(mapLoadService.createLoadEntity(newInfo, warpFacing, playerZ))
|
||||
ctx.send(MapTransitionAckPacket(0))
|
||||
ctx.send(MapTransitionAckPacket(2))
|
||||
|
||||
if (destMap != null) {
|
||||
ctx.send(mapManager.createLoadMapPacket(destMap, reloadPlayer = true, deleteCache = true))
|
||||
@@ -120,10 +119,15 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// Release the fade after loading the destination.
|
||||
ctx.send(mapLoadService.createLoadEntity(newInfo, warpFacing, playerZ))
|
||||
|
||||
presenceService.refresh(ctx)
|
||||
|
||||
if (state != null && destMap != null) mapScriptService.onMapEnter(ctx, state, destMap)
|
||||
|
||||
ctx.send(RenderScreenPacket(true))
|
||||
|
||||
log.info { "Player $charId warped to bank=${warp.targetBankId} map=${warp.targetMapId}" }
|
||||
}
|
||||
}
|
||||
@@ -15,4 +15,6 @@ data class PlayerState(
|
||||
var mapId: Int = 3,
|
||||
var x: Short = 4,
|
||||
var y: Short = 2,
|
||||
/** Trusts one source tile after scripted movement. */
|
||||
var acceptNextMoveSource: Boolean = false,
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.fiereu.openmmo.server.game.session
|
||||
|
||||
import de.fiereu.network.SessionAttribute
|
||||
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@@ -9,5 +10,9 @@ val PLAYER_STATE = SessionAttribute.of<PlayerState>("playerState")
|
||||
/** Completed when the player advances or closes the dialog box a script is currently waiting on. */
|
||||
val PENDING_DIALOG = SessionAttribute.of<CompletableDeferred<Unit>>("pendingDialog")
|
||||
|
||||
/** Completes with the selected dialog value. */
|
||||
val PENDING_DIALOG_RESPONSE =
|
||||
SessionAttribute.of<CompletableDeferred<DialogActionResponsePacket>>("pendingDialogResponse")
|
||||
|
||||
/** Scope the connection's scripts run in. Cancelled on disconnect so a waiting script unwinds. */
|
||||
val SCRIPT_SCOPE = SessionAttribute.of<CoroutineScope>("scriptScope")
|
||||
+11
@@ -30,6 +30,9 @@ interface CharacterRepository {
|
||||
suspend fun insertAggregate(stored: StoredCharacter)
|
||||
|
||||
suspend fun saveAggregate(stored: StoredCharacter)
|
||||
|
||||
/** Deletes a character owned by the user. */
|
||||
suspend fun deleteById(userId: Int, id: Long): Boolean
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@@ -66,6 +69,14 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteById(userId: Int, id: Long): Boolean =
|
||||
withContext(dispatcher) {
|
||||
dsl.deleteFrom(CHARACTERS)
|
||||
.where(CHARACTERS.ID.eq(id))
|
||||
.and(CHARACTERS.USER_ID.eq(userId))
|
||||
.execute() == 1
|
||||
}
|
||||
|
||||
private fun insert(tx: DSLContext, stored: StoredCharacter) {
|
||||
tx.insertInto(CHARACTERS).set(stored.info.toRecord()).execute()
|
||||
val monsters = stored.pokemon + stored.pcStorage
|
||||
|
||||
+88
-18
@@ -3,7 +3,10 @@ package de.fiereu.openmmo.server.game.storage
|
||||
import de.fiereu.openmmo.common.CharacterInfo
|
||||
import de.fiereu.openmmo.common.DynamicWarp
|
||||
import de.fiereu.openmmo.common.Pokemon
|
||||
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.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.time.LocalDateTime
|
||||
@@ -25,6 +28,19 @@ private val log = KotlinLogging.logger {}
|
||||
private val FLUSH_TICK = 5.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(
|
||||
val info: CharacterInfo,
|
||||
val pokemon: MutableList<Pokemon>,
|
||||
@@ -64,7 +80,12 @@ constructor(
|
||||
suspend fun createCharacter(
|
||||
userId: Int,
|
||||
name: String,
|
||||
gender: CharacterGender,
|
||||
startingRegion: Region,
|
||||
): StoredCharacter {
|
||||
val female = gender == CharacterGender.FEMALE
|
||||
val startingPosition = SHOWCASE_STARTS.getValue(startingRegion)
|
||||
val isHoenn = startingRegion == Region.HOENN
|
||||
val id = entityIds.newCharacterId()
|
||||
val now = LocalDateTime.now()
|
||||
val info =
|
||||
@@ -73,7 +94,8 @@ constructor(
|
||||
name = name,
|
||||
namePrefix = "",
|
||||
userId = userId,
|
||||
rivalSex = 0,
|
||||
// This historical field stores the player's gender.
|
||||
rivalSex = gender.wireValue,
|
||||
lastLogin = now,
|
||||
createdAt = now,
|
||||
money = 30000,
|
||||
@@ -83,30 +105,55 @@ constructor(
|
||||
pcExtraSlots = 0,
|
||||
battleBoxExtraSlots = 0,
|
||||
templateAmount = 0,
|
||||
// New characters start inside the moving truck (InsideOfTruck, bank 75 map 40). Walking
|
||||
// out warps to Littleroot, where the intro var below drives the mom cutscene.
|
||||
positionRegionId = 1,
|
||||
positionBankId = 75,
|
||||
positionMapId = 40,
|
||||
positionX = 2,
|
||||
positionY = 2,
|
||||
// Hoenn starts inside the moving truck.
|
||||
positionRegionId = startingRegion.wireValue,
|
||||
positionBankId = startingPosition.bankId,
|
||||
positionMapId = startingPosition.mapId,
|
||||
positionX = startingPosition.x,
|
||||
positionY = startingPosition.y,
|
||||
repelLeft = 0,
|
||||
repelItemId = 0,
|
||||
lureLeft = 0,
|
||||
lureItemId = 0,
|
||||
// The truck's exit is a MAP_DYNAMIC warp. Point it at Littleroot Town for the intro,
|
||||
// the
|
||||
// same thing the decomp setdynamicwarp does at new game. Facing right off the truck.
|
||||
dynamicWarp = DynamicWarp(1, 50, 9, 3, 10, Direction.RIGHT),
|
||||
// The truck exit uses the player's dynamic warp.
|
||||
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,
|
||||
)
|
||||
// Male intro path. Gender selection is not implemented yet, so everyone takes the male branch.
|
||||
// TODO Support the female intro path
|
||||
// Add character gender (checkplayergender) so new characters can take the female Littleroot
|
||||
// intro (VAR_LITTLEROOT_INTRO_STATE = 2, May's house at 12,10) instead of always the male one.
|
||||
val storyVars = mutableMapOf(HoennVars.VAR_LITTLEROOT_INTRO_STATE to 1)
|
||||
val stored =
|
||||
StoredCharacter(
|
||||
info, mutableListOf(), mutableListOf(), mutableMapOf(), storyVars = storyVars)
|
||||
info,
|
||||
mutableListOf(),
|
||||
mutableListOf(),
|
||||
mutableMapOf(),
|
||||
storyFlags = storyFlags,
|
||||
storyVars = storyVars,
|
||||
)
|
||||
repository.insertAggregate(stored)
|
||||
characters[id] = stored
|
||||
charactersByUser.computeIfAbsent(userId) { CopyOnWriteArrayList() }.add(id)
|
||||
@@ -137,6 +184,16 @@ constructor(
|
||||
return loaded
|
||||
}
|
||||
|
||||
/** Permanently delete an owned character and evict every cached reference to it. */
|
||||
suspend fun deleteCharacter(userId: Int, characterId: Long): Boolean {
|
||||
if (!repository.deleteById(userId, characterId)) return false
|
||||
characters.remove(characterId)
|
||||
charactersByUser[userId]?.remove(characterId)
|
||||
dirtySince.remove(characterId)
|
||||
pendingUnload.remove(characterId)
|
||||
return true
|
||||
}
|
||||
|
||||
fun updateCharacter(info: CharacterInfo) {
|
||||
val stored = characters[info.id] ?: return
|
||||
characters[info.id] = stored.copy(info = info)
|
||||
@@ -185,6 +242,19 @@ constructor(
|
||||
markDirty(characterId)
|
||||
}
|
||||
|
||||
/** Add (or remove with a negative amount) one persisted bag stack. */
|
||||
fun addItem(characterId: Long, itemId: Int, amount: Int): Boolean {
|
||||
val stored = characters[characterId] ?: return false
|
||||
val oldQuantity = stored.items[itemId] ?: 0
|
||||
val newQuantity = oldQuantity + amount
|
||||
if (newQuantity < 0) return false
|
||||
val items = stored.items.toMutableMap()
|
||||
if (newQuantity == 0) items.remove(itemId) else items[itemId] = newQuantity
|
||||
characters[characterId] = stored.copy(items = items)
|
||||
markDirty(characterId)
|
||||
return true
|
||||
}
|
||||
|
||||
/** Set (or clear with null) the runtime destination for MAP_DYNAMIC warps (setdynamicwarp). */
|
||||
fun setDynamicWarp(characterId: Long, warp: DynamicWarp?) {
|
||||
val stored = characters[characterId] ?: return
|
||||
|
||||
+2
@@ -3,6 +3,7 @@ package de.fiereu.openmmo.server.game.handler
|
||||
import de.fiereu.openmmo.net.game.packets.AddFriendPacket
|
||||
import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessagePacket
|
||||
import de.fiereu.openmmo.net.game.packets.DeleteCharacterPacket
|
||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||
@@ -34,6 +35,7 @@ class GameAppHandlerTest :
|
||||
handler.isRegistered(AddFriendPacket::class) shouldBe true
|
||||
handler.isRegistered(RemoveFriendPacket::class) shouldBe true
|
||||
handler.isRegistered(BlockPlayerPacket::class) shouldBe true
|
||||
handler.isRegistered(DeleteCharacterPacket::class) shouldBe true
|
||||
handler.isRegistered(BattleActionPacket::class) shouldBe true
|
||||
handler.isRegistered(BattleChallengeRequestPacket::class) shouldBe true
|
||||
}
|
||||
|
||||
+310
-2
@@ -1,20 +1,37 @@
|
||||
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.DialogDataPacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcSpawnPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcUpdatePacket
|
||||
import de.fiereu.openmmo.net.game.packets.StoryFlagUpdatePacket
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.LittlerootTown_BrendansHouse_2F_OnTransition
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.LittlerootTown_MaysHouse_2F_OnTransition
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.LittlerootTown_OnTransition
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.Route101_EventScript_HideMapNamePopup
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.Route101_EventScript_StartBirchRescue
|
||||
import de.fiereu.openmmo.server.game.script.generated.hoenn.setWallClock
|
||||
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.PENDING_DIALOG
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.advanceUntilIdle
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@@ -23,18 +40,309 @@ class MapTransitionScriptTest :
|
||||
test("Littleroot on-transition sets the visited flag on the player") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "Ash").info.id
|
||||
val charId = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
|
||||
val session = FakeSession(characterId = charId)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager), store)
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
LittlerootTown_OnTransition.run(ctx)
|
||||
|
||||
story.isFlagSet(charId, HoennFlags.FLAG_VISITED_LITTLEROOT_TOWN) shouldBe true
|
||||
session.sent.filterIsInstance<StoryFlagUpdatePacket>() shouldBe
|
||||
listOf(StoryFlagUpdatePacket(regionId = 1, flagId = 0x086f, enabled = true))
|
||||
}
|
||||
}
|
||||
|
||||
test("female bedroom transition advances the intro to the clock step") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
story.setVar(
|
||||
charId,
|
||||
de.fiereu.openmmo.story.generated.hoenn.HoennVars.VAR_LITTLEROOT_INTRO_STATE,
|
||||
4)
|
||||
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = 3)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
LittlerootTown_MaysHouse_2F_OnTransition.run(ctx)
|
||||
|
||||
story.getVar(
|
||||
charId,
|
||||
de.fiereu.openmmo.story.generated.hoenn.HoennVars.VAR_LITTLEROOT_INTRO_STATE) shouldBe
|
||||
5
|
||||
}
|
||||
}
|
||||
|
||||
test("the wall-clock cutscene removes Mom and her collision from the bedroom stairs") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
store.updatePosition(charId, 3, 3, 51, 3)
|
||||
val story = StoryService(store)
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = 3)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val npcs = NpcService(mapManager, store)
|
||||
val movement = ScriptMovementService(mapManager, npcs, store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
val momEntityId = npcs.entityIdFor(51, 3, 13)
|
||||
|
||||
val cutscene = launch { setWallClock(ctx, female = true) }
|
||||
advanceUntilIdle()
|
||||
session.attributes[PENDING_DIALOG]!!.complete(Unit)
|
||||
advanceUntilIdle()
|
||||
session.attributes[PENDING_DIALOG]!!.complete(Unit)
|
||||
advanceUntilIdle()
|
||||
cutscene.join()
|
||||
|
||||
val momMovement =
|
||||
session.sent
|
||||
.filterIsInstance<DialogDataPacket>()
|
||||
.filter { it.entityId == momEntityId }
|
||||
.map { it.data.toList() }
|
||||
momMovement shouldBe
|
||||
listOf(
|
||||
listOf(0x1B, 0x10, 0x03, 0x1C, 0x1B, 0x13).map(Int::toByte),
|
||||
listOf(0x12, 0x11, 0x1B).map(Int::toByte),
|
||||
)
|
||||
session.sent.filterIsInstance<EntityLeavePacket>() shouldBe
|
||||
listOf(EntityLeavePacket(momEntityId))
|
||||
}
|
||||
}
|
||||
|
||||
test("the generated registry exposes the female truck path") {
|
||||
(ScriptRegistry.generated().forLabel("LittlerootTown_EventScript_StepOffTruckFemale") !=
|
||||
null) shouldBe true
|
||||
}
|
||||
|
||||
test("the mandatory Hoenn path through Rustboro Gym has no missing trigger scripts") {
|
||||
val registry = ScriptRegistry.generated()
|
||||
val mandatoryLabels =
|
||||
listOf(
|
||||
"Route101_EventScript_StartBirchRescue",
|
||||
"Route101_EventScript_BirchsBag",
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_GiveStarterEvent",
|
||||
"Route103_EventScript_Rival",
|
||||
"OldaleTown_EventScript_RivalTrigger1",
|
||||
"LittlerootTown_ProfessorBirchsLab_EventScript_GivePokedexEvent",
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer0",
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer1",
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer2",
|
||||
"PetalburgCity_EventScript_ShowGymToPlayer3",
|
||||
"PetalburgCity_Gym_EventScript_Norman",
|
||||
"PetalburgCity_Gym_EventScript_ReturnFromWallyTutorial",
|
||||
"PetalburgWoods_EventScript_DevonResearcherLeft",
|
||||
"PetalburgWoods_EventScript_DevonResearcherRight",
|
||||
"RustboroCity_OnTransition",
|
||||
"RustboroCity_Gym_EventScript_Roxanne",
|
||||
)
|
||||
|
||||
mandatoryLabels.forEach { label -> (registry.forLabel(label) != null) shouldBe true }
|
||||
}
|
||||
|
||||
test("female players become ready to meet Brendan on entering his bedroom") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = 1)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
LittlerootTown_BrendansHouse_2F_OnTransition.run(ctx)
|
||||
|
||||
story.getVar(charId, HoennVars.VAR_LITTLEROOT_RIVAL_STATE) shouldBe 2
|
||||
}
|
||||
}
|
||||
|
||||
test("male players become ready to meet May on entering her bedroom") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId =
|
||||
store.createCharacter(1, "Brendan", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = 3)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
LittlerootTown_MaysHouse_2F_OnTransition.run(ctx)
|
||||
|
||||
story.getVar(charId, HoennVars.VAR_LITTLEROOT_RIVAL_STATE) shouldBe 2
|
||||
}
|
||||
}
|
||||
|
||||
test("completed rival meetings repair both bedroom stair-tile hide flags") {
|
||||
data class RivalRoom(
|
||||
val playerName: String,
|
||||
val gender: CharacterGender,
|
||||
val mapId: Byte,
|
||||
val hideFlag: String,
|
||||
val transition: Script,
|
||||
val expectedX: Int,
|
||||
val expectedY: Int,
|
||||
)
|
||||
|
||||
val rooms =
|
||||
listOf(
|
||||
RivalRoom(
|
||||
"May",
|
||||
CharacterGender.FEMALE,
|
||||
1,
|
||||
HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_RIVAL_BEDROOM,
|
||||
LittlerootTown_BrendansHouse_2F_OnTransition,
|
||||
0,
|
||||
2,
|
||||
),
|
||||
RivalRoom(
|
||||
"Brendan",
|
||||
CharacterGender.MALE,
|
||||
3,
|
||||
HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_RIVAL_BEDROOM,
|
||||
LittlerootTown_MaysHouse_2F_OnTransition,
|
||||
8,
|
||||
2,
|
||||
),
|
||||
)
|
||||
|
||||
runTest {
|
||||
rooms.forEach { room ->
|
||||
val store =
|
||||
CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId =
|
||||
store.createCharacter(1, room.playerName, room.gender, Region.HOENN).info.id
|
||||
store.updatePosition(charId, 3, 3, 51, room.mapId)
|
||||
val story = StoryService(store)
|
||||
story.clearFlag(charId, room.hideFlag)
|
||||
story.setVar(charId, HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 3)
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = room.mapId.toInt())
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
room.transition.run(ctx)
|
||||
|
||||
story.isFlagSet(charId, room.hideFlag) shouldBe true
|
||||
val spawn = session.sent.filterIsInstance<NpcSpawnPacket>().single()
|
||||
spawn.x shouldBe room.expectedX
|
||||
spawn.y shouldBe room.expectedY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("Route 101 entry arms the Birch rescue coordinate triggers") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
val session = FakeSession(characterId = charId, bankId = 50, mapId = 16)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val movement = ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
|
||||
Route101_EventScript_HideMapNamePopup.run(ctx)
|
||||
|
||||
story.getVar(charId, HoennVars.VAR_ROUTE101_STATE) shouldBe 1
|
||||
val route = mapManager.getMap(1, 50, 16)!!
|
||||
route.coordScripts.count { it.script == "Route101_EventScript_StartBirchRescue" } shouldBe
|
||||
2
|
||||
(ScriptRegistry.generated().forLabel("Route101_EventScript_StartBirchRescue") !=
|
||||
null) shouldBe true
|
||||
}
|
||||
}
|
||||
|
||||
test("Birch rescue repositions existing npcs and keeps Zigzagoon one tile away") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
store.updatePosition(charId, 10, 19, 50, 16)
|
||||
val story = StoryService(store)
|
||||
val session = FakeSession(characterId = charId, bankId = 50, mapId = 16)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val npcs = NpcService(mapManager, store)
|
||||
val movement = ScriptMovementService(mapManager, npcs, store)
|
||||
val ctx = ScriptContext(session, state, entityId = -1, DialogService(), story, movement)
|
||||
val birchId = npcs.entityIdFor(50, 16, 1)
|
||||
val zigzagoonId = npcs.entityIdFor(50, 16, 3)
|
||||
|
||||
val cutscene = launch { Route101_EventScript_StartBirchRescue.run(ctx) }
|
||||
advanceUntilIdle()
|
||||
session.attributes[PENDING_DIALOG]!!.complete(Unit)
|
||||
advanceUntilIdle()
|
||||
session.attributes[PENDING_DIALOG]!!.complete(Unit)
|
||||
advanceUntilIdle()
|
||||
cutscene.join()
|
||||
|
||||
session.sent.filterIsInstance<NpcUpdatePacket>() shouldBe
|
||||
listOf(
|
||||
NpcUpdatePacket(birchId, 1, 50, 16, 0, 15, 0xF6, 3),
|
||||
NpcUpdatePacket(zigzagoonId, 1, 50, 16, 0, 16, 0xF6, 2),
|
||||
)
|
||||
val chase =
|
||||
session.sent
|
||||
.filterIsInstance<DialogDataPacket>()
|
||||
.single { it.entityId == zigzagoonId && it.data.size > 20 }
|
||||
.data
|
||||
// Birch and Zigzagoon finish one tile apart.
|
||||
chase.takeLast(2) shouldBe listOf(0x1F.toByte(), 0x1F.toByte())
|
||||
chase.size shouldBe 30
|
||||
}
|
||||
}
|
||||
|
||||
test("Brendan meeting completes the rival state and opens the north intro path") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val charId = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
store.updatePosition(charId, 3, 3, 51, 1)
|
||||
val story = StoryService(store)
|
||||
story.setVar(charId, HoennVars.VAR_LITTLEROOT_RIVAL_STATE, 2)
|
||||
val session = FakeSession(characterId = charId, bankId = 51, mapId = 1)
|
||||
val state = session.attributes[PLAYER_STATE]!!
|
||||
val mapManager = MapManager()
|
||||
val npcs = NpcService(mapManager, store)
|
||||
val movement = ScriptMovementService(mapManager, npcs, store)
|
||||
val dialog = DialogService()
|
||||
val ctx =
|
||||
ScriptContext(
|
||||
session,
|
||||
state,
|
||||
entityId = npcs.entityIdFor(51, 1, 14),
|
||||
dialog,
|
||||
story,
|
||||
movement,
|
||||
)
|
||||
|
||||
val cutscene = launch {
|
||||
LittlerootTown_BrendansHouse_2F_EventScript_RivalsPokeBall.run(ctx)
|
||||
}
|
||||
advanceUntilIdle()
|
||||
session.attributes[PENDING_DIALOG]!!.complete(Unit)
|
||||
advanceUntilIdle()
|
||||
cutscene.join()
|
||||
|
||||
story.getVar(charId, HoennVars.VAR_LITTLEROOT_RIVAL_STATE) shouldBe 3
|
||||
story.getVar(charId, HoennVars.VAR_LITTLEROOT_TOWN_STATE) shouldBe 1
|
||||
story.isFlagSet(
|
||||
charId, HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F_POKE_BALL) shouldBe
|
||||
true
|
||||
story.isFlagSet(
|
||||
charId, HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_RIVAL_BEDROOM) shouldBe
|
||||
true
|
||||
}
|
||||
}
|
||||
})
|
||||
+17
-3
@@ -4,13 +4,16 @@ import de.fiereu.network.PacketEvent
|
||||
import de.fiereu.openmmo.common.Pokemon
|
||||
import de.fiereu.openmmo.common.PokemonMove
|
||||
import de.fiereu.openmmo.common.enums.BattleAction
|
||||
import de.fiereu.openmmo.common.enums.CharacterGender
|
||||
import de.fiereu.openmmo.common.enums.EVs
|
||||
import de.fiereu.openmmo.common.enums.IVs
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.moves.MoveRegistry
|
||||
import de.fiereu.openmmo.net.game.packets.ChatMessageSendPacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityMovePpPacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityPresencePacket
|
||||
import de.fiereu.openmmo.net.game.packets.MapLoadedAckPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleActionSelectPacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleBulkStatePacket
|
||||
import de.fiereu.openmmo.net.game.packets.battle.BattleEntityDeltaPacket
|
||||
@@ -86,10 +89,11 @@ private class Fixture(scope: CoroutineScope) {
|
||||
rewards = BattleRewards(),
|
||||
interestManager = interestManager,
|
||||
speciesRegistry = SpeciesRegistry(),
|
||||
moveRegistry = MoveRegistry(),
|
||||
)
|
||||
|
||||
suspend fun playerWithParty(level: Byte = 50, hp: Short = 999): Pair<FakeSession, Long> {
|
||||
val created = store.createCharacter(1, "Ash")
|
||||
val created = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN)
|
||||
store.addPokemon(created.info.id, bulbasaur(created.info.id, level, hp))
|
||||
return FakeSession(created.info.id) to created.info.id
|
||||
}
|
||||
@@ -103,6 +107,10 @@ private fun FakeSession.act(service: BattleService, action: BattleAction, value:
|
||||
service.onBattleAction(PacketEvent(BattleActionSelectPacket(0, action, value, 0L, 0), this))
|
||||
}
|
||||
|
||||
private fun FakeSession.finishBattleTransition(service: BattleService) {
|
||||
service.onClientReady(PacketEvent(MapLoadedAckPacket(), this))
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class BattleServiceTest :
|
||||
FunSpec({
|
||||
@@ -174,7 +182,7 @@ class BattleServiceTest :
|
||||
}
|
||||
}
|
||||
|
||||
test("fleeing sends the flee markers and clears the battle") {
|
||||
test("fleeing waits for the overworld before clearing the battle") {
|
||||
runTest {
|
||||
val fx = Fixture(backgroundScope)
|
||||
val (session, charId) = fx.playerWithParty()
|
||||
@@ -182,6 +190,10 @@ class BattleServiceTest :
|
||||
|
||||
session.act(fx.service, BattleAction.RUN)
|
||||
|
||||
fx.registry.byChar(charId).shouldNotBeNull()
|
||||
fx.service.onClientReady(PacketEvent(MapLoadedAckPacket(byteArrayOf(1, 2, 3)), session))
|
||||
fx.registry.byChar(charId).shouldNotBeNull()
|
||||
session.finishBattleTransition(fx.service)
|
||||
fx.registry.byChar(charId).shouldBeNull()
|
||||
session.sent.filterIsInstance<BattleBulkStatePacket>().shouldNotBeEmpty()
|
||||
session.startBattle(fx.service)
|
||||
@@ -196,10 +208,12 @@ class BattleServiceTest :
|
||||
session.startBattle(fx.service)
|
||||
|
||||
var rounds = 0
|
||||
while (fx.registry.byChar(charId) != null && rounds < 10) {
|
||||
while (fx.registry.byChar(charId)?.pendingResult == null && rounds < 10) {
|
||||
session.act(fx.service, BattleAction.MOVE, TACKLE)
|
||||
rounds += 1
|
||||
}
|
||||
fx.registry.byChar(charId).shouldNotBeNull()
|
||||
session.finishBattleTransition(fx.service)
|
||||
fx.registry.byChar(charId).shouldBeNull()
|
||||
advanceUntilIdle()
|
||||
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
import de.fiereu.openmmo.common.enums.TileBehavior
|
||||
import de.fiereu.openmmo.maps.MapDef
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import java.util.Base64
|
||||
|
||||
class LedgeMovementTest :
|
||||
FunSpec({
|
||||
test("each directional ledge lands two tiles away") {
|
||||
val cases =
|
||||
listOf(
|
||||
Direction.DOWN to TileBehavior.JUMP_SOUTH,
|
||||
Direction.UP to TileBehavior.JUMP_NORTH,
|
||||
Direction.LEFT to TileBehavior.JUMP_WEST,
|
||||
Direction.RIGHT to TileBehavior.JUMP_EAST,
|
||||
)
|
||||
|
||||
cases.forEach { (direction, behavior) ->
|
||||
val map = testMap(behavior)
|
||||
val fromX = 2 - direction.dx
|
||||
val fromY = 2 - direction.dy
|
||||
|
||||
ledgeLanding(map, fromX, fromY, direction) shouldBe (2 + direction.dx to 2 + direction.dy)
|
||||
ledgeLanding(map, fromX, fromY, direction.opposite()) shouldBe null
|
||||
}
|
||||
}
|
||||
|
||||
test("a ledge hop is rejected when its landing tile is blocked") {
|
||||
val map = testMap(TileBehavior.JUMP_SOUTH, blockedX = 2, blockedY = 3)
|
||||
|
||||
ledgeLanding(map, 2, 1, Direction.DOWN) shouldBe null
|
||||
}
|
||||
})
|
||||
|
||||
private fun testMap(
|
||||
ledgeBehavior: TileBehavior,
|
||||
blockedX: Int? = null,
|
||||
blockedY: Int? = null,
|
||||
): MapDef {
|
||||
val width = 5
|
||||
val height = 5
|
||||
val blocks = ByteArray(width * height * 2)
|
||||
if (blockedX != null && blockedY != null) {
|
||||
val offset = (blockedY * width + blockedX) * 2
|
||||
blocks[offset + 1] = 0x04 // movement collision 1 in raw metatile bits 10-11
|
||||
}
|
||||
val behaviors = ByteArray(width * height)
|
||||
behaviors[2 * width + 2] = ledgeBehavior.ordinal.toByte()
|
||||
return MapDef(
|
||||
regionId = 1,
|
||||
bankId = 50,
|
||||
mapId = 0,
|
||||
width = width,
|
||||
height = height,
|
||||
blockData = Base64.getEncoder().encodeToString(blocks),
|
||||
behaviorData = Base64.getEncoder().encodeToString(behaviors),
|
||||
)
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
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.NpcSpawnPacket
|
||||
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.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class NpcStoryFlagSyncTest :
|
||||
FunSpec({
|
||||
test("persisted hide flags determine the entities restored for a map") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val character = store.createCharacter(1, "Brendan", CharacterGender.MALE, Region.HOENN)
|
||||
val session = FakeSession(characterId = character.info.id, bankId = 50, mapId = 9)
|
||||
val npcs = NpcService(MapManager(), store)
|
||||
|
||||
npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9)
|
||||
|
||||
// Only Brendan's truck starts visible.
|
||||
(npcs.getNpcEntityId(50, 9, 4) != null) shouldBe true
|
||||
npcs.getNpcEntityId(50, 9, 5) shouldBe null
|
||||
npcs.getNpcEntityId(50, 9, 3) shouldBe null
|
||||
|
||||
StoryService(store)
|
||||
.clearFlag(character.info.id, HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MOM_OUTSIDE)
|
||||
npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9)
|
||||
|
||||
(npcs.getNpcEntityId(50, 9, 3) != null) shouldBe true
|
||||
}
|
||||
}
|
||||
|
||||
test("bedroom decoration placeholders are not spawned as npcs") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val character = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
val session = FakeSession(characterId = character.info.id, bankId = 51, mapId = 3)
|
||||
val npcs = NpcService(MapManager(), store)
|
||||
|
||||
npcs.spawnNpcsForMap(session, bankId = 51, mapId = 3)
|
||||
|
||||
// Decoration slots are not normal NPCs.
|
||||
(1..12).forEach { localId -> npcs.getNpcEntityId(51, 3, localId) shouldBe null }
|
||||
}
|
||||
}
|
||||
|
||||
test("the Littleroot twin moves beside the north exit after meeting the rival") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val character = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
val session = FakeSession(characterId = character.info.id, bankId = 50, mapId = 9)
|
||||
val story = StoryService(store)
|
||||
story.setVar(character.info.id, HoennVars.VAR_LITTLEROOT_TOWN_STATE, 1)
|
||||
val npcs = NpcService(MapManager(), store)
|
||||
|
||||
npcs.spawnNpcsForMap(session, bankId = 50, mapId = 9)
|
||||
|
||||
val twinId = npcs.getNpcEntityId(50, 9, 0)
|
||||
val twin =
|
||||
session.sent.filterIsInstance<NpcSpawnPacket>().single { it.entityId == twinId }
|
||||
twin.x shouldBe 10
|
||||
twin.y shouldBe 1
|
||||
}
|
||||
}
|
||||
|
||||
test("dynamic rival graphics resolve to the opposite player gender") {
|
||||
runTest {
|
||||
val mapManager = MapManager()
|
||||
|
||||
val femaleStore =
|
||||
CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val female = femaleStore.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
StoryService(femaleStore).clearFlag(female.info.id, HoennFlags.FLAG_HIDE_ROUTE_103_RIVAL)
|
||||
val femaleSession = FakeSession(characterId = female.info.id, bankId = 50, mapId = 18)
|
||||
val femaleNpcs = NpcService(mapManager, femaleStore)
|
||||
femaleNpcs.spawnNpcsForMap(femaleSession, bankId = 50, mapId = 18)
|
||||
val brendanId = femaleNpcs.getNpcEntityId(50, 18, 1)
|
||||
femaleSession.sent
|
||||
.filterIsInstance<NpcSpawnPacket>()
|
||||
.single { it.entityId == brendanId }
|
||||
.unk2 shouldBe 100
|
||||
|
||||
val maleStore =
|
||||
CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val male = maleStore.createCharacter(2, "Brendan", CharacterGender.MALE, Region.HOENN)
|
||||
StoryService(maleStore).clearFlag(male.info.id, HoennFlags.FLAG_HIDE_ROUTE_103_RIVAL)
|
||||
val maleSession = FakeSession(characterId = male.info.id, bankId = 50, mapId = 18)
|
||||
val maleNpcs = NpcService(mapManager, maleStore)
|
||||
maleNpcs.spawnNpcsForMap(maleSession, bankId = 50, mapId = 18)
|
||||
val mayId = maleNpcs.getNpcEntityId(50, 18, 1)
|
||||
maleSession.sent
|
||||
.filterIsInstance<NpcSpawnPacket>()
|
||||
.single { it.entityId == mayId }
|
||||
.unk2 shouldBe 105
|
||||
}
|
||||
}
|
||||
|
||||
test("completed rescue saves never restore the Route 101 Zigzagoon") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val character = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
StoryService(store).setFlag(character.info.id, HoennFlags.FLAG_RESCUED_BIRCH)
|
||||
val session = FakeSession(characterId = character.info.id, bankId = 50, mapId = 16)
|
||||
val npcs = NpcService(MapManager(), store)
|
||||
|
||||
npcs.spawnNpcsForMap(session, bankId = 50, mapId = 16)
|
||||
|
||||
npcs.getNpcEntityId(50, 16, 3) shouldBe null
|
||||
}
|
||||
}
|
||||
})
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
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.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.EntityLeavePacket
|
||||
import de.fiereu.openmmo.net.game.packets.EntityMovePacket
|
||||
@@ -35,7 +37,7 @@ class PresenceServiceTest :
|
||||
}
|
||||
|
||||
suspend fun CharacterStore.session(name: String, mapId: Int = 3): FakeSession {
|
||||
val character = createCharacter(userId = 1, name = name)
|
||||
val character = createCharacter(1, name, CharacterGender.MALE, Region.HOENN)
|
||||
return FakeSession(characterId = character.info.id, mapId = mapId)
|
||||
}
|
||||
|
||||
|
||||
+24
-2
@@ -1,8 +1,11 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
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.maps.MapManager
|
||||
import de.fiereu.openmmo.net.game.packets.DialogDataPacket
|
||||
import de.fiereu.openmmo.net.game.packets.NpcUpdatePacket
|
||||
import de.fiereu.openmmo.server.game.script.MovementStep
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import de.fiereu.openmmo.server.game.storage.EntityIdService
|
||||
@@ -18,7 +21,7 @@ class ScriptMovementServiceTest :
|
||||
FunSpec({
|
||||
fun service(store: CharacterStore): ScriptMovementService {
|
||||
val mapManager = MapManager()
|
||||
return ScriptMovementService(mapManager, NpcService(mapManager), store)
|
||||
return ScriptMovementService(mapManager, NpcService(mapManager, store), store)
|
||||
}
|
||||
|
||||
test("drive walks one tile per step and returns the final pose") {
|
||||
@@ -61,7 +64,7 @@ class ScriptMovementServiceTest :
|
||||
test("moveSelf commits the final tile to the character store") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val created = store.createCharacter(1, "Ash")
|
||||
val created = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN)
|
||||
val charId = created.info.id
|
||||
val session = FakeSession(characterId = charId)
|
||||
val state = session.attributes[de.fiereu.openmmo.server.game.session.PLAYER_STATE]!!
|
||||
@@ -75,4 +78,23 @@ class ScriptMovementServiceTest :
|
||||
store.getCharacter(charId)!!.info.positionX.toInt() shouldBe startX
|
||||
}
|
||||
}
|
||||
|
||||
test("repositionSelf sends the captured coordinate update and commits it") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val created = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
store.updatePosition(created.info.id, 7, 14, 50, 16)
|
||||
val session = FakeSession(characterId = created.info.id, bankId = 50, mapId = 16)
|
||||
val state = session.state()
|
||||
|
||||
service(store).repositionSelf(session, state, 6, 13, Direction.UP)
|
||||
|
||||
session.sent shouldBe
|
||||
listOf(
|
||||
NpcUpdatePacket(created.info.id, 1, 50, 16, 6, 13, 0xF6, 1),
|
||||
)
|
||||
store.getCharacter(created.info.id)!!.info.positionX shouldBe 6
|
||||
store.getCharacter(created.info.id)!!.info.positionY shouldBe 13
|
||||
}
|
||||
}
|
||||
})
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.openmmo.net.game.packets.PlayerVariableEntry
|
||||
import de.fiereu.openmmo.net.game.packets.StoryFlagUpdatePacket
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
class StoryClientStateTest :
|
||||
FunSpec({
|
||||
test("maps persisted GBA flags to the captured region and numeric id") {
|
||||
StoryClientState.flags(
|
||||
regionId = 1,
|
||||
flags = setOf(HoennFlags.FLAG_VISITED_LITTLEROOT_TOWN),
|
||||
) shouldBe listOf(StoryFlagUpdatePacket(1, 0x086f, enabled = true))
|
||||
}
|
||||
|
||||
test("maps GBA variable ids to their one-byte client keys") {
|
||||
StoryClientState.variables(
|
||||
regionId = 1,
|
||||
vars = mapOf(HoennVars.VAR_LITTLEROOT_INTRO_STATE to 7),
|
||||
) shouldBe listOf(PlayerVariableEntry(0x92.toByte(), 7))
|
||||
}
|
||||
|
||||
test("does not leak another region's story state") {
|
||||
StoryClientState.flags(
|
||||
regionId = 0,
|
||||
flags = setOf(HoennFlags.FLAG_VISITED_LITTLEROOT_TOWN),
|
||||
) shouldBe emptyList()
|
||||
StoryClientState.variables(
|
||||
regionId = 0,
|
||||
vars = mapOf(HoennVars.VAR_LITTLEROOT_INTRO_STATE to 7),
|
||||
) shouldBe emptyList()
|
||||
}
|
||||
})
|
||||
+12
-7
@@ -1,5 +1,7 @@
|
||||
package de.fiereu.openmmo.server.game.services
|
||||
|
||||
import de.fiereu.openmmo.common.enums.CharacterGender
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.server.game.storage.CharacterStore
|
||||
import de.fiereu.openmmo.server.game.storage.EntityIdService
|
||||
import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository
|
||||
@@ -14,7 +16,7 @@ class StoryServiceTest :
|
||||
test("flags default unset, can be set and cleared") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
|
||||
story.isFlagSet(id, "hoenn/FLAG_ADVENTURE_STARTED") shouldBe false
|
||||
@@ -28,7 +30,7 @@ class StoryServiceTest :
|
||||
test("vars default to 0, store a value, and drop back to default on 0") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
|
||||
story.getVar(id, "hoenn/VAR_LITTLEROOT_TOWN_STATE") shouldBe 0
|
||||
@@ -45,13 +47,15 @@ class StoryServiceTest :
|
||||
test("setFlag copies instead of mutating the cached set") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val before = store.getCharacter(id)!!.storyFlags
|
||||
val initialSize = before.size
|
||||
|
||||
StoryService(store).setFlag(id, "hoenn/FLAG_RESCUED_BIRCH")
|
||||
|
||||
before.size shouldBe 0
|
||||
store.getCharacter(id)!!.storyFlags.size shouldBe 1
|
||||
before.size shouldBe initialSize
|
||||
("hoenn/FLAG_RESCUED_BIRCH" in before) shouldBe false
|
||||
store.getCharacter(id)!!.storyFlags.size shouldBe initialSize + 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +63,15 @@ class StoryServiceTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
val story = StoryService(store)
|
||||
|
||||
story.setFlag(id, "hoenn/FLAG_ADVENTURE_STARTED")
|
||||
story.setVar(id, "hoenn/VAR_LITTLEROOT_TOWN_STATE", 4)
|
||||
store.flushAll()
|
||||
|
||||
repo.saved[id]!!.storyFlags shouldBe setOf("hoenn/FLAG_ADVENTURE_STARTED")
|
||||
repo.saved[id]!!.storyFlags shouldBe store.getCharacter(id)!!.storyFlags
|
||||
("hoenn/FLAG_ADVENTURE_STARTED" in repo.saved[id]!!.storyFlags) shouldBe true
|
||||
// New characters are seeded with the intro var, so check the entry rather than the map.
|
||||
repo.saved[id]!!.storyVars["hoenn/VAR_LITTLEROOT_TOWN_STATE"] shouldBe 4
|
||||
}
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package de.fiereu.openmmo.server.game.storage
|
||||
|
||||
import de.fiereu.openmmo.common.enums.CharacterGender
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennFlags
|
||||
import de.fiereu.openmmo.story.generated.hoenn.HoennVars
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class CharacterIntroTest :
|
||||
FunSpec({
|
||||
test("male characters start on Brendan's side of the moving truck intro") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
|
||||
val character = store.createCharacter(1, "Brendan", CharacterGender.MALE, Region.HOENN)
|
||||
|
||||
character.info.rivalSex shouldBe 0
|
||||
character.info.dynamicWarp!!.x shouldBe 3
|
||||
character.storyVars[HoennVars.VAR_LITTLEROOT_INTRO_STATE] shouldBe 1
|
||||
character.storyVars[HoennVars.VAR_LITTLEROOT_HOUSES_STATE_BRENDAN] shouldBe 1
|
||||
(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_TRUCK in character.storyFlags) shouldBe
|
||||
true
|
||||
(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_TRUCK in
|
||||
character.storyFlags) shouldBe false
|
||||
}
|
||||
}
|
||||
|
||||
test("female characters start on May's side of the moving truck intro") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
|
||||
val character = store.createCharacter(1, "May", CharacterGender.FEMALE, Region.HOENN)
|
||||
|
||||
character.info.rivalSex shouldBe 1
|
||||
character.info.dynamicWarp!!.x shouldBe 12
|
||||
character.storyVars[HoennVars.VAR_LITTLEROOT_INTRO_STATE] shouldBe 2
|
||||
character.storyVars[HoennVars.VAR_LITTLEROOT_HOUSES_STATE_MAY] shouldBe 1
|
||||
(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_BRENDANS_HOUSE_TRUCK in
|
||||
character.storyFlags) shouldBe true
|
||||
(HoennFlags.FLAG_HIDE_LITTLEROOT_TOWN_MAYS_HOUSE_TRUCK in character.storyFlags) shouldBe
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
test("Kanto characters use the captured Pallet bedroom start") {
|
||||
runTest {
|
||||
val store = CharacterStore(FakeCharacterRepository(), EntityIdService(), backgroundScope)
|
||||
|
||||
val character =
|
||||
store.createCharacter(
|
||||
userId = 1,
|
||||
name = "Leaf",
|
||||
gender = CharacterGender.FEMALE,
|
||||
startingRegion = Region.KANTO,
|
||||
)
|
||||
|
||||
character.info.positionRegionId shouldBe 0
|
||||
character.info.positionBankId shouldBe 4
|
||||
character.info.positionMapId shouldBe 1
|
||||
character.info.positionX shouldBe 6
|
||||
character.info.positionY shouldBe 6
|
||||
character.info.dynamicWarp shouldBe null
|
||||
character.storyFlags shouldBe emptySet()
|
||||
character.storyVars shouldBe emptyMap()
|
||||
}
|
||||
}
|
||||
|
||||
test("unsupported region wire values remain locked") { Region.byWireValue(2) shouldBe null }
|
||||
})
|
||||
+41
-11
@@ -1,9 +1,11 @@
|
||||
package de.fiereu.openmmo.server.game.storage
|
||||
|
||||
import de.fiereu.openmmo.common.Pokemon
|
||||
import de.fiereu.openmmo.common.enums.CharacterGender
|
||||
import de.fiereu.openmmo.common.enums.EVs
|
||||
import de.fiereu.openmmo.common.enums.IVs
|
||||
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||
import de.fiereu.openmmo.common.enums.Region
|
||||
import de.fiereu.openmmo.server.game.testsupport.FakeCharacterRepository
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.nulls.shouldNotBeNull
|
||||
@@ -45,7 +47,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val created = store.createCharacter(1, "Ash")
|
||||
val created = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN)
|
||||
repo.saved[created.info.id].shouldNotBeNull()
|
||||
repo.saved[created.info.id]!!.pokemon.size shouldBe 0
|
||||
}
|
||||
@@ -55,7 +57,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
|
||||
store.updatePosition(id, 10, 20)
|
||||
store.flushAll()
|
||||
@@ -69,7 +71,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
|
||||
store.addMoney(id, 5000)
|
||||
|
||||
@@ -82,7 +84,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val created = store.createCharacter(1, "Ash")
|
||||
val created = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN)
|
||||
val before = store.getCharacter(created.info.id)!!.pokemon
|
||||
|
||||
store.addPokemon(created.info.id, testPokemon(created.info.id))
|
||||
@@ -96,7 +98,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val created = store.createCharacter(1, "Ash")
|
||||
val created = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN)
|
||||
val mon = testPokemon(created.info.id)
|
||||
store.addPokemon(created.info.id, mon)
|
||||
store.flushAll()
|
||||
@@ -118,7 +120,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
|
||||
store.addMoney(id, 1)
|
||||
repo.failNextSave = true
|
||||
@@ -135,7 +137,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), this)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
store.addMoney(id, 5)
|
||||
|
||||
store.unloadCharacterAsync(id)
|
||||
@@ -151,7 +153,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), this)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
store.addMoney(id, 1)
|
||||
repo.failNextSave = true
|
||||
|
||||
@@ -169,7 +171,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), this)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
|
||||
store.unloadCharacterAsync(id)
|
||||
store.getOrLoadCharacter(id).shouldNotBeNull()
|
||||
@@ -183,7 +185,7 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), this)
|
||||
val id = store.createCharacter(1, "Ash").info.id
|
||||
val id = store.createCharacter(1, "Ash", CharacterGender.MALE, Region.HOENN).info.id
|
||||
store.addMoney(id, 7)
|
||||
|
||||
store.shutdown()
|
||||
@@ -196,7 +198,8 @@ class CharacterStoreCacheTest :
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val seedStore = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = seedStore.createCharacter(7, "Misty").info.id
|
||||
val id =
|
||||
seedStore.createCharacter(7, "Misty", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val loaded = store.getCharactersByUser(7)
|
||||
@@ -204,4 +207,31 @@ class CharacterStoreCacheTest :
|
||||
store.getCharacter(id).shouldNotBeNull()
|
||||
}
|
||||
}
|
||||
|
||||
test("deleting an owned character removes its persisted and cached aggregate") {
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(7, "Misty", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
|
||||
store.deleteCharacter(userId = 7, characterId = id) shouldBe true
|
||||
|
||||
repo.saved[id] shouldBe null
|
||||
store.getCharacter(id) shouldBe null
|
||||
store.getCharactersByUser(7) shouldBe emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
test("character deletion rejects an id owned by another user") {
|
||||
runTest {
|
||||
val repo = FakeCharacterRepository()
|
||||
val store = CharacterStore(repo, EntityIdService(), backgroundScope)
|
||||
val id = store.createCharacter(7, "Misty", CharacterGender.FEMALE, Region.HOENN).info.id
|
||||
|
||||
store.deleteCharacter(userId = 8, characterId = id) shouldBe false
|
||||
|
||||
repo.saved[id].shouldNotBeNull()
|
||||
store.getCharacter(id).shouldNotBeNull()
|
||||
}
|
||||
}
|
||||
})
|
||||
+6
@@ -27,4 +27,10 @@ class FakeCharacterRepository : CharacterRepository {
|
||||
saveCount.incrementAndGet()
|
||||
saved[stored.info.id] = stored
|
||||
}
|
||||
|
||||
override suspend fun deleteById(userId: Int, id: Long): Boolean {
|
||||
val stored = saved[id] ?: return false
|
||||
if (stored.info.userId != userId) return false
|
||||
return saved.remove(id, stored)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user