TileMap now uses Tile instances instead of ints. No changes in the way it is stored in the database

This commit is contained in:
Simon
2018-11-15 12:08:44 -05:00
parent e50bcdeab7
commit 4be1bf2e8a
21 changed files with 268 additions and 100 deletions

View File

@@ -4,6 +4,8 @@ import net.simon987.npcplugin.event.CpuInitialisationListener;
import net.simon987.npcplugin.event.VaultCompleteListener;
import net.simon987.npcplugin.event.VaultWorldUpdateListener;
import net.simon987.npcplugin.event.WorldCreationListener;
import net.simon987.npcplugin.world.TileVaultFloor;
import net.simon987.npcplugin.world.TileVaultWall;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.game.objects.GameRegistry;
import net.simon987.server.logging.LogManager;
@@ -37,6 +39,9 @@ public class NpcPlugin extends ServerPlugin {
registry.registerHardware(RadioReceiverHardware.class);
registry.registerTile(TileVaultFloor.ID, TileVaultFloor.class);
registry.registerTile(TileVaultWall.ID, TileVaultWall.class);
radioTowers = new ArrayList<>(32);
LogManager.LOGGER.info("Initialised NPC plugin");

View File

@@ -1,10 +1,10 @@
package net.simon987.npcplugin;
import net.simon987.npcplugin.world.TileVaultFloor;
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;
import net.simon987.server.game.world.World;
import net.simon987.server.logging.LogManager;
import org.bson.types.ObjectId;
@@ -140,7 +140,7 @@ public class VaultDimension {
//4. Choose a random world from the last layer and create the vault box there (objective)
World objectiveWorld = lastLayerWorlds.get(random.nextInt(lastLayerWorlds.size()));
Point exitPortalPt = objectiveWorld.getRandomTileWithAdjacent(8, TileMap.VAULT_FLOOR);
Point exitPortalPt = objectiveWorld.getRandomTileWithAdjacent(8, TileVaultFloor.ID);
if (exitPortalPt != null) {
@@ -159,7 +159,7 @@ public class VaultDimension {
}
//5. Create an exit portal in the home World
Point homePortalPt = homeWorld.getRandomTileWithAdjacent(8, TileMap.VAULT_FLOOR);
Point homePortalPt = homeWorld.getRandomTileWithAdjacent(8, TileVaultFloor.ID);
if (homePortalPt != null) {
Portal homePortal = new Portal();

View File

@@ -2,6 +2,7 @@ package net.simon987.npcplugin;
import net.simon987.server.game.objects.Direction;
import net.simon987.server.game.world.TileMap;
import net.simon987.server.game.world.TileVoid;
import net.simon987.server.game.world.World;
import java.awt.*;
@@ -216,7 +217,7 @@ public class VaultWorldGenerator {
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) {
if (map.getTileAt(x, y) != floorTile && hasTileAdjacent(x, y, map, floorTile)) {
if (map.getTileIdAt(x, y) != floorTile && hasTileAdjacent(x, y, map, floorTile)) {
map.setTileAt(wallTile, x, y);
}
}
@@ -226,8 +227,8 @@ public class VaultWorldGenerator {
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) {
if (map.getTileAt(x, y) != floorTile && map.getTileAt(x, y) != wallTile) {
map.setTileAt(TileMap.VOID, x, y);
if (map.getTileIdAt(x, y) != floorTile && map.getTileIdAt(x, y) != wallTile) {
map.setTileAt(new TileVoid(), x, y);
}
}
}
@@ -241,7 +242,7 @@ public class VaultWorldGenerator {
for (int dX = -1; dX <= 1; dX++) {
for (int dY = -1; dY <= 1; dY++) {
if (map.getTileAt(x + dX, y + dY) == tile) {
if (map.getTileIdAt(x + dX, y + dY) == tile) {
return true;
}
}

View File

@@ -1,5 +1,6 @@
package net.simon987.npcplugin;
import net.simon987.npcplugin.world.TileVaultFloor;
import net.simon987.server.game.world.TileMap;
import net.simon987.server.game.world.World;
import org.bson.types.ObjectId;
@@ -19,12 +20,12 @@ public class VaultWorldUtils {
//Count number of floor tiles. If there is less plain tiles than desired amount of boxes,
//set the desired amount of blobs to the plain tile count
int[][] tiles = world.getTileMap().getTiles();
TileMap m = world.getTileMap();
int floorCount = 0;
for (int y = 0; y < world.getWorldSize(); y++) {
for (int x = 0; x < world.getWorldSize(); x++) {
if (tiles[x][y] == TileMap.VAULT_FLOOR) {
if (m.getTileIdAt(x, y) == TileVaultFloor.ID) {
floorCount++;
}
}
@@ -37,14 +38,14 @@ public class VaultWorldUtils {
outerLoop:
for (int i = 0; i < boxesCount; i++) {
Point p = world.getTileMap().getRandomTile(TileMap.VAULT_FLOOR);
Point p = m.getRandomTile(TileVaultFloor.ID);
if (p != null) {
//Don't block worlds
int counter = 0;
while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 ||
world.getGameObjectsAt(p.x, p.y).size() != 0) {
p = world.getTileMap().getRandomTile(TileMap.VAULT_FLOOR);
p = m.getRandomTile(TileVaultFloor.ID);
counter++;
if (counter > 25) {

View File

@@ -7,7 +7,7 @@ import net.simon987.npcplugin.VaultDoor;
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.TilePlain;
import net.simon987.server.game.world.World;
import org.bson.types.ObjectId;
@@ -69,7 +69,7 @@ public class WorldCreationListener implements GameEventListener {
}
//Also spawn a radio tower in the same World
Point p = world.getRandomTileWithAdjacent(8, TileMap.PLAIN_TILE);
Point p = world.getRandomTileWithAdjacent(8, TilePlain.ID);
if (p != null) {
while (p.x == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || p.y == 0) {
p = world.getRandomPassableTile();

View File

@@ -0,0 +1,13 @@
package net.simon987.npcplugin.world;
import net.simon987.server.game.world.Tile;
public class TileVaultFloor extends Tile {
public static final int ID = 4;
@Override
public int getId() {
return ID;
}
}

View File

@@ -0,0 +1,24 @@
package net.simon987.npcplugin.world;
import net.simon987.server.game.objects.GameObject;
import net.simon987.server.game.world.Tile;
public class TileVaultWall extends Tile {
public static final int ID = 5;
@Override
public int getId() {
return ID;
}
@Override
public boolean walk(GameObject object) {
return false; //always blocked
}
@Override
public boolean isBlocked() {
return true;
}
}