mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 22:59:02 +00:00
Merge branch 'master' into vaults
# Conflicts: # Server/src/main/java/net/simon987/server/game/GameObject.java # Server/src/main/java/net/simon987/server/game/World.java # Server/src/main/java/net/simon987/server/webserver/TerrainRequestHandler.java
This commit is contained in:
@@ -10,13 +10,11 @@ import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Cubot extends GameObject implements Updatable, ControllableUnit, Programmable {
|
||||
public class Cubot extends GameObject implements Updatable, ControllableUnit, Programmable, Attackable {
|
||||
|
||||
private static final char MAP_INFO = 0x0080;
|
||||
public static final int ID = 1;
|
||||
|
||||
public static int TYPE_ID = 2;
|
||||
|
||||
private int hologram = 0;
|
||||
private String hologramString = "";
|
||||
private HologramMode hologramMode = HologramMode.CLEARED;
|
||||
@@ -27,11 +25,16 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
* Hit points
|
||||
*/
|
||||
private int hp;
|
||||
private int shield;
|
||||
private int maxShield;
|
||||
private int heldItem;
|
||||
|
||||
private Action currentAction = Action.IDLE;
|
||||
private Action lastAction = Action.IDLE;
|
||||
|
||||
private char currentStatus;
|
||||
private char lastStatus;
|
||||
|
||||
private ArrayList<Integer> keyboardBuffer = new ArrayList<>();
|
||||
|
||||
private ArrayList<char[]> consoleMessagesBuffer = new ArrayList<>(CONSOLE_BUFFER_MAX_SIZE);
|
||||
@@ -90,6 +93,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
|
||||
lastConsoleMessagesBuffer = new ArrayList<>(consoleMessagesBuffer);
|
||||
consoleMessagesBuffer.clear();
|
||||
|
||||
//And the status..
|
||||
lastStatus = currentStatus;
|
||||
currentStatus = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,6 +109,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
json.put("direction", getDirection().ordinal());
|
||||
json.put("heldItem", heldItem);
|
||||
json.put("hp", hp);
|
||||
json.put("shield", shield);
|
||||
json.put("action", lastAction.ordinal());
|
||||
json.put("holo", hologram);
|
||||
json.put("holoStr", hologramString);
|
||||
@@ -127,6 +135,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
dbObject.put("direction", getDirection().ordinal());
|
||||
dbObject.put("heldItem", heldItem);
|
||||
dbObject.put("hp", hp);
|
||||
dbObject.put("shield", shield);
|
||||
dbObject.put("action", lastAction.ordinal());
|
||||
dbObject.put("holo", hologram);
|
||||
dbObject.put("holoStr", hologramString);
|
||||
@@ -148,6 +157,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
cubot.setX((int) obj.get("x"));
|
||||
cubot.setY((int) obj.get("y"));
|
||||
cubot.hp = (int) obj.get("hp");
|
||||
// cubot.shield = (int) obj.get("shield");
|
||||
// cubot.maxShield = GameServer.INSTANCE.getConfig().getInt("max_shield");
|
||||
cubot.setDirection(Direction.getDirection((int) obj.get("direction")));
|
||||
cubot.heldItem = (int) obj.get("heldItem");
|
||||
cubot.energy = (int) obj.get("energy");
|
||||
@@ -240,6 +251,41 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
public int getShield() {
|
||||
return shield;
|
||||
}
|
||||
|
||||
public void setShield(int shield) {
|
||||
this.shield = shield;
|
||||
}
|
||||
|
||||
public boolean chargeShield(int qty) {
|
||||
qty = Math.min(qty, maxShield - shield);
|
||||
int cost = GameServer.INSTANCE.getConfig().getInt("shield_energy_cost");
|
||||
int energySpent = qty * cost;
|
||||
if(spendEnergy(energySpent)) {
|
||||
shield += qty;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages shield by qty.
|
||||
*
|
||||
* Return damage that broke through the shield.
|
||||
*/
|
||||
public int damageShield(int qty) {
|
||||
int after = shield - qty;
|
||||
if(after < 0) {
|
||||
shield = 0;
|
||||
return -after;
|
||||
}
|
||||
shield = after;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Memory getFloppyData() {
|
||||
|
||||
@@ -305,4 +351,58 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
public void setHologramColor(int hologramColor) {
|
||||
this.hologramColor = hologramColor;
|
||||
}
|
||||
|
||||
public void addStatus(CubotStatus status) {
|
||||
|
||||
currentStatus |= status.val;
|
||||
}
|
||||
|
||||
public void removeStatus(CubotStatus status) {
|
||||
|
||||
currentStatus &= (~status.val);
|
||||
}
|
||||
|
||||
public char getStatus() {
|
||||
return lastStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealRate(int hp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHp() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHp(int hp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHp() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxHp(int hp) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDeadCallback() {
|
||||
return true; //always cancelled
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
|
||||
public class CubotCore extends CpuHardware {
|
||||
|
||||
public static final int DEFAULT_ADDRESS = 0x000E;
|
||||
|
||||
/**
|
||||
* Hardware ID (Should be unique)
|
||||
*/
|
||||
public static final char HWID = 0x000E;
|
||||
|
||||
private static final int CORE_STATUS_POLL = 1;
|
||||
private static final int CORE_HULL_POLL = 2;
|
||||
|
||||
private Cubot cubot;
|
||||
|
||||
public CubotCore(Cubot cubot) {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
|
||||
if (a == CORE_STATUS_POLL) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getStatus());
|
||||
} else if (a == CORE_HULL_POLL) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getHp());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getId() {
|
||||
return HWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDBObject mongoSerialise() {
|
||||
|
||||
BasicDBObject dbObject = new BasicDBObject();
|
||||
|
||||
dbObject.put("hwid", (int) HWID);
|
||||
dbObject.put("cubot", cubot.getObjectId());
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
|
||||
public static CubotCore deserialize(DBObject obj) {
|
||||
return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
|
||||
return CubotFloppyDrive.deserialize(obj);
|
||||
case CubotComPort.HWID:
|
||||
return CubotComPort.deserialize(obj);
|
||||
case CubotShield.HWID:
|
||||
return CubotShield.deserialize(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
|
||||
public class CubotShield extends CpuHardware {
|
||||
static final char HWID = 0x000F;
|
||||
|
||||
private static final int SHIELD_CHARGE = 1;
|
||||
private static final int SHIELD_POLL = 2;
|
||||
private Cubot cubot;
|
||||
|
||||
public CubotShield(Cubot cubot) {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getId() {
|
||||
return HWID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasicDBObject mongoSerialise() {
|
||||
BasicDBObject dbObject = new BasicDBObject();
|
||||
|
||||
dbObject.put("hwid", HWID);
|
||||
dbObject.put("cubot", cubot.getObjectId());
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
int a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||
// b = amount to charge
|
||||
if(a == SHIELD_CHARGE) {
|
||||
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||
cubot.chargeShield(b);
|
||||
} else if (a == SHIELD_POLL) {
|
||||
int shield = cubot.getShield();
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(shield);
|
||||
}
|
||||
}
|
||||
|
||||
public static CubotShield deserialize(DBObject obj) {
|
||||
return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
/**
|
||||
* Status of a Cubot (Special buff or debuff)
|
||||
*/
|
||||
public enum CubotStatus {
|
||||
|
||||
DEFAULT(0),
|
||||
RADIATED(1),
|
||||
DAMAGED(2);
|
||||
|
||||
public char val;
|
||||
|
||||
CubotStatus(int val) {
|
||||
this.val = (char) val;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user