mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Hacked NPC minimum viable
This commit is contained in:
@@ -91,25 +91,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
*/
|
||||
private User parent;
|
||||
|
||||
/**
|
||||
* Energy units in kJ
|
||||
*/
|
||||
private int energy;
|
||||
|
||||
/**
|
||||
* Maximum energy units in kJ
|
||||
*/
|
||||
private int maxEnergy;
|
||||
|
||||
/**
|
||||
* Solar panel multiplier
|
||||
* <br>TODO: Set this constant in dimension
|
||||
*/
|
||||
private static final float SOLAR_PANEL_MULTIPLIER = 1;
|
||||
/**
|
||||
* Maximum size of the console buffer (also called 'internal buffer')
|
||||
*/
|
||||
private static final int CONSOLE_BUFFER_MAX_SIZE = 40;
|
||||
public static final int CONSOLE_BUFFER_MAX_SIZE = 40;
|
||||
|
||||
/**
|
||||
* List of attached hardware, 'modules'
|
||||
@@ -143,10 +128,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
hp = document.getInteger("hp");
|
||||
shield = document.getInteger("shield");
|
||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||
energy = document.getInteger("energy");
|
||||
|
||||
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
maxEnergy = config.getInt("battery_max_energy");
|
||||
maxHp = config.getInt("cubot_max_hp");
|
||||
maxShield = config.getInt("cubot_max_shield");
|
||||
|
||||
@@ -176,8 +159,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
storeEnergy((int) (SOLAR_PANEL_MULTIPLIER * GameServer.INSTANCE.getDayNightCycle().getSunIntensity()));
|
||||
|
||||
if (currentAction == Action.WALKING) {
|
||||
if (spendEnergy(100)) {
|
||||
if (!incrementLocation()) {
|
||||
@@ -225,7 +206,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
json.put("hp", hp);
|
||||
json.put("shield", shield);
|
||||
json.put("action", lastAction.ordinal());
|
||||
json.put("energy", energy);
|
||||
|
||||
if (parent != null) {
|
||||
json.put("parent", parent.getUsername()); //Only used client-side for now
|
||||
@@ -249,7 +229,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
dbObject.put("hp", hp);
|
||||
dbObject.put("shield", shield);
|
||||
dbObject.put("action", lastAction.ordinal());
|
||||
dbObject.put("energy", energy);
|
||||
|
||||
if (parent != null) {
|
||||
dbObject.put("parent", parent.getUsername()); //Only used client-side for now
|
||||
@@ -279,7 +258,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
setDead(false);
|
||||
setHp(maxHp);
|
||||
setShield(0);
|
||||
setEnergy(maxEnergy);
|
||||
setEnergy(((CubotBattery) getHardware(CubotBattery.class)).getMaxEnergy());
|
||||
clearKeyboardBuffer();
|
||||
consoleMessagesBuffer.clear();
|
||||
lastConsoleMessagesBuffer.clear();
|
||||
@@ -354,34 +333,41 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
}
|
||||
|
||||
public int getEnergy() {
|
||||
return energy;
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
return battery.getEnergy();
|
||||
}
|
||||
|
||||
public void setEnergy(int energy) {
|
||||
this.energy = energy;
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
battery.setEnergy(energy);
|
||||
}
|
||||
|
||||
public boolean spendEnergy(int amount) {
|
||||
|
||||
if (energy - amount < 0) {
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
|
||||
if (battery.getEnergy() - amount < 0) {
|
||||
return false;
|
||||
} else {
|
||||
energy -= amount;
|
||||
battery.setEnergy(battery.getEnergy() - amount);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void storeEnergy(int amount) {
|
||||
|
||||
energy = Math.min(energy + amount, maxEnergy);
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
battery.setEnergy(Math.min(battery.getEnergy() + amount, battery.getMaxEnergy()));
|
||||
}
|
||||
|
||||
public void setMaxEnergy(int maxEnergy) {
|
||||
this.maxEnergy = maxEnergy;
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
battery.setMaxEnergy(maxEnergy);
|
||||
}
|
||||
|
||||
public int getMaxEnergy() {
|
||||
return maxEnergy;
|
||||
CubotBattery battery = (CubotBattery) getHardware(CubotBattery.class);
|
||||
return battery.getMaxEnergy();
|
||||
}
|
||||
|
||||
public int getShield() {
|
||||
@@ -422,8 +408,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
@Override
|
||||
public Memory getFloppyData() {
|
||||
|
||||
//TODO change DEFAULT_ADDRESS to getHW(class) to allow mutable addresses
|
||||
CubotFloppyDrive drive = ((CubotFloppyDrive) getHardware(CubotFloppyDrive.DEFAULT_ADDRESS));
|
||||
CubotFloppyDrive drive = (CubotFloppyDrive) getHardware(CubotFloppyDrive.class);
|
||||
|
||||
if (drive.getFloppy() != null) {
|
||||
return drive.getFloppy().getMemory();
|
||||
@@ -515,6 +500,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
public void setMaxShield(int maxShield) {
|
||||
this.maxShield = maxShield;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int amount) {
|
||||
hp += amount;
|
||||
@@ -538,11 +524,13 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachHardware(HardwareModule hardware, int address) {
|
||||
hardwareAddresses.put(address, hardware);
|
||||
hardwareModules.put(hardware.getClass(), address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachHardware(int address) {
|
||||
hardwareAddresses.remove(address);
|
||||
|
||||
@@ -555,6 +543,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
hardwareModules.remove(toRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hardwareInterrupt(int address, Status status) {
|
||||
HardwareModule hardware = hardwareAddresses.get(address);
|
||||
|
||||
@@ -566,6 +555,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hardwareQuery(int address) {
|
||||
HardwareModule hardware = hardwareAddresses.get(address);
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class CubotBattery extends CubotHardwareModule {
|
||||
public class CubotBattery extends HardwareModule {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 0x000A;
|
||||
|
||||
@@ -12,16 +15,38 @@ public class CubotBattery extends CubotHardwareModule {
|
||||
* Hardware ID (Should be unique)
|
||||
*/
|
||||
public static final char HWID = 0x000A;
|
||||
/**
|
||||
* Solar panel multiplier
|
||||
* <br>TODO: Set this constant in dimension
|
||||
*/
|
||||
private static final float SOLAR_PANEL_MULTIPLIER = 1;
|
||||
|
||||
/**
|
||||
* Energy units in kJ
|
||||
*/
|
||||
private int energy;
|
||||
|
||||
/**
|
||||
* Maximum energy units in kJ
|
||||
*/
|
||||
private int maxEnergy;
|
||||
|
||||
|
||||
private static final int BATTERY_POLL = 1;
|
||||
private static final int BATTERY_GET_MAX_CAPACITY = 2;
|
||||
|
||||
public CubotBattery(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotBattery(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
|
||||
energy = GameServer.INSTANCE.getConfig().getInt("battery_max_energy");
|
||||
maxEnergy = GameServer.INSTANCE.getConfig().getInt("battery_max_energy");
|
||||
}
|
||||
|
||||
public CubotBattery(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
|
||||
energy = document.getInteger("energy");
|
||||
maxEnergy = document.getInteger("max_energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,16 +55,12 @@ public class CubotBattery extends CubotHardwareModule {
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
|
||||
if (a == BATTERY_POLL) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getEnergy());
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(energy);
|
||||
|
||||
} else if (a == BATTERY_GET_MAX_CAPACITY) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getMaxEnergy());
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(maxEnergy);
|
||||
|
||||
//TODO: Remove debug action
|
||||
} else if (a == 0xFFFF) {
|
||||
cubot.setEnergy(cubot.getMaxEnergy());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,4 +68,53 @@ public class CubotBattery extends CubotHardwareModule {
|
||||
return HWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject jsonSerialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("energy", energy);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject debugJsonSerialise() {
|
||||
JSONObject json = jsonSerialise();
|
||||
|
||||
json.put("max_energy", maxEnergy);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document document = super.mongoSerialise();
|
||||
|
||||
document.put("energy", energy);
|
||||
document.put("max_energy", maxEnergy);
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
public int getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public void setEnergy(int energy) {
|
||||
this.energy = energy;
|
||||
}
|
||||
|
||||
public int getMaxEnergy() {
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
public void setMaxEnergy(int maxEnergy) {
|
||||
this.maxEnergy = maxEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
energy = Math.min(maxEnergy,
|
||||
energy + (int) (SOLAR_PANEL_MULTIPLIER * GameServer.INSTANCE.getDayNightCycle().getSunIntensity()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
@@ -9,7 +10,7 @@ import org.bson.Document;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CubotComPort extends CubotHardwareModule {
|
||||
public class CubotComPort extends HardwareModule {
|
||||
|
||||
public static final char HWID = 0xD;
|
||||
public static final int DEFAULT_ADDRESS = 0xD;
|
||||
@@ -20,8 +21,8 @@ public class CubotComPort extends CubotHardwareModule {
|
||||
private static final int COMPORT_SELF_OUT = 3;
|
||||
private static final int COMPORT_CONSOLE_CLEAR = 4;
|
||||
|
||||
public CubotComPort(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotComPort(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotComPort(Document document, ControllableUnit cubot) {
|
||||
@@ -37,21 +38,23 @@ public class CubotComPort extends CubotHardwareModule {
|
||||
|
||||
if (a == COMPORT_BUFFER_CLEAR) {
|
||||
|
||||
cubot.getConsoleMessagesBuffer().clear();
|
||||
unit.getConsoleMessagesBuffer().clear();
|
||||
|
||||
} else if (a == COMPORT_CONSOLE_CLEAR) {
|
||||
|
||||
cubot.setConsoleMode(Cubot.ConsoleMode.CLEAR);
|
||||
|
||||
if (unit instanceof Cubot) {
|
||||
((Cubot) unit).setConsoleMode(Cubot.ConsoleMode.CLEAR);
|
||||
}
|
||||
|
||||
} else if (a == COMPORT_POLL) {
|
||||
|
||||
if (cubot.spendEnergy(4)) {
|
||||
if (unit.spendEnergy(4)) {
|
||||
|
||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
|
||||
//Read all messages in the console buffer to memory at X
|
||||
|
||||
for (char[] message : cubot.getConsoleMessagesBuffer()) {
|
||||
for (char[] message : unit.getConsoleMessagesBuffer()) {
|
||||
if (x + MESSAGE_LENGTH >= getCpu().getMemory().getWords().length) {
|
||||
//todo set interrupt ?
|
||||
getCpu().getStatus().setErrorFlag(true);
|
||||
@@ -61,17 +64,17 @@ public class CubotComPort extends CubotHardwareModule {
|
||||
}
|
||||
|
||||
//Set B = number of messages
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getConsoleMessagesBuffer().size());
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(unit.getConsoleMessagesBuffer().size());
|
||||
|
||||
}
|
||||
|
||||
} else if (a == COMPORT_FRONT_PORT_OUT) {
|
||||
|
||||
if (cubot.spendEnergy(5)) {
|
||||
if (unit.spendEnergy(5)) {
|
||||
//Get object directly in front of the Cubot
|
||||
Point frontTile = cubot.getFrontTile();
|
||||
Point frontTile = unit.getFrontTile();
|
||||
//Todo will have to add getGameObjectsBlockingAt to enable Factory
|
||||
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
||||
ArrayList<GameObject> objects = unit.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
||||
|
||||
if (objects.size() > 0 && objects.get(0) instanceof MessageReceiver) {
|
||||
|
||||
@@ -98,7 +101,7 @@ public class CubotComPort extends CubotHardwareModule {
|
||||
|
||||
} else if (a == COMPORT_SELF_OUT) {
|
||||
|
||||
if (cubot.spendEnergy(1)) {
|
||||
if (unit.spendEnergy(1)) {
|
||||
|
||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
|
||||
@@ -111,7 +114,7 @@ public class CubotComPort extends CubotHardwareModule {
|
||||
//Get MESSAGE_LENGTH-word message pointed by X
|
||||
char[] message = new char[MESSAGE_LENGTH];
|
||||
System.arraycopy(getCpu().getMemory().getWords(), x, message, 0, MESSAGE_LENGTH);
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.sendMessage(message) ? 1 : 0);
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(unit.sendMessage(message) ? 1 : 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotCore extends CubotHardwareModule {
|
||||
public class CubotCore extends HardwareModule {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 0x000E;
|
||||
|
||||
@@ -16,12 +17,12 @@ public class CubotCore extends CubotHardwareModule {
|
||||
private static final int CORE_STATUS_POLL = 1;
|
||||
private static final int CORE_HULL_POLL = 2;
|
||||
|
||||
public CubotCore(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotCore(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotCore(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
public CubotCore(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,9 +31,11 @@ public class CubotCore extends CubotHardwareModule {
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
|
||||
if (a == CORE_STATUS_POLL) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getStatus());
|
||||
if (unit instanceof Cubot) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(((Cubot) unit).getStatus());
|
||||
}
|
||||
} else if (a == CORE_HULL_POLL) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getHp());
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(unit.getHp());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
@@ -7,7 +8,7 @@ import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.world.Tile;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotDrill extends CubotHardwareModule {
|
||||
public class CubotDrill extends HardwareModule {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -19,8 +20,8 @@ public class CubotDrill extends CubotHardwareModule {
|
||||
private static final int DRILL_POLL = 1;
|
||||
private static final int DRILL_GATHER = 2; // simplified gather
|
||||
|
||||
public CubotDrill(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotDrill(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotDrill(Document document, ControllableUnit cubot) {
|
||||
@@ -42,15 +43,15 @@ public class CubotDrill extends CubotHardwareModule {
|
||||
|
||||
} else if (a == DRILL_GATHER) {
|
||||
|
||||
if (cubot.spendEnergy(1400)) {
|
||||
if (cubot.getCurrentAction() == Action.IDLE) {
|
||||
if (unit.spendEnergy(1400)) {
|
||||
if (unit.getCurrentAction() == Action.IDLE) {
|
||||
|
||||
Tile tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
|
||||
Tile tile = unit.getWorld().getTileMap().getTileAt(unit.getX(), unit.getY());
|
||||
|
||||
Item newItem = tile.drill();
|
||||
if (newItem != null) {
|
||||
cubot.setCurrentAction(Action.DIGGING);
|
||||
cubot.giveItem(newItem);
|
||||
unit.setCurrentAction(Action.DIGGING);
|
||||
unit.giveItem(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,4 @@ public abstract class CubotHardwareModule extends HardwareModule {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document document = new Document();
|
||||
|
||||
document.put("type", getClass().getCanonicalName());
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class CubotHologram extends CubotHardwareModule {
|
||||
public class CubotHologram extends HardwareModule {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -31,8 +32,8 @@ public class CubotHologram extends CubotHardwareModule {
|
||||
*/
|
||||
private int displayColor = 0;
|
||||
|
||||
public CubotHologram(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotHologram(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotHologram(Document document, ControllableUnit cubot) {
|
||||
@@ -80,7 +81,7 @@ public class CubotHologram extends CubotHardwareModule {
|
||||
|
||||
} else if (a == HOLO_DISPLAY_COLOR) {
|
||||
|
||||
if (cubot.spendEnergy(4)) {
|
||||
if (unit.spendEnergy(4)) {
|
||||
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||
int c = getCpu().getRegisterSet().getRegister("C").getValue();
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.item.ItemCopper;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CubotInventory extends CubotHardwareModule {
|
||||
public class CubotInventory extends HardwareModule {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -29,11 +29,10 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
private int position = 0;
|
||||
|
||||
|
||||
public CubotInventory(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotInventory(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
|
||||
inventory = new HashMap<>();
|
||||
inventory.put(2, new ItemCopper(new Document())); // TODO: Remove debug value
|
||||
}
|
||||
|
||||
public CubotInventory(Document document, ControllableUnit cubot) {
|
||||
@@ -56,12 +55,12 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
private void scanItem() {
|
||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
Item item = inventory.get(position);
|
||||
item.digitize(cubot.getCpu().getMemory(), x);
|
||||
item.digitize(unit.getCpu().getMemory(), x);
|
||||
}
|
||||
|
||||
public Item clearItem() {
|
||||
Item item = inventory.get(position);
|
||||
item.clear(cubot);
|
||||
item.clear(unit);
|
||||
inventory.remove(position);
|
||||
|
||||
return item;
|
||||
@@ -100,13 +99,13 @@ public class CubotInventory extends CubotHardwareModule {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(result);
|
||||
|
||||
} else if (a == INV_CLEAR) {
|
||||
if (cubot.spendEnergy(100)) {
|
||||
if (unit.spendEnergy(100)) {
|
||||
clearItem();
|
||||
}
|
||||
} else if (a == INV_SEEK) {
|
||||
setPosition(getCpu().getRegisterSet().getRegister("X").getValue());
|
||||
} else if (a == INV_SCAN) {
|
||||
if (cubot.spendEnergy(200)) {
|
||||
if (unit.spendEnergy(200)) {
|
||||
scanItem();
|
||||
clearItem();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import org.bson.Document;
|
||||
@@ -8,7 +9,7 @@ import org.bson.Document;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CubotLaser extends CubotHardwareModule {
|
||||
public class CubotLaser extends HardwareModule {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -23,8 +24,8 @@ public class CubotLaser extends CubotHardwareModule {
|
||||
|
||||
private static final int LASER_DAMAGE = 25;
|
||||
|
||||
public CubotLaser(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotLaser(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotLaser(Document document, ControllableUnit cubot) {
|
||||
@@ -46,19 +47,19 @@ public class CubotLaser extends CubotHardwareModule {
|
||||
if (a == LASER_WITHDRAW) {
|
||||
|
||||
|
||||
Point frontTile = cubot.getFrontTile();
|
||||
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
|
||||
Point frontTile = unit.getFrontTile();
|
||||
ArrayList<GameObject> objects = unit.getWorld().getGameObjectsBlockingAt(frontTile.x, frontTile.y);
|
||||
|
||||
if (cubot.getCurrentAction() == Action.IDLE && objects.size() > 0) {
|
||||
if (unit.getCurrentAction() == Action.IDLE && objects.size() > 0) {
|
||||
//FIXME: Problem here if more than 1 object
|
||||
if (objects.get(0) instanceof InventoryHolder) {
|
||||
|
||||
if (((InventoryHolder) objects.get(0)).canTakeItem(b)) {
|
||||
if (cubot.spendEnergy(30)) {
|
||||
if (unit.spendEnergy(30)) {
|
||||
//Take the item
|
||||
((InventoryHolder) objects.get(0)).takeItem(b);
|
||||
cubot.giveItem(GameServer.INSTANCE.getRegistry().makeItem(b));
|
||||
cubot.setCurrentAction(Action.WITHDRAWING);
|
||||
unit.giveItem(GameServer.INSTANCE.getRegistry().makeItem(b));
|
||||
unit.setCurrentAction(Action.WITHDRAWING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,12 +70,12 @@ public class CubotLaser extends CubotHardwareModule {
|
||||
// TODO
|
||||
} else if (a == LASER_ATTACK) {
|
||||
|
||||
if (cubot.getCurrentAction() == Action.IDLE) {
|
||||
if (cubot.spendEnergy(70)) {
|
||||
if (unit.getCurrentAction() == Action.IDLE) {
|
||||
if (unit.spendEnergy(70)) {
|
||||
|
||||
//Get object directly in front of the Cubot
|
||||
Point frontTile = cubot.getFrontTile();
|
||||
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
|
||||
Point frontTile = unit.getFrontTile();
|
||||
ArrayList<GameObject> objects = unit.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)) {
|
||||
@@ -83,7 +84,7 @@ public class CubotLaser extends CubotHardwareModule {
|
||||
|
||||
}
|
||||
|
||||
cubot.setCurrentAction(Action.ATTACKING);
|
||||
unit.setCurrentAction(Action.ATTACKING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotLeg extends CubotHardwareModule {
|
||||
public class CubotLeg extends HardwareModule {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 1;
|
||||
|
||||
@@ -18,12 +19,12 @@ public class CubotLeg extends CubotHardwareModule {
|
||||
*/
|
||||
static final char HWID = 0x0001;
|
||||
|
||||
public CubotLeg(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotLeg(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotLeg(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
public CubotLeg(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,7 +35,7 @@ public class CubotLeg extends CubotHardwareModule {
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
|
||||
if (cubot.getCurrentAction() == Action.IDLE) {
|
||||
if (unit.getCurrentAction() == Action.IDLE) {
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||
|
||||
@@ -44,8 +45,8 @@ public class CubotLeg extends CubotHardwareModule {
|
||||
Direction dir = Direction.getDirection(b);
|
||||
|
||||
if (dir != null) {
|
||||
if (cubot.spendEnergy(20)) {
|
||||
cubot.setDirection(Direction.getDirection(b));
|
||||
if (unit.spendEnergy(20)) {
|
||||
unit.setDirection(Direction.getDirection(b));
|
||||
status.setErrorFlag(false);
|
||||
}
|
||||
} else {
|
||||
@@ -55,17 +56,17 @@ public class CubotLeg extends CubotHardwareModule {
|
||||
|
||||
} else if (a == LEGS_SET_DIR_AND_WALK) {
|
||||
|
||||
if (cubot.getMaxEnergy() >= 100) {
|
||||
if (unit.getMaxEnergy() >= 100) {
|
||||
Direction dir = Direction.getDirection(b);
|
||||
|
||||
if (dir != null) {
|
||||
cubot.setDirection(Direction.getDirection(b));
|
||||
unit.setDirection(Direction.getDirection(b));
|
||||
status.setErrorFlag(false);
|
||||
} else {
|
||||
status.setErrorFlag(true);
|
||||
}
|
||||
|
||||
cubot.setCurrentAction(Action.WALKING);
|
||||
unit.setCurrentAction(Action.WALKING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
@@ -9,7 +10,7 @@ import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CubotLidar extends CubotHardwareModule {
|
||||
public class CubotLidar extends HardwareModule {
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
@@ -24,12 +25,12 @@ public class CubotLidar extends CubotHardwareModule {
|
||||
private static final int LIDAR_GET_WORLD_POS = 4;
|
||||
private static final int LIDAR_GET_WORLD_SIZE = 5;
|
||||
|
||||
public CubotLidar(Cubot cubot) {
|
||||
super(cubot);
|
||||
public CubotLidar(ControllableUnit unit) {
|
||||
super(null, unit);
|
||||
}
|
||||
|
||||
public CubotLidar(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
public CubotLidar(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,18 +45,18 @@ public class CubotLidar extends CubotHardwareModule {
|
||||
|
||||
switch (a) {
|
||||
case LIDAR_GET_POS:
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(cubot.getX());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getY());
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(unit.getX());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(unit.getY());
|
||||
break;
|
||||
case LIDAR_GET_PATH:
|
||||
if (cubot.spendEnergy(50)) {
|
||||
if (unit.spendEnergy(50)) {
|
||||
int c = getCpu().getRegisterSet().getRegister("C").getValue();
|
||||
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||
int destX = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
int destY = getCpu().getRegisterSet().getRegister("Y").getValue();
|
||||
|
||||
//Get path
|
||||
ArrayList<Node> nodes = Pathfinder.findPath(cubot.getWorld(), cubot.getX(), cubot.getY(),
|
||||
ArrayList<Node> nodes = Pathfinder.findPath(unit.getWorld(), unit.getX(), unit.getY(),
|
||||
destX, destY, b);
|
||||
|
||||
//Write to memory
|
||||
@@ -102,13 +103,13 @@ public class CubotLidar extends CubotHardwareModule {
|
||||
break;
|
||||
|
||||
case LIDAR_GET_MAP:
|
||||
if (cubot.spendEnergy(10)) {
|
||||
char[][] mapInfo = cubot.getWorld().getMapInfo();
|
||||
if (unit.spendEnergy(10)) {
|
||||
char[][] mapInfo = unit.getWorld().getMapInfo();
|
||||
|
||||
//Write map data to the location specified by register X
|
||||
int i = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
for (int x = 0; x < cubot.getWorld().getWorldSize(); x++) {
|
||||
for (int y = 0; y < cubot.getWorld().getWorldSize(); y++) {
|
||||
for (int x = 0; x < unit.getWorld().getWorldSize(); x++) {
|
||||
for (int y = 0; y < unit.getWorld().getWorldSize(); y++) {
|
||||
getCpu().getMemory().set(i++, mapInfo[x][y]);
|
||||
}
|
||||
}
|
||||
@@ -116,13 +117,13 @@ public class CubotLidar extends CubotHardwareModule {
|
||||
break;
|
||||
|
||||
case LIDAR_GET_WORLD_SIZE:
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(cubot.getWorld().getWorldSize());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getWorld().getWorldSize());
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(unit.getWorld().getWorldSize());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(unit.getWorld().getWorldSize());
|
||||
break;
|
||||
|
||||
case LIDAR_GET_WORLD_POS:
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(cubot.getWorld().getX());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getWorld().getY());
|
||||
getCpu().getRegisterSet().getRegister("X").setValue(unit.getWorld().getX());
|
||||
getCpu().getRegisterSet().getRegister("Y").setValue(unit.getWorld().getY());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -50,13 +50,6 @@ public class UserCreationListener implements GameEventListener {
|
||||
cubot.getWorld().addObject(cubot);
|
||||
cubot.getWorld().incUpdatable();
|
||||
|
||||
cubot.setEnergy(config.getInt("battery_max_energy"));
|
||||
cubot.setMaxEnergy(config.getInt("battery_max_energy"));
|
||||
|
||||
cubot.setHp(config.getInt("cubot_max_hp"));
|
||||
cubot.setMaxHp(config.getInt("cubot_max_hp"));
|
||||
cubot.setMaxShield(config.getInt("cubot_max_shield"));
|
||||
|
||||
cubot.setParent(user);
|
||||
user.setControlledUnit(cubot);
|
||||
|
||||
@@ -81,6 +74,10 @@ public class UserCreationListener implements GameEventListener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
cubot.setHp(config.getInt("cubot_max_hp"));
|
||||
cubot.setMaxHp(config.getInt("cubot_max_hp"));
|
||||
cubot.setMaxShield(config.getInt("cubot_max_shield"));
|
||||
|
||||
LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user