root.monsterParameters

This commit is contained in:
DBotThePony 2023-04-22 11:37:06 +07:00
parent f04df9feda
commit 30c63e5845
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 50 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import ru.dbotthepony.kstarbound.api.IStarboundFile
import ru.dbotthepony.kstarbound.lua.LuaState import ru.dbotthepony.kstarbound.lua.LuaState
import ru.dbotthepony.kstarbound.util.PathStack import ru.dbotthepony.kstarbound.util.PathStack
import ru.dbotthepony.kstarbound.util.set import ru.dbotthepony.kstarbound.util.set
import ru.dbotthepony.kstarbound.util.traverseJsonPath
import java.util.* import java.util.*
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -116,6 +117,10 @@ class RegistryObject<T : Any>(
return mergeJsonElements(json, gson.toJsonTree(value)) 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 { override fun equals(other: Any?): Boolean {
return other === this || other is RegistryObject<*> && other.value == value && other.json == json return other === this || other is RegistryObject<*> && other.value == value && other.json == json
} }

View File

@ -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.LiquidItemPrototype
import ru.dbotthepony.kstarbound.defs.item.impl.MaterialItemPrototype import ru.dbotthepony.kstarbound.defs.item.impl.MaterialItemPrototype
import ru.dbotthepony.kstarbound.defs.monster.MonsterSkillDefinition 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.NpcTypeDefinition
import ru.dbotthepony.kstarbound.defs.npc.TenantDefinition import ru.dbotthepony.kstarbound.defs.npc.TenantDefinition
import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
@ -152,6 +153,9 @@ class Starbound : ISBFileLocator {
private val _monsterSkills = ObjectRegistry("monster skills", MonsterSkillDefinition::name) private val _monsterSkills = ObjectRegistry("monster skills", MonsterSkillDefinition::name)
val monsterSkills = _monsterSkills.view val monsterSkills = _monsterSkills.view
private val _monsterTypes = ObjectRegistry("monster types", MonsterTypeDefinition::type)
val monsterTypes = _monsterTypes.view
val gson: Gson = with(GsonBuilder()) { val gson: Gson = with(GsonBuilder()) {
serializeNulls() serializeNulls()
setDateFormat(DateFormat.LONG) setDateFormat(DateFormat.LONG)
@ -245,6 +249,8 @@ class Starbound : ISBFileLocator {
add(_projectiles) add(_projectiles)
add(_tenants) add(_tenants)
add(_treasurePools) add(_treasurePools)
add(_monsterSkills)
add(_monsterTypes)
}) })
registerTypeAdapter(LongRangeAdapter) registerTypeAdapter(LongRangeAdapter)
@ -736,6 +742,13 @@ class Starbound : ISBFileLocator {
1 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.pop()
state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua")
@ -931,6 +944,7 @@ class Starbound : ISBFileLocator {
loadStage(callback, _projectiles, ext2files["projectile"] ?: listOf()) loadStage(callback, _projectiles, ext2files["projectile"] ?: listOf())
loadStage(callback, _tenants, ext2files["tenant"] ?: listOf()) loadStage(callback, _tenants, ext2files["tenant"] ?: listOf())
loadStage(callback, _monsterSkills, ext2files["monsterskill"] ?: listOf()) loadStage(callback, _monsterSkills, ext2files["monsterskill"] ?: listOf())
loadStage(callback, _monsterTypes, ext2files["monstertype"] ?: listOf())
pathStack.block("/") { pathStack.block("/") {
//playerDefinition = gson.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java) //playerDefinition = gson.fromJson(locate("/player.config").reader(), PlayerDefinition::class.java)

View File

@ -0,0 +1,7 @@
package ru.dbotthepony.kstarbound.defs.monster
data class ActionDefinition(
val name: String, // ссылается на .nodes?
val cooldown: Double = -1.0,
// val parameters
)

View File

@ -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<String> = ImmutableSet.of(),
val parts: ImmutableSet<String> = ImmutableSet.of(),
val animation: AssetReference<AnimationDefinition>,
// [ { "default" : "poptopTreasure", "bow" : "poptopHunting" } ],
val dropPools: ImmutableList<ImmutableMap<String, RegistryReference<TreasurePoolDefinition>>>,
// val baseParameters
) : IThingWithDescription