replace .getZone().is with .isInZone, no null check needed

This commit is contained in:
Hans Mackowiak
2019-10-14 18:46:43 +00:00
committed by Michael Kamensky
parent 6e2ac756c9
commit 773df25b53
12 changed files with 19 additions and 19 deletions

View File

@@ -1846,7 +1846,7 @@ public class AiController {
// Special case for Bow to My Command which simulates a complex tap cost via ChooseCard // Special case for Bow to My Command which simulates a complex tap cost via ChooseCard
// TODO: consider enhancing support for tapXType<Any/...> in UnlessCost to get rid of this hack // TODO: consider enhancing support for tapXType<Any/...> in UnlessCost to get rid of this hack
if ("BowToMyCommand".equals(sa.getParam("AILogic"))) { if ("BowToMyCommand".equals(sa.getParam("AILogic"))) {
if (!sa.getHostCard().getZone().is(ZoneType.Command)) { if (!sa.getHostCard().isInZone(ZoneType.Command)) {
// Make sure that other opponents do not tap for an already abandoned scheme // Make sure that other opponents do not tap for an already abandoned scheme
result.clear(); result.clear();
break; break;

View File

@@ -2403,7 +2403,7 @@ public class ComputerUtil {
} }
// if source is not on the battlefield anymore, choose +1/+1 // if source is not on the battlefield anymore, choose +1/+1
// ones // ones
if (!game.getCardState(source).getZone().is(ZoneType.Battlefield)) { if (!game.getCardState(source).isInZone(ZoneType.Battlefield)) {
return opponent ? "Feather" : "Quill"; return opponent ? "Feather" : "Quill";
} }
// if no hand cards, try to mill opponent // if no hand cards, try to mill opponent
@@ -2435,7 +2435,7 @@ public class ComputerUtil {
} }
// if source is not on the battlefield anymore // if source is not on the battlefield anymore
if (!game.getCardState(source).getZone().is(ZoneType.Battlefield)) { if (!game.getCardState(source).isInZone(ZoneType.Battlefield)) {
return opponent ? "Strength" : "Numbers"; return opponent ? "Strength" : "Numbers";
} }
@@ -2484,7 +2484,7 @@ public class ComputerUtil {
} }
// if source is not on the battlefield anymore // if source is not on the battlefield anymore
if (!game.getCardState(source).getZone().is(ZoneType.Battlefield)) { if (!game.getCardState(source).isInZone(ZoneType.Battlefield)) {
return opponent ? "Sprout" : "Harvest"; return opponent ? "Sprout" : "Harvest";
} }
// TODO add Lifegain to +1/+1 counters trigger // TODO add Lifegain to +1/+1 counters trigger

View File

@@ -1294,7 +1294,7 @@ public class ComputerUtilCard {
// cast it during Declare Blockers, thus ruining its attacker // cast it during Declare Blockers, thus ruining its attacker
if (holdCombatTricks && sa.getApi() == ApiType.Pump if (holdCombatTricks && sa.getApi() == ApiType.Pump
&& sa.hasParam("NumAtt") && sa.getHostCard() != null && sa.hasParam("NumAtt") && sa.getHostCard() != null
&& sa.getHostCard().getZone() != null && sa.getHostCard().getZone().is(ZoneType.Hand) && sa.getHostCard().isInZone(ZoneType.Hand)
&& c.getNetPower() > 0 // too obvious if attacking with a 0-power creature && c.getNetPower() > 0 // too obvious if attacking with a 0-power creature
&& sa.getHostCard().isInstant() // only do it for instant speed spells in hand && sa.getHostCard().isInstant() // only do it for instant speed spells in hand
&& ComputerUtilMana.hasEnoughManaSourcesToCast(sa, ai)) { && ComputerUtilMana.hasEnoughManaSourcesToCast(sa, ai)) {

View File

@@ -729,7 +729,7 @@ public class PlayerControllerAi extends PlayerController {
return true; return true;
} else { } else {
Card rem = (Card) source.getFirstRemembered(); Card rem = (Card) source.getFirstRemembered();
if (!rem.getZone().is(ZoneType.Battlefield)) { if (!rem.isInZone(ZoneType.Battlefield)) {
return true; return true;
} }
} }
@@ -737,7 +737,7 @@ public class PlayerControllerAi extends PlayerController {
case "BetterTgtThanRemembered": case "BetterTgtThanRemembered":
if (source.getRememberedCount() > 0) { if (source.getRememberedCount() > 0) {
Card rem = (Card) source.getFirstRemembered(); Card rem = (Card) source.getFirstRemembered();
if (!rem.getZone().is(ZoneType.Battlefield)) { if (!rem.isInZone(ZoneType.Battlefield)) {
return true; return true;
} }
for (Card c : source.getController().getCreaturesInPlay()) { for (Card c : source.getController().getCreaturesInPlay()) {

View File

@@ -76,7 +76,7 @@ public class DamageDealAi extends DamageAiBase {
// Set PayX here to maximum value. // Set PayX here to maximum value.
dmg = ComputerUtilMana.determineLeftoverMana(sa, ai); dmg = ComputerUtilMana.determineLeftoverMana(sa, ai);
source.setSVar("PayX", Integer.toString(dmg)); source.setSVar("PayX", Integer.toString(dmg));
} else if (sa.getSVar(damage).equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) { } else if (sa.getSVar(damage).equals("Count$CardsInYourHand") && source.isInZone(ZoneType.Hand)) {
dmg--; // the card will be spent casting the spell, so actual damage is 1 less dmg--; // the card will be spent casting the spell, so actual damage is 1 less
} }
} }
@@ -113,7 +113,7 @@ public class DamageDealAi extends DamageAiBase {
// Set PayX here to maximum value. It will be adjusted later depending on the target. // Set PayX here to maximum value. It will be adjusted later depending on the target.
source.setSVar("PayX", Integer.toString(dmg)); source.setSVar("PayX", Integer.toString(dmg));
} else if (sa.getSVar(damage).contains("InYourHand") && source.getZone().is(ZoneType.Hand)) { } else if (sa.getSVar(damage).contains("InYourHand") && source.isInZone(ZoneType.Hand)) {
dmg = CardFactoryUtil.xCount(source, sa.getSVar(damage)) - 1; // the card will be spent casting the spell, so actual damage is 1 less dmg = CardFactoryUtil.xCount(source, sa.getSVar(damage)) - 1; // the card will be spent casting the spell, so actual damage is 1 less
} else if (sa.getSVar(damage).equals("TargetedPlayer$CardsInHand")) { } else if (sa.getSVar(damage).equals("TargetedPlayer$CardsInHand")) {
// cards that deal damage by the number of cards in target player's hand, e.g. Sudden Impact // cards that deal damage by the number of cards in target player's hand, e.g. Sudden Impact

View File

@@ -409,7 +409,7 @@ public class DrawAi extends SpellAbilityAi {
if (computerHandSize + numCards > computerMaxHandSize && game.getPhaseHandler().isPlayerTurn(ai)) { if (computerHandSize + numCards > computerMaxHandSize && game.getPhaseHandler().isPlayerTurn(ai)) {
if (xPaid) { if (xPaid) {
numCards = computerMaxHandSize - computerHandSize; numCards = computerMaxHandSize - computerHandSize;
if (sa.getHostCard().getZone().is(ZoneType.Hand)) { if (sa.getHostCard().isInZone(ZoneType.Hand)) {
numCards++; // the card will be spent numCards++; // the card will be spent
} }
source.setSVar("PayX", Integer.toString(numCards)); source.setSVar("PayX", Integer.toString(numCards));

View File

@@ -309,7 +309,7 @@ public class PumpAi extends PumpAiBase {
} }
} else { } else {
defense = AbilityUtils.calculateAmount(sa.getHostCard(), numDefense, sa); defense = AbilityUtils.calculateAmount(sa.getHostCard(), numDefense, sa);
if (numDefense.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) { if (numDefense.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.isInZone(ZoneType.Hand)) {
defense--; // the card will be spent casting the spell, so actual toughness is 1 less defense--; // the card will be spent casting the spell, so actual toughness is 1 less
} }
} }
@@ -328,7 +328,7 @@ public class PumpAi extends PumpAiBase {
} }
} else { } else {
attack = AbilityUtils.calculateAmount(sa.getHostCard(), numAttack, sa); attack = AbilityUtils.calculateAmount(sa.getHostCard(), numAttack, sa);
if (numAttack.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.getZone().is(ZoneType.Hand)) { if (numAttack.contains("X") && sa.getSVar("X").equals("Count$CardsInYourHand") && source.isInZone(ZoneType.Hand)) {
attack--; // the card will be spent casting the spell, so actual power is 1 less attack--; // the card will be spent casting the spell, so actual power is 1 less
} }
} }

View File

@@ -148,7 +148,7 @@ public class SetStateAi extends SpellAbilityAi {
if (card.isFaceDown()) { if (card.isFaceDown()) {
// hidden agenda // hidden agenda
if (card.getState(CardStateName.Original).hasIntrinsicKeyword("Hidden agenda") if (card.getState(CardStateName.Original).hasIntrinsicKeyword("Hidden agenda")
&& card.getZone().is(ZoneType.Command)) { && card.isInZone(ZoneType.Command)) {
String chosenName = card.getNamedCard(); String chosenName = card.getNamedCard();
for (Card cast : ai.getGame().getStack().getSpellsCastThisTurn()) { for (Card cast : ai.getGame().getStack().getSpellsCastThisTurn()) {
if (cast.getController() == ai && cast.getName().equals(chosenName)) { if (cast.getController() == ai && cast.getName().equals(chosenName)) {

View File

@@ -251,7 +251,7 @@ public class GameAction {
} }
if(noLandLKI.isLand()) { if(noLandLKI.isLand()) {
// if it isn't on the Stack, it stays in that Zone // if it isn't on the Stack, it stays in that Zone
if (!c.getZone().is(ZoneType.Stack)) { if (!c.isInZone(ZoneType.Stack)) {
return c; return c;
} }
// if something would only be a land when entering the battlefield and not before // if something would only be a land when entering the battlefield and not before

View File

@@ -300,12 +300,12 @@ public final class GameActionUtil {
costs.add(new OptionalCostValue(type, cost)); costs.add(new OptionalCostValue(type, cost));
} }
} else if (keyword.equals("Retrace")) { } else if (keyword.equals("Retrace")) {
if (source.getZone().is(ZoneType.Graveyard)) { if (source.isInZone(ZoneType.Graveyard)) {
final Cost cost = new Cost("Discard<1/Land>", false); final Cost cost = new Cost("Discard<1/Land>", false);
costs.add(new OptionalCostValue(OptionalCost.Retrace, cost)); costs.add(new OptionalCostValue(OptionalCost.Retrace, cost));
} }
} else if (keyword.equals("Jump-start")) { } else if (keyword.equals("Jump-start")) {
if (source.getZone().is(ZoneType.Graveyard)) { if (source.isInZone(ZoneType.Graveyard)) {
final Cost cost = new Cost("Discard<1/Card>", false); final Cost cost = new Cost("Discard<1/Card>", false);
costs.add(new OptionalCostValue(OptionalCost.Jumpstart, cost)); costs.add(new OptionalCostValue(OptionalCost.Jumpstart, cost));
} }

View File

@@ -110,7 +110,7 @@ public class CloneEffect extends SpellAbilityEffect {
} }
if (sa.hasParam("CloneZone")) { if (sa.hasParam("CloneZone")) {
if (!tgtCard.getZone().is(ZoneType.smartValueOf(sa.getParam("CloneZone")))) { if (!tgtCard.isInZone(ZoneType.smartValueOf(sa.getParam("CloneZone")))) {
return; return;
} }
} }
@@ -134,7 +134,7 @@ public class CloneEffect extends SpellAbilityEffect {
tgtCard.clearImprintedCards(); tgtCard.clearImprintedCards();
// check if clone is now an Aura that needs to be attached // check if clone is now an Aura that needs to be attached
if (tgtCard.isAura() && !tgtCard.getZone().is(ZoneType.Battlefield)) { if (tgtCard.isAura() && !tgtCard.isInZone(ZoneType.Battlefield)) {
AttachEffect.attachAuraOnIndirectEnterBattlefield(tgtCard); AttachEffect.attachAuraOnIndirectEnterBattlefield(tgtCard);
} }

View File

@@ -1850,7 +1850,7 @@ public class GameSimulatorTest extends SimulationTestCase {
Card simSpark = (Card)sim.getGameCopier().find(sparkDouble); Card simSpark = (Card)sim.getGameCopier().find(sparkDouble);
assertNotNull(simSpark); assertNotNull(simSpark);
assertTrue(simSpark.getZone().is(ZoneType.Battlefield)); assertTrue(simSpark.isInZone(ZoneType.Battlefield));
assertEquals(1, simSpark.getCounters(CounterType.P1P1)); assertEquals(1, simSpark.getCounters(CounterType.P1P1));
assertEquals(5, simSpark.getCounters(CounterType.LOYALTY)); assertEquals(5, simSpark.getCounters(CounterType.LOYALTY));
} }