From 30c63e58451eafe8516416138bda43119cb29bdf Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 22 Apr 2023 11:37:06 +0700 Subject: [PATCH] root.monsterParameters --- .../dbotthepony/kstarbound/ObjectRegistry.kt | 5 ++++ .../ru/dbotthepony/kstarbound/Starbound.kt | 14 +++++++++++ .../defs/monster/ActionDefinition.kt | 7 ++++++ .../defs/monster/MonsterTypeDefinition.kt | 24 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/ActionDefinition.kt create mode 100644 src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt index 75b61523..f0c38ccd 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt @@ -20,6 +20,7 @@ import ru.dbotthepony.kstarbound.api.IStarboundFile import ru.dbotthepony.kstarbound.lua.LuaState import ru.dbotthepony.kstarbound.util.PathStack import ru.dbotthepony.kstarbound.util.set +import ru.dbotthepony.kstarbound.util.traverseJsonPath import java.util.* import kotlin.reflect.KClass @@ -116,6 +117,10 @@ class RegistryObject( return mergeJsonElements(json, gson.toJsonTree(value)) } + fun traverseJsonPath(path: String): JsonElement? { + return traverseJsonPath(path, mergeJsonElements(json, gson.toJsonTree(value))) + } + override fun equals(other: Any?): Boolean { return other === this || other is RegistryObject<*> && other.value == value && other.json == json } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 454dda7f..7a84a806 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -34,6 +34,7 @@ import ru.dbotthepony.kstarbound.defs.item.impl.LegsArmorItemPrototype import ru.dbotthepony.kstarbound.defs.item.impl.LiquidItemPrototype import ru.dbotthepony.kstarbound.defs.item.impl.MaterialItemPrototype import ru.dbotthepony.kstarbound.defs.monster.MonsterSkillDefinition +import ru.dbotthepony.kstarbound.defs.monster.MonsterTypeDefinition import ru.dbotthepony.kstarbound.defs.npc.NpcTypeDefinition import ru.dbotthepony.kstarbound.defs.npc.TenantDefinition import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition @@ -152,6 +153,9 @@ class Starbound : ISBFileLocator { private val _monsterSkills = ObjectRegistry("monster skills", MonsterSkillDefinition::name) val monsterSkills = _monsterSkills.view + private val _monsterTypes = ObjectRegistry("monster types", MonsterTypeDefinition::type) + val monsterTypes = _monsterTypes.view + val gson: Gson = with(GsonBuilder()) { serializeNulls() setDateFormat(DateFormat.LONG) @@ -245,6 +249,8 @@ class Starbound : ISBFileLocator { add(_projectiles) add(_tenants) add(_treasurePools) + add(_monsterSkills) + add(_monsterTypes) }) registerTypeAdapter(LongRangeAdapter) @@ -736,6 +742,13 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("monsterParameters", this) { args -> + val name = args.getString() + val monster = monsterTypes[name] ?: throw NoSuchElementException("No such monster type $name") + args.push(monster.traverseJsonPath("baseParameters")) + 1 + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") @@ -931,6 +944,7 @@ class Starbound : ISBFileLocator { loadStage(callback, _projectiles, ext2files["projectile"] ?: listOf()) loadStage(callback, _tenants, ext2files["tenant"] ?: listOf()) loadStage(callback, _monsterSkills, ext2files["monsterskill"] ?: listOf()) + loadStage(callback, _monsterTypes, ext2files["monstertype"] ?: listOf()) pathStack.block("/") { //playerDefinition = gson.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/ActionDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/ActionDefinition.kt new file mode 100644 index 00000000..6c0db657 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/ActionDefinition.kt @@ -0,0 +1,7 @@ +package ru.dbotthepony.kstarbound.defs.monster + +data class ActionDefinition( + val name: String, // ссылается на .nodes? + val cooldown: Double = -1.0, + // val parameters +) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt new file mode 100644 index 00000000..bf3db1dc --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt @@ -0,0 +1,24 @@ +package ru.dbotthepony.kstarbound.defs.monster + +import com.google.common.collect.ImmutableList +import com.google.common.collect.ImmutableMap +import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kstarbound.defs.AssetReference +import ru.dbotthepony.kstarbound.defs.IThingWithDescription +import ru.dbotthepony.kstarbound.defs.RegistryReference +import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition +import ru.dbotthepony.kstarbound.defs.item.TreasurePoolDefinition +import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory + +@JsonFactory +data class MonsterTypeDefinition( + val type: String, + override val shortdescription: String, + override val description: String, + val categories: ImmutableSet = ImmutableSet.of(), + val parts: ImmutableSet = ImmutableSet.of(), + val animation: AssetReference, + // [ { "default" : "poptopTreasure", "bow" : "poptopHunting" } ], + val dropPools: ImmutableList>>, + // val baseParameters +) : IThingWithDescription