mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 02:36:41 +00:00
Started working on Vault worlds generation
This commit is contained in:
parent
8c6e580ea9
commit
62f1403cb3
@ -1,5 +1,11 @@
|
|||||||
package net.simon987.npcplugin;
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
|
import net.simon987.server.GameServer;
|
||||||
|
import net.simon987.server.game.Direction;
|
||||||
|
import net.simon987.server.game.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class VaultDimension {
|
public class VaultDimension {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,7 +17,18 @@ public class VaultDimension {
|
|||||||
|
|
||||||
name = "v" + vaultDoorId + "-";
|
name = "v" + vaultDoorId + "-";
|
||||||
|
|
||||||
|
VaultWorldGenerator generator = new VaultWorldGenerator();
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<Direction> openings = new ArrayList<>();
|
||||||
|
openings.add(Direction.WEST);
|
||||||
|
openings.add(Direction.SOUTH);
|
||||||
|
openings.add(Direction.EAST);
|
||||||
|
openings.add(Direction.NORTH);
|
||||||
|
|
||||||
|
World vWorld = generator.generateVaultWorld(0x7FFF, 0x7FFF, openings, name);
|
||||||
|
|
||||||
|
GameServer.INSTANCE.getGameUniverse().addWorld(vWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,7 @@ import com.mongodb.BasicDBObject;
|
|||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
import net.simon987.server.GameServer;
|
import net.simon987.server.GameServer;
|
||||||
import net.simon987.server.crypto.RandomStringGenerator;
|
import net.simon987.server.crypto.RandomStringGenerator;
|
||||||
import net.simon987.server.game.Enterable;
|
import net.simon987.server.game.*;
|
||||||
import net.simon987.server.game.GameObject;
|
|
||||||
import net.simon987.server.game.Programmable;
|
|
||||||
import net.simon987.server.game.Updatable;
|
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
@ -31,6 +28,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
|||||||
*/
|
*/
|
||||||
private boolean open = false;
|
private boolean open = false;
|
||||||
|
|
||||||
|
private World homeWorld;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of ticks to remain the door open
|
* Number of ticks to remain the door open
|
||||||
@ -40,11 +38,25 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
|||||||
private int openedTimer = 0;
|
private int openedTimer = 0;
|
||||||
private int cypherId;
|
private int cypherId;
|
||||||
|
|
||||||
public VaultDoor(int cypherId) {
|
public VaultDoor(int cypherId, long objectId) {
|
||||||
this.cypherId = cypherId;
|
this.cypherId = cypherId;
|
||||||
this.randomStringGenerator = new RandomStringGenerator();
|
this.randomStringGenerator = new RandomStringGenerator();
|
||||||
|
setObjectId(objectId);
|
||||||
|
|
||||||
this.password = "12345678".toCharArray();
|
this.password = "12345678".toCharArray();
|
||||||
|
|
||||||
|
|
||||||
|
//Get or generate vault world
|
||||||
|
World world = GameServer.INSTANCE.getGameUniverse().getWorld(0x7FFF, 0x7FFF,
|
||||||
|
false, "v" + getObjectId() + "-");
|
||||||
|
|
||||||
|
if (world != null) {
|
||||||
|
homeWorld = world;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
VaultDimension vaultDimension = new VaultDimension(getObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -143,11 +155,10 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
|||||||
|
|
||||||
public static VaultDoor deserialize(DBObject obj) {
|
public static VaultDoor deserialize(DBObject obj) {
|
||||||
|
|
||||||
VaultDoor vaultDoor = new VaultDoor(0); //cypherId ?
|
VaultDoor vaultDoor = new VaultDoor(0, (long) obj.get("i")); //cypherId ?
|
||||||
vaultDoor.setObjectId((long) obj.get("i"));
|
|
||||||
vaultDoor.setX((int) obj.get("x"));
|
vaultDoor.setX((int) obj.get("x"));
|
||||||
vaultDoor.setY((int) obj.get("y"));
|
vaultDoor.setY((int) obj.get("y"));
|
||||||
// vaultDoor.password = (char[]) obj.get("pw");
|
vaultDoor.password = ((String) obj.get("pw")).toCharArray();
|
||||||
|
|
||||||
return vaultDoor;
|
return vaultDoor;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package net.simon987.npcplugin;
|
|
||||||
|
|
||||||
import net.simon987.server.game.TileMap;
|
|
||||||
import net.simon987.server.game.World;
|
|
||||||
|
|
||||||
public class VaultWorld extends World {
|
|
||||||
|
|
||||||
private String dimension;
|
|
||||||
|
|
||||||
public VaultWorld(int x, int y, TileMap tileMap) {
|
|
||||||
super(x, y, tileMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +1,112 @@
|
|||||||
package net.simon987.npcplugin;
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
|
import net.simon987.server.game.Direction;
|
||||||
|
import net.simon987.server.game.TileMap;
|
||||||
|
import net.simon987.server.game.World;
|
||||||
|
import net.simon987.server.logging.LogManager;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class VaultWorldGenerator {
|
public class VaultWorldGenerator {
|
||||||
|
|
||||||
public VaultWorld generateVaultWorld() {
|
public World generateVaultWorld(int x, int y, ArrayList<Direction> openings, String dimension) {
|
||||||
return null;
|
|
||||||
|
LogManager.LOGGER.info("Generating vault World");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Openings are always at the same spot (marked by '?')
|
||||||
|
* 1. Rectangles of random size are generated
|
||||||
|
* 2. They are connected with tunnels from bottom to top,
|
||||||
|
* by their roomCenter, alternating between horizontal first
|
||||||
|
* tunnels and vertical first
|
||||||
|
* 3. Tiles adjacent to floor tiles are set to wall tiles
|
||||||
|
* Example map:
|
||||||
|
*
|
||||||
|
* # # # # # # # - - - # ? ? # - - - - - - - - - -
|
||||||
|
* # o o o o o # - - - # ? ? # - - - - - - - - - -
|
||||||
|
* # o o o o o # # # # # # o # - - - - - - - - - -
|
||||||
|
* # o o o o o o o o o o o o # - - - - - - - - - -
|
||||||
|
* # o o o o o # # # # # # # # # # # - - - - - - -
|
||||||
|
* # o o o o o # - - - - # o o o o # - - - - - - -
|
||||||
|
* # o o o o o # # # # # # o o o o # - - - - - - -
|
||||||
|
* # # o o o o o o o o o o o o o o # - - - - - - -
|
||||||
|
* - # o # # # # # # # # # o o o o # - - - - - - -
|
||||||
|
* - # o # - - - - - - - # # # # # # - - - - - - -
|
||||||
|
* # # o # - - - - - - - - - - - - - - - - - # # #
|
||||||
|
* ? ? o # # # # # # # # # # # # # # # # # # # ? ?
|
||||||
|
* ? ? o o o o o o o o o o o o o o o o o o o o ? ?
|
||||||
|
* # # # # # # # # # # # # # # # # # # o # # # # #
|
||||||
|
* - - - - - - - - - - - - - - - - - # o # - - - -
|
||||||
|
* - # # # # # # # # # - - - - - - - # o # - - - -
|
||||||
|
* - # o o o o o o o # - - - # # # # # o # # # # -
|
||||||
|
* - # o o o o o o o # # # # # o o o o o o o o # -
|
||||||
|
* - # o o o o o o o o o o o # o o o o o o o o # -
|
||||||
|
* - # o o o o o o o # # # o # o o o o o o o o # -
|
||||||
|
* - # o o o o o o o # - # o # # # # # # # # # # -
|
||||||
|
* - # o o o o o o o # # # o # - - - - - - - - - -
|
||||||
|
* - # # # # # # # # # # ? ? # - - - - - - - - - -
|
||||||
|
* - - - - - - - - - - # ? ? # - - - - - - - - - -
|
||||||
|
*/
|
||||||
|
|
||||||
|
int worldSize = 20;
|
||||||
|
int floorTile = 4;
|
||||||
|
int wallTile = 5;
|
||||||
|
int minRoomCount = 3;
|
||||||
|
int maxRoomCount = 6;
|
||||||
|
int minRoomWidth = 4;
|
||||||
|
int minRoomHeight = 4;
|
||||||
|
int maxRoomWidth = 8;
|
||||||
|
int maxRoomHeight = 8;
|
||||||
|
|
||||||
|
ArrayList<Point> roomCenters = new ArrayList<>();
|
||||||
|
|
||||||
|
World world = new World(x, y, new TileMap(worldSize, worldSize), dimension);
|
||||||
|
|
||||||
|
TileMap map = world.getTileMap();
|
||||||
|
|
||||||
|
//Create openings
|
||||||
|
for (Direction opening : openings) {
|
||||||
|
switch (opening) {
|
||||||
|
case NORTH:
|
||||||
|
|
||||||
|
map.setTileAt(floorTile, worldSize / 2, 0);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2, 1);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2 - 1, 0);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2 - 1, 1);
|
||||||
|
roomCenters.add(new Point(worldSize / 2, 1));
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
|
||||||
|
map.setTileAt(floorTile, worldSize - 1, worldSize / 2);
|
||||||
|
map.setTileAt(floorTile, worldSize - 1, worldSize / 2 - 1);
|
||||||
|
map.setTileAt(floorTile, worldSize - 2, worldSize / 2);
|
||||||
|
map.setTileAt(floorTile, worldSize - 2, worldSize / 2 - 1);
|
||||||
|
roomCenters.add(new Point(worldSize - 1, worldSize / 2 - 1));
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
|
||||||
|
map.setTileAt(floorTile, worldSize / 2, worldSize - 1);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2, worldSize - 2);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2 - 1, worldSize - 1);
|
||||||
|
map.setTileAt(floorTile, worldSize / 2 - 1, worldSize - 2);
|
||||||
|
roomCenters.add(new Point(worldSize / 2, worldSize - 2));
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
|
||||||
|
map.setTileAt(floorTile, 0, worldSize / 2);
|
||||||
|
map.setTileAt(floorTile, 0, worldSize / 2 - 1);
|
||||||
|
map.setTileAt(floorTile, 1, worldSize / 2);
|
||||||
|
map.setTileAt(floorTile, 1, worldSize / 2 - 1);
|
||||||
|
roomCenters.add(new Point(0, worldSize / 2 - 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Generate rectangles of random size
|
||||||
|
|
||||||
|
return world;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -99,10 +99,9 @@ public class WorldCreationListener implements GameEventListener {
|
|||||||
p = world.getRandomPassableTile();
|
p = world.getRandomPassableTile();
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
|
|
||||||
VaultDoor vaultDoor = new VaultDoor(0); //todo cypherId ?
|
VaultDoor vaultDoor = new VaultDoor(0, GameServer.INSTANCE.getGameUniverse().getNextObjectId()); //todo cypherId ?
|
||||||
|
|
||||||
vaultDoor.setWorld(world);
|
vaultDoor.setWorld(world);
|
||||||
vaultDoor.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
|
||||||
vaultDoor.setX(p.x);
|
vaultDoor.setX(p.x);
|
||||||
vaultDoor.setY(p.y);
|
vaultDoor.setY(p.y);
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ public class GameUniverse {
|
|||||||
public World getWorld(int x, int y, boolean createNew, String dimension) {
|
public World getWorld(int x, int y, boolean createNew, String dimension) {
|
||||||
|
|
||||||
// Wrapping coordinates around cyclically
|
// Wrapping coordinates around cyclically
|
||||||
x %= maxWidth+1;
|
x %= maxWidth;
|
||||||
y %= maxWidth+1;
|
y %= maxWidth;
|
||||||
|
|
||||||
// Looks for a previously loaded world
|
// Looks for a previously loaded world
|
||||||
World world = getLoadedWorld(x, y, dimension);
|
World world = getLoadedWorld(x, y, dimension);
|
||||||
@ -113,8 +113,8 @@ public class GameUniverse {
|
|||||||
|
|
||||||
World getLoadedWorld(int x, int y, String dimension) {
|
World getLoadedWorld(int x, int y, String dimension) {
|
||||||
// Wrapping coordinates around cyclically
|
// Wrapping coordinates around cyclically
|
||||||
x %= maxWidth+1;
|
x %= maxWidth;
|
||||||
y %= maxWidth+1;
|
y %= maxWidth;
|
||||||
|
|
||||||
return worlds.get(World.idFromCoordinates(x, y, dimension));
|
return worlds.get(World.idFromCoordinates(x, y, dimension));
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class World implements MongoSerialisable {
|
|||||||
|
|
||||||
private TileMap tileMap;
|
private TileMap tileMap;
|
||||||
|
|
||||||
private static String dimension = "w-";
|
private String dimension;
|
||||||
|
|
||||||
private ConcurrentHashMap<Long, GameObject> gameObjects = new ConcurrentHashMap<>(8);
|
private ConcurrentHashMap<Long, GameObject> gameObjects = new ConcurrentHashMap<>(8);
|
||||||
|
|
||||||
@ -40,10 +40,11 @@ public class World implements MongoSerialisable {
|
|||||||
*/
|
*/
|
||||||
private int updatable = 0;
|
private int updatable = 0;
|
||||||
|
|
||||||
public World(int x, int y, TileMap tileMap) {
|
public World(int x, int y, TileMap tileMap, String dimension) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.tileMap = tileMap;
|
this.tileMap = tileMap;
|
||||||
|
this.dimension = dimension;
|
||||||
|
|
||||||
this.worldSize = tileMap.getWidth();
|
this.worldSize = tileMap.getWidth();
|
||||||
}
|
}
|
||||||
@ -174,6 +175,7 @@ public class World implements MongoSerialisable {
|
|||||||
|
|
||||||
|
|
||||||
dbObject.put("_id", getId());
|
dbObject.put("_id", getId());
|
||||||
|
dbObject.put("dimension", getDimension());
|
||||||
|
|
||||||
dbObject.put("objects", objects);
|
dbObject.put("objects", objects);
|
||||||
dbObject.put("terrain", tileMap.mongoSerialise());
|
dbObject.put("terrain", tileMap.mongoSerialise());
|
||||||
@ -210,6 +212,7 @@ public class World implements MongoSerialisable {
|
|||||||
World world = new World((int) dbObject.get("size"));
|
World world = new World((int) dbObject.get("size"));
|
||||||
world.x = (int) dbObject.get("x");
|
world.x = (int) dbObject.get("x");
|
||||||
world.y = (int) dbObject.get("y");
|
world.y = (int) dbObject.get("y");
|
||||||
|
world.dimension = (String) dbObject.get("dimension");
|
||||||
world.updatable = (int) dbObject.get("updatable");
|
world.updatable = (int) dbObject.get("updatable");
|
||||||
|
|
||||||
world.tileMap = TileMap.deserialize((BasicDBObject) dbObject.get("terrain"), world.getWorldSize());
|
world.tileMap = TileMap.deserialize((BasicDBObject) dbObject.get("terrain"), world.getWorldSize());
|
||||||
|
@ -87,7 +87,7 @@ public class WorldGenerator {
|
|||||||
*/
|
*/
|
||||||
private static World generateEmptyWorld(int locX, int locY) {
|
private static World generateEmptyWorld(int locX, int locY) {
|
||||||
|
|
||||||
return new World(locX, locY, new TileMap(DEFAULT_WORLD_SIZE, DEFAULT_WORLD_SIZE));
|
return new World(locX, locY, new TileMap(DEFAULT_WORLD_SIZE, DEFAULT_WORLD_SIZE), "w-");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user