diff --git a/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/DataLoader.kt b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/DataLoader.kt index 84e1bcfec..bb68a940c 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/DataLoader.kt +++ b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/DataLoader.kt @@ -56,7 +56,8 @@ abstract class DataLoader { fun vehicles(): VehicleLoader = ServerData.vehicles fun specialLines(): SpecialLineLoader = ServerData.specialLines fun staticPvpZones(): StaticPvpZoneLoader = ServerData.staticPvpZones - + fun gcwRegionLoader(): GcwRegionLoader = ServerData.gcwRegionLoader + } } diff --git a/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/GcwRegionLoader.java b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/GcwRegionLoader.java new file mode 100644 index 000000000..52cec24f3 --- /dev/null +++ b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/GcwRegionLoader.java @@ -0,0 +1,96 @@ +/*********************************************************************************** + * Copyright (c) 2018 /// 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 com.projectswg.holocore.resources.support.data.server_info.loader; + +import com.projectswg.common.data.location.Terrain; +import com.projectswg.holocore.resources.support.data.server_info.SdbLoader; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +public class GcwRegionLoader extends DataLoader { + + private final Map> regions; + + public GcwRegionLoader() { + regions = new HashMap<>(); + } + + @NotNull + public Map> getRegionsByTerrain() { + return Collections.unmodifiableMap(regions); + } + + @Override + public void load() throws IOException { + try (SdbLoader.SdbResultSet set = SdbLoader.load(new File("serverdata/nge/gcw/regions_gcw.sdb"))) { + while (set.next()) { + GcwRegionInfo regionInfo = new GcwRegionInfo(set); + + regions.computeIfAbsent(regionInfo.getTerrain(), a -> new ArrayList<>()).add(regionInfo); + } + } + } + + public static class GcwRegionInfo { + private final Terrain terrain; + private final String regionName; + private final long centerX; + private final long centerZ; + private final long radius; + + public GcwRegionInfo(SdbLoader.SdbResultSet set) { + terrain = Terrain.getTerrainFromName(set.getText("terrain")); + regionName = set.getText("regionName"); + centerX = set.getInt("centerX"); + centerZ = set.getInt("centerZ"); + radius = set.getInt("radius"); + } + + public Terrain getTerrain() { + return terrain; + } + + public String getRegionName() { + return regionName; + } + + public long getCenterX() { + return centerX; + } + + public long getCenterZ() { + return centerZ; + } + + public long getRadius() { + return radius; + } + } +} diff --git a/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/ServerData.kt b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/ServerData.kt index 60683c7ea..387cc8ae9 100644 --- a/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/ServerData.kt +++ b/src/main/java/com/projectswg/holocore/resources/support/data/server_info/loader/ServerData.kt @@ -92,7 +92,8 @@ object ServerData { val travelCosts by SoftDataLoaderDelegate(::TravelCostLoader) val vehicles by SoftDataLoaderDelegate(::VehicleLoader) val staticPvpZones by SoftDataLoaderDelegate(::StaticPvpZoneLoader) - + val gcwRegionLoader by SoftDataLoaderDelegate(::GcwRegionLoader) + private class WeakDataLoaderDelegate(loaderCreator: () -> T): DataLoaderDelegate(::WeakReference, loaderCreator) private class SoftDataLoaderDelegate(loaderCreator: () -> T): DataLoaderDelegate(::SoftReference, loaderCreator)