@@ -28,6 +28,7 @@ package com.projectswg.holocore.resources.support.global.commands.callbacks.admi
2828
2929import com.projectswg.common.data.location.Location
3030import com.projectswg.holocore.intents.support.global.chat.SystemMessageIntent.Companion.broadcastPersonal
31+ import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData
3132import com.projectswg.holocore.resources.support.global.commands.ICmdCallback
3233import com.projectswg.holocore.resources.support.global.player.Player
3334import com.projectswg.holocore.resources.support.objects.swg.SWGObject
@@ -38,17 +39,29 @@ import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureSt
3839import com.projectswg.holocore.services.support.global.zone.CharacterLookupService.PlayerLookup
3940import com.projectswg.holocore.services.support.objects.ObjectStorageService.BuildingLookup
4041import me.joshlarson.jlcommon.log.Log
42+ import java.util.*
43+ import kotlin.Comparator
44+ import kotlin.NoSuchElementException
4145
4246class CmdGoto : ICmdCallback {
4347 override fun execute (player : Player , target : SWGObject ? , args : String ) {
4448 val teleportee = player.creatureObject ? : return
4549 val parts = args.split(" " .toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
46- if (parts.isEmpty() || parts[0 ].trim { it <= ' ' }.isEmpty()) return
50+ if (parts.size < 2 || parts. isEmpty() || parts[0 ].trim { it <= ' ' }.isEmpty() || parts[ 1 ].trim { it <= ' ' }.isEmpty()) return
4751
48- val destination = parts[0 ].trim { it <= ' ' }
49- val message = if ( PlayerLookup .doesCharacterExistByFirstName(destination)) teleportToPlayer(player, teleportee, destination) else teleportToBuilding(player, teleportee, destination, parts)
52+ val type = parts[0 ].trim { it <= ' ' }
53+ val destination = parts[ 1 ].trim { it <= ' ' }
5054
51- if (message != null ) broadcastPersonal(player, message)
55+ var message = " "
56+ when (type) {
57+ " player" -> message = (teleportToPlayer(player, teleportee, destination)) ? : return
58+ " building" -> message = teleportToBuilding(player, teleportee, destination, parts) ? : return
59+ " spawn" -> message = teleportToSpawnId(player, teleportee, destination) ? : return
60+ " patrol" -> message = teleportToPatrolId(player, teleportee, destination) ? : return
61+ else -> broadcastPersonal(player, " Invalid goto command" )
62+ }
63+
64+ broadcastPersonal(player, message)
5265 }
5366
5467 private fun teleportToPlayer (player : Player , teleportee : CreatureObject , playerName : String ): String? {
@@ -80,6 +93,42 @@ class CmdGoto : ICmdCallback {
8093 return teleportToGoto(teleportee, building, cell)
8194 }
8295
96+
97+ private fun teleportToSpawnId (player : Player , teleportee : CreatureObject , spawnId : String ): String? {
98+ val spawnInfo = try {
99+ ServerData .npcStaticSpawns.spawns.first { it.id == spawnId }
100+ } catch (e: NoSuchElementException ) {
101+ broadcastPersonal(player, " Spawn ID '$spawnId ' did not return a spawn." )
102+ return null
103+ }
104+ val newLocation = Location .builder().setPosition(spawnInfo.x, spawnInfo.y, spawnInfo.z).setTerrain(spawnInfo.terrain).build()
105+ if (spawnInfo.buildingId.isEmpty() || spawnInfo.buildingId.endsWith(" _world" )) {
106+ teleportee.moveToLocation(newLocation)
107+ return " Succesfully teleported " + teleportee.objectName + " to patrol " + spawnId
108+ }
109+ val newParent = BuildingLookup .getBuildingByTag(spawnInfo.buildingId)?.getCellByNumber(spawnInfo.cellId)
110+ teleportee.moveToContainer(newParent, newLocation)
111+ return " Succesfully teleported " + teleportee.objectName + " to patrol " + spawnId
112+ }
113+
114+ private fun teleportToPatrolId (player : Player , teleportee : CreatureObject , patrolId : String ): String? {
115+ val groupIdFromPatrolId = patrolId.dropLast(2 ) + " 00"
116+ val patrolWaypoint = try {
117+ Objects .requireNonNull(ServerData .npcPatrolRoutes[groupIdFromPatrolId], " Invalid patrol group ID: $groupIdFromPatrolId " ).first { it.patrolId == patrolId }
118+ } catch (e: NoSuchElementException ) {
119+ broadcastPersonal(player, " Spawn ID '$patrolId ' did not return a spawn." )
120+ return null
121+ }
122+ val newLocation = Location .builder().setPosition(patrolWaypoint.x, patrolWaypoint.y, patrolWaypoint.z).setTerrain(patrolWaypoint.terrain).build()
123+ if (patrolWaypoint.buildingId.isEmpty() || patrolWaypoint.buildingId.endsWith(" _world" )) {
124+ teleportee.moveToLocation(newLocation)
125+ return " Succesfully teleported " + teleportee.objectName + " to patrol " + patrolId
126+ }
127+ val newParent = BuildingLookup .getBuildingByTag(patrolWaypoint.buildingId)?.getCellByNumber(patrolWaypoint.cellId)
128+ teleportee.moveToContainer(newParent, newLocation)
129+ return " Succesfully teleported " + teleportee.objectName + " to patrol " + patrolId
130+ }
131+
83132 private fun teleportToGoto (obj : SWGObject , building : BuildingObject , cellNumber : Int ): String {
84133 val cell = building.getCellByNumber(cellNumber)
85134 if (cell == null ) {
0 commit comments