- Fixed more possible NPE's caused by combat == null.

This commit is contained in:
Sloth
2013-06-26 14:19:33 +00:00
parent f280ba4e05
commit 07590fba08
5 changed files with 20 additions and 18 deletions

View File

@@ -6489,7 +6489,8 @@ public class Card extends GameEntity implements Comparable<Card> {
} else if (property.startsWith("notattacking")) { } else if (property.startsWith("notattacking")) {
return null == combat || !combat.isAttacking(this); return null == combat || !combat.isAttacking(this);
} else if (property.equals("attackedBySourceThisCombat")) { } else if (property.equals("attackedBySourceThisCombat")) {
final GameEntity defender = game.getCombat().getDefenderByAttacker(source); if ( null == combat ) return false;
final GameEntity defender = combat.getDefenderByAttacker(source);
if (defender instanceof Card) { if (defender instanceof Card) {
if (!this.equals((Card) defender)) { if (!this.equals((Card) defender)) {
return false; return false;
@@ -6554,7 +6555,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
} }
} else if (property.startsWith("unblocked")) { } else if (property.startsWith("unblocked")) {
if (!game.getCombat().isUnblocked(this)) { if (game.getCombat() == null || !game.getCombat().isUnblocked(this)) {
return false; return false;
} }
} else if (property.equals("attackersBandedWith")) { } else if (property.equals("attackersBandedWith")) {

View File

@@ -188,7 +188,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return true; return true;
} }
Predicate<Card> flyingOrReach = Predicates.or(CardPredicates.hasKeyword("Flying"), CardPredicates.hasKeyword("Reach")); Predicate<Card> flyingOrReach = Predicates.or(CardPredicates.hasKeyword("Flying"), CardPredicates.hasKeyword("Reach"));
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| !Iterables.any(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)), || !Iterables.any(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)),
@@ -203,7 +203,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
&& ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) { && ComputerUtilCombat.lifeInDanger(ai, game.getCombat())) {
return true; return true;
} }
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| CardLists.getNotKeyword(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)), || CardLists.getNotKeyword(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)),
@@ -241,33 +241,33 @@ public abstract class PumpAiBase extends SpellAbilityAi {
} }
return false; return false;
} else if (combatRelevant) { } else if (combatRelevant) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)
|| (opp.getCreaturesInPlay().size() < 1) || (opp.getCreaturesInPlay().size() < 1)
|| CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)).isEmpty()) { || CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)).isEmpty()) {
return false; return false;
} }
} else if (keyword.equals("Double Strike")) { } else if (keyword.equals("Double Strike")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) { || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
return false; return false;
} }
} else if (keyword.startsWith("Rampage")) { } else if (keyword.startsWith("Rampage")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)).size() < 2) { || CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)).size() < 2) {
return false; return false;
} }
} else if (keyword.startsWith("Flanking")) { } else if (keyword.startsWith("Flanking")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| CardLists.getNotKeyword(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)), || CardLists.getNotKeyword(CardLists.filter(opp.getCreaturesInPlay(), CardPredicates.possibleBlockers(card)),
"Flanking").isEmpty()) { "Flanking").isEmpty()) {
return false; return false;
} }
} else if (keyword.startsWith("Trample")) { } else if (keyword.startsWith("Trample")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| !CombatUtil.canBeBlocked(card, opp) || !CombatUtil.canBeBlocked(card, opp)
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() + attack <= 1 || card.getNetCombatDamage() + attack <= 1
@@ -282,7 +282,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return true; return true;
} }
if ((ph.isPlayerTurn(opp)) if ((ph.isPlayerTurn(opp))
|| !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) { || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
return false; return false;
} }
@@ -290,7 +290,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
if (card.getNetCombatDamage() <= 0) { if (card.getNetCombatDamage() <= 0) {
return false; return false;
} }
return combat != null && ( combat.isBlocking(card) || combat.isAttacking(card) && combat.isBlocked(card) ); return combat != null && ( combat.isBlocking(card) || (combat.isAttacking(card) && combat.isBlocked(card)) );
} else if (keyword.equals("Lifelink")) { } else if (keyword.equals("Lifelink")) {
if (card.getNetCombatDamage() <= 0) { if (card.getNetCombatDamage() <= 0) {
return false; return false;
@@ -333,7 +333,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return false; return false;
} }
} else if (keyword.equals("Islandwalk")) { } else if (keyword.equals("Islandwalk")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| CardLists.getType(opp.getLandsInPlay(), "Island").isEmpty() || CardLists.getType(opp.getLandsInPlay(), "Island").isEmpty()
@@ -341,7 +341,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return false; return false;
} }
} else if (keyword.equals("Swampwalk")) { } else if (keyword.equals("Swampwalk")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| CardLists.getType(opp.getLandsInPlay(), "Swamp").isEmpty() || CardLists.getType(opp.getLandsInPlay(), "Swamp").isEmpty()
@@ -349,7 +349,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return false; return false;
} }
} else if (keyword.equals("Mountainwalk")) { } else if (keyword.equals("Mountainwalk")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| CardLists.getType(opp.getLandsInPlay(), "Mountain").isEmpty() || CardLists.getType(opp.getLandsInPlay(), "Mountain").isEmpty()
@@ -357,7 +357,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return false; return false;
} }
} else if (keyword.equals("Forestwalk")) { } else if (keyword.equals("Forestwalk")) {
if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || combat != null && combat.isAttacking(card)) if (ph.isPlayerTurn(opp) || !(CombatUtil.canAttack(card, opp) || (combat != null && combat.isAttacking(card)))
|| ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| card.getNetCombatDamage() <= 0 || card.getNetCombatDamage() <= 0
|| CardLists.getType(opp.getLandsInPlay(), "Forest").isEmpty() || CardLists.getType(opp.getLandsInPlay(), "Forest").isEmpty()

View File

@@ -1228,7 +1228,8 @@ public class GameAction {
c.setDamage(0); c.setDamage(0);
c.tap(); c.tap();
c.addRegeneratedThisTurn(); c.addRegeneratedThisTurn();
game.getCombat().removeFromCombat(c); if (game.getCombat() != null)
game.getCombat().removeFromCombat(c);
// Play the Regen sound // Play the Regen sound
game.fireEvent(new GameEventCardRegenerated()); game.fireEvent(new GameEventCardRegenerated());

View File

@@ -300,7 +300,7 @@ public class ComputerUtilCombat {
*/ */
public static boolean lifeInDanger(final Player ai, final Combat combat) { public static boolean lifeInDanger(final Player ai, final Combat combat) {
// life in danger only cares about the player's life. Not Planeswalkers' life // life in danger only cares about the player's life. Not Planeswalkers' life
if (ai.cantLose() || combat.getAttackingPlayer() == ai) { if (ai.cantLose() || combat == null || combat.getAttackingPlayer() == ai) {
return false; return false;
} }

View File

@@ -2328,7 +2328,7 @@ public class Player extends GameEntity implements Comparable<Player> {
return false; return false;
} }
} else if (property.equals("attackedBySourceThisCombat")) { } else if (property.equals("attackedBySourceThisCombat")) {
if (!this.equals(game.getCombat().getDefenderPlayerByAttacker(source))) { if (game.getCombat() == null || !this.equals(game.getCombat().getDefenderPlayerByAttacker(source))) {
return false; return false;
} }
} else if (property.startsWith("wasDealtDamageThisTurn")) { } else if (property.startsWith("wasDealtDamageThisTurn")) {