mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Fixed some debug commands. Added blueprint item deserialization, Added inventory SCAN and SEEK actions
This commit is contained in:
@@ -21,12 +21,14 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
|
||||
private static final int INV_CLEAR = 0;
|
||||
private static final int INV_POLL = 1;
|
||||
private static final int INV_SEEK = 2;
|
||||
private static final int INV_SCAN = 3;
|
||||
|
||||
private int inventorySize = 4;
|
||||
|
||||
private int inventorySize = 4; //TODO: load from config
|
||||
private Map<Integer, Item> inventory;
|
||||
private int position = 0;
|
||||
|
||||
|
||||
public CubotInventory(Cubot cubot) {
|
||||
super(cubot);
|
||||
|
||||
@@ -51,7 +53,13 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
inventory.put(position, item);
|
||||
}
|
||||
|
||||
public Item popItem() {
|
||||
private void scanItem() {
|
||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
Item item = inventory.get(position);
|
||||
item.digitize(cubot.getCpu().getMemory(), x);
|
||||
}
|
||||
|
||||
public Item clearItem() {
|
||||
Item item = inventory.get(position);
|
||||
item.clear(cubot);
|
||||
inventory.remove(position);
|
||||
@@ -92,7 +100,16 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(result);
|
||||
|
||||
} else if (a == INV_CLEAR) {
|
||||
popItem();
|
||||
if (cubot.spendEnergy(100)) {
|
||||
clearItem();
|
||||
}
|
||||
} else if (a == INV_SEEK) {
|
||||
setPosition(getCpu().getRegisterSet().getRegister("X").getValue());
|
||||
} else if (a == INV_SCAN) {
|
||||
if (cubot.spendEnergy(200)) {
|
||||
scanItem();
|
||||
clearItem();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.cubotplugin.event.*;
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
@@ -10,7 +10,7 @@ public class CubotPlugin extends ServerPlugin {
|
||||
|
||||
|
||||
@Override
|
||||
public void init(ServerConfiguration config, GameRegistry registry) {
|
||||
public void init(GameServer gameServer) {
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
listeners.add(new UserCreationListener());
|
||||
//Debug commands
|
||||
@@ -19,6 +19,8 @@ public class CubotPlugin extends ServerPlugin {
|
||||
listeners.add(new PutItemCommandListener());
|
||||
listeners.add(new PopItemCommandListener());
|
||||
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
registry.registerGameObject(Cubot.class);
|
||||
|
||||
registry.registerHardware(CubotLeg.class);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class PopItemCommandListener implements GameEventListener {
|
||||
|
||||
DebugCommandEvent e = (DebugCommandEvent) event;
|
||||
|
||||
if (e.getName().equals("popItem")) {
|
||||
if (e.getName().equals("clearItem")) {
|
||||
|
||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PopItemCommandListener implements GameEventListener {
|
||||
|
||||
CubotInventory inventory = (CubotInventory) ((Cubot) object).getHardware(CubotInventory.class);
|
||||
|
||||
e.reply("Removed item from inventory: " + inventory.popItem());
|
||||
e.reply("Removed item from inventory: " + inventory.clearItem());
|
||||
} else {
|
||||
e.reply("Object is not a Cubot");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user