Fixed some possible exceptions.

This commit is contained in:
LevelX2 2016-02-06 02:12:51 +01:00
parent e936f7dc0f
commit d2eb6151f1
20 changed files with 133 additions and 132 deletions

View file

@ -46,6 +46,7 @@ import mage.game.GameState;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.command.Emblem; import mage.game.command.Emblem;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentToken; import mage.game.permanent.PermanentToken;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.game.stack.StackAbility; import mage.game.stack.StackAbility;
@ -62,7 +63,7 @@ public class GameView implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(GameView.class); private static final Logger LOGGER = Logger.getLogger(GameView.class);
private final int priorityTime; private final int priorityTime;
private final List<PlayerView> players = new ArrayList<>(); private final List<PlayerView> players = new ArrayList<>();
@ -101,6 +102,9 @@ public class GameView implements Serializable {
// Stack Ability // Stack Ability
MageObject object = game.getObject(stackObject.getSourceId()); MageObject object = game.getObject(stackObject.getSourceId());
Card card = game.getCard(stackObject.getSourceId()); Card card = game.getCard(stackObject.getSourceId());
if (card == null && (object instanceof PermanentCard)) {
card = ((PermanentCard) object).getCard();
}
if (card != null) { if (card != null) {
if (object != null) { if (object != null) {
if (object instanceof Permanent) { if (object instanceof Permanent) {
@ -139,19 +143,17 @@ public class GameView implements Serializable {
stack.put(stackObject.getId(), stack.put(stackObject.getId(),
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView)); new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
checkPaid(stackObject.getId(), ((StackAbility) stackObject)); checkPaid(stackObject.getId(), ((StackAbility) stackObject));
} else { } else if (object instanceof StackAbility) {
if (object instanceof StackAbility) {
StackAbility stackAbility = ((StackAbility) object); StackAbility stackAbility = ((StackAbility) object);
stackAbility.newId(); stackAbility.newId();
stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject))); stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject)));
checkPaid(stackObject.getId(), ((StackAbility) stackObject)); checkPaid(stackObject.getId(), ((StackAbility) stackObject));
} else { } else {
logger.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString() + " " + object.getClass().toString()); LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString() + " " + object.getClass().toString());
}
} }
} else { } else {
// can happen if a player times out while ability is on the stack // can happen if a player times out while ability is on the stack
logger.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule()); LOGGER.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule());
} }
} else { } else {
// Spell // Spell
@ -186,7 +188,7 @@ public class GameView implements Serializable {
} }
if (isPlayer) { if (isPlayer) {
// has only to be set for active palyer with priority (e.g. pay mana by delve or Quenchable Fire special action) // has only to be set for active palyer with priority (e.g. pay mana by delve or Quenchable Fire special action)
if (createdForPlayer != null && createdForPlayerId.equals(state.getPriorityPlayerId())) { if (createdForPlayer != null && createdForPlayerId != null && createdForPlayerId.equals(state.getPriorityPlayerId())) {
this.special = state.getSpecialActions().getControlledBy(state.getPriorityPlayerId(), createdForPlayer.isInPayManaMode()).size() > 0; this.special = state.getSpecialActions().getControlledBy(state.getPriorityPlayerId(), createdForPlayer.isInPayManaMode()).size() > 0;
} }
} else { } else {

View file

@ -436,18 +436,17 @@ public class HumanPlayer extends PlayerImpl {
@Override @Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
if (cards == null) {
return false;
}
updateGameStatePriority("choose(4)", game); updateGameStatePriority("choose(4)", game);
while (!abort) { while (!abort) {
boolean required = target.isRequired(); boolean required = target.isRequired();
// if there is no cards to select from, then add possibility to cancel choosing action // if there is no cards to select from, then add possibility to cancel choosing action
if (cards == null) {
required = false;
} else {
int count = cards.count(target.getFilter(), game); int count = cards.count(target.getFilter(), game);
if (count == 0) { if (count == 0) {
required = false; required = false;
} }
}
if (target.getTargets().size() >= target.getNumberOfTargets()) { if (target.getTargets().size() >= target.getNumberOfTargets()) {
required = false; required = false;
} }
@ -1227,7 +1226,7 @@ public class HumanPlayer extends PlayerImpl {
updateGameStatePriority("activateAbility", game); updateGameStatePriority("activateAbility", game);
if (abilities.size() == 1 && suppressAbilityPicker(abilities.values().iterator().next())) { if (abilities.size() == 1 && suppressAbilityPicker(abilities.values().iterator().next())) {
ActivatedAbility ability = abilities.values().iterator().next(); ActivatedAbility ability = abilities.values().iterator().next();
if (ability.getTargets().size() != 0 if (!ability.getTargets().isEmpty()
|| !(ability.getCosts().size() == 1 && ability.getCosts().get(0) instanceof SacrificeSourceCost) || !(ability.getCosts().size() == 1 && ability.getCosts().get(0) instanceof SacrificeSourceCost)
|| !(ability.getCosts().size() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) { || !(ability.getCosts().size() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) {
activateAbility(ability, game); activateAbility(ability, game);
@ -1236,7 +1235,7 @@ public class HumanPlayer extends PlayerImpl {
} }
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values())); game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values()));
waitForResponse(game); waitForResponse(game);
if (response.getUUID() != null) { if (response.getUUID() != null && isInGame()) {
if (abilities.containsKey(response.getUUID())) { if (abilities.containsKey(response.getUUID())) {
activateAbility(abilities.get(response.getUUID()), game); activateAbility(abilities.get(response.getUUID()), game);
} }

View file

@ -188,11 +188,10 @@ public class UserManager {
public void handleException(Exception ex) { public void handleException(Exception ex) {
if (ex != null) { if (ex != null) {
LOGGER.fatal("User manager exception " + (ex.getMessage() == null ? "null" : ex.getMessage())); LOGGER.fatal("User manager exception ", ex);
if (ex.getCause() != null) { if (ex.getStackTrace() != null) {
LOGGER.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null" : ex.getCause().getMessage())); LOGGER.fatal(ex.getStackTrace());
} }
ex.printStackTrace();
} else { } else {
LOGGER.fatal("User manager exception - null"); LOGGER.fatal("User manager exception - null");
} }

View file

@ -43,6 +43,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.filter.common.FilterInstantOrSorceryCard; import mage.filter.common.FilterInstantOrSorceryCard;
import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.stack.Spell; import mage.game.stack.Spell;
@ -152,9 +153,11 @@ class JelevaNephaliasCastEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
if (controller.chooseUse(outcome, "Cast an instant or sorcery from exile?", source, game)) { ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(), game) > 0) {
if (controller.chooseUse(outcome, "Cast an instant or sorcery card from exile?", source, game)) {
TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source)); TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source));
if (controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)), target, game)) { if (controller.choose(Outcome.PlayForFree, exileZone, target, game)) {
Card card = game.getCard(target.getFirstTarget()); Card card = game.getCard(target.getFirstTarget());
if (card != null) { if (card != null) {
game.getExile().removeCard(card, game); game.getExile().removeCard(card, game);
@ -162,6 +165,7 @@ class JelevaNephaliasCastEffect extends OneShotEffect {
} }
} }
} }
}
return true; return true;
} }
return false; return false;

View file

@ -13,7 +13,6 @@ import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.cost.CostModificationEffectImpl; import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.choices.ChoiceImpl; import mage.choices.ChoiceImpl;
import mage.constants.CardType; import mage.constants.CardType;
@ -24,6 +23,7 @@ import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
@ -125,10 +125,9 @@ class CloudKeyCostModificationEffect extends CostModificationEffectImpl {
@Override @Override
public boolean applies(Ability abilityToModify, Ability source, Game game) { public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility && abilityToModify.getControllerId().equals(source.getControllerId())) { if (abilityToModify instanceof SpellAbility && abilityToModify.getControllerId().equals(source.getControllerId())) {
Card card = game.getCard(abilityToModify.getSourceId()); Spell spell = game.getStack().getSpell(abilityToModify.getSourceId());
if (card.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) { if (spell != null && spell.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) {
return true; return true;
} }
} }

View file

@ -32,9 +32,7 @@ import mage.abilities.Ability;
import mage.abilities.common.DiesAttachedTriggeredAbility; import mage.abilities.common.DiesAttachedTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.abilities.effects.common.continuous.BoostEquippedEffect; import mage.abilities.effects.common.continuous.BoostEquippedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.cards.Card; import mage.cards.Card;
@ -45,9 +43,6 @@ import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.other.AuraCardCanAttachToPermanentId;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -86,7 +81,7 @@ class DeathrenderEffect extends OneShotEffect {
DeathrenderEffect() { DeathrenderEffect() {
super(Outcome.PutCardInPlay); super(Outcome.PutCardInPlay);
this.staticText = "you may put a creature card from your hand onto the battlefield and attach {this} to it."; this.staticText = "you may put a creature card from your hand onto the battlefield and attach {this} to it";
} }
DeathrenderEffect(final DeathrenderEffect effect) { DeathrenderEffect(final DeathrenderEffect effect) {
@ -102,14 +97,13 @@ class DeathrenderEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null) { if (controller != null && sourcePermanent != null) {
FilterCard filter = new FilterCreatureCard(); FilterCard filter = new FilterCreatureCard();
TargetCardInHand target = new TargetCardInHand(0, 1, filter); TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) { if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card creatureInHand = game.getCard(target.getFirstTarget()); Card creatureInHand = game.getCard(target.getFirstTarget());
if (creatureInHand != null) { if (creatureInHand != null) {
game.getState().setValue("attachTo:" + sourcePermanent.getId(), game.getPermanent(creatureInHand.getId())); if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game)) {
if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game) && sourcePermanent != null) {
game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), game); game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), game);
} }
} }

