Added electric boxes, debug command to teleport objects across Worlds.

This commit is contained in:
simon
2018-02-27 16:49:32 -05:00
parent f530dafdee
commit 039088ac00
16 changed files with 426 additions and 42 deletions

View File

@@ -254,6 +254,9 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
/**
* Called before this GameObject is removed from the world - defaults to doing nothing
* @return cancelled
*/
public void onDeadCallback() { }
public boolean onDeadCallback() {
return false;
}
}

View File

@@ -25,6 +25,8 @@ public class TileMap implements JSONSerialisable, MongoSerialisable {
public static final int WALL_TILE = 1;
public static final int IRON_TILE = 2;
public static final int COPPER_TILE = 3;
public static final int VAULT_FLOOR = 4;
public static final int VAULT_WALL = 5;
public static final int ITEM_IRON = 3;
public static final int ITEM_COPPER = 4;
@@ -164,7 +166,7 @@ public class TileMap implements JSONSerialisable, MongoSerialisable {
}
public Point getRandomPlainTile() {
public Point getRandomTile(int tile) {
Random random = new Random();
@@ -180,7 +182,7 @@ public class TileMap implements JSONSerialisable, MongoSerialisable {
int rx = random.nextInt(width);
int ry = random.nextInt(height);
if (tiles[rx][ry] == TileMap.PLAIN_TILE) {
if (tiles[rx][ry] == tile) {
return new Point(rx, ry);
}
}

View File

@@ -66,7 +66,10 @@ public class World implements MongoSerialisable {
*/
public boolean isTileBlocked(int x, int y) {
return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE;
int tile = tileMap.getTileAt(x, y);
return getGameObjectsBlockingAt(x, y).size() > 0 || tile == TileMap.WALL_TILE ||
tile == TileMap.VAULT_WALL;
}
/**
@@ -154,9 +157,10 @@ public class World implements MongoSerialisable {
for (GameObject object : gameObjects.values()) {
//Clean up dead objects
if (object.isDead()) {
object.onDeadCallback();
removeObject(object);
//LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId());
if (!object.onDeadCallback()) {
removeObject(object);
}
} else if (object instanceof Updatable) {
((Updatable) object).update();
}
@@ -249,7 +253,7 @@ public class World implements MongoSerialisable {
if (tiles[x][y] == TileMap.PLAIN_TILE) {
mapInfo[x][y] = 0;
} else if (tiles[x][y] == TileMap.WALL_TILE) {
} else if (tiles[x][y] == TileMap.WALL_TILE || tiles[x][y] == TileMap.VAULT_WALL) {
mapInfo[x][y] = INFO_BLOCKED;
} else if (tiles[x][y] == TileMap.COPPER_TILE) {

View File

@@ -169,7 +169,7 @@ public class WorldGenerator {
for (int i = 0; i < ironCount; i++) {
Point p = world.getTileMap().getRandomPlainTile();
Point p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE);
if (p != null) {
world.getTileMap().getTiles()[p.x][p.y] = TileMap.IRON_TILE;
@@ -177,7 +177,7 @@ public class WorldGenerator {
}
for (int i = 0; i < copperCount; i++) {
Point p = world.getTileMap().getRandomPlainTile();
Point p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE);
if (p != null) {
world.getTileMap().getTiles()[p.x][p.y] = TileMap.COPPER_TILE;

View File

@@ -5,6 +5,7 @@ import com.mongodb.util.JSON;
import net.simon987.server.GameServer;
import net.simon987.server.game.ControllableUnit;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.Updatable;
import net.simon987.server.game.World;
import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User;
@@ -88,6 +89,15 @@ public class DebugHandler implements MessageHandler {
(String) json.get("data"),
(String) json.get("dimension")));
break;
case "tpObj":
response.put("message", moveObj(
(long) json.get("objectId"),
(int) (long) json.get("x"),
(int) (long) json.get("y"),
(int) (long) json.get("worldX"),
(int) (long) json.get("worldY"),
(String) json.get("dimension")));
break;
default:
LogManager.LOGGER.severe("Unknown command: " + command);
@@ -213,12 +223,48 @@ public class DebugHandler implements MessageHandler {
object.setX(x);
object.setY(y);
return "Sucess";
return "Success";
} else {
return "Object not found: " + objectId;
}
}
private String moveObj(long objectId, int x, int y, int worldX, int worldY, String dimension) {
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(objectId);
World world = GameServer.INSTANCE.getGameUniverse().getWorld(worldX, worldY, false, dimension);
if (object != null) {
if (world != null) {
if (object instanceof Updatable) {
object.getWorld().decUpdatable();
}
object.getWorld().removeObject(object);
object.setWorld(world);
world.addObject(object);
if (object instanceof Updatable) {
world.incUpdatable();
}
object.setX(x);
object.setY(y);
return "Success";
} else {
return "World not found: " + World.idFromCoordinates(worldX, worldY, dimension);
}
} else {
return "Object not found: " + objectId;
}
}
private String userInfo(String username) {
User user = GameServer.INSTANCE.getGameUniverse().getUser(username);
@@ -243,4 +289,5 @@ public class DebugHandler implements MessageHandler {
}
}
}

View File

@@ -88,4 +88,11 @@ user_timeout=100
# ----------------------------------------------
vault_door_open_time=4
vault_door_open_time=4
electric_box_hp=250
min_electric_box_count=3
min_electric_box_respawn_count=3
max_electric_box_respawn_count=5
electric_box_respawnTime=64
electric_box_damage=5
electric_box_energy_given=70