first blocker is assigned all damage initially

This commit is contained in:
Maxmtg
2013-02-12 02:35:25 +00:00
parent 795b394a53
commit 7f453661c3

View File

@@ -320,18 +320,19 @@ public class VAssignDamage {
// will assign all damage to defenders and rest to player, if present // will assign all damage to defenders and rest to player, if present
private void initialAssignDamage(boolean onlyFirstBlocker) { private void initialAssignDamage(boolean onlyFirstBlocker) {
int dmgLeft = totalDamageToAssign; int dmgLeft = totalDamageToAssign;
for(DamageTarget dt : defenders) { DamageTarget dtLast = null;
for(DamageTarget dt : defenders) { // MUST NOT RUN WITH EMPTY collection
int lethal = getDamageToKill(dt.card); int lethal = getDamageToKill(dt.card);
int damage = Math.min(lethal, dmgLeft); int damage = Math.min(lethal, dmgLeft);
addDamage(dt.card, damage); addDamage(dt.card, damage);
dmgLeft -= damage; dmgLeft -= damage;
dtLast = dt;
if ( dmgLeft <= 0 || onlyFirstBlocker ) break; if ( dmgLeft <= 0 || onlyFirstBlocker ) break;
} }
if ( dmgLeft < 0 ) if ( dmgLeft < 0 )
throw new RuntimeException("initialAssignDamage managed to assign more damage than it could"); throw new RuntimeException("initialAssignDamage managed to assign more damage than it could");
if ( dmgLeft > 0 && !onlyFirstBlocker) { // flush the remaining damage into last defender if ( dmgLeft > 0) { // flush the remaining damage into last defender
DamageTarget dt = defenders.get(defenders.size()-1); addDamage(dtLast.card, dmgLeft );
addDamage(dt.card, dmgLeft );
} }
updateLabels(); updateLabels();
} }