mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
read/writeactor to process all subclasses of Actor, not just a player; actor possession confirmed working
This commit is contained in:
@@ -207,8 +207,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
lateinit var gameLoadMode: GameLoadMode
|
||||
lateinit var gameLoadInfoPayload: Any
|
||||
lateinit var theRealGamer: IngamePlayer
|
||||
// get() = actorGamer as IngamePlayer
|
||||
|
||||
|
||||
|
||||
@@ -255,7 +253,6 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
}
|
||||
|
||||
actorNowPlaying = actor
|
||||
theRealGamer = actor
|
||||
addNewActor(actorNowPlaying)
|
||||
}
|
||||
|
||||
@@ -736,23 +733,23 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
// check if currently pocessed actor is removed from game
|
||||
if (!theGameHasActor(actorNowPlaying)) {
|
||||
// re-possess canonical player
|
||||
if (theGameHasActor(Terrarum.PLAYER_REF_ID))
|
||||
changePossession(Terrarum.PLAYER_REF_ID)
|
||||
if (theGameHasActor(actorGamer))
|
||||
changePossession(actorGamer)
|
||||
else
|
||||
changePossession(0x51621D) // FIXME fallback debug mode (FIXME is there for a reminder visible in ya IDE)
|
||||
actorNowPlaying = null
|
||||
}
|
||||
}
|
||||
|
||||
private fun changePossession(newActor: ActorHumanoid) {
|
||||
internal fun changePossession(newActor: ActorHumanoid) {
|
||||
if (!theGameHasActor(actorNowPlaying)) {
|
||||
throw IllegalArgumentException("No such actor in the game: $newActor")
|
||||
throw NoSuchActorWithRefException(newActor)
|
||||
}
|
||||
|
||||
actorNowPlaying = newActor
|
||||
//WorldSimulator(actorNowPlaying, AppLoader.getSmoothDelta().toFloat())
|
||||
}
|
||||
|
||||
private fun changePossession(refid: Int) {
|
||||
internal fun changePossession(refid: Int) {
|
||||
val actorToChange = getActorByID(refid)
|
||||
|
||||
if (actorToChange !is ActorHumanoid) {
|
||||
@@ -916,8 +913,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
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.")
|
||||
if (actor.referenceID == actorGamer.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
|
||||
throw ProtectedActorRemovalException("Player")
|
||||
|
||||
forceRemoveActor(actor)
|
||||
}
|
||||
@@ -970,7 +967,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
if (actor == null) return
|
||||
|
||||
if (AppLoader.IS_DEVELOPMENT_BUILD && theGameHasActor(actor.referenceID)) {
|
||||
throw Error("The actor $actor already exists in the game")
|
||||
throw ReferencedActorAlreadyExistsException(actor)
|
||||
}
|
||||
else {
|
||||
if (actor.referenceID !in ReferencingRanges.ACTORS_WIRES && actor.referenceID !in ReferencingRanges.ACTORS_WIRES_HELPER) {
|
||||
@@ -985,10 +982,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
fun activateDormantActor(actor: Actor) {
|
||||
if (AppLoader.IS_DEVELOPMENT_BUILD && !isInactive(actor.referenceID)) {
|
||||
if (isActive(actor.referenceID))
|
||||
/*if (isActive(actor.referenceID))
|
||||
throw Error("The actor $actor is already activated")
|
||||
else
|
||||
throw Error("The actor $actor already exists in the game")
|
||||
throw Error("The actor $actor already exists in the game")*/
|
||||
return
|
||||
}
|
||||
else {
|
||||
actorContainerInactive.remove(actor)
|
||||
|
||||
30
src/net/torvald/terrarum/modulebasegame/console/Possess.kt
Normal file
30
src/net/torvald/terrarum/modulebasegame/console/Possess.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2021-08-29.
|
||||
*/
|
||||
object Possess : ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
val ingame = Terrarum.ingame!! as TerrarumIngame
|
||||
if (args[1].lowercase() == "reset")
|
||||
ingame.changePossession(ingame.actorGamer)
|
||||
else
|
||||
ingame.changePossession(args[1].toInt())
|
||||
}
|
||||
else {
|
||||
printUsage()
|
||||
}
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
Echo("Usage: possess (id) | possess reset")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user