Various bug fixes

This commit is contained in:
simon
2017-11-05 14:13:53 -05:00
parent 626c55bcce
commit 98b0c480b9
19 changed files with 145 additions and 68 deletions

View File

@@ -70,7 +70,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
json.put("heldItem", heldItem);
json.put("hp", hp);
json.put("action", lastAction.ordinal());
if(parent != null){
if (parent != null) {
json.put("parent", parent.getUsername()); //Only used client-side for now
}
@@ -86,7 +86,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
cubot.hp = (int)(long)json.get("hp");
cubot.setDirection(Direction.getDirection((int)(long)json.get("direction")));
cubot.heldItem = (int)(long)json.get("heldItem");
cubot.heldItem = (int)(long)json.get("heldItem");
return cubot;
@@ -125,4 +124,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public void setParent(User parent) {
this.parent = parent;
}
public CubotAction getAction() {
return lastAction;
}
}

View File

@@ -3,6 +3,8 @@ package net.simon987.cubotplugin;
public enum CubotAction {
IDLE,
DIGGING,
WALKING
WALKING,
WITHDRAWING,
DEPOSITING
}

View File

@@ -11,7 +11,7 @@ public class CubotDrill extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0005;
static final char HWID = 0x0005;
public static final int DEFAULT_ADDRESS = 5;
@@ -23,24 +23,35 @@ public class CubotDrill extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
if (a == GATHER) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
if (cubot.getAction() != CubotAction.IDLE) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
if (tile == TileMap.IRON_TILE) {
cubot.setHeldItem(TileMap.ITEM_IRON);
if (tile == TileMap.IRON_TILE) {
cubot.setHeldItem(TileMap.ITEM_IRON);
cubot.setCurrentAction(CubotAction.DIGGING);
} else if (tile == TileMap.COPPER_TILE) {
cubot.setHeldItem(TileMap.ITEM_COPPER);
} else if (tile == TileMap.COPPER_TILE) {
cubot.setHeldItem(TileMap.ITEM_COPPER);
cubot.setCurrentAction(CubotAction.DIGGING);
} else {
System.out.println("FAILED: dig");
} else {
System.out.println("FAILED: dig");
}
}
}
}

View File

@@ -10,7 +10,7 @@ public class CubotInventory extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0006;
static final int HWID = 0x0006;
public static final int DEFAULT_ADDRESS = 6;
@@ -23,6 +23,11 @@ public class CubotInventory extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {

View File

@@ -15,7 +15,7 @@ public class CubotLaser extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0002;
static final int HWID = 0x0002;
public static final int DEFAULT_ADDRESS = 2;
@@ -28,6 +28,11 @@ public class CubotLaser extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
@@ -42,7 +47,8 @@ public class CubotLaser extends CpuHardware {
Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
if(objects.size() > 0){
if (cubot.getAction() != CubotAction.IDLE && objects.size() > 0) {
if (objects.get(0) instanceof InventoryHolder) {
//Take the item
@@ -50,6 +56,7 @@ public class CubotLaser extends CpuHardware {
cubot.setHeldItem(b);
System.out.println("took " + b);
cubot.setCurrentAction(CubotAction.WITHDRAWING);
} else {
//The inventory holder can't provide this item
@@ -60,8 +67,7 @@ public class CubotLaser extends CpuHardware {
}
} else {
//Nothing in front
//todo Add emote here
System.out.println("DEBUG: FAILED: take (Nothing in front)");
System.out.println("DEBUG: FAILED: take (Nothing in front or Cubot is busy)");
}
}

View File

@@ -19,7 +19,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0001;
static final int HWID = 0x0001;
private Cubot cubot;
@@ -27,6 +27,11 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();

View File

@@ -16,7 +16,7 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0003;
public static final char HWID = 0x0003;
public static final int DEFAULT_ADDRESS = 3;
@@ -30,6 +30,12 @@ public class CubotRadar extends CpuHardware implements JSONSerialisable {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {

View File

@@ -18,7 +18,7 @@ public class Keyboard extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x0004;
public static final char HWID = 0x0004;
private Cubot cubot;
@@ -26,6 +26,11 @@ public class Keyboard extends CpuHardware {
this.cubot = cubot;
}
@Override
public char getId() {
return HWID;
}
@Override
public void handleInterrupt(Status status) {