mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-10-14 04:13:14 -04:00
Added shuttling system, can travel between points
Only the Mos Eisley transport ship exists. Will more than likely change how shuttles/transports are added to the game world.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
def setup():
|
||||
return
|
||||
|
||||
def run(core, actor, target, commandString):
|
||||
trvSvc = core.travelService
|
||||
ticketList = trvSvc.getTicketList(actor)
|
||||
print ('command called')
|
||||
if ticketList.size() >= 1:
|
||||
trvSvc.sendTicketWindow(actor)
|
||||
return
|
||||
|
||||
elif ticketList.size() == 1:
|
||||
planetArrival = ticketList.get[0].getStringAttribute('@obj_attr_n:travel_arrival_planet')
|
||||
locationArrival = ticketList.get[0].getStringAttribute('@obj_attr_n:travel_arrival_point')
|
||||
tpArrival = trvSvc.getTravelPointByName(planet, location)
|
||||
|
||||
trvSvc.doTransport(actor, tpArrival)
|
||||
|
||||
return
|
||||
elif ticketList.isEmpty == True:
|
||||
actor.sendSystemMessage("You don't have a travel ticket for this shuttle.", 0)
|
||||
return
|
||||
#--tp = core.travelService.getTravelPointByName(travelTicket.getStringAttribute('@obj_attr_n:travel_arrival_point'))
|
||||
return
|
||||
@@ -1,4 +1,7 @@
|
||||
import sys
|
||||
|
||||
def setup(core, object):
|
||||
object.setPosture(0) # land = 0 : away = 2
|
||||
object.setOptionsBitmask(256)
|
||||
core.travelService.addShuttleToPoint(object)
|
||||
return
|
||||
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
|
||||
def setup(core, object):
|
||||
object.setAttachment('radial_filename', 'npc_ticket_collector')
|
||||
return
|
||||
@@ -0,0 +1,17 @@
|
||||
from resources.common import RadialOptions
|
||||
import sys
|
||||
|
||||
def createRadial(core, owner, target, radials):
|
||||
return
|
||||
|
||||
def handleSelection(core, owner, target, option):
|
||||
trvSvc = core.travelService
|
||||
if option == 21 and target:
|
||||
core.commandService.callCommand(owner, 'boardshuttle', target, '')
|
||||
print ('command called')
|
||||
return
|
||||
return
|
||||
|
||||
def handleSUI(owner, window, eventType, returnList):
|
||||
|
||||
return
|
||||
@@ -10,6 +10,9 @@ def addPlanetSpawns(core, planet):
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(-1382.15), float(12), float(-3583.25), float(1), float(-0.08)) # bestine starport
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(3427.5), float(5.6), float(-4644.1), float(-0.485545), float(0.874212)) # mos eisley shuttleport
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(3623.5), float(5), float(-4793.5), float(-0.103924), float(0.994585)) # mos eisley starport
|
||||
|
||||
stcSvc.spawnObject('object/creature/npc/theme_park/shared_player_transport.iff', 'tatooine', long(0), float(3619), float(5), float(-4801), float(-0.103924), float(0)) # mos eisley starport
|
||||
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(-2886.3), float(5.6), float(1929.4), float(-0.113814), float(0.993502)) # mos espa shuttleport a
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(-3116.3), float(5.6), float(2166.1), float(-0.621933), float(0.783071)) # mos espa shuttleport b
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(3623.5), float(5.6), float(2178.4), float(-0.123692), float(0.992321)) # mos espa shuttleport c
|
||||
@@ -19,7 +22,6 @@ def addPlanetSpawns(core, planet):
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(1721.5), float(7.6), float(3191.3), float(1), float(0)) # mos entha shuttleport b
|
||||
stcSvc.spawnObject('object/tangible/travel/ticket_collector/shared_ticket_collector.iff', 'tatooine', long(0), float(-2820.5), float(5), float(2083.71), float(0), float(1)) # mos espa starport
|
||||
|
||||
|
||||
|
||||
stcSvc.spawnObject('object/tangible/terminal/shared_terminal_travel.iff', 'tatooine', long(0), float(-1091.9), float(12.6), float(-3572.7), float(-0.645025), float(0.764162)) # bestine shuttleport
|
||||
stcSvc.spawnObject('object/tangible/terminal/shared_terminal_travel.iff', 'tatooine', long(0), float(-2903.5), float(5.6), float(1924), float(-0.113814), float(0.993502)) # mos espa shuttleport a
|
||||
|
||||
@@ -72,11 +72,11 @@ def nabooPoints(core, planet):
|
||||
|
||||
def roriPoints(core, planet):
|
||||
trvSvc = core.travelService
|
||||
|
||||
|
||||
trvSvc.addTravelPoint(planet, "Narmle Starport", -5472, 80, 2161)
|
||||
trvSvc.addTravelPoint(planet, "Rebel Outpost", 3672, 96, -6421)
|
||||
return
|
||||
|
||||
|
||||
def talusPoints(core, planet):
|
||||
trvSvc = core.travelService
|
||||
|
||||
|
||||
@@ -250,12 +250,12 @@ public class NGECore {
|
||||
simulationService = new SimulationService(this);
|
||||
zoneDispatch.addService(simulationService);
|
||||
|
||||
// Static Spawns
|
||||
staticService.spawnStatics();
|
||||
|
||||
// Travel Points
|
||||
travelService.loadTravelPoints();
|
||||
|
||||
// Static Spawns
|
||||
staticService.spawnStatics();
|
||||
|
||||
guildService = new GuildService(this);
|
||||
zoneDispatch.addService(guildService);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PlanetTravelPointListResponse extends SWGMessage {
|
||||
public IoBuffer serialize() {
|
||||
IoBuffer result = IoBuffer.allocate(700).order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
result.putShort((short) 9);
|
||||
result.putShort((short) 6);
|
||||
result.putInt(0x4D32541F);
|
||||
|
||||
result.put(getAsciiString(planetString));
|
||||
|
||||
@@ -40,6 +40,11 @@ public class SpawnPoint {
|
||||
this.setOrientation(orientation);
|
||||
}
|
||||
|
||||
public SpawnPoint(Point3D position, float oY, float oW) {
|
||||
this.setPosition(position);
|
||||
this.setOrientation(new Quaternion(oW, 0, oY, 0));
|
||||
}
|
||||
|
||||
public SpawnPoint(float x, float y, float z, float oY, float oW) {
|
||||
this.setPosition(new Point3D(x, y, z));
|
||||
this.setOrientation(new Quaternion(oW, 0, oY, 0));
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package resources.common;
|
||||
|
||||
public class StateStatus {
|
||||
// States.iff
|
||||
public static int Invalid = -1;
|
||||
public static int Cover = 0;
|
||||
public static int Combat = 1;
|
||||
public static int Peace = 2;
|
||||
public static int Aiming = 3;
|
||||
public static int Alert = 4;
|
||||
public static int Berserk = 5;
|
||||
public static int FeignDeath = 6;
|
||||
public static int CombatAttitudeEvasive = 7;
|
||||
public static int CombatAttitudeNormal = 8;
|
||||
public static int CombatAttitudeAggressive = 9;
|
||||
public static int Tumbling = 10;
|
||||
public static int Rallied = 11;
|
||||
public static int Stunned = 12;
|
||||
public static int Blinded = 13;
|
||||
public static int Dizzy = 14;
|
||||
public static int Intimidated =15;
|
||||
public static int Immobilized = 16;
|
||||
public static int Frozen = 17;
|
||||
public static int Swimming = 18;
|
||||
public static int SittingOnChair = 19;
|
||||
public static int Crafting = 20;
|
||||
public static int GlowingJedi = 21;
|
||||
public static int MaskScent = 22;
|
||||
public static int Poisoned = 23;
|
||||
public static int Bleeding = 24;
|
||||
public static int Diseased = 25;
|
||||
public static int OnFire = 26;
|
||||
public static int RidingMount = 27;
|
||||
public static int MountedCreature = 28;
|
||||
public static int PilotingShip = 29;
|
||||
public static int ShipOperations = 30;
|
||||
public static int ShipGunner = 31;
|
||||
public static int ShipInterior = 32;
|
||||
public static int PilotingPobShip = 33;
|
||||
public static int PerformingDeathBlow = 34;
|
||||
public static int Disguised = 35;
|
||||
public static int ElectricBurned = 36;
|
||||
public static int ColdBurned = 37;
|
||||
public static int AcidBurned = 38;
|
||||
public static int EnergyBurned = 39;
|
||||
public static int KineticBurned = 40;
|
||||
}
|
||||
@@ -95,6 +95,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
|
||||
buffer.put(getAsciiString(creature.getStfFilename()));
|
||||
buffer.putInt(0);
|
||||
buffer.put(getAsciiString(creature.getStfName()));
|
||||
if (creature.getCustomName() == null) { creature.setCustomName(""); }//Not all CreatureObjects have CustomName (Shuttles)
|
||||
buffer.put(getUnicodeString(creature.getCustomName()));
|
||||
buffer.putInt(0x000F4240); // unk
|
||||
String factionCRC = creature.getFaction();
|
||||
@@ -109,7 +110,7 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder {
|
||||
|
||||
byte[] customizationData = creature.getCustomization();
|
||||
|
||||
if(customizationData.length <= 0)
|
||||
if(customizationData == null || customizationData.length <= 0) // Shuttles have no customization data
|
||||
buffer.putShort((short) 0);
|
||||
else {
|
||||
buffer.putShort((short) customizationData.length);
|
||||
|
||||
@@ -139,6 +139,7 @@ public class SimulationService implements INetworkDispatch {
|
||||
core.commandService.registerCommand("endduel");
|
||||
core.commandService.registerCommand("duel");
|
||||
core.commandService.registerCommand("purchaseticket");
|
||||
core.commandService.registerCommand("boardshuttle");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -250,6 +250,18 @@ public class CommandService implements INetworkDispatch {
|
||||
|
||||
}
|
||||
|
||||
public void callCommand(CreatureObject actor, String commandName, SWGObject target, String commandArgs) {
|
||||
if (actor == null)
|
||||
return;
|
||||
|
||||
BaseSWGCommand command = getCommandByName(commandName);
|
||||
|
||||
if (command == null)
|
||||
return;
|
||||
|
||||
core.scriptService.callScript("scripts/commands/", command.getCommandName(), "run", core, actor, target, commandArgs);
|
||||
System.out.println("Script called.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
@@ -77,6 +77,7 @@ import resources.objects.staticobject.StaticObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
import resources.objects.waypoint.WaypointObject;
|
||||
import resources.objects.weapon.WeaponObject;
|
||||
import services.travel.ShuttleObject;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -142,7 +143,11 @@ public class ObjectService implements INetworkDispatch {
|
||||
if(objectID == 0)
|
||||
objectID = generateObjectID();
|
||||
|
||||
if(Template.startsWith("object/creature")) {
|
||||
if(Template.equals(ShuttleObject.ShuttleType.CIVILIAN.toString()) || Template.equals(ShuttleObject.ShuttleType.STARSHIP.toString()) ||
|
||||
Template.equals(ShuttleObject.ShuttleType.THEED.toString())) {
|
||||
object = new ShuttleObject(objectID, planet, position, orientation, Template);
|
||||
|
||||
} else if(Template.startsWith("object/creature")) {
|
||||
|
||||
object = new CreatureObject(objectID, planet, position, orientation, Template);
|
||||
|
||||
@@ -182,7 +187,7 @@ public class ObjectService implements INetworkDispatch {
|
||||
|
||||
object = new WaypointObject(objectID, planet, position);
|
||||
|
||||
} else {
|
||||
} else {
|
||||
|
||||
return null;
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package services.travel;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import engine.resources.scene.Planet;
|
||||
import engine.resources.scene.Point3D;
|
||||
import engine.resources.scene.Quaternion;
|
||||
import resources.objects.creature.CreatureObject;
|
||||
|
||||
public class ShuttleObject extends CreatureObject {
|
||||
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private boolean isInPort;
|
||||
private int nextShuttleTime;
|
||||
|
||||
|
||||
public ShuttleObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) {
|
||||
super(objectID, planet, position, orientation, Template);
|
||||
scheduleShuttle();
|
||||
}
|
||||
|
||||
public ShuttleObject() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void scheduleShuttle() {
|
||||
final Runnable myRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isInPort) {
|
||||
setPosture((byte) 2);
|
||||
isInPort = false;
|
||||
nextShuttleTime = 60;
|
||||
} else {
|
||||
setPosture((byte) 0);
|
||||
isInPort = true;
|
||||
nextShuttleTime = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
scheduler.scheduleAtFixedRate(myRunnable, 60, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public enum ShuttleType {
|
||||
STARSHIP,
|
||||
CIVILIAN,
|
||||
THEED;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
case CIVILIAN:
|
||||
return "object/creature/npc/theme_park/shared_player_shuttle.iff";
|
||||
case STARSHIP:
|
||||
return "object/creature/npc/theme_park/shared_player_transport.iff";
|
||||
case THEED:
|
||||
return "object/creature/npc/theme_park/shared_player_transport_theed_hangar.iff";
|
||||
default:
|
||||
return "object/creature/npc/theme_park/shared_player_shuttle.iff";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ScheduledExecutorService getSchedule() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
public boolean isInPort() {
|
||||
return this.isInPort;
|
||||
}
|
||||
|
||||
public int getNextShuttleTime() {
|
||||
return this.nextShuttleTime;
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,17 @@
|
||||
******************************************************************************/
|
||||
package services.travel;
|
||||
|
||||
import resources.common.SpawnPoint;
|
||||
import engine.resources.scene.Point3D;
|
||||
|
||||
public class TravelPoint {
|
||||
|
||||
private String planetName;
|
||||
private String name;
|
||||
//private float posX;
|
||||
//private float posY;
|
||||
//private float posZ;
|
||||
private Point3D location;
|
||||
private SpawnPoint spawnLocation;
|
||||
private int ticketPrice;
|
||||
private ShuttleObject shuttleObject;
|
||||
|
||||
public TravelPoint() {
|
||||
}
|
||||
@@ -39,6 +39,8 @@ public class TravelPoint {
|
||||
public TravelPoint(String name, float x, float y, float z, int price) {
|
||||
this.name = name;
|
||||
this.location = new Point3D(x, y, z);
|
||||
this.spawnLocation = new SpawnPoint(this.location, 0, 1);
|
||||
this.shuttleObject = new ShuttleObject();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -72,4 +74,20 @@ public class TravelPoint {
|
||||
public void setPlanetName(String planetName) {
|
||||
this.planetName = planetName;
|
||||
}
|
||||
|
||||
public SpawnPoint getSpawnLocation() {
|
||||
return this.spawnLocation;
|
||||
}
|
||||
|
||||
public void setSpawnLocation(SpawnPoint point) {
|
||||
this.spawnLocation = point;
|
||||
}
|
||||
|
||||
public ShuttleObject getShuttle() {
|
||||
return this.shuttleObject;
|
||||
}
|
||||
|
||||
public void setShuttle(ShuttleObject shuttleObj) {
|
||||
this.shuttleObject = shuttleObj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,13 @@
|
||||
package services.travel;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
@@ -34,8 +37,10 @@ import org.apache.mina.core.session.IoSession;
|
||||
import protocol.swg.PlanetTravelPointListRequest;
|
||||
import protocol.swg.PlanetTravelPointListResponse;
|
||||
import engine.clients.Client;
|
||||
import engine.resources.container.Traverser;
|
||||
import engine.resources.objects.SWGObject;
|
||||
import engine.resources.scene.Planet;
|
||||
import engine.resources.scene.Point3D;
|
||||
import engine.resources.scene.quadtree.QuadTree;
|
||||
import engine.resources.service.INetworkDispatch;
|
||||
import engine.resources.service.INetworkRemoteEvent;
|
||||
@@ -45,12 +50,16 @@ import resources.objects.creature.CreatureObject;
|
||||
import resources.objects.player.PlayerObject;
|
||||
import resources.objects.tangible.TangibleObject;
|
||||
import services.map.*;
|
||||
import services.sui.SUIService.ListBoxType;
|
||||
import services.sui.SUIWindow.SUICallback;
|
||||
import services.sui.SUIWindow.Trigger;
|
||||
import services.sui.SUIWindow;
|
||||
|
||||
public class TravelService implements INetworkDispatch {
|
||||
|
||||
private NGECore core;
|
||||
|
||||
private Map<Planet, Vector<TravelPoint>> travelMap = new ConcurrentHashMap<Planet, Vector<TravelPoint>>();
|
||||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
public TravelService(NGECore core) {
|
||||
this.core = core;
|
||||
@@ -88,37 +97,64 @@ public class TravelService implements INetworkDispatch {
|
||||
PlanetTravelPointListResponse response = new PlanetTravelPointListResponse(planetString, travelMap.get(planet), planetList);
|
||||
client.getSession().write(response.serialize());
|
||||
break;
|
||||
//System.out.println("Sent the list for the planet " + planet.getName());
|
||||
|
||||
}
|
||||
}
|
||||
//PlanetTravelPointListResponse response = new PlanetTravelPointListResponse(request.getPlanet(), travelMap.get(request.getPlanet()));
|
||||
//client.getSession().write(response.serialize());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public TravelPoint getNearestTravelPoint() {
|
||||
TravelPoint returnedPoint = null;
|
||||
|
||||
|
||||
return returnedPoint;
|
||||
}
|
||||
|
||||
public TravelPoint getTravelPointByName(String planet, String tpName) {
|
||||
Planet planetObj = core.terrainService.getPlanetByName(planet.toLowerCase());
|
||||
|
||||
Vector<TravelPoint> tpMap = travelMap.get(planetObj);
|
||||
|
||||
TravelPoint returnedPoint = null;
|
||||
|
||||
for (TravelPoint tp : tpMap) {
|
||||
if (tp.getName().equals(tpName)) {
|
||||
returnedPoint = tp;
|
||||
}
|
||||
}
|
||||
if (returnedPoint == null) { System.out.println("Couldn't find a travelpoint w/ name " + tpName); }
|
||||
return returnedPoint;
|
||||
}
|
||||
|
||||
public void addPlanet(Planet planet) {
|
||||
Vector<TravelPoint> travelPointVector = new Vector<TravelPoint>();
|
||||
travelMap.put(planet, travelPointVector);
|
||||
core.scriptService.callScript("scripts/", "addPoints", "static_travel_points", core, planet);
|
||||
}
|
||||
|
||||
|
||||
public void addShuttleToPoint(SWGObject obj) {
|
||||
Vector<TravelPoint> travelPoints = travelMap.get(obj.getPlanet());
|
||||
|
||||
for (TravelPoint tp : travelPoints) {
|
||||
float distancePoint = tp.getLocation().getDistance2D(obj.getPosition());
|
||||
System.out.println("Distance from point " + tp.getName() + ": " + distancePoint);
|
||||
|
||||
// Travel points must be within 50 meters of shuttles!
|
||||
if (distancePoint <= (float) 50) {
|
||||
tp.setShuttle((ShuttleObject) obj);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void addTravelPoint(Planet planet, String name, float x, float y, float z) {
|
||||
// z should be y for 2d map
|
||||
TravelPoint travelPoint = new TravelPoint(name, x, y, z, 100);
|
||||
|
||||
travelPoint.setPlanetName(WordUtils.capitalize(planet.getName()));
|
||||
|
||||
//CreatureObject shuttleObj = (CreatureObject) core.objectService.createObject("object/creature/npc/theme_park/player_transport.iff", planet, x, z, y);
|
||||
// x z y
|
||||
//core.objectService.createObject("object/creature/npc/theme_park/shared_player_transport.iff", planet, 3622, 5, -4792);
|
||||
//TangibleObject collector = (TangibleObject) core.objectService.createObject("object/tangible/travel/ticket_collector/shared_ticket_collector.iff", planet, 3622, 5, -4792);
|
||||
//core.simulationService.add(collector, collector.getPosition().x, collector.getPosition().y);
|
||||
|
||||
if (travelMap.containsKey(planet)) {
|
||||
|
||||
travelMap.get(planet).add(travelPoint);
|
||||
@@ -131,8 +167,6 @@ public class TravelService implements INetworkDispatch {
|
||||
System.out.println("Added planet " + planet.getName() + " to TravelMap.");
|
||||
System.out.println("Added travel point " + travelPoint.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void removeTravelPointByName(Planet planet, String name){
|
||||
@@ -155,32 +189,6 @@ public class TravelService implements INetworkDispatch {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTravelAttachment(SWGObject obj) {
|
||||
Vector<TravelPoint> planetTravelPoints = travelMap.get(obj.getPlanet());
|
||||
|
||||
TravelPoint travelPoint = null;
|
||||
|
||||
for (TravelPoint point : planetTravelPoints) {
|
||||
if (obj.getPosition().x == point.getLocation().x && obj.getPosition().y == point.getLocation().y && obj.getPosition().z == point.getLocation().z) {
|
||||
|
||||
point = travelPoint;
|
||||
|
||||
if (travelPoint == null)
|
||||
return;
|
||||
|
||||
obj.setAttachment("transport", travelPoint);
|
||||
System.out.println("Set the objects travel point.");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
else {
|
||||
System.out.println("Could not set a travel attachment for obj!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SWGObject createTravelTicket(String departurePlanet, String departureLoc, String arrivalPlanet, String arrivalLoc) {
|
||||
|
||||
Planet planet = core.terrainService.getPlanetByName(departurePlanet.toLowerCase());
|
||||
@@ -192,31 +200,110 @@ public class TravelService implements INetworkDispatch {
|
||||
travelTicket.setStringAttribute("@obj_attr_n:travel_arrival_planet", WordUtils.capitalize(arrivalPlanet));
|
||||
travelTicket.setStringAttribute("@obj_attr_n:travel_arrival_point", arrivalLoc);
|
||||
|
||||
travelTicket.setAttachment("objType", "ticket");
|
||||
System.out.println("Object type: " + travelTicket.getAttachment("objType"));
|
||||
|
||||
return travelTicket;
|
||||
}
|
||||
|
||||
public void purchaseTravelTicket(SWGObject player, String departurePlanet, String departureLoc, String arrivalPlanet, String arrivalLoc) {
|
||||
//PlayerObject playerObj = (PlayerObject) player.getSlottedObject("ghost");
|
||||
CreatureObject creatureObj = (CreatureObject) player;
|
||||
|
||||
|
||||
SWGObject travelTicket = createTravelTicket(departurePlanet, departureLoc, arrivalPlanet, arrivalLoc);
|
||||
|
||||
creatureObj.getSlottedObject("inventory").add(travelTicket);
|
||||
travelTicket.isSubChildOf(player);
|
||||
|
||||
creatureObj.sendSystemMessage("@travel:ticket_purchase_complete", (byte) 0);
|
||||
System.out.println("Created travel ticket: " + departurePlanet + " " + departureLoc + " " + arrivalPlanet + " " + arrivalLoc);
|
||||
}
|
||||
|
||||
public void handleTicketCollector(SWGObject player, TravelPoint tp) {
|
||||
List<SWGObject> objectList = core.simulationService.get(player.getPlanet(), tp.getLocation().x, tp.getLocation().y, 100);
|
||||
for (SWGObject obj : objectList) {
|
||||
if (obj.getAttachment("transport") == tp) {
|
||||
System.out.println("Shuttle is in range!");
|
||||
break;
|
||||
//obj.setAttachment(arg0, arg1);
|
||||
// This returns all ticket objects in a players inventory
|
||||
public Vector<SWGObject> getTicketList(SWGObject player) {
|
||||
|
||||
final Vector<SWGObject> ticketList = new Vector<SWGObject>();
|
||||
|
||||
TangibleObject playerInventory = (TangibleObject) player.getSlottedObject("inventory");
|
||||
|
||||
playerInventory.viewChildren(player, false, false, new Traverser() {
|
||||
// ^-topDown-^-recursive
|
||||
// topDown - If true, objects that are at the top of the tree are viewed first.
|
||||
// the "viewer" needs to be whatever object wants to know this information (player)
|
||||
@Override
|
||||
public void process(SWGObject obj) {
|
||||
if (obj.getAttachment("objType") != null) {
|
||||
String objType = (String) obj.getAttachment("objType");
|
||||
String ticket = "ticket";
|
||||
if (objType.equals(ticket)) {
|
||||
ticketList.add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return ticketList;
|
||||
}
|
||||
|
||||
// TravelPoint = the travelpoint player is going to travel to!
|
||||
public void doTransport(SWGObject actor, TravelPoint tp) {
|
||||
|
||||
if (tp.getPlanetName().toLowerCase().equals(actor.getPlanet().name)) {
|
||||
core.simulationService.teleport(actor, tp.getSpawnLocation().getPosition(), tp.getSpawnLocation().getOrientation(), 0);
|
||||
}
|
||||
|
||||
else { core.simulationService.transferToPlanet(actor, core.terrainService.getPlanetByName(tp.getPlanetName()), tp.getSpawnLocation().getPosition(), tp.getSpawnLocation().getOrientation(), actor); }
|
||||
}
|
||||
|
||||
|
||||
public void sendTicketWindow(final CreatureObject creature) {
|
||||
|
||||
if (creature == null)
|
||||
return;
|
||||
|
||||
Map<Long, String> ticketData = new HashMap<Long, String>();
|
||||
Vector<SWGObject> invTickets = getTicketList(creature);
|
||||
|
||||
for (SWGObject ticket : invTickets) {
|
||||
ticketData.put(ticket.getObjectId(), ticket.getStringAttribute("@obj_attr_n:travel_arrival_planet") + " -- "
|
||||
+ ticket.getStringAttribute("@obj_attr_n:travel_arrival_point"));
|
||||
}
|
||||
|
||||
final SUIWindow window = core.suiService.createListBox(ListBoxType.LIST_BOX_OK_CANCEL, "Select Destination", "Select Destination", ticketData, creature, null, 0);
|
||||
Vector<String> returnList = new Vector<String>();
|
||||
returnList.add("List.lstList:SelectedRow");
|
||||
|
||||
window.addHandler(0, "", Trigger.TRIGGER_OK, returnList, new SUICallback() {
|
||||
|
||||
@Override
|
||||
public void process(SWGObject owner, int eventType, Vector<String> returnList) {
|
||||
// return list = int number of selected row
|
||||
int index = Integer.parseInt(returnList.get(0));
|
||||
|
||||
SWGObject selectedTicket = core.objectService.getObject(window.getObjectIdByIndex(index));
|
||||
System.out.println("Selected ticket obj: " + window.getObjectIdByIndex(index));
|
||||
|
||||
TravelPoint arrivalPoint = getTravelPointByName(selectedTicket.getStringAttribute("@obj_attr_n:travel_arrival_planet").toLowerCase(),
|
||||
selectedTicket.getStringAttribute("@obj_attr_n:travel_arrival_point"));
|
||||
|
||||
TravelPoint departurePoint = getTravelPointByName(creature.getPlanet().name, selectedTicket.getStringAttribute("@obj_attr_n:travel_departure_point"));
|
||||
|
||||
if (departurePoint.getShuttle() == null) {
|
||||
System.out.println("TravelPoint has no associated shuttle!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (departurePoint.getShuttle().isInPort()) {
|
||||
selectedTicket.getContainer().remove(selectedTicket);
|
||||
core.objectService.destroyObject(selectedTicket);
|
||||
doTransport(creature, arrivalPoint);
|
||||
}
|
||||
else {
|
||||
creature.sendSystemMessage("The next shuttle arrives in " + departurePoint.getShuttle().getNextShuttleTime() + " seconds.", (byte) 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
core.suiService.openSUIWindow(window);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user