Skip to content

Commit 6bfaf5b

Browse files
committed
Removed "about to begin boarding" printout from travel, replacing with number of seconds remaining
1 parent 6e22d5b commit 6bfaf5b

3 files changed

Lines changed: 39 additions & 38 deletions

File tree

src/main/java/com/projectswg/holocore/resources/gameplay/world/travel/TravelGroup.kt

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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

2928
import com.projectswg.common.data.encodables.tangible.Posture
3029
import 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
3334
import java.util.concurrent.CopyOnWriteArrayList
3435
import 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) {

src/main/java/com/projectswg/holocore/resources/gameplay/world/travel/TravelHelper.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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
* *
@@ -44,15 +43,16 @@ import com.projectswg.holocore.resources.support.objects.swg.SWGObject
4443
import com.projectswg.holocore.resources.support.objects.swg.creature.CreatureObject
4544
import com.projectswg.holocore.resources.support.objects.swg.tangible.TangibleObject
4645
import com.projectswg.holocore.resources.support.objects.swg.tangible.TicketInformation
47-
import me.joshlarson.jlcommon.concurrency.ThreadPool
46+
import com.projectswg.holocore.utilities.HolocoreCoroutine
47+
import com.projectswg.holocore.utilities.cancelAndWait
4848
import me.joshlarson.jlcommon.log.Log
4949
import java.io.File
5050
import java.io.IOException
5151
import java.util.concurrent.ConcurrentHashMap
5252

5353
class TravelHelper {
5454
private val travel: MutableMap<String, TravelGroup> = ConcurrentHashMap()
55-
private val travelExecutor = ThreadPool(3, "travel-shuttles-%d")
55+
private val coroutineScope = HolocoreCoroutine.childScope()
5656
private val pointContainer = TravelPointContainer()
5757

5858
init {
@@ -61,12 +61,11 @@ class TravelHelper {
6161
}
6262

6363
fun start() {
64-
travelExecutor.start()
65-
for (gt in travel.values) travelExecutor.execute(gt)
64+
for (group in travel.values) group.launch(coroutineScope)
6665
}
6766

6867
fun stop() {
69-
travelExecutor.stop(true)
68+
coroutineScope.cancelAndWait()
7069
}
7170

7271
fun addTravelPoint(point: TravelPoint) {
@@ -185,7 +184,7 @@ class TravelHelper {
185184
}
186185

187186
private fun createGalaxyTravel(template: String, landTime: Long, groundTime: Long, airTime: Long) {
188-
travel[template] = TravelGroup(landTime * 1000 + 10000, groundTime * 1000, airTime * 1000)
187+
travel[template] = TravelGroup(landTime + 10, groundTime, airTime)
189188
}
190189

191190
private fun loadTravelPoints() {

src/main/java/com/projectswg/holocore/services/gameplay/world/travel/TravelService.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,11 @@ class TravelService : Service() {
143143
}
144144

145145
when (nearestPoint.group!!.status) {
146-
ShuttleStatus.GROUNDED -> if (tui.ticket == null) handleTicketUseSui(tui.player)
146+
ShuttleStatus.GROUNDED -> if (tui.ticket == null) handleTicketUseSui(tui.player)
147147
else travel.handleTicketUse(tui.player, tui.ticket, travel.getNearestTravelPoint(tui.ticket)!!, travel.getDestinationPoint(tui.ticket)!!)
148148

149-
ShuttleStatus.LANDING -> sendTravelMessage(creature, "@travel/travel:shuttle_begin_boarding")
150-
ShuttleStatus.LEAVING -> sendTravelMessage(creature, "@travel:shuttle_not_available")
151-
ShuttleStatus.AWAY -> sendTravelMessage(creature, "@travel/travel:shuttle_board_delay", "DI", nearestPoint.group.getTimeRemaining())
149+
ShuttleStatus.LEAVING -> sendTravelMessage(creature, "@travel:shuttle_not_available")
150+
ShuttleStatus.LANDING, ShuttleStatus.AWAY -> sendTravelMessage(creature, "@travel/travel:shuttle_board_delay", "DI", nearestPoint.group.getTimeRemaining())
152151
}
153152
}
154153

0 commit comments

Comments
 (0)