Browse Source

Begin refactor location collections.

master
MagicBot 2 years ago
parent
commit
7c079c3998
  1. 9
      src/engine/db/handlers/dbBuildingLocationHandler.java
  2. 5
      src/engine/gameManager/BuildingManager.java
  3. 33
      src/engine/objects/BuildingLocation.java
  4. 1
      src/engine/server/world/WorldServer.java

9
src/engine/db/handlers/dbBuildingLocationHandler.java

@ -20,8 +20,17 @@ public class dbBuildingLocationHandler extends dbHandlerBase { @@ -20,8 +20,17 @@ public class dbBuildingLocationHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
prepareCallable("select * from static_building_location " +
"where type = 6 or type = 8 " +
"GROUP BY buildingID, slot " +
"ORDER BY buildingID, slot ASC;");
return getObjectList();
}
public ArrayList<BuildingLocation> LOAD_ALL_BUILDING_LOCATIONS() {
prepareCallable("SELECT * FROM `static_building_location`;");
return getObjectList();
}
}

5
src/engine/gameManager/BuildingManager.java

@ -25,12 +25,17 @@ import org.pmw.tinylog.Logger; @@ -25,12 +25,17 @@ import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom;
public enum BuildingManager {
BUILDINGMANAGER;
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations;
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations;
public static boolean playerCanManage(PlayerCharacter player, Building building) {
if (player == null)

33
src/engine/objects/BuildingLocation.java

@ -9,12 +9,16 @@ @@ -9,12 +9,16 @@
package engine.objects;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@ -122,6 +126,35 @@ public class BuildingLocation extends AbstractGameObject { @@ -122,6 +126,35 @@ public class BuildingLocation extends AbstractGameObject {
public void updateDatabase() {
}
public static void loadBuildingLocations() {
ArrayList<BuildingLocation> buildingLocations = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();
HashMap<Integer, ArrayList<BuildingLocation>> locationCollection = new HashMap<>();
// Only slot locations and stuck locations are currently loaded.
for (BuildingLocation buildingLocation : buildingLocations) {
switch (buildingLocation.type) {
case 6:
locationCollection = BuildingManager._slotLocations;
break;
case 8:
locationCollection = BuildingManager._stuckLocations;
break;
}
// Add location to the collection in BuildingManager
if (locationCollection.containsKey(buildingLocation.buildingUUID))
locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation);
else {
locationCollection.put(buildingLocation.buildingUUID, new ArrayList<>());
locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation);
}
}
}
public static void loadAllLocations() {
ArrayList<BuildingLocation> bls = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();

1
src/engine/server/world/WorldServer.java

@ -338,6 +338,7 @@ public class WorldServer { @@ -338,6 +338,7 @@ public class WorldServer {
Logger.info("Loading building mountpoint data.");
BuildingLocation.loadAllLocations();
BuildingLocation.loadBuildingLocations();
// Starting before loading of structures/guilds/characters
// so the database connections are available to write

Loading…
Cancel
Save