- Prevent NPE in getDefenderByAttacker.

This commit is contained in:
Sloth
2013-06-16 21:00:56 +00:00
parent f6f80da995
commit 56df11005b
2 changed files with 6 additions and 2 deletions

View File

@@ -6654,10 +6654,11 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
public final boolean isAttacking(GameEntity ge) {
Combat combat = getGame().getCombat();
if (!combat.isAttacking(this)) {
GameEntity defender = combat.getDefenderByAttacker(this);
if (!combat.isAttacking(this) || defender == null) {
return false;
}
return combat.getDefenderByAttacker(this).equals(ge);
return defender.equals(ge);
}
/**

View File

@@ -272,6 +272,9 @@ public class Combat {
* @return a {@link java.lang.Object} object.
*/
public final GameEntity getDefenderByAttacker(final Card c) {
if (!this.attackerToBandMap.containsKey(c)) {
return null;
}
return this.attackerToBandMap.get(c).getDefender();
}