mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 22:59:02 +00:00
Added structure class #145 and moved many constants to config.properties
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
/**
|
||||
* Game objects that regularly creates NonPlayerCharacters
|
||||
*/
|
||||
public class Factory extends GameObject implements Updatable {
|
||||
public class Factory extends Structure implements Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x0200;
|
||||
|
||||
@@ -48,10 +48,11 @@ public class Factory extends GameObject implements Updatable {
|
||||
private boolean initialised = false;
|
||||
|
||||
public Factory() {
|
||||
super(2, 2);
|
||||
}
|
||||
|
||||
public Factory(Document document) {
|
||||
super(document);
|
||||
super(document, 2, 2);
|
||||
|
||||
tmpNpcArray = ((ArrayList) document.get("npcs")).toArray();
|
||||
}
|
||||
@@ -112,18 +113,6 @@ public class Factory extends GameObject implements Updatable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAt(int x, int y) {
|
||||
|
||||
/*
|
||||
* Object is 2x2 tiles, the (x,y) coordinates of the object being
|
||||
* at top-left.
|
||||
* # .
|
||||
* . .
|
||||
*/
|
||||
return (x == getX() + 1 || x == getX()) && (y == getY() + 1 || y == getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = super.mongoSerialise();
|
||||
@@ -139,54 +128,6 @@ public class Factory extends GameObject implements Updatable {
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first non-blocked tile that is directly adjacent to the factory, starting from the north-east corner
|
||||
* going clockwise.
|
||||
*
|
||||
* @return The coordinates of the first non-blocked tile, null otherwise.
|
||||
*/
|
||||
public Point getAdjacentTile() {
|
||||
|
||||
/*
|
||||
* (2,0)
|
||||
* (2,1)
|
||||
* (1,2)
|
||||
* (0,2)
|
||||
* (-1,1)
|
||||
* (-1,0)
|
||||
* (0,-1)
|
||||
* (1,-1)
|
||||
*/
|
||||
|
||||
if (!getWorld().isTileBlocked(getX() + 2, getY())) {
|
||||
return new Point(getX() + 2, getY());
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX() + 2, getY() + 1)) {
|
||||
return new Point(getX() + 2, getY() + 1);
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX() + 1, getY() + 2)) {
|
||||
return new Point(getX() + 1, getY() + 2);
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX(), getY() + 2)) {
|
||||
return new Point(getX(), getY() + 2);
|
||||
|
||||
} else if (!getWorld().isTileBlocked(getX() + -1, getY() + 1)) {
|
||||
return new Point(getX() + -1, 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 if (!getWorld().isTileBlocked(getX() + 1, getY() + -1)) {
|
||||
return new Point(getX() + 1, getY() + -1);
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ArrayList<NonPlayerCharacter> getNpcs() {
|
||||
return npcs;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class NpcPlugin extends ServerPlugin {
|
||||
@Override
|
||||
public void init(ServerConfiguration configuration, GameRegistry registry) {
|
||||
|
||||
listeners.add(new WorldCreationListener());
|
||||
listeners.add(new WorldCreationListener(configuration.getInt("factory_spawn_rate")));
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
listeners.add(new VaultWorldUpdateListener(configuration));
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Obstacle extends GameObject implements Attackable {
|
||||
}
|
||||
|
||||
public Obstacle(Document document) {
|
||||
super(document);
|
||||
style = document.getInteger("style");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ package net.simon987.npcplugin;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.Document;
|
||||
|
||||
|
||||
public class Portal extends GameObject implements Enterable {
|
||||
public class Portal extends Structure implements Enterable {
|
||||
|
||||
/**
|
||||
* Destination location
|
||||
@@ -19,11 +20,11 @@ public class Portal extends GameObject implements Enterable {
|
||||
public static final int MAP_INFO = 0x0020;
|
||||
|
||||
public Portal() {
|
||||
|
||||
super(1, 1);
|
||||
}
|
||||
|
||||
public Portal(Document document) {
|
||||
super(document);
|
||||
super(document, 1, 1);
|
||||
|
||||
destination = new Location(
|
||||
document.getInteger("dstWorldX"),
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.Programmable;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
public class RadioTower extends Structure implements Programmable, Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x1000;
|
||||
|
||||
public static final int MAX_RANGE = 3; //todo load from config
|
||||
public static final int MAX_RANGE = GameServer.INSTANCE.getConfig().getInt("radio_tower_range");
|
||||
|
||||
private static final int MAX_MESSAGES = 16;
|
||||
|
||||
public RadioTower() {
|
||||
|
||||
super(1, 1);
|
||||
}
|
||||
|
||||
public RadioTower(Document document) {
|
||||
super(document);
|
||||
super(document, 1, 1);
|
||||
NpcPlugin.getRadioTowers().add(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
@@ -43,16 +44,18 @@ public class VaultDimension {
|
||||
* 4. Choose a random world from the last layer and create the vault box there (objective)
|
||||
* 5. Create an exit portal in the home world
|
||||
*
|
||||
* This process is actually done in 2 passes, in the first pass, worlds are defined
|
||||
* This process is done in 2 passes, in the first pass, worlds are defined
|
||||
* as a set of coordinates + a list of opening directions, then they are actually generated
|
||||
*/
|
||||
|
||||
int minLayerCount = 4;
|
||||
int maxLayerCount = 6;
|
||||
int minAttachedWorld = 0;
|
||||
int maxAttachedWorld = 4; //todo cap at 4 to avoid infinite loop
|
||||
int minElectricBoxCount = 2;
|
||||
int maxElectricBoxCount = 4;
|
||||
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
|
||||
int minLayerCount = config.getInt("vault_wg_min_layer_count");
|
||||
int maxLayerCount = config.getInt("vault_wg_max_layer_count");
|
||||
int minAttachedWorld = config.getInt("vault_wg_min_attached_world");
|
||||
int maxAttachedWorld = Math.min(config.getInt("vault_wg_max_attached_world"), 4);
|
||||
int minElectricBoxCount = config.getInt("vault_wg_min_electric_box_count");
|
||||
int maxElectricBoxCount = config.getInt("vault_wg_max_electric_box_count");
|
||||
|
||||
HashMap<Integer, ArrayList<WorldBluePrint>> worldLayers = new HashMap<>();
|
||||
VaultWorldGenerator generator = new VaultWorldGenerator();
|
||||
|
||||
@@ -2,10 +2,7 @@ package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.crypto.RandomStringGenerator;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Programmable;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
@@ -13,7 +10,7 @@ import org.bson.Document;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class VaultDoor extends GameObject implements Programmable, Enterable, Updatable {
|
||||
public class VaultDoor extends Structure implements Programmable, Enterable, Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x0800;
|
||||
|
||||
@@ -43,6 +40,8 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
private int cypherId;
|
||||
|
||||
public VaultDoor(int cypherId) {
|
||||
super(1, 1);
|
||||
|
||||
this.cypherId = cypherId;
|
||||
|
||||
this.randomStringGenerator = new RandomStringGenerator();
|
||||
@@ -51,7 +50,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
}
|
||||
|
||||
public VaultDoor(Document document) {
|
||||
super(document);
|
||||
super(document, 1, 1);
|
||||
|
||||
setX(document.getInteger("x"));
|
||||
setY(document.getInteger("y"));
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldGenerationEvent;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
@@ -18,12 +19,15 @@ public class WorldCreationListener implements GameEventListener {
|
||||
|
||||
/**
|
||||
* Spawn rate. Higher = rarer: A factory will be spawn about every FACTORY_SPAWN_RATE generated Worlds
|
||||
* <br>TODO: Get from config.properties
|
||||
*/
|
||||
private static final int FACTORY_SPAWN_RATE = 35;
|
||||
private static int FACTORY_SPAWN_RATE = 0;
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
public WorldCreationListener(int factorySpawnRate) {
|
||||
FACTORY_SPAWN_RATE = factorySpawnRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
return WorldGenerationEvent.class;
|
||||
@@ -66,7 +70,7 @@ public class WorldCreationListener implements GameEventListener {
|
||||
}
|
||||
|
||||
//Also spawn a radio tower in the same World
|
||||
Point p = world.getRandomPassableTile();
|
||||
Point p = world.getRandomTileWithAdjacent(8, TileMap.PLAIN_TILE);
|
||||
if (p != null) {
|
||||
while (p.x == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || p.y == 0) {
|
||||
p = world.getRandomPassableTile();
|
||||
|
||||
Reference in New Issue
Block a user