diff --git a/scripts/commands/boardshuttle.py b/scripts/commands/boardshuttle.py index cc928a09..f84f7e9b 100644 --- a/scripts/commands/boardshuttle.py +++ b/scripts/commands/boardshuttle.py @@ -20,15 +20,22 @@ def run(core, actor, target, commandString): elif ticketList.isEmpty: actor.sendSystemMessage('You do not have a ticket to board this shuttle.', 0) return - return + elif nearestPoint.isShuttleLanding() is True: actor.sendSystemMessage('The next shuttle is about to begin boarding.', 0) return else: - - actor.sendSystemMessage('The next shuttle will arrive in 60 seconds.', 0) - #TODO: Counter for time when shuttle will arrive + # We don't want the remaining time to show as soon as the shuttle leaves, instead, we want an unavilable message. + if nearestPoint.isShuttleAvailable() is False and nearestPoint.isShuttleDeparting() is True: + actor.sendSystemMessage('@travel:shuttle_not_available', 0) + return + elif nearestPoint.getSecondsRemaining() == 0: + actor.sendSystemMessage('The next shuttle is about to begin boarding.', 0) + return + else: + actor.sendSystemMessage('The next shuttle will arrive in ' + str(nearestPoint.getSecondsRemaining()) + ' seconds.', 0) + return return return # NOTE: In NGE video from Jan. 4th, 2010, ticket purchase window is shown with just 1 ticket and does not diff --git a/src/services/command/CommandService.java b/src/services/command/CommandService.java index 9d8a4487..0449ac0b 100644 --- a/src/services/command/CommandService.java +++ b/src/services/command/CommandService.java @@ -260,7 +260,6 @@ public class CommandService implements INetworkDispatch { return; core.scriptService.callScript("scripts/commands/", command.getCommandName(), "run", core, actor, target, commandArgs); - System.out.println("Script called."); } @Override diff --git a/src/services/travel/ShuttleCountdown.java b/src/services/travel/ShuttleCountdown.java new file mode 100644 index 00000000..ce4c7042 --- /dev/null +++ b/src/services/travel/ShuttleCountdown.java @@ -0,0 +1,39 @@ +package services.travel; + +import java.util.Vector; +import java.util.Map.Entry; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import main.NGECore; +import resources.common.Console; +import engine.resources.scene.Planet; + +public class ShuttleCountdown implements Runnable { + + private NGECore core; + private final AtomicInteger runCount = new AtomicInteger(); + private final Runnable delegate; + private volatile ScheduledFuture self; + + public ShuttleCountdown(Runnable delegate, NGECore core) { + this.core = core; + this.delegate = delegate; + } + + @Override + public void run() { + delegate.run(); + Console.println("Atomic int: " + runCount.get()); + if (runCount.incrementAndGet() == 60) { + Console.println("Shutting down countdown!"); + self.cancel(false); + } + } + + public void startCountdown(ScheduledExecutorService scheduler) { + self = scheduler.scheduleAtFixedRate(delegate, 0, 1, TimeUnit.SECONDS); + } +} diff --git a/src/services/travel/TravelPoint.java b/src/services/travel/TravelPoint.java index 1c0a4266..27baf809 100644 --- a/src/services/travel/TravelPoint.java +++ b/src/services/travel/TravelPoint.java @@ -35,6 +35,8 @@ public class TravelPoint { private CreatureObject shuttle; private boolean shuttleAvailable; private boolean shuttleLanding; + private int secondsRemaining; + private boolean shuttleDeparting; public TravelPoint() { } @@ -45,6 +47,7 @@ public class TravelPoint { this.spawnLocation = new SpawnPoint(this.location, 0, 1); this.shuttleAvailable = false; this.shuttleLanding = false; + this.secondsRemaining = 0; } public String getName() { @@ -110,4 +113,20 @@ public class TravelPoint { public void setShuttleLanding(boolean shuttleLanding) { this.shuttleLanding = shuttleLanding; } + + public int getSecondsRemaining() { + return secondsRemaining; + } + + public void setSecondsRemaining(int secondsRemaining) { + this.secondsRemaining = secondsRemaining; + } + + public boolean isShuttleDeparting() { + return shuttleDeparting; + } + + public void setShuttleDeparting(boolean shuttleDeparting) { + this.shuttleDeparting = shuttleDeparting; + } } diff --git a/src/services/travel/TravelService.java b/src/services/travel/TravelService.java index 0aad702d..1464328a 100644 --- a/src/services/travel/TravelService.java +++ b/src/services/travel/TravelService.java @@ -129,12 +129,15 @@ public class TravelService implements INetworkDispatch { tp.getShuttle().setPosture((byte) 0); tp.setShuttleLanding(true); handleShuttleLanding(); + //Console.println("Started handle shuttle landing"); } else { tp.getShuttle().setPosture((byte) 2); tp.setShuttleAvailable(false); tp.setShuttleLanding(false); - Console.println("Shuttle is not available."); + tp.setShuttleDeparting(true); + handleShuttleDeparture(); + //Console.println("Shuttle is not available."); } } } @@ -144,10 +147,12 @@ public class TravelService implements INetworkDispatch { }; - scheduler.scheduleAtFixedRate(shuttleRun, 60, 60, TimeUnit.SECONDS); + scheduler.scheduleAtFixedRate(shuttleRun, 83, 83, TimeUnit.SECONDS); + + //shuttleCountdown(); } - public void handleShuttleLanding() { + private void handleShuttleLanding() { scheduler.schedule(new Runnable() { @Override @@ -157,16 +162,58 @@ public class TravelService implements INetworkDispatch { if (tp.isShuttleLanding()) { tp.setShuttleLanding(false); tp.setShuttleAvailable(true); - Console.println("Shuttle has landed!"); + //Console.println("Shuttle has landed!"); } } } } - }, 26, TimeUnit.SECONDS); + }, 27, TimeUnit.SECONDS); } + private void handleShuttleDeparture() { + scheduler.schedule(new Runnable() { + + @Override + public void run() { + for (Entry> entry : travelMap.entrySet()) { + for(TravelPoint tp : entry.getValue()) { + tp.setShuttleDeparting(false); + tp.setSecondsRemaining(60); + + } + } + shuttleCountdown(); + //Console.println("Countdown initiated"); + } + + }, 20, TimeUnit.SECONDS); + } + + private void shuttleCountdown() { + Runnable countDown = new Runnable() { + @Override + public void run() { + for (Entry> entry : travelMap.entrySet()) { + for(TravelPoint tp : entry.getValue()) { + if (tp.getShuttle() == null || tp.isShuttleDeparting() == true || tp.isShuttleAvailable() == true || tp.getSecondsRemaining() == 0) + continue; + + else { + tp.setSecondsRemaining(tp.getSecondsRemaining() - 1); + //Console.println("Time Remaining: " + tp.getSecondsRemaining()); + } + } + } + } + + }; + + runCountdown(countDown, scheduler); + + } + public TravelPoint getNearestTravelPoint(SWGObject obj) { TravelPoint returnedPoint = null; Vector planetTp = travelMap.get(obj.getPlanet()); @@ -376,6 +423,8 @@ public class TravelService implements INetworkDispatch { selectedTicket.getContainer().remove(selectedTicket); core.objectService.destroyObject(selectedTicket); doTransport(creature, arrivalPoint); + } else { + creature.sendSystemMessage("@travel:shuttle_not_available ", (byte) 0); } } }); @@ -429,6 +478,14 @@ public class TravelService implements INetworkDispatch { } } + public Map> getTravelMap() { + return this.travelMap; + } + + public void runCountdown(Runnable task, ScheduledExecutorService executor) { + new ShuttleCountdown(task, this.core).startCountdown(executor); + } + @Override public void shutdown() {