mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-01-15 23:05:45 -05:00
Added ability to teleport to spawns and patrols by ID
This commit is contained in:
@@ -28,6 +28,7 @@ package com.projectswg.holocore.resources.support.global.commands.callbacks.admi
|
||||
|
||||
import com.projectswg.common.data.location.Location
|
||||
import com.projectswg.holocore.intents.support.global.chat.SystemMessageIntent.Companion.broadcastPersonal
|
||||
import com.projectswg.holocore.resources.support.data.server_info.loader.ServerData
|
||||
import com.projectswg.holocore.resources.support.global.commands.ICmdCallback
|
||||
import com.projectswg.holocore.resources.support.global.player.Player
|
||||
import com.projectswg.holocore.resources.support.objects.swg.SWGObject
|
||||
@@ -38,17 +39,29 @@ import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureSt
|
||||
import com.projectswg.holocore.services.support.global.zone.CharacterLookupService.PlayerLookup
|
||||
import com.projectswg.holocore.services.support.objects.ObjectStorageService.BuildingLookup
|
||||
import me.joshlarson.jlcommon.log.Log
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
import kotlin.NoSuchElementException
|
||||
|
||||
class CmdGoto : ICmdCallback {
|
||||
override fun execute(player: Player, target: SWGObject?, args: String) {
|
||||
val teleportee = player.creatureObject ?: return
|
||||
val parts = args.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
if (parts.isEmpty() || parts[0].trim { it <= ' ' }.isEmpty()) return
|
||||
if (parts.size < 2 ||parts.isEmpty() || parts[0].trim { it <= ' ' }.isEmpty() || parts[1].trim { it <= ' ' }.isEmpty()) return
|
||||
|
||||
val destination = parts[0].trim { it <= ' ' }
|
||||
val message = if (PlayerLookup.doesCharacterExistByFirstName(destination)) teleportToPlayer(player, teleportee, destination) else teleportToBuilding(player, teleportee, destination, parts)
|
||||
val type = parts[0].trim { it <= ' ' }
|
||||
val destination = parts[1].trim { it <= ' ' }
|
||||
|
||||
if (message != null) broadcastPersonal(player, message)
|
||||
var message = ""
|
||||
when (type) {
|
||||
"player" -> message = (teleportToPlayer(player, teleportee, destination)) ?: return
|
||||
"building" -> message = teleportToBuilding(player, teleportee, destination, parts) ?: return
|
||||
"spawn" -> message = teleportToSpawnId(player, teleportee, destination) ?: return
|
||||
"patrol" -> message = teleportToPatrolId(player, teleportee, destination) ?: return
|
||||
else -> broadcastPersonal(player, "Invalid goto command")
|
||||
}
|
||||
|
||||
broadcastPersonal(player, message)
|
||||
}
|
||||
|
||||
private fun teleportToPlayer(player: Player, teleportee: CreatureObject, playerName: String): String? {
|
||||
@@ -80,6 +93,42 @@ class CmdGoto : ICmdCallback {
|
||||
return teleportToGoto(teleportee, building, cell)
|
||||
}
|
||||
|
||||
|
||||
private fun teleportToSpawnId(player: Player, teleportee: CreatureObject, spawnId: String): String? {
|
||||
val spawnInfo = try {
|
||||
ServerData.npcStaticSpawns.spawns.first { it.id == spawnId }
|
||||
} catch (e: NoSuchElementException) {
|
||||
broadcastPersonal(player, "Spawn ID '$spawnId' did not return a spawn.")
|
||||
return null
|
||||
}
|
||||
val newLocation = Location.builder().setPosition(spawnInfo.x, spawnInfo.y, spawnInfo.z).setTerrain(spawnInfo.terrain).build()
|
||||
if (spawnInfo.buildingId.isEmpty() || spawnInfo.buildingId.endsWith("_world")) {
|
||||
teleportee.moveToLocation(newLocation)
|
||||
return "Succesfully teleported " + teleportee.objectName + " to patrol " + spawnId
|
||||
}
|
||||
val newParent = BuildingLookup.getBuildingByTag(spawnInfo.buildingId)?.getCellByNumber(spawnInfo.cellId)
|
||||
teleportee.moveToContainer(newParent, newLocation)
|
||||
return "Succesfully teleported " + teleportee.objectName + " to patrol " + spawnId
|
||||
}
|
||||
|
||||
private fun teleportToPatrolId(player: Player, teleportee: CreatureObject, patrolId: String): String? {
|
||||
val groupIdFromPatrolId = patrolId.dropLast(2) + "00"
|
||||
val patrolWaypoint = try {
|
||||
Objects.requireNonNull(ServerData.npcPatrolRoutes[groupIdFromPatrolId], "Invalid patrol group ID: $groupIdFromPatrolId").first { it.patrolId == patrolId }
|
||||
} catch (e: NoSuchElementException) {
|
||||
broadcastPersonal(player, "Spawn ID '$patrolId' did not return a spawn.")
|
||||
return null
|
||||
}
|
||||
val newLocation = Location.builder().setPosition(patrolWaypoint.x, patrolWaypoint.y, patrolWaypoint.z).setTerrain(patrolWaypoint.terrain).build()
|
||||
if (patrolWaypoint.buildingId.isEmpty() || patrolWaypoint.buildingId.endsWith("_world")) {
|
||||
teleportee.moveToLocation(newLocation)
|
||||
return "Succesfully teleported " + teleportee.objectName + " to patrol " + patrolId
|
||||
}
|
||||
val newParent = BuildingLookup.getBuildingByTag(patrolWaypoint.buildingId)?.getCellByNumber(patrolWaypoint.cellId)
|
||||
teleportee.moveToContainer(newParent, newLocation)
|
||||
return "Succesfully teleported " + teleportee.objectName + " to patrol " + patrolId
|
||||
}
|
||||
|
||||
private fun teleportToGoto(obj: SWGObject, building: BuildingObject, cellNumber: Int): String {
|
||||
val cell = building.getCellByNumber(cellNumber)
|
||||
if (cell == null) {
|
||||
|
||||
Reference in New Issue
Block a user