11/* **********************************************************************************
2- * Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
2+ * Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
33 * *
4- * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
4+ * ProjectSWG is an emulation project for Star Wars Galaxies founded on *
55 * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6- * Our goal is to create an emulator which will provide a server for players to *
7- * continue playing a game similar to the one they used to play. We are basing *
8- * it on the final publish of the game prior to end-game events. *
6+ * Our goal is to create one or more emulators which will provide servers for *
7+ * players to continue playing a game similar to the one they used to play. *
98 * *
109 * This file is part of Holocore. *
1110 * *
@@ -28,12 +27,14 @@ package com.projectswg.holocore.resources.gameplay.world.travel
2827
2928import com.projectswg.common.data.encodables.tangible.Posture
3029import com.projectswg.common.network.packets.swg.zone.PlayMusicMessage
31- import me.joshlarson.jlcommon.concurrency.Delay
32- import me.joshlarson.jlcommon.log.Log
30+ import kotlinx.coroutines.CoroutineScope
31+ import kotlinx.coroutines.delay
32+ import kotlinx.coroutines.isActive
33+ import kotlinx.coroutines.launch
3334import java.util.concurrent.CopyOnWriteArrayList
3435import java.util.concurrent.atomic.AtomicLong
3536
36- class TravelGroup (private val landTime : Long , private val groundTime : Long , private val airTime : Long ) : Runnable {
37+ class TravelGroup (private val landTime : Long , private val groundTime : Long , private val airTime : Long ) {
3738 private val points: MutableList <TravelPoint > = CopyOnWriteArrayList ()
3839 private val timeRemaining: AtomicLong = AtomicLong (airTime / 1000 )
3940 var status: ShuttleStatus
@@ -51,9 +52,9 @@ class TravelGroup(private val landTime: Long, private val groundTime: Long, priv
5152 return timeRemaining.toInt()
5253 }
5354
54- override fun run ( ) {
55- try {
56- while (! Delay .isInterrupted() ) {
55+ fun launch ( scope : CoroutineScope ) {
56+ scope.launch {
57+ while (isActive ) {
5758 // GROUNDED
5859 handleStatusGrounded()
5960 // LEAVING
@@ -63,35 +64,37 @@ class TravelGroup(private val landTime: Long, private val groundTime: Long, priv
6364 // LANDING
6465 handleStatusLanding()
6566 }
66- } catch (e: Exception ) {
67- Log .e(e)
6867 }
6968 }
7069
71- private fun handleStatusGrounded () {
70+ private suspend fun handleStatusGrounded () {
7271 status = ShuttleStatus .GROUNDED
73- Delay .sleepMilli (groundTime)
72+ delay (groundTime * 1000L )
7473 }
7574
76- private fun handleStatusLeaving () {
75+ private suspend fun handleStatusLeaving () {
7776 status = ShuttleStatus .LEAVING
7877 updateShuttlePostures(false )
79- Delay .sleepMilli (landTime)
78+ delay (landTime * 1000L )
8079 }
8180
82- private fun handleStatusAway () {
81+ private suspend fun handleStatusAway () {
8382 status = ShuttleStatus .AWAY
84- for (timeElapsed in 0 until airTime / 1000 ) {
85- if (Delay .sleepSeconds(1 )) break
83+ timeRemaining.set(airTime + landTime) // Reset the timer
84+ for (timeElapsed in 0 until airTime) {
85+ delay(1000L )
8686 timeRemaining.decrementAndGet()
8787 }
88- timeRemaining.set(airTime / 1000 ) // Reset the timer
8988 }
9089
91- private fun handleStatusLanding () {
90+ private suspend fun handleStatusLanding () {
9291 status = ShuttleStatus .LANDING
9392 updateShuttlePostures(true )
94- Delay .sleepMilli(landTime)
93+ timeRemaining.set(landTime) // Reset the timer
94+ for (timeElapsed in 0 until landTime) {
95+ delay(1000L )
96+ timeRemaining.decrementAndGet()
97+ }
9598 }
9699
97100 private fun updateShuttlePostures (landed : Boolean ) {
0 commit comments