AI script is now persistent (you can keep variables)

Former-commit-id: 20ca0a8e80f0712c4a3d6a21ee9ae5f15c46c406
Former-commit-id: 2f1cfc2c9b60981053e928a3e7b07117d3b18919
This commit is contained in:
Song Minjae
2016-12-27 21:56:34 +09:00
parent c77a89d0db
commit 9fc2d1db08
6 changed files with 51 additions and 79 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.AIControlled
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.ActorWithBody
@@ -13,13 +14,13 @@ import org.luaj.vm2.lib.ZeroArgFunction
/**
* Created by minjaesong on 16-10-24.
*/
internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
internal class AILuaAPI(val g: Globals, actor: ActorWithBody) {
init {
if (actor !is AIControlled)
throw IllegalArgumentException("The actor is not AIControlled! $actor")
// load things. WARNING: THIS IS MANUAL!
// load functions and set up constants
g["ai"] = LuaValue.tableOf()
g["ai"]["getSelfActorInfo"] = GetSelfActorInfo(actor)
@@ -35,7 +36,10 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
g["ai"]["moveRight"] = MoveRight(actor)
g["ai"]["moveTo"] = MoveTo(actor)
g["ai"]["jump"] = Jump(actor)
}
fun update(delta: Int) {
// set up variables
}
companion object {
@@ -59,7 +63,7 @@ internal class AILuaAPI(g: Globals, actor: ActorWithBody) {
t["collisionType"] = actor.collisionType
t["strength"] = actor.actorValue.getAsInt(AVKey.STRENGTH) ?: 0
t["strength"] = actor.avStrength
val lumrgb: Int = actor.actorValue.getAsInt(AVKey.LUMINOSITY) ?: 0
val MUL_2 = LightmapRenderer.MUL_2

View File

@@ -7,10 +7,14 @@ package net.torvald.terrarum.gameactors.ai.scripts
*/
object PokemonNPCAI {
operator fun invoke(): String = """
ai.jump()
ai.moveRight()
thisActorInfo = ai.getSelfActorInfo()
print(thisActorInfo.strength)
counter = 1
function update(delta)
ai.moveRight()
print("delta", delta)
counter = counter + delta
print("testcounter", counter)
end
"""
}