View file

@ -28,16 +28,11 @@
package mage.sets.magic2010; package mage.sets.magic2010;
import java.util.UUID; import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DrawCardOpponentTriggeredAbility; import mage.abilities.common.DrawCardOpponentTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/** /**
* *
@ -49,7 +44,6 @@ public class UnderworldDreams extends CardImpl {
super(ownerId, 115, "Underworld Dreams", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{B}{B}{B}"); super(ownerId, 115, "Underworld Dreams", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{B}{B}{B}");
this.expansionSetCode = "M10"; this.expansionSetCode = "M10";
// Whenever an opponent draws a card, Underworld Dreams deals 1 damage to him or her. // Whenever an opponent draws a card, Underworld Dreams deals 1 damage to him or her.
this.addAbility(new DrawCardOpponentTriggeredAbility(new DamageTargetEffect(1, true, "him or her"), false, true)); this.addAbility(new DrawCardOpponentTriggeredAbility(new DamageTargetEffect(1, true, "him or her"), false, true));
} }

View file

@ -75,6 +75,7 @@ public class HamletbackGoliath extends CardImpl {
} }
class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl { class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl {
HamletbackGoliathTriggeredAbility() { HamletbackGoliathTriggeredAbility() {
super(Zone.BATTLEFIELD, new HamletbackGoliathEffect(), true); super(Zone.BATTLEFIELD, new HamletbackGoliathEffect(), true);
} }
@ -109,11 +110,12 @@ class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public String getRule() { public String getRule() {
return "Whenever another creature enters the battlefield, you may put X +1/+1 counters on Hamletback Goliath, where X is that creature's power."; return "Whenever another creature enters the battlefield, you may put X +1/+1 counters on {this}, where X is that creature's power.";
} }
} }
class HamletbackGoliathEffect extends OneShotEffect { class HamletbackGoliathEffect extends OneShotEffect {
HamletbackGoliathEffect() { HamletbackGoliathEffect() {
super(Outcome.BoostCreature); super(Outcome.BoostCreature);
} }
@ -125,15 +127,14 @@ class HamletbackGoliathEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(targetPointer.getFirst(game, source)); Permanent creature = game.getPermanent(targetPointer.getFirst(game, source));
Permanent HamletbackGoliath = game.getPermanent(source.getSourceId()); Permanent sourceObject = game.getPermanent(source.getSourceId());
if (creature == null) { if (creature == null) {
creature = (Permanent) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD); creature = (Permanent) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD);
} }
if (creature != null) { if (creature != null && sourceObject != null) {
HamletbackGoliath.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game); sourceObject.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game);
return true;
} }
return false; return true;
} }
@Override @Override

View file

@ -63,7 +63,6 @@ public class ErayoSoratamiAscendant extends CardImpl {
this.flipCard = true; this.flipCard = true;
this.flipCardName = "Erayo's Essence"; this.flipCardName = "Erayo's Essence";
// Flying // Flying
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Whenever the fourth spell of a turn is cast, flip Erayo, Soratami Ascendant. // Whenever the fourth spell of a turn is cast, flip Erayo, Soratami Ascendant.
@ -129,13 +128,16 @@ class ErayosEssence extends Token {
color.setBlue(true); color.setBlue(true);
// Whenever an opponent casts a spell for the first time in a turn, counter that spell. // Whenever an opponent casts a spell for the first time in a turn, counter that spell.
this.addAbility(new ErayosEssenceTriggeredAbility()); Effect effect = new CounterTargetEffect();
effect.setText("counter that spell");
this.addAbility(new ErayosEssenceTriggeredAbility(effect));
} }
} }
class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl { class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl {
public ErayosEssenceTriggeredAbility() { public ErayosEssenceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, new CounterTargetEffect(), false); super(Zone.BATTLEFIELD, effect, false);
} }
public ErayosEssenceTriggeredAbility(final ErayosEssenceTriggeredAbility ability) { public ErayosEssenceTriggeredAbility(final ErayosEssenceTriggeredAbility ability) {
@ -163,7 +165,7 @@ class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public String getRule() { public String getRule() {
return "Whenever an opponent casts a spell for the first time each turn, counter that spell."; return "Whenever an opponent casts a spell for the first time each turn, " + super.getRule();
} }
@Override @Override

View file

@ -78,10 +78,10 @@ public class EternalDominion extends CardImpl {
class EternalDominionEffect extends OneShotEffect { class EternalDominionEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard("an artifact, creature, enchantment, or land card"); private static final FilterCard FILTER = new FilterCard("an artifact, creature, enchantment, or land card");
static { static {
filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), FILTER.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE), new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.ENCHANTMENT), new CardTypePredicate(CardType.ENCHANTMENT),
new CardTypePredicate(CardType.LAND))); new CardTypePredicate(CardType.LAND)));
@ -102,7 +102,7 @@ class EternalDominionEffect extends OneShotEffect {
Player opponent = game.getPlayer(source.getFirstTarget()); Player opponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (opponent != null && controller != null) { if (opponent != null && controller != null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter); TargetCardInLibrary target = new TargetCardInLibrary(FILTER);
controller.searchLibrary(target, game, opponent.getId()); controller.searchLibrary(target, game, opponent.getId());
Card targetCard = game.getCard(target.getFirstTarget()); Card targetCard = game.getCard(target.getFirstTarget());
if (targetCard != null) { if (targetCard != null) {

View file

@ -32,12 +32,12 @@ import java.util.UUID;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer; import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer; import mage.constants.SubLayer;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
@ -50,7 +50,6 @@ import mage.target.common.TargetControlledCreaturePermanent;
*/ */
public class SigilBlessing extends CardImpl { public class SigilBlessing extends CardImpl {
public SigilBlessing(UUID ownerId) { public SigilBlessing(UUID ownerId) {
super(ownerId, 195, "Sigil Blessing", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{G}{W}"); super(ownerId, 195, "Sigil Blessing", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{G}{W}");
this.expansionSetCode = "ALA"; this.expansionSetCode = "ALA";
@ -71,6 +70,7 @@ public class SigilBlessing extends CardImpl {
} }
class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl { class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl {
public SigilBlessingBoostControlledEffect() { public SigilBlessingBoostControlledEffect() {
super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
staticText = "Until end of turn, target creature you control gets +3/+3 and other creatures you control get +1/+1"; staticText = "Until end of turn, target creature you control gets +3/+3 and other creatures you control get +1/+1";
@ -99,7 +99,7 @@ class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl {
Permanent permanent = it.next().getPermanent(game); Permanent permanent = it.next().getPermanent(game);
if (permanent != null) { if (permanent != null) {
int boost = 1; int boost = 1;
if (getTargetPointer().getFirst(game, source).equals(permanent.getId())) { if (permanent.getId().equals(getTargetPointer().getFirst(game, source))) {
boost = 3; boost = 3;
} }
permanent.addPower(boost); permanent.addPower(boost);

View file

@ -25,11 +25,9 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.costs.common; package mage.abilities.costs.common;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl; import mage.abilities.costs.CostImpl;
@ -67,7 +65,7 @@ public class PayLoyaltyCost extends CostImpl {
@Override @Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent planeswalker = game.getPermanent(sourceId); Permanent planeswalker = game.getPermanent(sourceId);
if (planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) { if (planeswalker != null && planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
if (amount > 0) { if (amount > 0) {
planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount)); planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount));
} else if (amount < 0) { } else if (amount < 0) {

View file

@ -43,6 +43,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.MageSingleton; import mage.abilities.MageSingleton;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility; import mage.abilities.StaticAbility;
@ -743,6 +744,9 @@ public class ContinuousEffects implements Serializable {
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) { if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
effect.setValue("targetAbility", targetAbility); effect.setValue("targetAbility", targetAbility);
if (effect.applies(event, sourceAbility, game)) { if (effect.applies(event, sourceAbility, game)) {
if (targetAbility instanceof ActivatedAbility && ((ActivatedAbility) targetAbility).isCheckPlayableMode()) {
checkPlayableMode = true;
}
if (!checkPlayableMode) { if (!checkPlayableMode) {
String message = effect.getInfoMessage(sourceAbility, event, game); String message = effect.getInfoMessage(sourceAbility, event, game);
if (message != null && !message.isEmpty()) { if (message != null && !message.isEmpty()) {

View file

@ -88,10 +88,10 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
player.choose(Outcome.Damage, redirectTarget, null, game); player.choose(Outcome.Damage, redirectTarget, null, game);
} }
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(player.getLogName()).append(" redirects ") Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget());
.append(event.getAmount()) if (redirectTo != null) {
.append(" damage to ") game.informPlayers(player.getLogName() + " redirects " + event.getAmount() + " damage to " + redirectTo.getLogName());
.append(game.getPermanent(redirectTarget.getFirstTarget()).getLogName()).toString()); }
} }
return true; return true;
} }

View file

@ -69,6 +69,6 @@ public class CounterTargetEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) { if (staticText != null && !staticText.isEmpty()) {
return staticText; return staticText;
} }
return "counter target " + mode.getTargets().get(0).getTargetName(); return "counter target " + (mode.getTargets().get(0) != null ? mode.getTargets().get(0).getTargetName() : "spell");
} }
} }

View file

@ -34,7 +34,7 @@ import mage.players.Player;
*/ */
public class EpicEffect extends OneShotEffect { public class EpicEffect extends OneShotEffect {
final String rule = "<br><br/>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)"; final String rule = "<br>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)";
public EpicEffect() { public EpicEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);

View file

@ -553,7 +553,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override @Override
public int getSourceObjectZoneChangeCounter() { public int getSourceObjectZoneChangeCounter() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported.");
} }
@Override @Override
@ -563,7 +563,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override @Override
public int getZoneChangeCounter(Game game) { public int getZoneChangeCounter(Game game) {
throw new UnsupportedOperationException("Not supported."); return game.getState().getZoneChangeCounter(getSourceId());
} }
@Override @Override

View file

@ -209,12 +209,15 @@ public abstract class StackObjImpl implements StackObject {
} else { } else {
again = true; again = true;
} }
} else { } else // if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition
// if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition
if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) { if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) {
if (targetController.isHuman()) { if (targetController.isHuman()) {
game.informPlayer(targetController, "This target was already selected from origin spell. You can only keep this target!"); if (targetController.chooseUse(Outcome.Benefit, "This target was already selected from origin spell. Reset to original target?", ability, game)) {
// use previous target no target was selected
newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false);
} else {
again = true; again = true;
}
} else { } else {
newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false);
} }
@ -236,7 +239,6 @@ public abstract class StackObjImpl implements StackObject {
// valid target was selected, add it to the new target definition // valid target was selected, add it to the new target definition
newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false); newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false);
} }
}
} while (again && targetController.canRespond()); } while (again && targetController.canRespond());
} }
} // keep the target } // keep the target

View file

@ -898,7 +898,7 @@ public abstract class PlayerImpl implements Player, Serializable {
*/ */
@Override @Override
public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary, Game game, Ability source, boolean anyOrder) { public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary, Game game, Ability source, boolean anyOrder) {
if (!cardsToLibrary.isEmpty()) { if (cardsToLibrary != null && !cardsToLibrary.isEmpty()) {
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
UUID sourceId = (source == null ? null : source.getSourceId()); UUID sourceId = (source == null ? null : source.getSourceId());
if (!anyOrder) { if (!anyOrder) {
@ -982,6 +982,9 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public boolean cast(SpellAbility ability, Game game, boolean noMana) { public boolean cast(SpellAbility ability, Game game, boolean noMana) {
if (game == null || ability == null) {
return false;
}
if (!ability.getSpellAbilityType().equals(SpellAbilityType.BASE)) { if (!ability.getSpellAbilityType().equals(SpellAbilityType.BASE)) {
ability = chooseSpellAbilityForCast(ability, game, noMana); ability = chooseSpellAbilityForCast(ability, game, noMana);
} }