Added CubotRepair.java - Hardware that repairs the cubot and reports HP

This commit is contained in:
Dylan Sheehy 2018-01-01 15:35:35 -06:00
parent 068df67569
commit eef0ddf99b
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,64 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Register;
import org.json.simple.JSONObject;
public class CubotRepair extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
public static final int HWID = 0x000C;
/**
* If cubot has iron, increase HP, spend energy and iron.
*/
public static final int REPAIR_FIX = 1;
/**
* Set b to amount of HP.
*/
public static final int REPAIR_GET_HP = 2;
private Cubot cubot;
public CubotRepair(Cubot cubot) {
this.cubot = cubot;
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
Register b = getCpu().getRegisterSet().getRegister("B");
if(a == REPAIR_FIX) {
int repairCost = GameServer.INSTANCE.getConfig().getInt("repairEnergyCost");
int repairAmount = GameServer.INSTANCE.getConfig().getInt("repairHealing");
if(cubot.getHeldItem() == 0x0003) { // cubot is holding iron
if(cubot.spendEnergy(repairCost)) {
cubot.heal(repairAmount);
}
}
}
else if(a == REPAIR_GET_HP) {
b.setValue(cubot.getHp());
}
}
@Override
public char getId() {
return HWID;
}
}

View File

@ -58,6 +58,10 @@ npc_lifetime=1024
npc_max_factory_distance=3
# Maximum NPC per Factory
factory_max_npc_count=16
# Energy cost to use repair hardware
repairEnergyCost=100
# Amount of HP to heal when repairing
repairHealing=10
# ----------------------------------------------
# Minimum center point count for the WorldGenerator
wg_centerPointCountMin=5