use of spacesettlers.objects.weapons.EMP in project spacesettlers by amymcgovern.
the class CollisionHandler method EMPCollision.
/**
* Collide with a EMP
* @param object1
* @param object2
*/
private void EMPCollision(EMP emp, AbstractObject object2) {
// get the ship that fired
Ship firingShip = emp.getFiringShip();
firingShip.decrementWeaponCount();
if (object2.getClass() == Ship.class) {
Ship ship = (Ship) object2;
// only take a hit if not shielded
if (!ship.isShielded()) {
ship.updateEnergy(emp.getDamage());
ship.incrementDamageReceived(emp.getDamage());
ship.setFreezeCount(emp.getFreezeCount());
// it hit a ship
firingShip.incrementHitsInflicted();
}
}
if (object2.getClass() == Base.class) {
Base base = (Base) object2;
// only take a hit if not shielded
if (!base.isShielded()) {
base.updateEnergy(emp.getDamage());
base.incrementDamageReceived(emp.getDamage());
base.setFreezeCount(emp.getFreezeCount());
// it hit a base
firingShip.incrementHitsInflicted();
}
}
// Handle a emp hitting a emp (no damageInflicted but both weapons die)
if (object2.getClass() == EMP.class) {
object2.setAlive(false);
Ship otherFiringShip = ((EMP) object2).getFiringShip();
otherFiringShip.decrementWeaponCount();
}
// Did the EMP hit an AiCore? If so, destroy the AiCore.
if (object2.getClass() == AiCore.class) {
AiCore core = (AiCore) object2;
// Kill the core!
core.setAlive(false);
}
emp.setAlive(false);
}