diff --git a/README.md b/README.md index ba67d106..a40c4c07 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ ### **Branch** ### -**Quality Assurance:** Upload your Pull Requests here so it can be tested - -**Development:** This is the main working space +**Quality Assurance:** Upload your Pull Requests here so it can be tested. This is the main working space **Master:** Tested and approved commits will be moved to this branch (Test Center) @@ -77,5 +75,4 @@ In order to successfully build and run Holocore, you must: * quest * snapshot * string - * terrain - + * terrain \ No newline at end of file diff --git a/serverdata/spawn/static.sdf b/serverdata/spawn/static.sdf new file mode 100644 index 00000000..7f7b8bf9 --- /dev/null +++ b/serverdata/spawn/static.sdf @@ -0,0 +1,2 @@ +SpawnID TerrainName SpawnerType BuildingID Cell x y z oX oY oZ oW active +i s s i s f f f f f f f i diff --git a/src/resources/spawn/SpawnType.java b/src/resources/spawn/SpawnType.java new file mode 100644 index 00000000..fa8ea7ea --- /dev/null +++ b/src/resources/spawn/SpawnType.java @@ -0,0 +1,44 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package resources.spawn; + +public enum SpawnType { + + EGG("object/tangible/spawning/shared_spawn_egg.iff"); + + private String objectTemplate; + + SpawnType(String objectTemplate) { + this.objectTemplate = objectTemplate; + } + + public String getObjectTemplate() { + return objectTemplate; + } + +} diff --git a/src/resources/spawn/Spawner.java b/src/resources/spawn/Spawner.java new file mode 100644 index 00000000..beccc8bf --- /dev/null +++ b/src/resources/spawn/Spawner.java @@ -0,0 +1,43 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package resources.spawn; + +import resources.objects.SWGObject; + +public final class Spawner { + + private SWGObject spawnerObject; + + public Spawner(SWGObject spawnerObject) { + this.spawnerObject = spawnerObject; + } + + public SWGObject getSpawnerObject() { + return spawnerObject; + } +} diff --git a/src/services/objects/ObjectManager.java b/src/services/objects/ObjectManager.java index 47fb7830..18746e2c 100644 --- a/src/services/objects/ObjectManager.java +++ b/src/services/objects/ObjectManager.java @@ -73,12 +73,14 @@ import resources.server_info.ObjectDatabase; import resources.server_info.ObjectDatabase.Traverser; import services.map.MapManager; import services.player.PlayerManager; +import services.spawn.SpawnerService; import services.spawn.StaticService; public class ObjectManager extends Manager { private final MapManager mapService; private final StaticService staticService; + private final SpawnerService spawnerService; private final RadialService radialService; private final ObjectDatabase database; @@ -89,6 +91,7 @@ public class ObjectManager extends Manager { public ObjectManager() { mapService = new MapManager(); staticService = new StaticService(this); + spawnerService = new SpawnerService(this); radialService = new RadialService(); database = new CachedObjectDatabase("odb/objects.db"); objectAwareness = new ObjectAwareness(); @@ -98,6 +101,7 @@ public class ObjectManager extends Manager { addChildService(mapService); addChildService(staticService); addChildService(radialService); + addChildService(spawnerService); } @Override diff --git a/src/services/spawn/SpawnerService.java b/src/services/spawn/SpawnerService.java new file mode 100644 index 00000000..ff89f6bb --- /dev/null +++ b/src/services/spawn/SpawnerService.java @@ -0,0 +1,109 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package services.spawn; + +import java.util.ArrayList; +import java.util.Collection; + +import intents.server.ConfigChangedIntent; +import resources.Location; +import resources.Terrain; +import resources.client_info.ServerFactory; +import resources.client_info.visitors.DatatableData; +import resources.config.ConfigFile; +import resources.control.Intent; +import resources.control.Service; +import resources.objects.building.BuildingObject; +import resources.objects.SWGObject; +import resources.spawn.SpawnType; +import resources.spawn.Spawner; +import services.objects.ObjectManager; + +public final class SpawnerService extends Service { + + private final ObjectManager objectManager; + private final Collection spawners; + + public SpawnerService(ObjectManager objectManager) { + this.objectManager = objectManager; + spawners = new ArrayList<>(); + } + + @Override + public boolean initialize() { + registerForIntent(ConfigChangedIntent.TYPE); + + if (getConfig(ConfigFile.FEATURES).getBoolean("SPAWNERS-ENABLED", true)) + loadEggs(); + + return super.initialize(); + } + + @Override + public void onIntentReceived(Intent i) { + ConfigChangedIntent cgi = (ConfigChangedIntent) i; + String newValue, oldValue; + + if(cgi.getChangedConfig().equals(ConfigFile.FEATURES)) + if(cgi.getKey().equals("SPAWNERS-ENABLED")) { + newValue = cgi.getNewValue(); + oldValue = cgi.getOldValue(); + + if(!newValue.equals(oldValue)) { + if(Boolean.valueOf(newValue) && spawners.isEmpty()) { // If nothing's been spawned, create it. + loadEggs(); + } else { // If anything's been spawned, delete it. + for(Spawner spawner : spawners) + objectManager.destroyObject(spawner.getSpawnerObject()); + + spawners.clear(); + } + } + } + + } + + private void loadEggs() { + DatatableData eggs = ServerFactory.getDatatable("spawn/static.iff"); + + eggs.handleRows(rowIndex -> { + if((Integer) eggs.getCell(rowIndex, 12) == 1) { // We only spawn active eggs + final int buildingId = (int) eggs.getCell(rowIndex, 3); + final Location loc = new Location((float) eggs.getCell(rowIndex, 5), (float) eggs.getCell(rowIndex, 6), (float) eggs.getCell(rowIndex, 7), Terrain.valueOf((String) eggs.getCell(rowIndex, 1))); + final SpawnType spawnType = SpawnType.valueOf((String) eggs.getCell(rowIndex, 2)); + final boolean spawnInCell = buildingId != 0; + final SWGObject egg = objectManager.createObject(spawnType.getObjectTemplate(), loc, !spawnInCell, false); + + if(spawnInCell) // If it wants to be inside a building, make it so! + ((BuildingObject) objectManager.getObjectById(buildingId)).getCellByName((String) eggs.getCell(rowIndex, 4)).addObject(egg); + + spawners.add(new Spawner(egg)); + } + }); + } +}