Implemented shield hardware. Added heal, damage and charge shield debug commands.

This commit is contained in:
simon
2018-03-10 13:54:43 -05:00
parent e4269b83c4
commit 2565d3338c
9 changed files with 159 additions and 13 deletions

View File

@@ -265,12 +265,12 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
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;
public boolean chargeShield(int amount) {
amount = Math.min(amount, maxShield - shield);
int energySpent = amount * CubotShield.COST;
if(spendEnergy(energySpent)) {
shield += qty;
shield += amount;
return true;
} else {
return false;
@@ -278,12 +278,12 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
}
/**
* Damages shield by qty.
* Damages shield by amount.
*
* Return damage that broke through the shield.
*/
public int damageShield(int qty) {
int after = shield - qty;
public int damageShield(int amount) {
int after = shield - amount;
if(after < 0) {
shield = 0;
return -after;
@@ -409,7 +409,11 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
@Override
public void damage(int amount) {
hp -= amount;
//Damage shield first
int hullDamage = damageShield(amount);
hp -= hullDamage;
if (hp <= 0) {
setDead(true);

View File

@@ -1,6 +1,7 @@
package net.simon987.cubotplugin;
import com.mongodb.DBObject;
import net.simon987.cubotplugin.event.ChargeShieldCommandListener;
import net.simon987.cubotplugin.event.CpuInitialisationListener;
import net.simon987.cubotplugin.event.UserCreationListener;
import net.simon987.server.ServerConfiguration;
@@ -18,6 +19,7 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
public void init(ServerConfiguration config) {
listeners.add(new CpuInitialisationListener());
listeners.add(new UserCreationListener());
listeners.add(new ChargeShieldCommandListener());
LogManager.LOGGER.info("Initialised Cubot plugin");
}

View File

@@ -16,6 +16,8 @@ public class CubotShield extends CpuHardware {
private static final int SHIELD_POLL = 2;
private Cubot cubot;
public static final int COST = GameServer.INSTANCE.getConfig().getInt("shield_energy_cost");
public CubotShield(Cubot cubot) {
this.cubot = cubot;
}

View File

@@ -0,0 +1,45 @@
package net.simon987.cubotplugin.event;
import net.simon987.cubotplugin.Cubot;
import net.simon987.server.GameServer;
import net.simon987.server.event.DebugCommandEvent;
import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener;
import net.simon987.server.game.GameObject;
public class ChargeShieldCommandListener implements GameEventListener {
@Override
public Class getListenedEventType() {
return DebugCommandEvent.class;
}
@Override
public void handle(GameEvent event) {
DebugCommandEvent e = (DebugCommandEvent) event;
if (e.getName().equals("chargeShield")) {
GameObject cubot = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
if (cubot != null) {
if (cubot instanceof Cubot) {
String hp = ((Cubot) cubot).getHp() + "/" + ((Cubot) cubot).getMaxHp();
int oldShield = ((Cubot) cubot).getShield();
((Cubot) cubot).chargeShield(e.getInt("amount"));
e.reply("Success: " + hp + " (" + oldShield + ") -> " + hp + "(" + ((Cubot) cubot).getShield() +
")");
} else {
e.reply("Object is not a Cubot");
}
} else {
e.reply("Object not found: " + e.getLong("objectId"));
}
}
}
}