mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-18 10:16:43 +00:00
Vault Door generation
This commit is contained in:
parent
815f3de234
commit
ffca185fe5
@ -42,6 +42,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
||||
return Factory.deserialise(obj);
|
||||
} else if (objType == RadioTower.ID) {
|
||||
return RadioTower.deserialize(obj);
|
||||
} else if (objType == VaultDoor.ID) {
|
||||
return VaultDoor.deserialize(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -7,7 +7,6 @@ import net.simon987.server.game.Programmable;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
@ -96,25 +95,4 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
return lastMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first directly adjacent tile (starting east, going clockwise)
|
||||
*/
|
||||
public Point getAdjacentTile() {
|
||||
|
||||
if (!getWorld().isTileBlocked(getX() + 1, getY())) {
|
||||
return new Point(getX() + 1, getY());
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX(), getY() + 1)) {
|
||||
return new Point(getX(), getY() + 1);
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX() - 1, getY())) {
|
||||
return new Point(getX() - 1, getY());
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX(), getY() - 1)) {
|
||||
return new Point(getX(), getY() - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.crypto.RandomStringGenerator;
|
||||
import net.simon987.server.game.Enterable;
|
||||
@ -8,6 +9,7 @@ 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 org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -16,6 +18,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
|
||||
private static final int MAP_INFO = 0x0800;
|
||||
|
||||
public static final int ID = 5;
|
||||
/**
|
||||
* Password to open the vault door
|
||||
*/
|
||||
@ -107,7 +110,37 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
|
||||
@Override
|
||||
public BasicDBObject mongoSerialise() {
|
||||
return null;
|
||||
BasicDBObject dbObject = new BasicDBObject();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static VaultDoor deserialize(DBObject obj) {
|
||||
|
||||
VaultDoor vaultDoor = new VaultDoor(0); //cypherId ?
|
||||
vaultDoor.setObjectId((long) obj.get("i"));
|
||||
vaultDoor.setX((int) obj.get("x"));
|
||||
vaultDoor.setY((int) obj.get("y"));
|
||||
|
||||
return vaultDoor;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.simon987.npcplugin.event;
|
||||
import net.simon987.npcplugin.Factory;
|
||||
import net.simon987.npcplugin.NpcPlugin;
|
||||
import net.simon987.npcplugin.RadioTower;
|
||||
import net.simon987.npcplugin.VaultDoor;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
@ -93,6 +94,45 @@ public class WorldCreationListener implements GameEventListener {
|
||||
") (" + p.x + ", " + p.y + ")");
|
||||
}
|
||||
}
|
||||
|
||||
//Also spawn a Vault in the same World
|
||||
p = world.getRandomPassableTile();
|
||||
if (p != null) {
|
||||
|
||||
VaultDoor vaultDoor = new VaultDoor(0); //todo cypherId ?
|
||||
|
||||
vaultDoor.setWorld(world);
|
||||
vaultDoor.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
||||
vaultDoor.setX(p.x);
|
||||
vaultDoor.setY(p.y);
|
||||
|
||||
int counter = 300;
|
||||
while (p.x == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || p.y == 0
|
||||
|| vaultDoor.getAdjacentTileCount(true) < 8) {
|
||||
p = world.getRandomPassableTile();
|
||||
|
||||
if (p == null) {
|
||||
//World is full
|
||||
return;
|
||||
}
|
||||
|
||||
vaultDoor.setX(p.x);
|
||||
vaultDoor.setY(p.y);
|
||||
|
||||
counter--;
|
||||
|
||||
if (counter <= 0) {
|
||||
//Reached maximum amount of retries
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
world.addObject(vaultDoor);
|
||||
world.incUpdatable(); //In case the Factory & Radio Tower couldn't be spawned.
|
||||
|
||||
LogManager.LOGGER.info("Spawned Vault Door at (" + world.getX() + ", " + world.getY() +
|
||||
") (" + p.x + ", " + p.y + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +122,62 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first directly adjacent tile (starting east, going clockwise)
|
||||
*/
|
||||
public Point getAdjacentTile() {
|
||||
|
||||
if (!getWorld().isTileBlocked(getX() + 1, getY())) {
|
||||
return new Point(getX() + 1, getY());
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX(), getY() + 1)) {
|
||||
return new Point(getX(), getY() + 1);
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX() - 1, getY())) {
|
||||
return new Point(getX() - 1, getY());
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX(), getY() - 1)) {
|
||||
return new Point(getX(), getY() - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getAdjacentTileCount(boolean diagonals) {
|
||||
|
||||
int count = 0;
|
||||
|
||||
if (!getWorld().isTileBlocked(getX() + 1, getY())) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX(), getY() + 1)) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX() - 1, getY())) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX(), getY() - 1)) {
|
||||
count++;
|
||||
}
|
||||
|
||||
if (diagonals) {
|
||||
if (!getWorld().isTileBlocked(getX() + 1, getY() + 1)) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX() - 1, getY() + 1)) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX() + 1, getY() - 1)) {
|
||||
count++;
|
||||
}
|
||||
if (!getWorld().isTileBlocked(getX() - 1, getY() - 1)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public long getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user