* Phyrexian Ingester - Fixed possible null pointer exception.

This commit is contained in:
LevelX2 2016-06-18 11:58:08 +02:00
parent 34668ba5d9
commit 1bee035aaa
2 changed files with 30 additions and 32 deletions

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,12 +20,11 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.magic2010;
import java.util.ArrayList;
@ -33,13 +32,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -55,6 +54,8 @@ public class Fireball extends CardImpl {
super(ownerId, 136, "Fireball", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{X}{R}");
this.expansionSetCode = "M10";
// Fireball deals X damage divided evenly, rounded down, among any number of target creatures and/or players.
// Fireball costs 1 more to cast for each target beyond the first.
this.getSpellAbility().addTarget(new FireballTargetCreatureOrPlayer(0, Integer.MAX_VALUE));
this.getSpellAbility().addEffect(new FireballEffect());
}
@ -93,14 +94,13 @@ class FireballEffect extends OneShotEffect {
int numTargets = targetPointer.getTargets(game, source).size();
int damage = source.getManaCostsToPay().getX();
if (numTargets > 0) {
int damagePer = damage/numTargets;
int damagePer = damage / numTargets;
if (damagePer > 0) {
for (UUID targetId: targetPointer.getTargets(game, source)) {
for (UUID targetId : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.damage(damagePer, source.getSourceId(), game, false, true);
}
else {
} else {
Player player = game.getPlayer(targetId);
if (player != null) {
player.damage(damagePer, source.getSourceId(), game, false, true);
@ -130,7 +130,6 @@ class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer {
super(target);
}
/**
* This is only used by AI players
*
@ -140,25 +139,25 @@ class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer {
*/
@Override
public List<TargetCreatureOrPlayer> getTargetOptions(Ability source, Game game) {
List<TargetCreatureOrPlayer> options = new ArrayList<>();
int xVal = source.getManaCostsToPay().getX();
int xVal = source.getManaCostsToPay().getX();
if (xVal < 1) {
return options;
}
for (int numberTargets = 1; numberTargets == 1 || xVal / (numberTargets - 1) > 1 ; numberTargets++) {
for (int numberTargets = 1; numberTargets == 1 || xVal / (numberTargets - 1) > 1; numberTargets++) {
Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), source.getControllerId(), game);
// less possible targets than we're trying to set
if (possibleTargets.size() < numberTargets) {
return options;
}
// less than 1 damage per target = 0, add no such options
if ((xVal -(numberTargets -1))/numberTargets < 1) {
if ((xVal - (numberTargets - 1)) / numberTargets < 1) {
continue;
}
possibleTargets.removeAll(getTargets());
Iterator<UUID> it = possibleTargets.iterator();
while (it.hasNext()) {
@ -173,7 +172,7 @@ class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer {
if (!target.isChosen()) {
Iterator<UUID> it2 = possibleTargets.iterator();
while (it2.hasNext()&& !target.isChosen()) {
while (it2.hasNext() && !target.isChosen()) {
UUID nextTargetId = it2.next();
target.addTarget(nextTargetId, source, game, true);
@ -191,9 +190,8 @@ class FireballTargetCreatureOrPlayer extends TargetCreatureOrPlayer {
return options;
}
@Override
public FireballTargetCreatureOrPlayer copy() {
return new FireballTargetCreatureOrPlayer(this);
}
}
}

View file

@ -28,13 +28,6 @@
package mage.sets.newphyrexia;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
@ -44,6 +37,13 @@ import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.TokenPredicate;
@ -113,11 +113,11 @@ class PhyrexianIngesterImprintEffect extends OneShotEffect {
if (controller != null && sourceObject != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
if (targetPermanent != null) {
controller.moveCardToExileWithInfo(targetPermanent, getId(), sourceObject.getIdName() + " (Imprint)", source.getSourceId(), game, Zone.BATTLEFIELD, true);
if (sourcePermanent != null && targetPermanent != null) {
controller.moveCardToExileWithInfo(targetPermanent, getId(), sourceObject.getIdName() + " (Imprint)", source.getSourceId(), game, Zone.BATTLEFIELD, true);
sourcePermanent.imprint(targetPermanent.getId(), game);
return true;
}
}
}
return false;
}