mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
now accepts all the value punched into the creature raw
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
"strength": 1000,
|
"strength": 1000,
|
||||||
"strengthmult": [90,95,98,100,102,105,110],
|
"strengthmult": [90,95,98,100,102,105,110],
|
||||||
|
|
||||||
"accel": 0.32,
|
"accel": 0.67,
|
||||||
|
"accelbuff": 1.0,
|
||||||
|
|
||||||
"speed": 3.0,
|
"speed": 3.0,
|
||||||
"speedmult": [100,100,100,100,100,100,100],
|
"speedmult": [100,100,100,100,100,100,100],
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"strengthmult": [90,95,98,100,102,105,110],
|
"strengthmult": [90,95,98,100,102,105,110],
|
||||||
|
|
||||||
"accel": 0.67,
|
"accel": 0.67,
|
||||||
|
"accelbuff": 1.0,
|
||||||
|
|
||||||
"speed": 6.0,
|
"speed": 6.0,
|
||||||
"speedmult": [100,100,100,100,100,100,100],
|
"speedmult": [100,100,100,100,100,100,100],
|
||||||
|
|||||||
@@ -904,18 +904,23 @@ open class ActorWithBody(renderOrder: RenderOrder, val physProp: PhysProperties)
|
|||||||
)
|
)
|
||||||
|
|
||||||
// adjust finalDisplacement for honest-to-god staircasing
|
// adjust finalDisplacement for honest-to-god staircasing
|
||||||
if (staircaseStatus in listOf(1, 4) && selfCollisionStatus in (if (gravitation.y >= 0.0) listOf(3,6) else listOf(9, 12))) {
|
if (vectorSum.y <= 0.0 && staircaseStatus in listOf(1, 4) && selfCollisionStatus in (if (gravitation.y >= 0.0) listOf(3,6) else listOf(9, 12))) {
|
||||||
// TODO!!
|
// TODO!!
|
||||||
// remove Y displacement
|
// remove Y displacement
|
||||||
// let original X velocity to pass-thru instead of snapping to tiles coded above
|
// let original X velocity to pass-thru instead of snapping to tiles coded above
|
||||||
// pass-thru values are held by the vectorSum
|
// pass-thru values are held by the vectorSum
|
||||||
println("staiscasing: $staircaseStatus for $selfCollisionStatus")
|
println("staircasing: $staircaseStatus for $selfCollisionStatus")
|
||||||
|
|
||||||
finalDisplacement.y = if (staircaseStatus == COLLIDING_LEFT) -stairHeightLeft else -stairHeightRight
|
finalDisplacement.y = if (staircaseStatus == COLLIDING_LEFT) -stairHeightLeft else -stairHeightRight
|
||||||
finalDisplacement.x = vectorSum.x
|
finalDisplacement.x = vectorSum.x
|
||||||
|
|
||||||
bounceX = false
|
bounceX = false
|
||||||
bounceY = false
|
bounceY = false
|
||||||
|
|
||||||
|
// maybe slow down the player?
|
||||||
|
if (controllerV != null) {
|
||||||
|
controllerV!!.x *= 0.5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
bounceX = angleOfIncidence == angleThreshold || displacementUnitVector.x != 0.0
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.torvald.terrarum.utils.JsonFetcher
|
|||||||
import net.torvald.random.Fudge3
|
import net.torvald.random.Fudge3
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import net.torvald.terrarum.AppLoader.printdbg
|
||||||
import net.torvald.terrarum.ModMgr
|
import net.torvald.terrarum.ModMgr
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.ActorValue
|
import net.torvald.terrarum.gameactors.ActorValue
|
||||||
@@ -15,6 +16,7 @@ import java.security.SecureRandom
|
|||||||
object InjectCreatureRaw {
|
object InjectCreatureRaw {
|
||||||
|
|
||||||
private const val JSONMULT = "mult" // one appears in JSON files
|
private const val JSONMULT = "mult" // one appears in JSON files
|
||||||
|
private const val BUFF = AVKey.BUFF // one appears in JSON files
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Injects' creature raw ActorValue to the ActorValue reference provided.
|
* 'Injects' creature raw ActorValue to the ActorValue reference provided.
|
||||||
@@ -25,115 +27,46 @@ object InjectCreatureRaw {
|
|||||||
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
|
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
|
||||||
val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName"))
|
val jsonObj = JsonFetcher(ModMgr.getPath(module, "creatures/$jsonFileName"))
|
||||||
|
|
||||||
// TODO make it work for every possible keys (maybe except ones starts with '_')
|
jsonObj.keySet().filter { !it.startsWith("_") }.forEach { key ->
|
||||||
|
|
||||||
val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE)
|
val diceRollers = ArrayList<String>()
|
||||||
val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL)
|
|
||||||
val elementsDouble = arrayOf(AVKey.BASEMASS, AVKey.ACCEL)
|
|
||||||
val elementsDoubleVariable = arrayOf(AVKey.STRENGTH, AVKey.SPEED, AVKey.JUMPPOWER, AVKey.SCALE)
|
|
||||||
val elementsBoolean = arrayOf(AVKey.INTELLIGENT)
|
|
||||||
// val elementsMultiplyFromOne = arrayOf()
|
|
||||||
|
|
||||||
setAVInts(actorValueRef, elementsInt, jsonObj)
|
jsonObj[key].let {
|
||||||
setAVStrings(actorValueRef, elementsString, jsonObj)
|
if (it.isJsonPrimitive) {
|
||||||
setAVDoubles(actorValueRef, elementsDouble, jsonObj)
|
val raw = it.asString
|
||||||
setAVDoublesVariable(actorValueRef, elementsDoubleVariable, jsonObj)
|
val lowraw = raw.toLowerCase()
|
||||||
// setAVMultiplyFromOne(actorValueRef, elementsMultiplyFromOne, jsonObj)
|
// can the value be cast to Boolean?
|
||||||
setAVBooleans(actorValueRef, elementsBoolean, jsonObj)
|
if (lowraw == "true") actorValueRef[key] = true
|
||||||
|
else if (lowraw == "false") actorValueRef[key] = false
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
actorValueRef[key] =
|
||||||
|
if (raw.contains('.')) it.asDouble
|
||||||
|
else it.asInt
|
||||||
|
}
|
||||||
|
catch (e: NumberFormatException) {
|
||||||
|
actorValueRef[key] = raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key.endsWith(JSONMULT) && it.isJsonArray) {
|
||||||
|
diceRollers.add(key)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printdbg(this, "Unknown Creature Raw key: $key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
actorValueRef[AVKey.ACCEL] = ActorHumanoid.WALK_ACCEL_BASE
|
diceRollers.forEach { keymult ->
|
||||||
actorValueRef[AVKey.ACCELBUFF] = 1.0
|
val keybase = keymult.substring(0, keymult.length - 4)
|
||||||
}
|
val baseValue = jsonObj[keybase].asDouble
|
||||||
|
val selected = Fudge3(SecureRandom()).rollForArray()
|
||||||
|
val mult = jsonObj[keymult].asJsonArray.get(selected).asInt
|
||||||
|
val realValue = baseValue * mult / 100.0
|
||||||
|
|
||||||
/**
|
actorValueRef[keybase] = realValue
|
||||||
* Fetch and set actor values that have 'variable' appended. E.g. strength
|
actorValueRef[keybase + BUFF] = 1.0
|
||||||
* @param avRef
|
}
|
||||||
* *
|
|
||||||
* @param elemSet
|
|
||||||
* *
|
|
||||||
* @param jsonObject
|
|
||||||
*/
|
|
||||||
private fun setAVDoublesVariable(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
val baseValue = jsonObject.get(s).asDouble
|
|
||||||
// roll fudge dice and get value [-3, 3] as [0, 6]
|
|
||||||
val varSelected = Fudge3(SecureRandom()).rollForArray()
|
|
||||||
// get multiplier from json. Assuming percentile
|
|
||||||
val multiplier = jsonObject.get(s + JSONMULT).asJsonArray.get(varSelected).asInt
|
|
||||||
val realValue = baseValue * multiplier / 100.0
|
|
||||||
|
|
||||||
avRef[s] = realValue
|
|
||||||
avRef[s + "buff"] = 1.0 // buffed value: use multiplied value as 'base' for all sort of things
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch and set string actor values
|
|
||||||
* @param avRef
|
|
||||||
* *
|
|
||||||
* @param elemSet
|
|
||||||
* *
|
|
||||||
* @param jsonObject
|
|
||||||
*/
|
|
||||||
private fun setAVStrings(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
val key = jsonObject.get(s).asString
|
|
||||||
avRef[s] = Lang[key]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch and set double actor values
|
|
||||||
* @param avRef
|
|
||||||
* *
|
|
||||||
* @param elemSet
|
|
||||||
* *
|
|
||||||
* @param jsonObject
|
|
||||||
*/
|
|
||||||
private fun setAVDoubles(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
avRef[s] = jsonObject.get(s).asDouble
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch and set int actor values
|
|
||||||
* @param avRef
|
|
||||||
* *
|
|
||||||
* @param elemSet
|
|
||||||
* *
|
|
||||||
* @param jsonObject
|
|
||||||
*/
|
|
||||||
private fun setAVInts(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
avRef[s] = jsonObject.get(s).asInt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch and set actor values that should multiplier be applied to the base value of 1.
|
|
||||||
* @param avRef
|
|
||||||
* *
|
|
||||||
* @param elemSet
|
|
||||||
* *
|
|
||||||
* @param jsonObject
|
|
||||||
*/
|
|
||||||
private fun setAVMultiplyFromOne(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
val baseValue = 1.0
|
|
||||||
// roll fudge dice and get value [-3, 3] as [0, 6]
|
|
||||||
val varSelected = Fudge3(SecureRandom()).rollForArray()
|
|
||||||
// get multiplier from json. Assuming percentile
|
|
||||||
val multiplier = jsonObject.get(s).asJsonArray.get(varSelected).asInt
|
|
||||||
val realValue = baseValue * multiplier / 100.0
|
|
||||||
|
|
||||||
avRef[s] = realValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setAVBooleans(avRef: ActorValue, elemSet: Array<String>, jsonObject: JsonObject) {
|
|
||||||
for (s in elemSet) {
|
|
||||||
avRef[s] = jsonObject.get(s).asBoolean
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user