diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 7060d19ab9..bc0f5dc839 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -46,6 +46,7 @@ import mage.game.GameState; import mage.game.combat.CombatGroup; import mage.game.command.Emblem; import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentToken; import mage.game.stack.Spell; import mage.game.stack.StackAbility; @@ -62,7 +63,7 @@ public class GameView implements Serializable { 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 List players = new ArrayList<>(); @@ -101,6 +102,9 @@ public class GameView implements Serializable { // Stack Ability MageObject object = game.getObject(stackObject.getSourceId()); Card card = game.getCard(stackObject.getSourceId()); + if (card == null && (object instanceof PermanentCard)) { + card = ((PermanentCard) object).getCard(); + } if (card != null) { if (object != null) { if (object instanceof Permanent) { @@ -139,19 +143,17 @@ public class GameView implements Serializable { stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView)); checkPaid(stackObject.getId(), ((StackAbility) stackObject)); + } else if (object instanceof StackAbility) { + StackAbility stackAbility = ((StackAbility) object); + stackAbility.newId(); + stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject))); + checkPaid(stackObject.getId(), ((StackAbility) stackObject)); } else { - if (object instanceof StackAbility) { - StackAbility stackAbility = ((StackAbility) object); - stackAbility.newId(); - stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject))); - checkPaid(stackObject.getId(), ((StackAbility) stackObject)); - } 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 { // 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 { // Spell @@ -186,7 +188,7 @@ public class GameView implements Serializable { } if (isPlayer) { // 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; } } else { diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 9dc9d7ff02..95fa8274e3 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -436,17 +436,16 @@ public class HumanPlayer extends PlayerImpl { @Override public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { + if (cards == null) { + return false; + } updateGameStatePriority("choose(4)", game); while (!abort) { boolean required = target.isRequired(); // if there is no cards to select from, then add possibility to cancel choosing action - if (cards == null) { + int count = cards.count(target.getFilter(), game); + if (count == 0) { required = false; - } else { - int count = cards.count(target.getFilter(), game); - if (count == 0) { - required = false; - } } if (target.getTargets().size() >= target.getNumberOfTargets()) { required = false; @@ -1227,7 +1226,7 @@ public class HumanPlayer extends PlayerImpl { updateGameStatePriority("activateAbility", game); if (abilities.size() == 1 && suppressAbilityPicker(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() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) { activateAbility(ability, game); @@ -1236,7 +1235,7 @@ public class HumanPlayer extends PlayerImpl { } game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values())); waitForResponse(game); - if (response.getUUID() != null) { + if (response.getUUID() != null && isInGame()) { if (abilities.containsKey(response.getUUID())) { activateAbility(abilities.get(response.getUUID()), game); } diff --git a/Mage.Server/src/main/java/mage/server/UserManager.java b/Mage.Server/src/main/java/mage/server/UserManager.java index 09edbf2669..1cb20d01ec 100644 --- a/Mage.Server/src/main/java/mage/server/UserManager.java +++ b/Mage.Server/src/main/java/mage/server/UserManager.java @@ -188,11 +188,10 @@ public class UserManager { public void handleException(Exception ex) { if (ex != null) { - LOGGER.fatal("User manager exception " + (ex.getMessage() == null ? "null" : ex.getMessage())); - if (ex.getCause() != null) { - LOGGER.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null" : ex.getCause().getMessage())); + LOGGER.fatal("User manager exception ", ex); + if (ex.getStackTrace() != null) { + LOGGER.fatal(ex.getStackTrace()); } - ex.printStackTrace(); } else { LOGGER.fatal("User manager exception - null"); } diff --git a/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java b/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java index 2f93e94376..b0db946ee1 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java +++ b/Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java @@ -283,33 +283,33 @@ public class GameSessionPlayer extends GameSessionWatcher { if (player != null && player.isInGame()) { callExecutor.execute( new Runnable() { - @Override - public void run() { - try { - if (game.getStartTime() == null) { - // gameController is still waiting to start the game - player.leave(); - } else { - // game was already started - player.quit(game); - } + @Override + public void run() { + try { + if (game.getStartTime() == null) { + // gameController is still waiting to start the game + player.leave(); + } else { + // game was already started + player.quit(game); + } - } catch (Exception ex) { - if (ex != null) { - // It seems this can happen if two threads try to end the game at the exact same time (one wins and one ends here) - logger.fatal("Game session game quit exception " + (ex.getMessage() == null ? "null" : ex.getMessage())); - logger.debug("- gameId:" + game.getId() + " playerId: " + playerId); - if (ex.getCause() != null) { - logger.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null" : ex.getCause().getMessage()), ex); - } else { - logger.debug("- ex: " + ex.toString(), ex); - } - } else { - logger.fatal("Game session game quit exception - null gameId:" + game.getId() + " playerId: " + playerId); - } + } catch (Exception ex) { + if (ex != null) { + // It seems this can happen if two threads try to end the game at the exact same time (one wins and one ends here) + logger.fatal("Game session game quit exception " + (ex.getMessage() == null ? "null" : ex.getMessage())); + logger.debug("- gameId:" + game.getId() + " playerId: " + playerId); + if (ex.getCause() != null) { + logger.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null" : ex.getCause().getMessage()), ex); + } else { + logger.debug("- ex: " + ex.toString(), ex); } + } else { + logger.fatal("Game session game quit exception - null gameId:" + game.getId() + " playerId: " + playerId); } } + } + } ); } diff --git a/Mage.Sets/src/mage/sets/commander2013/JelevaNephaliasScourge.java b/Mage.Sets/src/mage/sets/commander2013/JelevaNephaliasScourge.java index 3808a36d45..9593704232 100644 --- a/Mage.Sets/src/mage/sets/commander2013/JelevaNephaliasScourge.java +++ b/Mage.Sets/src/mage/sets/commander2013/JelevaNephaliasScourge.java @@ -43,6 +43,7 @@ import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.WatcherScope; import mage.filter.common.FilterInstantOrSorceryCard; +import mage.game.ExileZone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.stack.Spell; @@ -152,13 +153,16 @@ class JelevaNephaliasCastEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - if (controller.chooseUse(outcome, "Cast an instant or sorcery from exile?", source, game)) { - TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source)); - if (controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)), target, game)) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - game.getExile().removeCard(card, game); - return controller.cast(card.getSpellAbility(), game, true); + 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)); + if (controller.choose(Outcome.PlayForFree, exileZone, target, game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + game.getExile().removeCard(card, game); + return controller.cast(card.getSpellAbility(), game, true); + } } } } diff --git a/Mage.Sets/src/mage/sets/futuresight/CloudKey.java b/Mage.Sets/src/mage/sets/futuresight/CloudKey.java index b357c8b83f..d60eb6964e 100644 --- a/Mage.Sets/src/mage/sets/futuresight/CloudKey.java +++ b/Mage.Sets/src/mage/sets/futuresight/CloudKey.java @@ -13,7 +13,6 @@ import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.cost.CostModificationEffectImpl; -import mage.cards.Card; import mage.cards.CardImpl; import mage.choices.ChoiceImpl; import mage.constants.CardType; @@ -24,6 +23,7 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.game.stack.Spell; import mage.players.Player; import mage.util.CardUtil; @@ -125,10 +125,9 @@ class CloudKeyCostModificationEffect extends CostModificationEffectImpl { @Override public boolean applies(Ability abilityToModify, Ability source, Game game) { - if (abilityToModify instanceof SpellAbility && abilityToModify.getControllerId().equals(source.getControllerId())) { - Card card = game.getCard(abilityToModify.getSourceId()); - if (card.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) { + Spell spell = game.getStack().getSpell(abilityToModify.getSourceId()); + if (spell != null && spell.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) { return true; } } diff --git a/Mage.Sets/src/mage/sets/lorwyn/Deathrender.java b/Mage.Sets/src/mage/sets/lorwyn/Deathrender.java index 5c0288c9c6..0560e06bac 100644 --- a/Mage.Sets/src/mage/sets/lorwyn/Deathrender.java +++ b/Mage.Sets/src/mage/sets/lorwyn/Deathrender.java @@ -32,9 +32,7 @@ import mage.abilities.Ability; import mage.abilities.common.DiesAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect; import mage.abilities.effects.common.continuous.BoostEquippedEffect; import mage.abilities.keyword.EquipAbility; import mage.cards.Card; @@ -45,9 +43,6 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.FilterCard; 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.permanent.Permanent; import mage.players.Player; @@ -86,7 +81,7 @@ class DeathrenderEffect extends OneShotEffect { DeathrenderEffect() { 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) { @@ -102,14 +97,13 @@ class DeathrenderEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if (controller != null) { + if (controller != null && sourcePermanent != null) { FilterCard filter = new FilterCreatureCard(); TargetCardInHand target = new TargetCardInHand(0, 1, filter); if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) { Card creatureInHand = game.getCard(target.getFirstTarget()); if (creatureInHand != null) { - game.getState().setValue("attachTo:" + sourcePermanent.getId(), game.getPermanent(creatureInHand.getId())); - if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game) && sourcePermanent != null) { + if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game)) { game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), game); } } diff --git a/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java b/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java index d6026349ea..f745f2be24 100644 --- a/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java +++ b/Mage.Sets/src/mage/sets/magic2010/UnderworldDreams.java @@ -28,16 +28,11 @@ package mage.sets.magic2010; import java.util.UUID; -import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.DrawCardOpponentTriggeredAbility; import mage.abilities.effects.common.DamageTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; 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}"); this.expansionSetCode = "M10"; - // 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)); } diff --git a/Mage.Sets/src/mage/sets/magic2013/HamletbackGoliath.java b/Mage.Sets/src/mage/sets/magic2013/HamletbackGoliath.java index f02794b92b..5bc2215211 100644 --- a/Mage.Sets/src/mage/sets/magic2013/HamletbackGoliath.java +++ b/Mage.Sets/src/mage/sets/magic2013/HamletbackGoliath.java @@ -75,6 +75,7 @@ public class HamletbackGoliath extends CardImpl { } class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl { + HamletbackGoliathTriggeredAbility() { super(Zone.BATTLEFIELD, new HamletbackGoliathEffect(), true); } @@ -109,11 +110,12 @@ class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl { @Override 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 { + HamletbackGoliathEffect() { super(Outcome.BoostCreature); } @@ -125,15 +127,14 @@ class HamletbackGoliathEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Permanent creature = game.getPermanent(targetPointer.getFirst(game, source)); - Permanent HamletbackGoliath = game.getPermanent(source.getSourceId()); + Permanent sourceObject = game.getPermanent(source.getSourceId()); if (creature == null) { creature = (Permanent) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD); } - if (creature != null) { - HamletbackGoliath.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game); - return true; + if (creature != null && sourceObject != null) { + sourceObject.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game); } - return false; + return true; } @Override diff --git a/Mage.Sets/src/mage/sets/saviorsofkamigawa/ErayoSoratamiAscendant.java b/Mage.Sets/src/mage/sets/saviorsofkamigawa/ErayoSoratamiAscendant.java index 6580d8908d..1df3ededb7 100644 --- a/Mage.Sets/src/mage/sets/saviorsofkamigawa/ErayoSoratamiAscendant.java +++ b/Mage.Sets/src/mage/sets/saviorsofkamigawa/ErayoSoratamiAscendant.java @@ -61,14 +61,13 @@ public class ErayoSoratamiAscendant extends CardImpl { this.toughness = new MageInt(1); this.flipCard = true; - this.flipCardName = "Erayo's Essence"; - - + this.flipCardName = "Erayo's Essence"; + // Flying this.addAbility(FlyingAbility.getInstance()); // Whenever the fourth spell of a turn is cast, flip Erayo, Soratami Ascendant. this.addAbility(new ErayoSoratamiAscendantTriggeredAbility()); - + } public ErayoSoratamiAscendant(final ErayoSoratamiAscendant card) { @@ -92,7 +91,7 @@ class ErayoSoratamiAscendantTriggeredAbility extends TriggeredAbilityImpl { effect.setText("flip {this}"); return effect; } - + public ErayoSoratamiAscendantTriggeredAbility(final ErayoSoratamiAscendantTriggeredAbility ability) { super(ability); } @@ -121,7 +120,7 @@ class ErayoSoratamiAscendantTriggeredAbility extends TriggeredAbilityImpl { class ErayosEssence extends Token { - ErayosEssence () { + ErayosEssence() { super("Erayo's Essence", ""); supertype.add("Legendary"); cardType.add(CardType.ENCHANTMENT); @@ -129,15 +128,18 @@ class ErayosEssence extends Token { color.setBlue(true); // 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 { - public ErayosEssenceTriggeredAbility() { - super(Zone.BATTLEFIELD, new CounterTargetEffect(), false); + public ErayosEssenceTriggeredAbility(Effect effect) { + super(Zone.BATTLEFIELD, effect, false); } - + public ErayosEssenceTriggeredAbility(final ErayosEssenceTriggeredAbility ability) { super(ability); } @@ -156,14 +158,14 @@ class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl { effect.setTargetPointer(new FixedTarget(event.getTargetId())); } return true; - } + } } return false; } @Override 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 diff --git a/Mage.Sets/src/mage/sets/saviorsofkamigawa/EternalDominion.java b/Mage.Sets/src/mage/sets/saviorsofkamigawa/EternalDominion.java index 7b63cd400f..81c15da577 100644 --- a/Mage.Sets/src/mage/sets/saviorsofkamigawa/EternalDominion.java +++ b/Mage.Sets/src/mage/sets/saviorsofkamigawa/EternalDominion.java @@ -78,10 +78,10 @@ public class EternalDominion extends CardImpl { 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 { - filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), + FILTER.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE), new CardTypePredicate(CardType.ENCHANTMENT), new CardTypePredicate(CardType.LAND))); @@ -102,7 +102,7 @@ class EternalDominionEffect extends OneShotEffect { Player opponent = game.getPlayer(source.getFirstTarget()); Player controller = game.getPlayer(source.getControllerId()); if (opponent != null && controller != null) { - TargetCardInLibrary target = new TargetCardInLibrary(filter); + TargetCardInLibrary target = new TargetCardInLibrary(FILTER); controller.searchLibrary(target, game, opponent.getId()); Card targetCard = game.getCard(target.getFirstTarget()); if (targetCard != null) { diff --git a/Mage.Sets/src/mage/sets/shardsofalara/SigilBlessing.java b/Mage.Sets/src/mage/sets/shardsofalara/SigilBlessing.java index 5c4a963120..394c853e75 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/SigilBlessing.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/SigilBlessing.java @@ -32,12 +32,12 @@ import java.util.UUID; import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; -import mage.constants.CardType; -import mage.constants.Rarity; 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.filter.common.FilterCreaturePermanent; import mage.game.Game; @@ -50,7 +50,6 @@ import mage.target.common.TargetControlledCreaturePermanent; */ public class SigilBlessing extends CardImpl { - public SigilBlessing(UUID ownerId) { super(ownerId, 195, "Sigil Blessing", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{G}{W}"); this.expansionSetCode = "ALA"; @@ -71,6 +70,7 @@ public class SigilBlessing extends CardImpl { } class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl { + public SigilBlessingBoostControlledEffect() { 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"; @@ -95,11 +95,11 @@ class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { + for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { Permanent permanent = it.next().getPermanent(game); if (permanent != null) { int boost = 1; - if (getTargetPointer().getFirst(game, source).equals(permanent.getId())) { + if (permanent.getId().equals(getTargetPointer().getFirst(game, source))) { boost = 3; } permanent.addPower(boost); diff --git a/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java b/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java index 04e96a416e..7bbfbc2c5a 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/PayLoyaltyCost.java @@ -24,12 +24,10 @@ * 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.abilities.costs.common; import java.util.UUID; - import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; @@ -67,7 +65,7 @@ public class PayLoyaltyCost extends CostImpl { @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { 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) { planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount)); } else if (amount < 0) { diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java index 4815c0f8bc..d693b46363 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java @@ -43,6 +43,7 @@ import java.util.Set; import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.ActivatedAbility; import mage.abilities.MageSingleton; import mage.abilities.SpellAbility; import mage.abilities.StaticAbility; @@ -743,6 +744,9 @@ public class ContinuousEffects implements Serializable { if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) { effect.setValue("targetAbility", targetAbility); if (effect.applies(event, sourceAbility, game)) { + if (targetAbility instanceof ActivatedAbility && ((ActivatedAbility) targetAbility).isCheckPlayableMode()) { + checkPlayableMode = true; + } if (!checkPlayableMode) { String message = effect.getInfoMessage(sourceAbility, event, game); if (message != null && !message.isEmpty()) { diff --git a/Mage/src/main/java/mage/abilities/effects/PlaneswalkerRedirectionEffect.java b/Mage/src/main/java/mage/abilities/effects/PlaneswalkerRedirectionEffect.java index e435a88f4c..be713663ad 100644 --- a/Mage/src/main/java/mage/abilities/effects/PlaneswalkerRedirectionEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/PlaneswalkerRedirectionEffect.java @@ -88,10 +88,10 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect { player.choose(Outcome.Damage, redirectTarget, null, game); } if (!game.isSimulation()) { - game.informPlayers(new StringBuilder(player.getLogName()).append(" redirects ") - .append(event.getAmount()) - .append(" damage to ") - .append(game.getPermanent(redirectTarget.getFirstTarget()).getLogName()).toString()); + Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget()); + if (redirectTo != null) { + game.informPlayers(player.getLogName() + " redirects " + event.getAmount() + " damage to " + redirectTo.getLogName()); + } } return true; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/CounterTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CounterTargetEffect.java index ea1c987bb9..c569241ae6 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/CounterTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/CounterTargetEffect.java @@ -69,6 +69,6 @@ public class CounterTargetEffect extends OneShotEffect { if (staticText != null && !staticText.isEmpty()) { return staticText; } - return "counter target " + mode.getTargets().get(0).getTargetName(); + return "counter target " + (mode.getTargets().get(0) != null ? mode.getTargets().get(0).getTargetName() : "spell"); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/EpicEffect.java b/Mage/src/main/java/mage/abilities/effects/common/EpicEffect.java index e3456a7681..0b6b895c50 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/EpicEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/EpicEffect.java @@ -34,7 +34,7 @@ import mage.players.Player; */ public class EpicEffect extends OneShotEffect { - final String rule = "

Epic (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 = "
Epic (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() { super(Outcome.Benefit); diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index 91c735bf9c..2177aaab12 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -553,7 +553,7 @@ public class StackAbility extends StackObjImpl implements Ability { @Override public int getSourceObjectZoneChangeCounter() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported."); } @Override @@ -563,7 +563,7 @@ public class StackAbility extends StackObjImpl implements Ability { @Override public int getZoneChangeCounter(Game game) { - throw new UnsupportedOperationException("Not supported."); + return game.getState().getZoneChangeCounter(getSourceId()); } @Override diff --git a/Mage/src/main/java/mage/game/stack/StackObjImpl.java b/Mage/src/main/java/mage/game/stack/StackObjImpl.java index 447b1a00c5..ea35138898 100644 --- a/Mage/src/main/java/mage/game/stack/StackObjImpl.java +++ b/Mage/src/main/java/mage/game/stack/StackObjImpl.java @@ -209,33 +209,35 @@ public abstract class StackObjImpl implements StackObject { } else { again = true; } - } 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 (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) { - if (targetController.isHuman()) { - game.informPlayer(targetController, "This target was already selected from origin spell. You can only keep this target!"); - 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 (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) { + if (targetController.isHuman()) { + 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 if (!target.canTarget(getControllerId(), tempTarget.getFirstTarget(), ability, game)) { - if (targetController.isHuman()) { - game.informPlayer(targetController, "This target is not valid!"); - again = true; } else { - // keep the old - newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); - } - } else if (newTarget.getFirstTarget() != null && filterNewTarget != null) { - Permanent newTargetPermanent = game.getPermanent(newTarget.getFirstTarget()); - if (newTargetPermanent == null || !filterNewTarget.match(newTargetPermanent, game)) { - game.informPlayer(targetController, "This target does not fullfil the target requirements (" + filterNewTarget.getMessage() + ")"); again = true; } } else { - // valid target was selected, add it to the new target definition - newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false); + newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); } + } else if (!target.canTarget(getControllerId(), tempTarget.getFirstTarget(), ability, game)) { + if (targetController.isHuman()) { + game.informPlayer(targetController, "This target is not valid!"); + again = true; + } else { + // keep the old + newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + } + } else if (newTarget.getFirstTarget() != null && filterNewTarget != null) { + Permanent newTargetPermanent = game.getPermanent(newTarget.getFirstTarget()); + if (newTargetPermanent == null || !filterNewTarget.match(newTargetPermanent, game)) { + game.informPlayer(targetController, "This target does not fullfil the target requirements (" + filterNewTarget.getMessage() + ")"); + again = true; + } + } else { + // valid target was selected, add it to the new target definition + newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false); } } while (again && targetController.canRespond()); } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 301900b70c..51d6b13b97 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -898,7 +898,7 @@ public abstract class PlayerImpl implements Player, Serializable { */ @Override 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 UUID sourceId = (source == null ? null : source.getSourceId()); if (!anyOrder) { @@ -982,6 +982,9 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean cast(SpellAbility ability, Game game, boolean noMana) { + if (game == null || ability == null) { + return false; + } if (!ability.getSpellAbilityType().equals(SpellAbilityType.BASE)) { ability = chooseSpellAbilityForCast(ability, game, noMana); }