Added Fluid Tile

This commit is contained in:
simon 2018-12-21 10:47:46 -05:00
parent bbaa338469
commit 70eeb1442d
9 changed files with 61 additions and 17 deletions

View File

@ -113,6 +113,7 @@ public class GameServer implements Runnable {
gameRegistry.registerTile(TileWall.ID, TileWall.class); gameRegistry.registerTile(TileWall.ID, TileWall.class);
gameRegistry.registerTile(TileCopper.ID, TileCopper.class); gameRegistry.registerTile(TileCopper.ID, TileCopper.class);
gameRegistry.registerTile(TileIron.ID, TileIron.class); gameRegistry.registerTile(TileIron.ID, TileIron.class);
gameRegistry.registerTile(TileFluid.ID, TileFluid.class);
} }
public GameUniverse getGameUniverse() { public GameUniverse getGameUniverse() {

View File

@ -1,6 +1,7 @@
package net.simon987.server.game.objects; package net.simon987.server.game.objects;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.game.world.Tile;
import net.simon987.server.game.world.World; import net.simon987.server.game.world.World;
import net.simon987.server.io.JSONSerializable; import net.simon987.server.io.JSONSerializable;
import net.simon987.server.io.MongoSerializable; import net.simon987.server.io.MongoSerializable;
@ -102,10 +103,15 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
} }
//Check collision //Check collision
if (!world.isTileBlocked(newX, newY)) { //Check for collision if (this.world.getGameObjectsBlockingAt(newX, newY).size() > 0) {
//Tile is passable return false;
x = newX; }
y = newY;
Tile tile = world.getTileMap().getTileAt(newX, newY);
if (tile.walk(this)) {
this.setX(newX);
this.setY(newY);
return true; return true;
} else { } else {
return false; return false;

View File

@ -0,0 +1,30 @@
package net.simon987.server.game.world;
import net.simon987.server.game.item.Item;
import net.simon987.server.game.objects.GameObject;
public class TileFluid extends Tile {
public static final int ID = 6;
@Override
public int getId() {
return 6;
}
@Override
public Item drill() {
return null;
}
@Override
public boolean walk(GameObject object) {
object.setDead(true);
return false;
}
@Override
public boolean isBlocked() {
return true;
}
}

View File

@ -30,6 +30,9 @@ public class WorldGenerator {
*/ */
private int wallPlainRatio; private int wallPlainRatio;
private int fluidCenterPointMin;
private int fluidCenterPointMax;
private int minIronCount; private int minIronCount;
private int maxIronCount; private int maxIronCount;
private int minCopperCount; private int minCopperCount;
@ -52,6 +55,8 @@ public class WorldGenerator {
maxIronCount = config.getInt("wg_maxIronCount"); maxIronCount = config.getInt("wg_maxIronCount");
minCopperCount = config.getInt("wg_minCopperCount"); minCopperCount = config.getInt("wg_minCopperCount");
maxCopperCount = config.getInt("wg_maxCopperCount"); maxCopperCount = config.getInt("wg_maxCopperCount");
fluidCenterPointMin = config.getInt("wg_fluidCenterPointMin");
fluidCenterPointMax = config.getInt("wg_fluidCenterPointMax");
} }
/** /**
@ -60,7 +65,6 @@ public class WorldGenerator {
private static int distanceBetween(int x1, int y1, int x2, int y2) { private static int distanceBetween(int x1, int y1, int x2, int y2) {
return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
} }
private int getClosestCenterPointTile(int x, int y) { private int getClosestCenterPointTile(int x, int y) {
@ -79,7 +83,6 @@ public class WorldGenerator {
return closest; return closest;
} }
/** /**
@ -101,6 +104,7 @@ public class WorldGenerator {
centerPointsMap = new HashMap<>(16); centerPointsMap = new HashMap<>(16);
int centerPointCount = random.nextInt(centerPointCountMax - centerPointCountMin) + centerPointCountMin; int centerPointCount = random.nextInt(centerPointCountMax - centerPointCountMin) + centerPointCountMin;
int fluidCenterPointCount = random.nextInt((fluidCenterPointMax - fluidCenterPointMin) + fluidCenterPointMin);
//Create center points //Create center points
for (int i = centerPointCount; i >= 0; i--) { for (int i = centerPointCount; i >= 0; i--) {
@ -109,6 +113,10 @@ public class WorldGenerator {
centerPointsMap.put(new Point(random.nextInt(DEFAULT_WORLD_SIZE), random.nextInt(DEFAULT_WORLD_SIZE)), tile); centerPointsMap.put(new Point(random.nextInt(DEFAULT_WORLD_SIZE), random.nextInt(DEFAULT_WORLD_SIZE)), tile);
} }
for (int i = fluidCenterPointCount; i >= 0; i--) {
centerPointsMap.put(new Point(random.nextInt(DEFAULT_WORLD_SIZE), random.nextInt(DEFAULT_WORLD_SIZE)), TileFluid.ID);
}
//Fill unset tiles //Fill unset tiles
for (int y = 0; y < DEFAULT_WORLD_SIZE; y++) { for (int y = 0; y < DEFAULT_WORLD_SIZE; y++) {
for (int x = 0; x < DEFAULT_WORLD_SIZE; x++) { for (int x = 0; x < DEFAULT_WORLD_SIZE; x++) {
@ -139,26 +147,25 @@ public class WorldGenerator {
if (x == 0 || x == DEFAULT_WORLD_SIZE - 1) { if (x == 0 || x == DEFAULT_WORLD_SIZE - 1) {
//Vertical (West & East) walls //Vertical (West & East) walls
if (y < 6 || y > 9) { if (y < 6 || y > 9) {
tile = 1; tile = TileWall.ID;
} else { } else {
tile = 0; tile = TilePlain.ID;
} }
} }
if (y == 0 || y == DEFAULT_WORLD_SIZE - 1) { if (y == 0 || y == DEFAULT_WORLD_SIZE - 1) {
// Horizontal (North & South) walls // Horizontal (North & South) walls
if (x < 6 || x > 9) { if (x < 6 || x > 9) {
tile = 1; tile = TileWall.ID;
} else { } else {
tile = 0; tile = TilePlain.ID;
} }
} }
if (((x == 1 || x == DEFAULT_WORLD_SIZE - 2) && y > 0 && y < DEFAULT_WORLD_SIZE - 1) || if (((x == 1 || x == DEFAULT_WORLD_SIZE - 2) && y > 0 && y < DEFAULT_WORLD_SIZE - 1) ||
((y == 1 || y == DEFAULT_WORLD_SIZE - 2) && x > 0 && x < DEFAULT_WORLD_SIZE - 1)) { ((y == 1 || y == DEFAULT_WORLD_SIZE - 2) && x > 0 && x < DEFAULT_WORLD_SIZE - 1)) {
//Inner border //Inner border
tile = 0; tile = TilePlain.ID;
} }
world.getTileMap().setTileAt(tile, x, y); world.getTileMap().setTileAt(tile, x, y);
} }
} }
@ -192,5 +199,4 @@ public class WorldGenerator {
return world; return world;
} }
} }

View File

@ -19,7 +19,7 @@ public class TerrainRequestHandler implements MessageHandler {
try { try {
world = GameServer.INSTANCE.getGameUniverse().getWorld( world = GameServer.INSTANCE.getGameUniverse().getWorld(
Long.valueOf((long) json.get("x")).intValue(), Long.valueOf((long) json.get("x")).intValue(),
Long.valueOf((long) json.get("y")).intValue(), false, Long.valueOf((long) json.get("y")).intValue(), true,
(String) json.get("dimension")); (String) json.get("dimension"));
} catch (NullPointerException e) { } catch (NullPointerException e) {
LogManager.LOGGER.severe("FIXME: handle TerrainRequestHandler"); LogManager.LOGGER.severe("FIXME: handle TerrainRequestHandler");

View File

@ -37,6 +37,8 @@ wg_minIronCount=0
wg_maxIronCount=2 wg_maxIronCount=2
wg_minCopperCount=0 wg_minCopperCount=0
wg_maxCopperCount=2 wg_maxCopperCount=2
wg_fluidCenterPointMin=0
wg_fluidCenterPointMax=2
#CPU #CPU
tick_length=1000 tick_length=1000
org_offset=512 org_offset=512

View File

@ -1593,7 +1593,7 @@ var FluidTile = (function (_super) {
_this.baseTint = config.tile.fluid; _this.baseTint = config.tile.fluid;
_this.tint = _this.baseTint; _this.tint = _this.baseTint;
_this.alpha = 0.6; _this.alpha = 0.6;
_this.baseZ = -15; _this.baseZ = -10;
_this.isoZ = _this.baseZ; _this.isoZ = _this.baseZ;
_this.tileType = "fluid"; _this.tileType = "fluid";
return _this; return _this;

View File

@ -565,7 +565,6 @@ class HarvesterNPC extends Cubot {
this.tileY = json.y; this.tileY = json.y;
this.walk(); this.walk();
} }
} }

View File

@ -192,7 +192,7 @@ class FluidTile extends Tile {
this.baseTint = config.tile.fluid; this.baseTint = config.tile.fluid;
this.tint = this.baseTint; this.tint = this.baseTint;
this.alpha = 0.6; this.alpha = 0.6;
this.baseZ = -15; this.baseZ = -10;
this.isoZ = this.baseZ; this.isoZ = this.baseZ;
this.tileType = "fluid"; this.tileType = "fluid";