mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
More obstacle WIP
This commit is contained in:
@@ -57,7 +57,8 @@ public class ConstructionArmHardware extends HardwareModule {
|
||||
|
||||
Point frontTile = unit.getFrontTile();
|
||||
|
||||
if (unit.getWorld().isTileBlocked(frontTile.x, frontTile.y)) {
|
||||
if (unit.getWorld().isTileBlocked(frontTile.x, frontTile.y) ||
|
||||
unit.getWorld().canBuild(frontTile.x, frontTile.y)) {
|
||||
regB.setValue(ERR_TILE_BLOCKED);
|
||||
return;
|
||||
}
|
||||
@@ -68,9 +69,10 @@ public class ConstructionArmHardware extends HardwareModule {
|
||||
}
|
||||
|
||||
GameObject constructionSite = new ConstructionSite(bluePrint);
|
||||
constructionSite.setObjectId(new ObjectId());
|
||||
constructionSite.setWorld(unit.getWorld());
|
||||
constructionSite.setX(frontTile.x);
|
||||
constructionSite.setY(frontTile.y);
|
||||
constructionSite.setObjectId(new ObjectId());
|
||||
|
||||
unit.getWorld().addObject(constructionSite);
|
||||
regB.setValue(OK);
|
||||
|
||||
@@ -2,12 +2,14 @@ package net.simon987.constructionplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.InventoryHolder;
|
||||
import net.simon987.server.game.objects.Structure;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ConstructionSite extends Structure implements Updatable, InventoryHolder {
|
||||
|
||||
public static final int MAP_INFO = 0xFFFF; //TODO: determine
|
||||
@@ -47,7 +49,31 @@ public class ConstructionSite extends Structure implements Updatable, InventoryH
|
||||
|
||||
@Override
|
||||
public boolean placeItem(Item item) {
|
||||
return bluePrint.placeItem(item);
|
||||
boolean ok = bluePrint.placeItem(item);
|
||||
|
||||
if (ok && bluePrint.isCompleted()) {
|
||||
instantiateTargetObject();
|
||||
setDead(true);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
private void instantiateTargetObject() {
|
||||
Class<? extends GameObject> targetClass = bluePrint.getTargetObject();
|
||||
try {
|
||||
GameObject targetObj = targetClass.getConstructor().newInstance();
|
||||
|
||||
targetObj.setWorld(getWorld());
|
||||
targetObj.setObjectId(new ObjectId());
|
||||
targetObj.setX(getX());
|
||||
targetObj.setY(getY());
|
||||
|
||||
getWorld().addObject(targetObj);
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,13 +18,15 @@ public class Obstacle extends Structure implements Attackable, Updatable {
|
||||
|
||||
public Obstacle() {
|
||||
super(1, 1);
|
||||
|
||||
setHp(MAX_HP);
|
||||
}
|
||||
|
||||
public Obstacle(Document document) {
|
||||
super(document, 1, 1);
|
||||
|
||||
hp = document.getInteger(hp);
|
||||
color = document.getInteger(color);
|
||||
hp = document.getInteger("hp");
|
||||
color = document.getInteger("color");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user