mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 22:59:02 +00:00
Objects can enter & leave vaults
This commit is contained in:
@@ -5,7 +5,7 @@ package net.simon987.server.event;
|
||||
*/
|
||||
public class ObjectDeathEvent extends GameEvent {
|
||||
/**
|
||||
* The GameObject type ID of object that init this event
|
||||
* The GameObject type ID of object that initialize this event
|
||||
*/
|
||||
private long sourceObjectId;
|
||||
|
||||
|
||||
@@ -259,4 +259,8 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
|
||||
public boolean onDeadCallback() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
}
|
||||
28
Server/src/main/java/net/simon987/server/game/Location.java
Normal file
28
Server/src/main/java/net/simon987/server/game/Location.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.simon987.server.game;
|
||||
|
||||
/**
|
||||
* Represents a location in the game universe
|
||||
*/
|
||||
public class Location {
|
||||
|
||||
public int worldX;
|
||||
public int worldY;
|
||||
|
||||
public String dimension;
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Location(int worldX, int worldY, String dimension, int x, int y) {
|
||||
this.worldX = worldX;
|
||||
this.worldY = worldY;
|
||||
this.dimension = dimension;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String getWorldId() {
|
||||
return World.idFromCoordinates(worldX, worldY, dimension);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.zip.DeflaterOutputStream;
|
||||
*/
|
||||
public class TileMap implements JSONSerialisable, MongoSerialisable {
|
||||
|
||||
public static final int VOID = -1;
|
||||
public static final int PLAIN_TILE = 0;
|
||||
public static final int WALL_TILE = 1;
|
||||
public static final int IRON_TILE = 2;
|
||||
@@ -186,6 +187,5 @@ public class TileMap implements JSONSerialisable, MongoSerialisable {
|
||||
return new Point(rx, ry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class World implements MongoSerialisable {
|
||||
int tile = tileMap.getTileAt(x, y);
|
||||
|
||||
return getGameObjectsBlockingAt(x, y).size() > 0 || tile == TileMap.WALL_TILE ||
|
||||
tile == TileMap.VAULT_WALL;
|
||||
tile == TileMap.VAULT_WALL || tile == TileMap.VOID;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,6 +229,8 @@ public class World implements MongoSerialisable {
|
||||
|
||||
object.setWorld(world);
|
||||
world.addObject(object);
|
||||
|
||||
object.initialize();
|
||||
}
|
||||
|
||||
return world;
|
||||
@@ -439,7 +441,80 @@ public class World implements MongoSerialisable {
|
||||
return res;
|
||||
}
|
||||
|
||||
public Point getAdjacentTile(int x, int y) {
|
||||
|
||||
if (!isTileBlocked(x + 1, y)) {
|
||||
return new Point(x + 1, y);
|
||||
|
||||
} else if (!isTileBlocked(x, y + 1)) {
|
||||
return new Point(x, getY() + 1);
|
||||
|
||||
} else if (!isTileBlocked(x - 1, y)) {
|
||||
return new Point(x - 1, getY());
|
||||
|
||||
} else if (!isTileBlocked(x, y - 1)) {
|
||||
return new Point(x, y - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<GameObject> getGameObjects() {
|
||||
return gameObjects.values();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a random tile with N adjacent non-blocked tile
|
||||
*
|
||||
* @param n Number of adjacent tiles of type X
|
||||
* @return null if no tile is found
|
||||
*/
|
||||
public Point getRandomTileWithAdjacent(int n, int tile) {
|
||||
int counter = 0;
|
||||
while (true) {
|
||||
counter++;
|
||||
|
||||
//Prevent infinite loop
|
||||
if (counter >= 2500) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Point rTile = getTileMap().getRandomTile(tile);
|
||||
|
||||
if (rTile != null) {
|
||||
int adjacentTiles = 0;
|
||||
|
||||
if (!isTileBlocked(rTile.x, rTile.y - 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x + 1, rTile.y)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x, rTile.y + 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x - 1, rTile.y)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x + 1, rTile.y + 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x - 1, rTile.y + 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x + 1, rTile.y - 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
if (!isTileBlocked(rTile.x - 1, rTile.y - 1)) {
|
||||
adjacentTiles++;
|
||||
}
|
||||
|
||||
if (adjacentTiles >= n) {
|
||||
return rTile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +156,9 @@ public class DebugHandler implements MessageHandler {
|
||||
|
||||
if (object != null) {
|
||||
world.addObject(object);
|
||||
object.setWorld(world);
|
||||
|
||||
object.initialize();
|
||||
|
||||
return "Created object " + object.getObjectId();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user