package electrosphere.server.macro.structure; import electrosphere.engine.Globals; import electrosphere.server.datacell.Realm; import electrosphere.server.macro.character.Character; import java.util.LinkedList; import java.util.List; import org.joml.Vector2f; /** * Utility functions for dealing with structures on the server */ public class VirtualStructureUtils { // public static Structure placeStructureAtPoint(float posX, float posY, float posZ, String type){ // Realm realm = Globals.realmManager.getRealms().iterator().next(); // int worldX = realm.getServerWorldData().convertRealToChunkSpace(posX); // int worldY = realm.getServerWorldData().convertRealToChunkSpace(posY); // Structure rVal = new Structure(worldX,worldY,posX,posY,type); // Globals.macroData.addStructure(rVal); // // double centerHeight = Globals.serverTerrainManager.getHeightAtPosition(posX, posY, posZ); // // StructureType currentTypeObject = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); // // float radius = currentTypeObject.getRadius(); // // for(int x = -(int)radius; x < radius; x++){ // // for(int y = -(int)radius; y < radius; y++){ // // int newWorldX = Globals.serverWorldData.convertRealToChunkSpace(posX + x); // // int newWorldY = Globals.serverWorldData.convertRealToChunkSpace(posY + y); // // double newLocationX = Globals.serverWorldData.getRelativeLocation(posX + x, newWorldX); // // double newLocationY = Globals.serverWorldData.getRelativeLocation(posY + y, newWorldY); // // // System.out.println("Set height: " + centerHeight); // // // System.out.println("Deform in chunk: " + newWorldX + "," + newWorldY); // // Globals.serverTerrainManager.deformTerrainAtLocationToValue(newWorldX, newWorldY, (int)(newLocationX), (int)(newLocationY), (float)centerHeight); // // } // // } // // StructureUtils.serverSpawnBasicStructure(type, realm, new Vector3d(posX,(float)centerHeight + 2.4f,posY), new Quaternionf()); // return rVal; // } public static boolean validStructurePlacementPosition(float posX, float posY, String type){ // StructureType toPlaceType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); // Vector2f toPlacePos = new Vector2f(posX, posY); // for(Structure virtualStruct : Globals.macroData.getStructures()){ // StructureType existantType = Globals.gameConfigCurrent.getStructureTypeMap().getType(virtualStruct.getType()); // Vector2f existantPos = new Vector2f(virtualStruct.getLocationX(),virtualStruct.getLocationY()); // if(existantPos.distance(toPlacePos) < toPlaceType.getRadius() + existantType.getRadius()){ // return false; // } // } return true; } public static void addResident(Structure structure, Character character){ List residents = null; if(structure.getDataKeys().contains(StructureDataStrings.RESIDENTS)){ residents = (List)structure.getData(StructureDataStrings.RESIDENTS); } else { residents = new LinkedList(); structure.putData(StructureDataStrings.RESIDENTS, residents); } residents.add(character); } public static List getResidents(Structure structure){ return (List)structure.getData(StructureDataStrings.RESIDENTS); } }