diff --git a/Mage/src/mage/abilities/effects/common/DevourEffect.java b/Mage/src/mage/abilities/effects/common/DevourEffect.java index bbe8238f4d..d4aac57628 100644 --- a/Mage/src/mage/abilities/effects/common/DevourEffect.java +++ b/Mage/src/mage/abilities/effects/common/DevourEffect.java @@ -131,8 +131,10 @@ public class DevourEffect extends ReplacementEffectImpl { int devouredCreatures = target.getTargets().size(); game.informPlayers(new StringBuilder(creature.getName()).append(" devours ").append(devouredCreatures).append(" creatures").toString()); for (UUID targetId: target.getTargets()) { - Permanent targetCreature = game.getPermanent(targetId); - cardSubtypes.add((ArrayList) targetCreature.getSubtype()); + Permanent targetCreature = game.getPermanent(targetId); + if (targetCreature != null) { + cardSubtypes.add((ArrayList) targetCreature.getSubtype()); + } if (targetCreature == null || !targetCreature.sacrifice(source.getSourceId(), game)) { return false; } diff --git a/Mage/src/mage/abilities/effects/common/RegenerateAttachedEffect.java b/Mage/src/mage/abilities/effects/common/RegenerateAttachedEffect.java index dd9d142ed9..d5fc24fb56 100644 --- a/Mage/src/mage/abilities/effects/common/RegenerateAttachedEffect.java +++ b/Mage/src/mage/abilities/effects/common/RegenerateAttachedEffect.java @@ -62,8 +62,11 @@ public class RegenerateAttachedEffect extends ReplacementEffectImpl 0) { - if (perm.tap(game)) { - Choice chooseManaType = buildChoice(manaCostsCreature, ability.getManaCostsToPay()); - if (chooseManaType.getChoices().size() > 0) { - if (chooseManaType.getChoices().size() > 1) { - chooseManaType.getChoices().add("Colorless"); - chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName()); - while (!chooseManaType.isChosen()) { - player.choose(Outcome.Benefit, chooseManaType, game); - } - } else { - chooseManaType.setChoice(chooseManaType.getChoices().iterator().next()); - } + if (perm == null) { + continue; + } - ManaCosts manaCostsToReduce = new ManaCostsImpl(); - if (chooseManaType.getChoice().equals("Black")) { - manaCostsToReduce.load("{B}"); - } - if (chooseManaType.getChoice().equals("Blue")) { - manaCostsToReduce.load("{U}"); - } - if (chooseManaType.getChoice().equals("Green")) { - manaCostsToReduce.load("{G}"); - } - if (chooseManaType.getChoice().equals("White")) { - manaCostsToReduce.load("{W}"); - } - if (chooseManaType.getChoice().equals("Red")) { - manaCostsToReduce.load("{R}"); - } - if (chooseManaType.getChoice().equals("Colorless")) { - ++adjCost; - } - CardUtil.adjustCost((SpellAbility)ability, manaCostsToReduce); - } else { - ++adjCost; + Card card = game.getCard(perm.getId()); + if (card == null) { + continue; + } + + ManaCosts manaCostsCreature = card.getSpellAbility().getManaCosts(); + if (manaCostsCreature != null && manaCostsCreature.convertedManaCost() > 0 && perm.tap(game)) { + Choice chooseManaType = buildChoice(manaCostsCreature, ability.getManaCostsToPay()); + if (chooseManaType.getChoices().size() > 0) { + if (chooseManaType.getChoices().size() > 1) { + chooseManaType.getChoices().add("Colorless"); + chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName()); + while (!chooseManaType.isChosen()) { + player.choose(Outcome.Benefit, chooseManaType, game); } + } else { + chooseManaType.setChoice(chooseManaType.getChoices().iterator().next()); } + + ManaCosts manaCostsToReduce = new ManaCostsImpl(); + if (chooseManaType.getChoice().equals("Black")) { + manaCostsToReduce.load("{B}"); + } + if (chooseManaType.getChoice().equals("Blue")) { + manaCostsToReduce.load("{U}"); + } + if (chooseManaType.getChoice().equals("Green")) { + manaCostsToReduce.load("{G}"); + } + if (chooseManaType.getChoice().equals("White")) { + manaCostsToReduce.load("{W}"); + } + if (chooseManaType.getChoice().equals("Red")) { + manaCostsToReduce.load("{R}"); + } + if (chooseManaType.getChoice().equals("Colorless")) { + ++adjCost; + } + CardUtil.adjustCost((SpellAbility)ability, manaCostsToReduce); + } else { + ++adjCost; } } } @@ -200,4 +202,3 @@ public class ConvokeAbility extends SimpleStaticAbility implements AdjustingSour return "Convoke (Each creature you tap while casting this spell reduces its cost by {1} or by one mana of that creature's color.)"; } } - diff --git a/Mage/src/mage/target/common/TargetCreatureOrPlayer.java b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java index bcb516c297..e1417a15f0 100644 --- a/Mage/src/mage/target/common/TargetCreatureOrPlayer.java +++ b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java @@ -89,8 +89,9 @@ public class TargetCreatureOrPlayer extends TargetImpl { return filter.match(permanent, game); } Player player = game.getPlayer(id); - if (player != null) + if (player != null) { return filter.match(player, game); + } return false; } @@ -101,20 +102,24 @@ public class TargetCreatureOrPlayer extends TargetImpl { public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { Permanent permanent = game.getPermanent(id); - MageObject targetSource = game.getObject(source.getSourceId()); - if (permanent != null) { - if (source != null) - //TODO: check for replacement effects - return permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game) && filter.match(permanent, source.getSourceId(), controllerId, game); - else - return filter.match(permanent, source.getSourceId(), controllerId, game); - } Player player = game.getPlayer(id); - if (player != null) - if (source != null) + + if (source != null) { + MageObject targetSource = game.getObject(source.getSourceId()); + if (permanent != null) { + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); + } + if (player != null) { return player.canBeTargetedBy(targetSource, game) && filter.match(player, game); - else - return filter.match(player, game); + } + } + + if (permanent != null) { + return filter.match(permanent, game); + } + if (player != null) { + return filter.match(player, game); + } return false; } @@ -135,15 +140,17 @@ public class TargetCreatureOrPlayer extends TargetImpl { Player player = game.getPlayer(playerId); if (player != null && player.canBeTargetedBy(targetSource, game) && filter.match(player, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; @@ -164,15 +171,17 @@ public class TargetCreatureOrPlayer extends TargetImpl { Player player = game.getPlayer(playerId); if (player != null && filter.match(player, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; diff --git a/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java b/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java index bce52eee5c..372b059d9a 100644 --- a/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java +++ b/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java @@ -75,27 +75,33 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; @@ -128,15 +136,17 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; diff --git a/Mage/src/mage/target/common/TargetCreaturePermanentAmount.java b/Mage/src/mage/target/common/TargetCreaturePermanentAmount.java index 5bad8b5687..115cd8f329 100644 --- a/Mage/src/mage/target/common/TargetCreaturePermanentAmount.java +++ b/Mage/src/mage/target/common/TargetCreaturePermanentAmount.java @@ -82,9 +82,9 @@ public class TargetCreaturePermanentAmount extends TargetAmount return filter.match(permanent, game); } Player player = game.getPlayer(id); - if (player != null) + if (player != null) { return filter.match(player, game); + } return false; } @Override public boolean canTarget(UUID id, Ability source, Game game) { Permanent permanent = game.getPermanent(id); - MageObject targetSource = game.getObject(source.getSourceId()); - if (permanent != null) { - if (source != null) - return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); - else - return filter.match(permanent, game); - } Player player = game.getPlayer(id); - if (player != null) - if (source != null) + + if (source != null) { + MageObject targetSource = game.getObject(source.getSourceId()); + if (permanent != null) { + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); + } + if (player != null) { return player.canBeTargetedBy(targetSource, game) && filter.match(player, game); - else - return filter.match(player, game); + } + } + + if (permanent != null) { + return filter.match(permanent, game); + } + if (player != null) { + return filter.match(player, game); + } return false; } @@ -138,15 +144,17 @@ public class TargetPermanentOrPlayer extends TargetImpl Player player = game.getPlayer(playerId); if (player != null && player.canBeTargetedBy(targetSource, game) && filter.match(player, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; @@ -167,15 +175,17 @@ public class TargetPermanentOrPlayer extends TargetImpl Player player = game.getPlayer(playerId); if (player != null && filter.match(player, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; diff --git a/Mage/src/mage/target/common/TargetSpellOrPermanent.java b/Mage/src/mage/target/common/TargetSpellOrPermanent.java index 0e4c027a88..9eca3270f7 100644 --- a/Mage/src/mage/target/common/TargetSpellOrPermanent.java +++ b/Mage/src/mage/target/common/TargetSpellOrPermanent.java @@ -104,24 +104,27 @@ public class TargetSpellOrPermanent extends TargetImpl { return filter.match(permanent, game); } Spell spell = game.getStack().getSpell(id); - if (spell != null) + if (spell != null) { return filter.match(spell, game); + } return false; } @Override public boolean canTarget(UUID id, Ability source, Game game) { Permanent permanent = game.getPermanent(id); - MageObject targetSource = game.getObject(source.getSourceId()); if (permanent != null) { - if (source != null) + if (source != null) { + MageObject targetSource = game.getObject(source.getSourceId()); return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); - else + } else { return filter.match(permanent, game); + } } Spell spell = game.getStack().getSpell(id); - if (spell != null) + if (spell != null) { return filter.match(spell, game); + } return false; } @@ -142,15 +145,17 @@ public class TargetSpellOrPermanent extends TargetImpl { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, sourceId, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; @@ -171,15 +176,17 @@ public class TargetSpellOrPermanent extends TargetImpl { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, null, sourceControllerId, game) && filter.match(spell, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) { count++; - if (count >= this.minNumberOfTargets) + if (count >= this.minNumberOfTargets) { return true; + } } } return false; diff --git a/Mage/src/mage/util/CardUtil.java b/Mage/src/mage/util/CardUtil.java index 5a4b84d1b0..becfbf174b 100644 --- a/Mage/src/mage/util/CardUtil.java +++ b/Mage/src/mage/util/CardUtil.java @@ -55,8 +55,9 @@ public class CardUtil { */ public static boolean shareTypes(Card card1, Card card2) { - if (card1 == null || card2 == null) + if (card1 == null || card2 == null) { throw new IllegalArgumentException("Params can't be null"); + } for (Constants.CardType type : card1.getCardType()) { if (card2.getCardType().contains(type)) { @@ -75,8 +76,9 @@ public class CardUtil { */ public static boolean shareSubtypes(Card card1, Card card2) { - if (card1 == null || card2 == null) + if (card1 == null || card2 == null) { throw new IllegalArgumentException("Params can't be null"); + } for (String subtype : card1.getSubtype()) { if (card2.getSubtype().contains(subtype)) { @@ -108,8 +110,8 @@ public class CardUtil { boolean reduced = false; for (ManaCost manaCost : previousCost) { Mana mana = manaCost.getOptions().get(0); - int colorless = mana.getColorless(); - if (!reduced && mana != null && colorless > 0) { + int colorless = mana != null ? mana.getColorless() : 0; + if (!reduced && colorless > 0) { if ((colorless - reduceCount) > 0) { int newColorless = colorless - reduceCount; adjustedCost.add(new GenericManaCost(newColorless));