player is now nullable; wtf is calling Ingame 5 times?

This commit is contained in:
minjaesong
2018-09-17 01:46:50 +09:00
parent d16e916502
commit 1b94d2ea14
35 changed files with 252 additions and 150 deletions

Binary file not shown.

View File

@@ -13,6 +13,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack;
import java.io.File;
import java.util.Arrays;
import java.util.Random;
@@ -271,6 +272,11 @@ public class AppLoader implements ApplicationListener {
@Override
public void dispose () {
if (screen != null) screen.hide();
System.out.println("Goodbye !");
// delete temp files
new File("./tmp_wenquanyi.tga").delete();
}
@Override

View File

@@ -726,10 +726,12 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
/** The actor the game is currently allowing you to control.
*
* Most of the time it'd be the "player", but think about the case where you have possessed
* some random actor of the game. Now that actor is now playableActor, the actual gamer's avatar
* (reference ID of 0x91A7E2) (must) stay in the actorContainer, but it's not a playableActor.
* some random actor of the game. Now that actor is now actorNowPlaying, the actual gamer's avatar
* (reference ID of 0x91A7E2) (must) stay in the actorContainer, but it's not a actorNowPlaying.
*
* Nullability of this property is believed to be unavoidable (trust me!). I'm sorry for the inconvenience.
*/
open lateinit var playableActor: ActorHumanoid
open var actorNowPlaying: ActorHumanoid? = null
val ACTORCONTAINER_INITIAL_SIZE = 64
val actorContainer = ArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
@@ -810,7 +812,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
* Any values behind the index will be automatically pushed to front.
* This is how remove function of [java.util.ArrayList] is defined.
*/
open fun removeActor(actor: Actor) {
open fun removeActor(actor: Actor?) {
if (actor == null) return
val indexToDelete = actorContainer.binarySearch(actor.referenceID!!)
if (indexToDelete >= 0) {
actorContainer.removeAt(indexToDelete)
@@ -820,7 +824,9 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
/**
* Check for duplicates, append actor and sort the list
*/
open fun addNewActor(actor: Actor) {
open fun addNewActor(actor: Actor?) {
if (actor == null) return
if (theGameHasActor(actor.referenceID!!)) {
throw Error("The actor $actor already exists in the game")
}

View File

@@ -137,7 +137,11 @@ class UIItemInventoryElem(
override fun keyDown(keycode: Int): Boolean {
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_1..Input.Keys.NUM_0) {
val inventory = (Terrarum.ingame!! as Ingame).playableActor.inventory
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
val inventory = player.inventory
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
val currentSlotItem = inventory?.getQuickBar(slot)
@@ -167,7 +171,9 @@ class UIItemInventoryElem(
// equip da shit
val itemEquipSlot = item!!.equipPosition
val player = (Terrarum.ingame!! as Ingame).playableActor
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it
player.equipItem(item!!)

View File

@@ -124,8 +124,10 @@ class UIItemInventoryElemSimple(
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_1..Input.Keys.NUM_0) {
println("keydown elemgrid")
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
val inventory = (Terrarum.ingame!! as Ingame).playableActor.inventory
val inventory = player.inventory
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
val currentSlotItem = inventory.getQuickBar(slot)
@@ -157,7 +159,8 @@ class UIItemInventoryElemSimple(
// equip da shit
val itemEquipSlot = item!!.equipPosition
val player = (Terrarum.ingame!! as Ingame).playableActor
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
if (item != player.inventory.itemEquipped.get(itemEquipSlot)) { // if this item is unequipped, equip it
player.equipItem(item!!)

View File

@@ -28,7 +28,8 @@ object BlockStats {
// Get stats on no-zoomed screen area. In other words, will behave as if screen zoom were 1.0
// no matter how the screen is zoomed.
val map = (Terrarum.ingame!!.world)
val player = (Terrarum.ingame!! as Ingame).playableActor
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val renderWidth = FastMath.ceil(Terrarum.WIDTH.toFloat())
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())

View File

@@ -39,7 +39,11 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable<Actor>, Runnable
var actorValue = ActorValue(this)
@Volatile var flagDespawn = false
override fun equals(other: Any?) = referenceID == (other as Actor).referenceID
override fun equals(other: Any?): Boolean {
if (other == null) return false
return referenceID == (other as Actor).referenceID
}
override fun hashCode() = referenceID!!
override fun toString() =
if (actorValue.getAsString("name").isNullOrEmpty())

View File

@@ -337,7 +337,7 @@ open class ActorWBMovable(val world: GameWorld, renderOrder: RenderOrder, val im
if (spriteGlow != null) spriteGlow!!.update(delta)
// make NoClip work for player
if (true) {//this == Terrarum.ingame!!.playableActor) {
if (true) {//this == Terrarum.ingame!!.actorNowPlaying) {
isNoSubjectToGrav = isNoClip || COLLISION_TEST_MODE
isNoCollideWorld = isNoClip
isNoSubjectToFluidResistance = isNoClip

View File

@@ -41,14 +41,17 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
// Use item: assuming the player has only one effective grip (EquipPosition.HAND_GRIP)
if (ingame.canPlayerControl) {
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary")) || Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) {
val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val itemOnGrip = player.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
itemOnGrip?.let {
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mouseprimary"))) {
ingame.playableActor.consumePrimary(it)
player.consumePrimary(it)
}
if (Gdx.input.isButtonPressed(Terrarum.getConfigInt("mousesecondary"))) {
ingame.playableActor.consumeSecondary(it)
player.consumeSecondary(it)
}
}
}
@@ -63,7 +66,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun keyDown(keycode: Int): Boolean {
if (ingame.canPlayerControl) {
ingame.playableActor.keyDown(keycode)
ingame.actorNowPlaying?.keyDown(keycode)
}
if (Terrarum.getConfigIntArray("keyquickselalt").contains(keycode)
@@ -112,7 +115,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
// don't separate Player from this! Physics will break, esp. airborne manoeuvre
if (ingame.canPlayerControl) {
val itemOnGrip = ingame.playableActor.inventory.itemEquipped[GameItem.EquipPosition.HAND_GRIP]
val itemOnGrip = ingame.actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP) ?: null
if (itemOnGrip != null) {
if (button == Terrarum.getConfigInt("mouseprimary")) {

View File

@@ -132,7 +132,7 @@ object ItemCodex {
override fun primaryUse(delta: Float): Boolean {
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val actorvalue = ingame.playableActor.actorValue
val actorvalue = ingame.actorNowPlaying.actorValue
using = true
@@ -155,7 +155,7 @@ object ItemCodex {
ingame.world.inflictTerrainDamage(
Terrarum.mouseTileX,
Terrarum.mouseTileY,
Calculate.pickaxePower(ingame.playableActor, material) * swingDmgToFrameDmg
Calculate.pickaxePower(ingame.actorNowPlaying, material) * swingDmgToFrameDmg
)
return true
}
@@ -163,7 +163,7 @@ object ItemCodex {
override fun endPrimaryUse(delta: Float): Boolean {
using = false
// reset action timer to zero
ingame.playableActor.actorValue[AVKey.__ACTION_TIMER] = 0.0
ingame.actorNowPlaying.actorValue[AVKey.__ACTION_TIMER] = 0.0
return true
}
}*/

View File

@@ -2,12 +2,9 @@ package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.IngameInstance
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
@@ -49,7 +46,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
override var playableActor: ActorHumanoid = MovableWorldCamera(world)
override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera(world)
val uiToolbox = UIBuildingMakerToolbox()
val notifier = Notification()
@@ -104,7 +101,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
playableActor.setPosition(512 * 16.0, 149 * 16.0)
actorNowPlaying?.setPosition(512 * 16.0, 149 * 16.0)
@@ -153,10 +150,10 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private fun updateGame(delta: Float) {
blockPointingCursor.update(delta)
playableActor.update(delta)
actorNowPlaying?.update(delta)
uiContainer.forEach { it.update(delta) }
WorldCamera.update(world, playableActor)
WorldCamera.update(world, actorNowPlaying)
}
private fun renderGame() {

View File

@@ -16,7 +16,6 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.gameworld.WorldSimulator
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
@@ -24,14 +23,12 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
import java.util.ArrayList
import java.util.concurrent.locks.ReentrantLock
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.modulebasegame.console.AVTracker
import net.torvald.terrarum.modulebasegame.console.ActorsList
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.console.SetGlobalLightOverride
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.*
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
@@ -53,9 +50,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var historicalFigureIDBucket: ArrayList<Int>
lateinit var gameworld: GameWorldExtension
lateinit var theRealGamer: IngamePlayer
/**
* list of Actors that is sorted by Actors' referenceID
@@ -150,6 +144,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var gameLoadMode: GameLoadMode
lateinit var gameLoadInfoPayload: Any
lateinit var gameworld: GameWorldExtension
lateinit var theRealGamer: IngamePlayer
enum class GameLoadMode {
CREATE_NEW, LOAD_FROM
@@ -189,6 +185,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// other worldgen options
)
private fun setTheRealGamerFirstTime(actor: IngamePlayer) {
actorNowPlaying = actor
theRealGamer = actor
addNewActor(actorNowPlaying)
}
/**
* Init instance by loading saved world
*/
@@ -203,17 +205,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
gameworld = gameSaveData.world
world = gameworld
historicalFigureIDBucket = gameSaveData.historicalFigureIDBucket
theRealGamer = gameSaveData.realGamePlayer
playableActor = gameSaveData.realGamePlayer
addNewActor(playableActor)
setTheRealGamerFirstTime(gameSaveData.realGamePlayer)
// set the randomisers right
RoguelikeRandomiser.loadFromSave(gameSaveData.rogueS0, gameSaveData.rogueS1)
WeatherMixer.loadFromSave(gameSaveData.weatherS0, gameSaveData.weatherS1)
//initGame()
}
}
@@ -221,6 +218,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
* Init instance by creating new world
*/
private fun enter(worldParams: NewWorldParameters) {
printdbg(this, "Ingame called")
Thread.currentThread().getStackTrace().forEach {
printdbg(this, "-> $it")
}
if (gameInitialised) {
printdbg(this, "loaded successfully.")
}
@@ -252,8 +254,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// test actor
//addNewActor(PlayerBuilderCynthia())
//initGame()
setTheRealGamerFirstTime(PlayerBuilderSigrid())
}
}
@@ -303,7 +304,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
-uiInventoryPlayer.width,
70
)*/
uiInventoryPlayer = UIInventoryFull(playableActor,
uiInventoryPlayer = UIInventoryFull(actorNowPlaying,
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
)
uiInventoryPlayer.setPosition(0, 0)
@@ -329,11 +330,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
//uiVitalItem.setAsAlwaysVisible()
// basic watch-style notification bar (temperature, new mail)
uiWatchBasic = UIBasicNotifier(playableActor)
uiWatchBasic = UIBasicNotifier(actorNowPlaying)
uiWatchBasic.setAsAlwaysVisible()
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.width, 0)
uiWatchTierOne = UITierOneWatch(playableActor)
uiWatchTierOne = UITierOneWatch(actorNowPlaying)
uiWatchTierOne.setAsAlwaysVisible()
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.width, uiWatchBasic.height - 2)
@@ -421,15 +422,15 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
if (!gameFullyLoaded) {
if (gameLoadMode == GameLoadMode.CREATE_NEW) {
playableActor = PlayerBuilderSigrid()
actorNowPlaying = PlayerBuilderSigrid()
// go to spawn position
playableActor.setPosition(
actorNowPlaying?.setPosition(
world.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
world.spawnY * FeaturesDrawer.TILE_SIZE.toDouble()
)
addNewActor(playableActor)
addNewActor(actorNowPlaying)
}
postInit()
@@ -505,7 +506,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
BlockPropUtil.dynamicLumFuncTickClock()
world.updateWorldTime(delta)
//WorldSimulator(player, delta)
WeatherMixer.update(delta, playableActor)
WeatherMixer.update(delta, actorNowPlaying)
BlockStats.update()
if (!(CommandDict["setgl"] as SetGlobalLightOverride).lightOverride)
gameworld.globalLight = WeatherMixer.globalLightNow
@@ -515,7 +516,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// camera-related updates //
////////////////////////////
FeaturesDrawer.update(delta)
WorldCamera.update(gameworld, playableActor)
WorldCamera.update(gameworld, actorNowPlaying)
@@ -558,7 +559,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderMidTop,
actorsRenderFront,
particlesContainer,
playableActor,
actorNowPlaying,
uiContainer
)
}
@@ -566,7 +567,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
private fun repossessActor() {
// check if currently pocessed actor is removed from game
if (!theGameHasActor(playableActor)) {
if (!theGameHasActor(actorNowPlaying)) {
// re-possess canonical player
if (theGameHasActor(Terrarum.PLAYER_REF_ID))
changePossession(Terrarum.PLAYER_REF_ID)
@@ -576,12 +577,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
private fun changePossession(newActor: ActorHumanoid) {
if (!theGameHasActor(playableActor)) {
if (!theGameHasActor(actorNowPlaying)) {
throw IllegalArgumentException("No such actor in the game: $newActor")
}
playableActor = newActor
WorldSimulator(playableActor, Terrarum.deltaTime)
actorNowPlaying = newActor
WorldSimulator(actorNowPlaying, Terrarum.deltaTime)
}
private fun changePossession(refid: Int) {
@@ -665,11 +666,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
ThreadParallel.startAll()
playableActor.update(delta)
actorNowPlaying?.update(delta)
}
else {
actorContainer.forEach {
if (it != playableActor) {
if (it != actorNowPlaying) {
it.update(delta)
if (it is Pocketed) {
@@ -682,7 +683,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
}
}
playableActor.update(delta)
actorNowPlaying?.update(delta)
//AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre)
}
}
@@ -734,7 +735,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
* Any values behind the index will be automatically pushed to front.
* This is how remove function of [java.util.ArrayList] is defined.
*/
override fun removeActor(actor: Actor) {
override fun removeActor(actor: Actor?) {
if (actor == null) return
if (actor.referenceID == theRealGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainer.binarySearch(actor.referenceID!!)
@@ -769,7 +772,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/**
* Check for duplicates, append actor and sort the list
*/
override fun addNewActor(actor: Actor) {
override fun addNewActor(actor: Actor?) {
if (actor == null) return
if (theGameHasActor(actor.referenceID!!)) {
throw Error("The actor $actor already exists in the game")
}

View File

@@ -16,7 +16,7 @@ internal object AVTracker : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size < 2) {
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).playableActor))
jPanelInstances.add(ActorValueTracker((Terrarum.ingame!! as Ingame).actorNowPlaying))
}
else {
try {

View File

@@ -15,8 +15,11 @@ internal object ExportAV : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
try {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
JsonWriter.writeToFile(
(Terrarum.ingame!! as Ingame).playableActor.actorValue,
player.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json")

View File

@@ -15,11 +15,13 @@ internal object GetAV : ConsoleCommand {
override fun execute(args: Array<String>) {
try {
val ingame = Terrarum.ingame!! as Ingame
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
if (args.size == 1 && ingame.playableActor != null) {
if (args.size == 1 && player != null) {
// print all actorvalue of player
val av = ingame.playableActor.actorValue
val av = player.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
@@ -36,15 +38,15 @@ internal object GetAV : ConsoleCommand {
// check if args[1] is number or not
if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
ingame.playableActor.actorValue[args[1]] +
" $ccO" +
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
ccG +
player.actorValue[args[1]] +
" $ccO" +
player.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
ingame.playableActor.actorValue[args[1]] +
player.actorValue[args[1]] +
" " +
ingame.playableActor.actorValue[args[1]]!!.javaClass.simpleName
player.actorValue[args[1]]!!.javaClass.simpleName
)
}
else {

View File

@@ -16,7 +16,7 @@ import java.io.IOException
internal object GsonTest : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2) {
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).playableActor)
val avelem = Gson().toJsonTree((Terrarum.ingame!! as Ingame).actorNowPlaying)
val jsonString = avelem.toString()

View File

@@ -21,7 +21,7 @@ object ImportLayerData : ConsoleCommand {
//val fis = GZIPInputStream(FileInputStream(args[1])) // this gzip is kaput
val fis = FileInputStream(args[1])
(Terrarum.ingame!!.world) = ReadLayerData(fis)
(Terrarum.ingame!! as Ingame).playableActor.setPosition(
(Terrarum.ingame!! as Ingame).actorNowPlaying?.setPosition(
(Terrarum.ingame!!.world).spawnY * FeaturesDrawer.TILE_SIZE.toDouble(),
(Terrarum.ingame!!.world).spawnX * FeaturesDrawer.TILE_SIZE.toDouble()
)

View File

@@ -4,7 +4,6 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
import net.torvald.terrarum.console.EchoError
import net.torvald.terrarum.modulebasegame.gameactors.IngamePlayer
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
@@ -14,7 +13,7 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object Inventory : ConsoleCommand {
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).playableActor
private var target: Pocketed? = (Terrarum.ingame!! as Ingame).actorNowPlaying
override fun execute(args: Array<String>) {
if (args.size == 1) {

View File

@@ -63,9 +63,16 @@ internal object SetAV : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).playableActor.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) {
EchoError("Player does not exist")
println("[SetAV] Player does not exist")
}
else {
player.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
}
}
else if (args.size == 4) {
try {

View File

@@ -14,7 +14,11 @@ internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) {
try {
val targetID = if (args.size == 3) args[1].toInt() else (Terrarum.ingame!! as Ingame).playableActor.referenceID
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val targetID = if (args.size == 3) args[1].toInt() else player.referenceID
val scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID!!)

View File

@@ -27,7 +27,7 @@ internal object Teleport : ConsoleCommand {
return
}
(Terrarum.ingame!! as Ingame).playableActor.setPosition(x.toDouble(), y.toDouble())
(Terrarum.ingame!! as Ingame).actorNowPlaying?.setPosition(x.toDouble(), y.toDouble())
}
else if (args.size == 4) {
if (args[2].toLowerCase() != "to") {
@@ -38,8 +38,15 @@ internal object Teleport : ConsoleCommand {
val targetActor: ActorWBMovable
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
(Terrarum.ingame!! as Ingame).playableActor.referenceID!!
val targetActorID = if (args[3].toLowerCase() == "player") {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) {
EchoError("Player does not exist")
return
}
else
player.referenceID!!
}
else
args[3].toInt()

View File

@@ -10,9 +10,13 @@ import net.torvald.terrarum.modulebasegame.Ingame
*/
internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) {
val status = (Terrarum.ingame!! as Ingame).playableActor.isNoClip
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
(Terrarum.ingame!! as Ingame).playableActor.isNoClip = !status
val status = player.isNoClip
player.isNoClip = !status
Echo("Set no-clip status to " + (!status).toString())
}

View File

@@ -84,7 +84,7 @@ class ActorValueTracker constructor() : JFrame() {
buttonChangeActor.addMouseListener(object : MouseAdapter() {
override fun mousePressed(e: MouseEvent?) {
if (actorIDField.text.toLowerCase() == "player") {
actor = (Terrarum.ingame!! as Ingame).playableActor
actor = (Terrarum.ingame!! as Ingame).actorNowPlaying
actorValue = actor!!.actorValue
}
else if (actorIDField.text.isNotBlank()) {

View File

@@ -145,7 +145,7 @@ open class ActorHumanoid(
protected var isRightDown = false
protected var isJumpDown = false
protected inline val isGamer: Boolean
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.playableActor
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.actorNowPlaying
private val nullItem = object : GameItem() {

View File

@@ -64,7 +64,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
if (item.originalID == Terrarum.PLAYER_REF_ID || item.originalID == 0x51621D) // do not delete this magic
throw IllegalArgumentException("Attempted to put human player into the inventory.")
if (((Terrarum.ingame as? Ingame)?.gameFullyLoaded ?: false) &&
(item.originalID == (Terrarum.ingame as? Ingame)?.playableActor?.referenceID))
(item.originalID == (Terrarum.ingame as? Ingame)?.actorNowPlaying?.referenceID))
throw IllegalArgumentException("Attempted to put active player into the inventory.")
if ((!item.stackable || item.dynamicID in ITEM_DYNAMIC) && count > 1)
throw IllegalArgumentException("Attempting to adding stack of item but the item is not stackable; item: $item, count: $count")

View File

@@ -8,9 +8,10 @@ import net.torvald.terrarum.gameactors.Controllable
* @param actor : here you 'attach' the actor you wish to control
* Created by minjaesong on 2016-10-23.
*/
@Deprecated("The ingame should discriminate 'theRealGamer' and 'actorNowPlaying'")
class PlayableActorDelegate(val actor: ActorHumanoid) {
init {
/*init {
if (actor !is Controllable)
throw IllegalArgumentException("Player must be 'Controllable'!")
}
@@ -27,5 +28,5 @@ class PlayableActorDelegate(val actor: ActorHumanoid) {
// LightmapRenderer.fireRecalculateEvent()
//}
// not going to work: think about stationery tiki torches, global lights, etc
}
}*/
}

View File

@@ -35,7 +35,10 @@ class SmarterSlimes : ActorAI {
// TEST: just target player
val playerXPos = (Terrarum.ingame!! as Ingame).playableActor.centrePosPoint.x
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return
val playerXPos = player.centrePosPoint.x
val thisXPos = actor.centrePosPoint.x
val xDiff = thisXPos - playerXPos

View File

@@ -34,11 +34,14 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
}
override fun primaryUse(delta: Float): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
val mouseTileX = Terrarum.mouseTileX
val mouseTileY = Terrarum.mouseTileY
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
val actorvalue = (Terrarum.ingame!! as Ingame).playableActor.actorValue
val actorvalue = player.actorValue
using = true
@@ -58,16 +61,19 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
(Terrarum.ingame!!.world).inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower((Terrarum.ingame!! as Ingame).playableActor, material) * swingDmgToFrameDmg
Calculate.pickaxePower(player, material) * swingDmgToFrameDmg
)
return true
}
override fun endPrimaryUse(delta: Float): Boolean {
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return false
using = false
// reset action timer to zero
(Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
}

View File

@@ -38,8 +38,8 @@ class UIPieMenu : UICanvas() {
var selection: Int = -1
override fun updateUI(delta: Float) {
if (selection >= 0)
(Terrarum.ingame!! as Ingame).playableActor.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
if (selection >= 0 && (Terrarum.ingame!! as Ingame).actorNowPlaying != null)
(Terrarum.ingame!! as Ingame).actorNowPlaying!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
@@ -83,7 +83,11 @@ class UIPieMenu : UICanvas() {
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return // don't draw actual items
val itemPair = player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -28,8 +28,8 @@ class UIQuickBar : UICanvas() {
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
private var selection: Int
get() = (Terrarum.ingame!! as Ingame).playableActor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).playableActor.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
get() = (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
override fun updateUI(delta: Float) {
}
@@ -54,7 +54,11 @@ class UIQuickBar : UICanvas() {
)
// draw item
val itemPair = (Terrarum.ingame!! as Ingame).playableActor.inventory.getQuickBar(i)
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
if (player == null) return // if player is null, don't draw actual items
val itemPair = player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)

View File

@@ -5,10 +5,14 @@ import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.AppLoader.printdbgerr
import net.torvald.terrarum.LoadScreen
import net.torvald.terrarum.Second
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.PlayerBuilderSigrid
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton
import net.torvald.terrarum.ui.UIItemTextButtonList
@@ -100,6 +104,22 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode<String>) : UICanvas() {
throw NullPointerException("No parent node to return")
}
}
else if (it.labelText.contains("Start New Random Game")) {
printdbg(this, 1)
val ingame = Ingame(Terrarum.batch)
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
printdbg(this, 2)
Terrarum.ingame = ingame
LoadScreen.screenToLoad = ingame
Terrarum.setScreen(LoadScreen)
printdbg(this, 3)
}
else {
// check if target exists
//println("current node: ${currentRemoConContents.data}")

View File

@@ -84,7 +84,9 @@ internal object WeatherMixer : RNGConsumer {
/**
* Part of Ingame update
*/
fun update(delta: Float, player: ActorWithBody) {
fun update(delta: Float, player: ActorWithBody?) {
if (player == null) return
currentWeather = weatherList[WEATHER_GENERIC]!![0]

View File

@@ -32,14 +32,16 @@ class BasicDebugInfoWindow : UICanvas() {
private val world = ingame.world as GameWorldExtension
override fun updateUI(delta: Float) {
val player = ingame.playableActor
val hitbox = player.hitbox
val player = ingame.actorNowPlaying
val hitbox = player?.hitbox
xdelta = hitbox.canonicalX - prevPlayerX
ydelta = hitbox.canonicalY - prevPlayerY
if (hitbox != null) {
xdelta = hitbox.canonicalX - prevPlayerX
ydelta = hitbox.canonicalY - prevPlayerY
prevPlayerX = hitbox.canonicalX
prevPlayerY = hitbox.canonicalY
prevPlayerX = hitbox.canonicalX
prevPlayerY = hitbox.canonicalY
}
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -47,58 +49,61 @@ class BasicDebugInfoWindow : UICanvas() {
fun Int.rawG() = this % LightmapRenderer.MUL_2 / LightmapRenderer.MUL
fun Int.rawB() = this % LightmapRenderer.MUL
val player = ingame.playableActor
val player = ingame.actorNowPlaying
batch.color = Color(0xFFEE88FF.toInt())
val hitbox = player.hitbox
val hitbox = player?.hitbox
/**
* First column
*/
printLineColumn(batch, 1, 1, "startX "
+ ccG
+ "${hitbox?.startX}"
+ " ("
+ "${(hitbox?.startX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 2, 1, "endX "
+ ccG
+ "${hitbox?.endX}"
+ " ("
+ "${(hitbox?.endX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 1, 2, "startY "
+ ccG
+ "${hitbox?.startY}"
+ " ("
+ "${(hitbox?.startY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 2, 2, "endY "
+ ccG
+ "${hitbox?.endY}"
+ " ("
+ "${(hitbox?.endY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
if (player != null) {
printLine(batch, 3, "veloX reported $ccG${player.externalForce?.x}")
printLine(batch, 4, "veloY reported $ccG${player.externalForce?.y}")
printLineColumn(batch, 1, 1, "startX "
+ ccG
+ "${hitbox?.startX}"
+ " ("
+ "${(hitbox?.startX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 2, 1, "endX "
+ ccG
+ "${hitbox?.endX}"
+ " ("
+ "${(hitbox?.endX?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 1, 2, "startY "
+ ccG
+ "${hitbox?.startY}"
+ " ("
+ "${(hitbox?.startY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLineColumn(batch, 2, 2, "endY "
+ ccG
+ "${hitbox?.endY}"
+ " ("
+ "${(hitbox?.endY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLine(batch, 5, "p_WalkX $ccG${player.controllerMoveDelta?.x}")
printLine(batch, 6, "p_WalkY $ccG${player.controllerMoveDelta?.y}")
printLine(batch, 3, "veloX reported $ccG${player.externalForce?.x}")
printLine(batch, 4, "veloY reported $ccG${player.externalForce?.y}")
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
printLine(batch, 5, "p_WalkX $ccG${player.controllerMoveDelta?.x}")
printLine(batch, 6, "p_WalkY $ccG${player.controllerMoveDelta?.y}")
printLineColumn(batch, 1, 7,
"walled " +
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
"${if (player.walledTop) "$ccR" else "$ccG"}${0x1E.toChar()}" +
"${if (player.walledRight) "$ccR" else "$ccG"}R" +
"${if (player.colliding) "$ccR" else "$ccG"}${0x08.toChar()}"
)
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
printLineColumn(batch, 1, 7,
"walled " +
"${if (player.walledLeft) "$ccR" else "$ccG"}L" +
"${if (player.walledBottom) "$ccR" else "$ccG"}${0x1F.toChar()}" +
"${if (player.walledTop) "$ccR" else "$ccG"}${0x1E.toChar()}" +
"${if (player.walledRight) "$ccR" else "$ccG"}R" +
"${if (player.colliding) "$ccR" else "$ccG"}${0x08.toChar()}"
)
}
@@ -138,10 +143,12 @@ class BasicDebugInfoWindow : UICanvas() {
printLineColumn(batch, 2, 5, "Time $ccG${world.time.todaySeconds.toString().padStart(5, '0')}" +
" (${world.time.getFormattedTime()})")
printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")
printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}")
if (player != null) {
printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")
printLineColumn(batch, 2, 7, "noClip $ccG${player.isNoClip}")
}
drawHistogram(batch, LightmapRenderer.histogram,
Terrarum.WIDTH - histogramW - 30,

View File

@@ -29,7 +29,8 @@ object WorldCamera {
inline val yCentre: Int
get() = y + height.ushr(1)
fun update(world: GameWorld, player: ActorWBMovable) {
fun update(world: GameWorld, player: ActorWBMovable?) {
if (player == null) return
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))

Binary file not shown.