From 62bc6a57719bf9b0aba6640feb1920089fb25750 Mon Sep 17 00:00:00 2001 From: Treeku Date: Sat, 3 May 2014 20:18:00 +0100 Subject: [PATCH] StaticService now reads from planetName folders Put any scripts in there, named anything. They could be separated into questlines, such as Jabbas Themepark, Rebel Themepark, Imperial Themepark, lifeday, corellia themepark. They can also be names of planet areas. This makes it easier for multiple people to work on different spawns on the same planet and makes the spawns for a particular subject easy to find. --- .../objects/weapon/WeaponObject.java | 1 - src/services/StaticService.java | 52 ++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/resources/objects/weapon/WeaponObject.java b/src/resources/objects/weapon/WeaponObject.java index 26115f42..65d15a72 100644 --- a/src/resources/objects/weapon/WeaponObject.java +++ b/src/resources/objects/weapon/WeaponObject.java @@ -24,7 +24,6 @@ package resources.objects.weapon; import java.io.Serializable; import resources.datatables.WeaponType; -import resources.objects.ObjectMessageBuilder; import resources.objects.tangible.TangibleObject; import com.sleepycat.persist.model.NotPersistent; diff --git a/src/services/StaticService.java b/src/services/StaticService.java index 41401fea..d41c26d8 100644 --- a/src/services/StaticService.java +++ b/src/services/StaticService.java @@ -21,10 +21,19 @@ ******************************************************************************/ package services; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; +import resources.common.FileUtilities; import resources.objects.building.BuildingObject; import resources.objects.cell.CellObject; import resources.objects.creature.CreatureObject; @@ -55,17 +64,34 @@ public class StaticService implements INetworkDispatch { } } - spawnObjects("rori"); - spawnObjects("naboo"); - spawnObjects("tatooine"); - spawnObjects("lok"); - //spawnObjects("kaas"); // Keep commented out unless you possess the latest build of Kaas! - } - - public void spawnObjects(String planetName) { - Planet planet = (Planet) core.terrainService.getPlanetByName(planetName); - core.scriptService.callScript("scripts/static_spawns/", planet.getName(), "addPlanetSpawns", core, planet); - System.out.println("Loaded static objects for " + planet.getName()); + for (Planet planet : core.terrainService.getPlanetList()) { + if (FileUtilities.doesFileExist("scripts/static_spawns/" + planet.getName())) { + Path p = Paths.get("scripts/static_spawns/" + planet.getName()); + + FileVisitor fv = new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.getFileName().toString().endsWith(".py")) { + core.scriptService.callScript("scripts/static_spawns/" + planet.getName() + "/", file.getFileName().toString().replace(".py", ""), "addPlanetSpawns", core, planet); + } + + return FileVisitResult.CONTINUE; + } + }; + + try { + Files.walkFileTree(p, fv); + } catch (IOException e) { + e.printStackTrace(); + } + } + + if (FileUtilities.doesFileExist("scripts/static_spawns/" + planet.getName() + ".py")) { + core.scriptService.callScript("scripts/static_spawns/", planet.getName(), "addPlanetSpawns", core, planet); + } + + System.out.println("Loaded static objects for " + planet.getName()); + } } public SWGObject spawnObject(String template, String planetName, long cellId, float x, float y, float z, float qY, float qW) { @@ -111,7 +137,9 @@ public class StaticService implements INetworkDispatch { ((CreatureObject) object).setStaticNPC(true); } - if (object instanceof BuildingObject) { + boolean checkCells = false; // shouldn't be needed; for debugging + + if (object instanceof BuildingObject && checkCells) { BuildingObject building = (BuildingObject) object; Map attributes = building.getTemplateData().getAttributes();