final TeleMissileAttackAction taa = (TeleMissileAttackAction) pr.aaa;
final Entity ae = game.getEntity(taa.getEntityId());
if (!(ae instanceof TeleMissile)) {
return;
}
TeleMissile tm = (TeleMissile) ae;
final Targetable target = game.getTarget(taa.getTargetType(), taa.getTargetId());
final ToHitData toHit = pr.toHit;
int roll = pr.roll;
Entity te = null;
if ((target != null) && (target.getTargetType() == Targetable.TYPE_ENTITY)) {
te = (Entity) target;
}
boolean throughFront = true;
if (te != null) {
throughFront = Compute.isThroughFrontHex(game, ae.getPosition(), te);
}
Report r;
if (lastEntityId != taa.getEntityId()) {
// who is making the attack
r = new Report(4005);
r.subject = ae.getId();
r.addDesc(ae);
addReport(r);
}
// should we even bother?
if ((target == null) || ((target.getTargetType() == Targetable.TYPE_ENTITY) && (te.isDestroyed() || te.isDoomed() || te.crew.isDead()))) {
r = new Report(4190);
r.subject = ae.getId();
r.indent();
addReport(r);
return;
}
r = new Report(9031);
r.subject = ae.getId();
r.indent();
r.add(target.getDisplayName());
r.newlines = 0;
addReport(r);
// add some stuff to the to hit value
// need to add damage done modifier
if (ae.damageThisRound > 10) {
toHit.addModifier((int) (Math.floor(ae.damageThisRound / 10.0)), "damage taken");
}
// add modifiers for the originating unit missing CIC, FCS, or sensors
Entity ride = game.getEntity(tm.getOriginalRideId());
if ((null != ride) && (ride instanceof Aero)) {
Aero aride = (Aero) ride;
int cic = aride.getCICHits();
if (cic > 0) {
toHit.addModifier(cic * 2, "CIC damage");
}
// sensor hits
int sensors = aride.getSensorHits();
if ((sensors > 0) && (sensors < 3)) {
toHit.addModifier(sensors, "sensor damage");
}
if (sensors > 2) {
toHit.addModifier(+5, "sensors destroyed");
}
// FCS hits
int fcs = aride.getFCSHits();
if (fcs > 0) {
toHit.addModifier(fcs * 2, "fcs damage");
}
}
if (toHit.getValue() == TargetRoll.AUTOMATIC_SUCCESS) {
roll = Integer.MAX_VALUE;
r = new Report(4225);
r.subject = ae.getId();
r.add(toHit.getDesc());
addReport(r);
} else {
// report the roll
r = new Report(9032);
r.subject = ae.getId();
r.add(toHit.getValue());
r.add(toHit.getDesc());
r.add(roll);
r.newlines = 0;
addReport(r);
}
// do we hit?
if (roll < toHit.getValue()) {
// miss
r = new Report(4035);
r.subject = ae.getId();
addReport(r);
} else {
// Resolve the damage.
HitData hit = te.rollHitLocation(ToHitData.HIT_NORMAL, te.sideTable(ae.getPosition(), true));
hit.setCapital(true);
hit.setCapMisCritMod(tm.getCritMod());
addReport(damageEntity(te, hit, TeleMissileAttackAction.getDamageFor(ae), false, DamageType.NONE, false, false, throughFront));
destroyEntity(ae, "successful attack");
}
}