mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Merge pull request #110 from djsheehy/shield-hardware
Added Shield hardware
This commit is contained in:
commit
d1a3cf9307
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,3 +15,6 @@ Server/Server.iml
|
||||
target/*
|
||||
Server/Server.iml
|
||||
Server/src/main/java/META-INF/MANIFEST.MF
|
||||
.settings
|
||||
.project
|
||||
.classpath
|
@ -27,6 +27,8 @@ 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;
|
||||
@ -102,6 +104,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 +130,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 +152,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 +246,42 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
|
||||
return maxEnergy;
|
||||
}
|
||||
|
||||
// shield methods are modeled after energy methods
|
||||
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() {
|
||||
|
||||
|
@ -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 = 0x000E;
|
||||
|
||||
private static final int SHIELD_CHARGE = 1;
|
||||
private static final int SHIELD_QUERY = 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_QUERY) {
|
||||
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")));
|
||||
}
|
||||
}
|
@ -48,6 +48,10 @@ maxBiomassRespawnCount=6
|
||||
biomassEnergyValue=4000
|
||||
# Maximum energy of the battery hardware in kJ
|
||||
battery_max_energy=60000
|
||||
# Maximum shield power
|
||||
max_shield=100
|
||||
# Energy cost per unit to charge shield
|
||||
shield_energy_cost=50
|
||||
# Time for biomass respawn in ticks
|
||||
biomassRespawnTime=64
|
||||
# Respawn timer will start when biomass count is below this number
|
||||
|
Loading…
x
Reference in New Issue
Block a user