actors are now active/dormant depending on the distance to the player, only the active actors are to be updated. Actors outside of the camera (actually a distance to the player) are not rendered

Former-commit-id: 5f80c2ef3592aab5567723087c264e05458e98b3
Former-commit-id: 7714c6f5a6d7a48d4f5adfe8f6990b249bdb80b0
This commit is contained in:
Song Minjae
2016-04-24 16:37:08 +09:00
parent 1a1159b643
commit c4b64140be
16 changed files with 332 additions and 146 deletions

View File

@@ -39,7 +39,7 @@ class CodexEdictis : ConsoleCommand {
private fun printList() {
val echo = Echo()
echo.execute(Lang.get("DEV_MESSAGE_CONSOLE_AVAILABLE_COMMANDS"))
CommandDict.dict.keys.forEach { s -> echo.execute("] " + s) }
CommandDict.dict.keys.forEach { s -> echo.execute(" " + s) }
}
}

View File

@@ -35,6 +35,7 @@ object CommandDict {
Pair("gettime", GetTime()),
Pair("settimedelta", SetTimeDelta()),
Pair("help", Help()),
Pair("version", Version()),
// Test codes
Pair("bulletintest", SetBulletin()),

View File

@@ -1,7 +1,10 @@
package net.torvald.terrarum.console
import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import java.time.LocalDateTime
import java.time.ZonedDateTime
import java.util.ArrayList
import java.util.Formatter
@@ -14,8 +17,14 @@ object CommandInterpreter {
private val commandsNoAuth = arrayOf("auth", "qqq", "zoom", "setlocale", "getlocale", "help")
private val ccW = GameFontBase.colToCode["w"]
private val ccG = GameFontBase.colToCode["g"]
private val ccY = GameFontBase.colToCode["y"]
private val ccR = GameFontBase.colToCode["r"]
fun execute(command: String) {
val cmd = parse(command)
val cmd: Array<CommandInput?> = parse(command)
val echo = Echo()
for (single_command in cmd) {
var commandObj: ConsoleCommand? = null
@@ -38,6 +47,8 @@ object CommandInterpreter {
}
finally {
echo.execute("$ccW> $single_command") // prints out the input
println("${ZonedDateTime.now()} [CommandInterpreter] issuing command '$single_command'")
try {
if (commandObj != null) {
commandObj.execute(single_command!!.toStringArray())
@@ -50,7 +61,7 @@ object CommandInterpreter {
catch (e: Exception) {
System.err.print("[CommandInterpreter] ")
e.printStackTrace()
Echo().error(Lang["ERROR_GENERIC_TEXT"])
echo.error(Lang["ERROR_GENERIC_TEXT"])
}
}
@@ -112,5 +123,16 @@ object CommandInterpreter {
val argsCount: Int
get() = tokens.size
override fun toString(): String {
val sb = StringBuilder()
tokens.forEachIndexed { i, s ->
if (i == 0)
sb.append("${ccY}$s${ccG}")
else
sb.append(" $s")
}
return sb.toString()
}
}
}

View File

@@ -1,13 +1,21 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.gameactors.ActorValue
import net.torvald.terrarum.Game
import com.sun.javaws.exceptions.InvalidArgumentException
import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.Terrarum
/**
* Created by minjaesong on 16-01-19.
*/
class GetAV : ConsoleCommand {
val ccW = GameFontBase.colToCode["w"]
val ccG = GameFontBase.colToCode["g"]
val ccY = GameFontBase.colToCode["y"]
val ccM = GameFontBase.colToCode["m"]
val ccK = GameFontBase.colToCode["k"]
val ccO = GameFontBase.colToCode["o"]
override fun execute(args: Array<String>) {
val echo = Echo()
@@ -17,8 +25,12 @@ class GetAV : ConsoleCommand {
val av = Terrarum.game.player.actorValue
val keyset = av.keySet
echo.execute("== ActorValue list for player ==")
keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") }
echo.execute("$ccW== ActorValue list for ${ccY}player $ccW==")
println("[GetAV] == ActorValue list for 'player' ==")
keyset.forEach { elem ->
echo.execute("$ccM$elem $ccW= $ccG${av[elem as String]}")
println("[GetAV] $elem = ${av[elem]}")
}
}
else if (args.size != 3 && args.size != 2) {
printUsage()
@@ -26,50 +38,69 @@ class GetAV : ConsoleCommand {
else if (args.size == 2) {
// check if args[1] is number or not
if (!args[1].isNum()) { // args[1] is ActorValue name
echo.execute("player.${args[1]} = "
+ Terrarum.game.player.actorValue[args[1]]
+ " ("
+ Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
+ ")"
echo.execute("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
Terrarum.game.player.actorValue[args[1]] +
" $ccO" +
Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
Terrarum.game.player.actorValue[args[1]] +
" " +
Terrarum.game.player.actorValue[args[1]]!!.javaClass.simpleName
)
}
else { // args[1] is actor ID
val av = Terrarum.game.getActor(args[1].toInt()).actorValue
else {
// args[1] is actor ID
val actor = Terrarum.game.getActor(args[1].toInt())
val av = actor.actorValue
val keyset = av.keySet
echo.execute("== ActorValue list for ${args[1].toInt()} ==")
if (keyset.size == 0)
echo.execute("(nothing)")
else
keyset.forEach { elem -> echo.execute("$elem = ${av[elem as String]}") }
echo.execute("$ccW== ActorValue list for $ccY$actor $ccW==")
println("[GetAV] == ActorValue list for '$actor' ==")
if (keyset.size == 0) {
echo.execute("$ccK(nothing)")
println("[GetAV] (nothing)")
}
else {
keyset.forEach { elem ->
echo.execute("$ccM$elem $ccW= $ccG${av[elem as String]}")
println("[GetAV] $elem = ${av[elem]}")
}
}
}
}
else if (args.size == 3) {
val id = args[1].toInt()
val av = args[2]
echo.execute("$id.$av = " +
echo.execute("$ccW$id.$ccM$av $ccW= $ccG" +
Terrarum.game.getActor(id).actorValue[av] +
" (" +
Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName +
")"
" $ccO" +
Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName
)
println("id.av = " +
Terrarum.game.getActor(id).actorValue[av] +
" " +
Terrarum.game.getActor(id).actorValue[av]!!.javaClass.simpleName
)
}
}
catch (e: NullPointerException) {
if (args.size == 2) {
echo.error(args[1] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[1]}: actor value does not exist.")
}
else if (args.size == 3) {
echo.error(args[2] + ": actor value does not exist.")
System.err.println("[GetAV] ${args[2]}: actor value does not exist.")
}
else {
throw NullPointerException()
}
}
catch (e1: IllegalArgumentException) {
if (args.size == 3) {
echo.error(args[1] + ": no actor with this ID.")
}
echo.error("${args[1]}: no actor with this ID.")
System.err.println("[GetAV] ${args[1]}: no actor with this ID.")
}
}
@@ -86,8 +117,8 @@ class GetAV : ConsoleCommand {
override fun printUsage() {
val echo = Echo()
echo.execute("Get desired actor value of specific target.")
echo.execute("Usage: getav (id) <av>")
echo.execute("blank ID for player")
echo.execute("${ccW}Get desired ActorValue of specific target.")
echo.execute("${ccW}Usage: ${ccY}getav ${ccG}(id) <av>")
echo.execute("${ccW}blank ID for player")
}
}

View File

@@ -1,47 +1,113 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.Terrarum
import java.util.HashSet
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.Factionable
import net.torvald.terrarum.gameactors.Player
/**
* Created by minjaesong on 16-02-17.
*/
class GetFactioning : ConsoleCommand {
val ccW = GameFontBase.colToCode["w"]
val ccG = GameFontBase.colToCode["g"]
val ccY = GameFontBase.colToCode["y"]
val ccM = GameFontBase.colToCode["m"]
val ccK = GameFontBase.colToCode["k"]
val ccB = GameFontBase.colToCode["b"]
private val PRINT_INDENTATION = " --> "
private val PRINT_INDENTATION = "$ccK --> $ccW"
override fun execute(args: Array<String>) {
val echo = Echo()
if (args.size == 1) {
// get all factioning data of player
val factionSet = Terrarum.game.player.faction
fun printOutFactioning(id: Int) {
val a = Terrarum.game.getActor(id)
if (a is Factionable) {
echo.execute("$ccW== Faction assignment for $ccY${if (id == Player.PLAYER_REF_ID) "player" else id.toString()} $ccW==")
println("[GetFactioning] == Faction assignment for '${if (id == Player.PLAYER_REF_ID) "player" else id.toString()}' ==")
if (factionSet.isEmpty()) {
echo.execute("The actor has empty faction set.")
// get all factioning data of player
val factionSet = a.faction
if (factionSet.isEmpty()) {
echo.execute("The actor has empty faction set.")
println("[GetFactioning] The actor has empty faction set.")
return
}
val count = factionSet.size
echo.execute("$ccG${count.toString()} $ccW${Lang.pluralise(" faction", count)} assigned.")
println("[GetFactioning] ${count.toString()} ${Lang.pluralise(" faction", count)} assigned.")
for (faction in factionSet) {
echo.execute("${ccW}faction $ccM${faction.factionName}")
println("[GetFactioning] faction '${faction.factionName}'")
echo.execute("$ccY Amicable")
println("[GetFactioning] Amicable")
faction.factionAmicable.forEach { s ->
echo.execute(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
echo.execute("$ccY Explicit neutral")
println("[GetFactioning] Explicit neutral")
faction.factionNeutral.forEach { s ->
echo.execute(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
echo.execute("$ccY Hostile")
println("[GetFactioning] Hostile")
faction.factionHostile.forEach { s ->
echo.execute(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
echo.execute("$ccY Fearful")
println("[GetFactioning] Fearful")
faction.factionFearful.forEach { s ->
echo.execute(PRINT_INDENTATION + s)
println("[GetFactioning] --> $s")
}
}
}
else {
echo.error("The actor is not factionable.")
System.err.println("[GetFactioning] The actor is not factionable.")
}
}
if (args.size == 1) {
printOutFactioning(Player.PLAYER_REF_ID)
}
else {
if (!args[1].isNum()) {
echo.error("Invalid actor ID input.")
System.err.println("[GetFactioning] Invalid actor ID input.")
return
}
val count = factionSet.size
echo.execute(count.toString() + Lang.pluralise(" faction", count) + " assigned.")
for (faction in factionSet) {
echo.execute("faction “${faction.factionName}")
echo.execute(" Amicable")
faction.factionAmicable.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
echo.execute(" Explicit neutral")
faction.factionNeutral.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
echo.execute(" Hostile")
faction.factionHostile.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
echo.execute(" Fearful")
faction.factionFearful.forEach { s -> echo.execute(PRINT_INDENTATION + s) }
try {
val actorID = args[1].toInt()
printOutFactioning(actorID)
}
catch (e: IllegalArgumentException) {
echo.error("${args[1]}: no actor with this ID.")
System.err.println("[GetFactioning] ${args[1]}: no actor with this ID.")
}
}
}
fun String.isNum(): Boolean {
try {
this.toInt()
return true
}
catch (e: NumberFormatException) {
return false
}
}

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.console
import net.torvald.imagefont.GameFontBase
import net.torvald.terrarum.Game
import net.torvald.terrarum.Terrarum
@@ -8,18 +9,23 @@ import net.torvald.terrarum.Terrarum
*/
internal class SetAV : ConsoleCommand {
val ccW = GameFontBase.colToCode["w"]
val ccG = GameFontBase.colToCode["g"]
val ccY = GameFontBase.colToCode["y"]
val ccR = GameFontBase.colToCode["r"]
val ccM = GameFontBase.colToCode["m"]
override fun printUsage() {
val echo = Echo()
echo.execute("Set actor value of specific target to desired value.")
echo.execute("Usage: setav (id) <av> <val>")
echo.execute("blank ID for player")
echo.execute("Contaminated (float -> string) actor value will crash the game,")
echo.execute(" so make it sure before you issue the command.")
echo.execute("Use '__true' and '__false' for boolean value.")
echo.execute("${ccW}Set actor value of specific target to desired value.")
echo.execute("${ccW}Usage: ${ccY}setav ${ccG}(id) <av> <val>")
echo.execute("${ccW}blank ID for player")
echo.execute("${ccR}Contaminated (float -> string) ActorValue will crash the game,")
echo.execute("${ccR}so make sure it will not happen before you issue the command!")
echo.execute("${ccW}Use ${ccG}__true ${ccW}and ${ccG}__false ${ccW}for boolean value.")
}
override fun execute(args: Array<String>) {
fun parseAVInput(arg: String): Any {
val `val`: Any
@@ -58,30 +64,37 @@ internal class SetAV : ConsoleCommand {
// check if av is number
if (args[1].isNum()) {
echo.error("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
echo.error("Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[1]}: ActorValue cannot be a number.")
return
}
Terrarum.game.player.actorValue[args[1]] = `val`
echo.execute("Set ${args[1]} to $`val`")
echo.execute("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$`val`")
println("[SetAV] set ActorValue '${args[1]}' for player to '$`val`'.")
}
else if (args.size == 4) {
try {
val id = args[1].toInt()
val `val` = parseAVInput(args[3])
val actor = Terrarum.game.getActor(id)
// check if av is number
if (args[2].isNum()) {
echo.error("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
echo.error("Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
System.err.println("[SetAV] Illegal ActorValue ${args[2]}: ActorValue cannot be a number.")
return
}
Terrarum.game.getActor(id).actorValue[args[2]] = `val`
echo.execute("Set ${args[2]} of $id to $`val`")
actor.actorValue[args[2]] = `val`
echo.execute("${ccW}Set $ccM${args[2]} ${ccW}for $ccY$id ${ccW}to $ccG$`val`")
println("[SetAV] set ActorValue '${args[2]}' for $actor to '$`val`'.")
}
catch (e: IllegalArgumentException) {
if (args.size == 4)
echo.error(args[1] + ": no actor with this ID.")
if (args.size == 4) {
echo.error("${args[1]}: no actor with this ID.")
System.err.println("[SetAV] ${args[1]}: no actor with this ID.")
}
}
}

View File

@@ -0,0 +1,16 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.VERSION_STRING
/**
* Created by minjaesong on 16-04-23.
*/
class Version : ConsoleCommand {
override fun execute(args: Array<String>) {
Echo().execute(VERSION_STRING)
}
override fun printUsage() {
Echo().execute("Prints out current version of the application")
}
}