mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
More work on vaults
This commit is contained in:
parent
039088ac00
commit
0ada6c29d4
@ -72,18 +72,22 @@ public class CubotLaser extends CpuHardware {
|
|||||||
// TODO
|
// TODO
|
||||||
} else if (a == LASER_ATTACK) {
|
} else if (a == LASER_ATTACK) {
|
||||||
|
|
||||||
if (cubot.spendEnergy(70)) {
|
if (cubot.getCurrentAction() == Action.IDLE) {
|
||||||
|
if (cubot.spendEnergy(70)) {
|
||||||
|
|
||||||
//Get object directly in front of the Cubot
|
//Get object directly in front of the Cubot
|
||||||
Point frontTile = cubot.getFrontTile();
|
Point frontTile = cubot.getFrontTile();
|
||||||
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
||||||
|
|
||||||
|
//todo: Add option in config to allow PvP
|
||||||
|
if (objects.size() > 0 && objects.get(0) instanceof Attackable && !(objects.get(0) instanceof Cubot)) {
|
||||||
|
((Attackable) objects.get(0)).damage(LASER_DAMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
if (objects.size() > 0 && objects.get(0) instanceof Attackable) {
|
|
||||||
((Attackable) objects.get(0)).damage(LASER_DAMAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cubot.setCurrentAction(Action.ATTACKING);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,74 @@
|
|||||||
package net.simon987.npcplugin;
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import com.mongodb.DBObject;
|
||||||
import net.simon987.server.GameServer;
|
import net.simon987.server.GameServer;
|
||||||
|
import net.simon987.server.game.Attackable;
|
||||||
|
import net.simon987.server.game.GameObject;
|
||||||
import net.simon987.server.game.Updatable;
|
import net.simon987.server.game.Updatable;
|
||||||
|
import net.simon987.server.logging.LogManager;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class ElectricBox extends Obstacle implements Updatable {
|
public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||||
|
|
||||||
public static final int STYLE = 1;
|
public static final int ID = 7;
|
||||||
|
|
||||||
private static final int maxHp = GameServer.INSTANCE.getConfig().getInt("electric_box_hp");
|
private static final int maxHp = GameServer.INSTANCE.getConfig().getInt("electric_box_hp");
|
||||||
private static final int damage = GameServer.INSTANCE.getConfig().getInt("electric_box_damage");
|
private static final int damage = GameServer.INSTANCE.getConfig().getInt("electric_box_damage");
|
||||||
private static final int energyGiven = GameServer.INSTANCE.getConfig().getInt("electric_box_energy_given");
|
private static final int energyGiven = GameServer.INSTANCE.getConfig().getInt("electric_box_energy_given");
|
||||||
|
|
||||||
public ElectricBox() {
|
private int hp;
|
||||||
super(maxHp);
|
|
||||||
|
|
||||||
setStyle(STYLE);
|
public ElectricBox() {
|
||||||
|
|
||||||
|
this.hp = maxHp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealRate(int hp) {
|
||||||
|
//no op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHp() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHp(int hp) {
|
||||||
|
this.hp = hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHp() {
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMaxHp(int hp) {
|
||||||
|
//No op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void heal(int amount) {
|
||||||
|
//No op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void damage(int amount) {
|
||||||
|
hp -= amount;
|
||||||
|
|
||||||
|
//YOU ARE DEAD
|
||||||
|
if (hp <= 0) {
|
||||||
|
setDead(true);
|
||||||
|
LogManager.LOGGER.severe("BOX DEAD");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char getMapInfo() {
|
||||||
|
return Obstacle.MAP_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -22,6 +76,43 @@ public class ElectricBox extends Obstacle implements Updatable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject serialise() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
json.put("i", getObjectId());
|
||||||
|
json.put("x", getX());
|
||||||
|
json.put("y", getY());
|
||||||
|
json.put("t", ID);
|
||||||
|
json.put("hp", hp);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BasicDBObject mongoSerialise() {
|
||||||
|
BasicDBObject dbObject = new BasicDBObject();
|
||||||
|
|
||||||
|
dbObject.put("i", getObjectId());
|
||||||
|
dbObject.put("x", getX());
|
||||||
|
dbObject.put("y", getY());
|
||||||
|
dbObject.put("t", ID);
|
||||||
|
dbObject.put("hp", getHp());
|
||||||
|
|
||||||
|
return dbObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ElectricBox deserialize(DBObject obj) {
|
||||||
|
|
||||||
|
ElectricBox electricBox = new ElectricBox();
|
||||||
|
electricBox.setHp((int) obj.get("hp"));
|
||||||
|
electricBox.setObjectId((long) obj.get("i"));
|
||||||
|
electricBox.setX((int) obj.get("x"));
|
||||||
|
electricBox.setY((int) obj.get("y"));
|
||||||
|
|
||||||
|
return electricBox;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDeadCallback() {
|
public boolean onDeadCallback() {
|
||||||
getWorld().decUpdatable();
|
getWorld().decUpdatable();
|
||||||
|
@ -48,6 +48,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
|||||||
return VaultDoor.deserialize(obj);
|
return VaultDoor.deserialize(obj);
|
||||||
} else if (objType == Obstacle.ID) {
|
} else if (objType == Obstacle.ID) {
|
||||||
return Obstacle.deserialize(obj);
|
return Obstacle.deserialize(obj);
|
||||||
|
} else if (objType == ElectricBox.ID) {
|
||||||
|
return ElectricBox.deserialize(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -13,6 +13,7 @@ import org.json.simple.JSONObject;
|
|||||||
public class Obstacle extends GameObject implements Attackable {
|
public class Obstacle extends GameObject implements Attackable {
|
||||||
|
|
||||||
public static final int ID = 6;
|
public static final int ID = 6;
|
||||||
|
public static final int MAP_INFO = 0x0400;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Style of the obstacle. Will tell the client which sprite to display
|
* Style of the obstacle. Will tell the client which sprite to display
|
||||||
@ -77,7 +78,7 @@ public class Obstacle extends GameObject implements Attackable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char getMapInfo() {
|
public char getMapInfo() {
|
||||||
return 0x0400;
|
return MAP_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStyle() {
|
public int getStyle() {
|
||||||
@ -96,6 +97,7 @@ public class Obstacle extends GameObject implements Attackable {
|
|||||||
dbObject.put("x", getX());
|
dbObject.put("x", getX());
|
||||||
dbObject.put("y", getY());
|
dbObject.put("y", getY());
|
||||||
dbObject.put("t", ID);
|
dbObject.put("t", ID);
|
||||||
|
dbObject.put("hp", hp);
|
||||||
dbObject.put("style", style);
|
dbObject.put("style", style);
|
||||||
|
|
||||||
return dbObject;
|
return dbObject;
|
||||||
@ -117,7 +119,6 @@ public class Obstacle extends GameObject implements Attackable {
|
|||||||
|
|
||||||
public static Obstacle deserialize(DBObject obj) {
|
public static Obstacle deserialize(DBObject obj) {
|
||||||
|
|
||||||
//Doesn't matter if we don't store maxHP, since obstacles can't be healed
|
|
||||||
Obstacle obstacle = new Obstacle((int) obj.get("hp"));
|
Obstacle obstacle = new Obstacle((int) obj.get("hp"));
|
||||||
obstacle.setObjectId((long) obj.get("i"));
|
obstacle.setObjectId((long) obj.get("i"));
|
||||||
obstacle.setX((int) obj.get("x"));
|
obstacle.setX((int) obj.get("x"));
|
||||||
|
@ -17,6 +17,8 @@ public class VaultDimension {
|
|||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private World homeWorld;
|
||||||
|
|
||||||
public VaultDimension(long vaultDoorId) {
|
public VaultDimension(long vaultDoorId) {
|
||||||
|
|
||||||
name = "v" + vaultDoorId + "-";
|
name = "v" + vaultDoorId + "-";
|
||||||
@ -42,6 +44,8 @@ public class VaultDimension {
|
|||||||
int maxLayerCount = 6;
|
int maxLayerCount = 6;
|
||||||
int minAttachedWorld = 0;
|
int minAttachedWorld = 0;
|
||||||
int maxAttachedWorld = 4; //todo cap at 4 to avoid infinite loop
|
int maxAttachedWorld = 4; //todo cap at 4 to avoid infinite loop
|
||||||
|
int minElectricBoxCount = 2;
|
||||||
|
int maxElectricBoxCount = 4;
|
||||||
|
|
||||||
HashMap<Integer, ArrayList<WorldBluePrint>> worldLayers = new HashMap<>();
|
HashMap<Integer, ArrayList<WorldBluePrint>> worldLayers = new HashMap<>();
|
||||||
VaultWorldGenerator generator = new VaultWorldGenerator();
|
VaultWorldGenerator generator = new VaultWorldGenerator();
|
||||||
@ -50,11 +54,11 @@ public class VaultDimension {
|
|||||||
int layerCount = random.nextInt(maxLayerCount - minLayerCount) + minLayerCount;
|
int layerCount = random.nextInt(maxLayerCount - minLayerCount) + minLayerCount;
|
||||||
|
|
||||||
//1. Create home world
|
//1. Create home world
|
||||||
WorldBluePrint homeWorld = new WorldBluePrint();
|
WorldBluePrint homeWorldBluePrint = new WorldBluePrint();
|
||||||
homeWorld.coords.x = 0x7FFF;
|
homeWorldBluePrint.coords.x = 0x7FFF;
|
||||||
homeWorld.coords.y = 0x7FFF;
|
homeWorldBluePrint.coords.y = 0x7FFF;
|
||||||
worldLayers.put(0, new ArrayList<>());
|
worldLayers.put(0, new ArrayList<>());
|
||||||
worldLayers.get(0).add(homeWorld);
|
worldLayers.get(0).add(homeWorldBluePrint);
|
||||||
|
|
||||||
//2. For each world in the current layer, attach a random number of new worlds
|
//2. For each world in the current layer, attach a random number of new worlds
|
||||||
for (int i = 1; i <= layerCount; i++) {
|
for (int i = 1; i <= layerCount; i++) {
|
||||||
@ -100,9 +104,21 @@ public class VaultDimension {
|
|||||||
World vWorld = generator.generateVaultWorld(bp.coords.x, bp.coords.y, bp.openings, name);
|
World vWorld = generator.generateVaultWorld(bp.coords.x, bp.coords.y, bp.openings, name);
|
||||||
GameServer.INSTANCE.getGameUniverse().addWorld(vWorld);
|
GameServer.INSTANCE.getGameUniverse().addWorld(vWorld);
|
||||||
|
|
||||||
|
ArrayList<ElectricBox> newBoxes = VaultWorldUtils.generateElectricBoxes(vWorld, minElectricBoxCount,
|
||||||
|
maxElectricBoxCount);
|
||||||
|
for (ElectricBox blob : newBoxes) {
|
||||||
|
vWorld.addObject(blob);
|
||||||
|
vWorld.incUpdatable();
|
||||||
|
}
|
||||||
|
|
||||||
if (key == layerCount - 1) {
|
if (key == layerCount - 1) {
|
||||||
lastLayerWorlds.add(vWorld);
|
lastLayerWorlds.add(vWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key == 0) {
|
||||||
|
this.homeWorld = vWorld;
|
||||||
|
//TODO: generate exit door here and save the coords
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +133,10 @@ public class VaultDimension {
|
|||||||
return worldLayers.values().stream().flatMap(Collection::stream).anyMatch(bp -> bp.coords.equals(coords));
|
return worldLayers.values().stream().flatMap(Collection::stream).anyMatch(bp -> bp.coords.equals(coords));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
World getHomeWorld() {
|
||||||
|
return homeWorld;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to plan the layout of a vault dimension
|
* Helper class to plan the layout of a vault dimension
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
VaultDimension vaultDimension = new VaultDimension(getObjectId());
|
VaultDimension vaultDimension = new VaultDimension(getObjectId());
|
||||||
|
homeWorld = vaultDimension.getHomeWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -111,7 +112,13 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
|||||||
LogManager.LOGGER.fine("VAULT enter " + open);
|
LogManager.LOGGER.fine("VAULT enter " + open);
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
//TODO: Enter in the vault
|
|
||||||
|
object.getWorld().decUpdatable();
|
||||||
|
object.getWorld().removeObject(object);
|
||||||
|
|
||||||
|
homeWorld.incUpdatable();
|
||||||
|
homeWorld.addObject(object);
|
||||||
|
object.setWorld(homeWorld);
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -53,10 +53,11 @@ public class VaultWorldUpdateListener implements GameEventListener {
|
|||||||
if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) {
|
if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) {
|
||||||
|
|
||||||
//If the timer was set less than respawn_time ticks ago, respawn the blobs
|
//If the timer was set less than respawn_time ticks ago, respawn the blobs
|
||||||
ArrayList<ElectricBox> newBlobs = VaultWorldUtils.generateElectricBoxes(world, minElectricBoxCount,
|
ArrayList<ElectricBox> newBoxes = VaultWorldUtils.generateElectricBoxes(world, minElectricBoxCount,
|
||||||
maxElectricBoxCount);
|
maxElectricBoxCount);
|
||||||
for (ElectricBox blob : newBlobs) {
|
for (ElectricBox blob : newBoxes) {
|
||||||
world.addObject(blob);
|
world.addObject(blob);
|
||||||
|
world.incUpdatable();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set the 'waitUntil' time to 0 to indicate that we are not waiting
|
//Set the 'waitUntil' time to 0 to indicate that we are not waiting
|
||||||
|
@ -6,6 +6,8 @@ public enum Action {
|
|||||||
WALKING,
|
WALKING,
|
||||||
WITHDRAWING,
|
WITHDRAWING,
|
||||||
DEPOSITING,
|
DEPOSITING,
|
||||||
LISTENING
|
LISTENING,
|
||||||
|
_PLACEHOLDER_,
|
||||||
|
ATTACKING,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -240,15 +240,13 @@ public class DebugHandler implements MessageHandler {
|
|||||||
|
|
||||||
if (object instanceof Updatable) {
|
if (object instanceof Updatable) {
|
||||||
object.getWorld().decUpdatable();
|
object.getWorld().decUpdatable();
|
||||||
|
world.incUpdatable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object.getWorld().removeObject(object);
|
object.getWorld().removeObject(object);
|
||||||
object.setWorld(world);
|
|
||||||
world.addObject(object);
|
world.addObject(object);
|
||||||
|
object.setWorld(world);
|
||||||
if (object instanceof Updatable) {
|
|
||||||
world.incUpdatable();
|
|
||||||
}
|
|
||||||
|
|
||||||
object.setX(x);
|
object.setX(x);
|
||||||
object.setY(y);
|
object.setY(y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user