From 589b63c5b1e974d42e4101a795b10a5b52fa51e4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 20:48:32 +0200 Subject: [PATCH 1/6] Fix for the "Modal Window bug under Linux (e.g. X value announcement) by Nidhoegger. --- .../main/java/mage/client/dialog/MageDialog.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java index 36bba61e1a..35eee6e10e 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java @@ -39,7 +39,6 @@ import java.awt.Component; import java.awt.EventQueue; import java.awt.KeyboardFocusManager; import java.awt.MenuComponent; -import java.awt.TrayIcon; import java.awt.event.MouseEvent; import java.beans.PropertyVetoException; import java.lang.reflect.InvocationTargetException; @@ -54,7 +53,7 @@ import org.apache.log4j.Logger; * @author BetaSteward_at_googlemail.com */ public class MageDialog extends javax.swing.JInternalFrame { - + private static final Logger logger = Logger.getLogger(MageDialog.class); protected boolean modal = false; @@ -119,10 +118,11 @@ public class MageDialog extends javax.swing.JInternalFrame { Object source = event.getSource(); boolean dispatch = true; - if (event.getSource() != null && event.getSource() instanceof TrayIcon) { - return; - } - + // LINUX: Workaround fix for announce X Value Bug that closes modal windows under linux before values can be entered + // https://github.com/magefree/mage/issues/584 +// if (event.getSource() != null && event.getSource() instanceof TrayIcon) { +// return; +// } if (event instanceof MouseEvent && event.getSource() instanceof Component) { MouseEvent e = (MouseEvent) event; MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this); @@ -226,7 +226,6 @@ public class MageDialog extends javax.swing.JInternalFrame { pack(); }// //GEN-END:initComponents - // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables } From 27e62a07a391d8609445afba04511d32e2513910 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 20:53:48 +0200 Subject: [PATCH 2/6] * Divine Reckoning - Fixed that the permanents to chose were handled targeted. --- .../mage/sets/innistrad/DivineReckoning.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java b/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java index 90b7cc12ee..e6b2260326 100644 --- a/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java +++ b/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java @@ -27,30 +27,27 @@ */ package mage.sets.innistrad; -import mage.constants.CardType; -import mage.constants.Rarity; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.FlashbackAbility; import mage.cards.Card; import mage.cards.CardImpl; +import mage.constants.CardType; import mage.constants.Outcome; -import mage.constants.TargetController; +import mage.constants.Rarity; import mage.constants.TimingRule; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; import mage.target.common.TargetControlledPermanent; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import mage.filter.common.FilterControlledCreaturePermanent; - /** * @author nantuko */ @@ -78,7 +75,7 @@ public class DivineReckoning extends CardImpl { } class DivineReckoningEffect extends OneShotEffect { - + public DivineReckoningEffect() { super(Outcome.DestroyPermanent); staticText = "Each player chooses a creature he or she controls. Destroy the rest"; @@ -93,10 +90,10 @@ class DivineReckoningEffect extends OneShotEffect { List chosen = new ArrayList<>(); Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - for (UUID playerId : controller.getInRange()) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); - Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), false); + Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true); if (target.canChoose(player.getId(), game)) { while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target, source, game); From 7375ba281953dd205f5ca13233a5f2717afdd92e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 21:24:18 +0200 Subject: [PATCH 3/6] * Delaying Shield - Fixed that always only 1 counter was removed but all had to be paid. --- .../src/mage/sets/odyssey/DelayingShield.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java b/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java index 28330c160d..188a4374f4 100644 --- a/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java +++ b/Mage.Sets/src/mage/sets/odyssey/DelayingShield.java @@ -62,10 +62,9 @@ public class DelayingShield extends CardImpl { super(ownerId, 17, "Delaying Shield", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}"); this.expansionSetCode = "ODY"; - // If damage would be dealt to you, put that many delay counters on Delaying Shield instead. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DelayingShieldReplacementEffect())); - + // At the beginning of your upkeep, remove all delay counters from Delaying Shield. For each delay counter removed this way, you lose 1 life unless you pay {1}{W}. this.addAbility(new BeginningOfUpkeepTriggeredAbility(new DelayingShieldUpkeepEffect(), TargetController.YOU, false)); } @@ -81,7 +80,7 @@ public class DelayingShield extends CardImpl { } class DelayingShieldReplacementEffect extends ReplacementEffectImpl { - + DelayingShieldReplacementEffect() { super(Duration.WhileOnBattlefield, Outcome.PreventDamage); staticText = "If damage would be dealt to you, put that many delay counters on {this} instead"; @@ -94,7 +93,7 @@ class DelayingShieldReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { DamageEvent damageEvent = (DamageEvent) event; - new AddCountersSourceEffect(CounterType.DELAY.createInstance(damageEvent.getAmount())).apply(game, source); + new AddCountersSourceEffect(CounterType.DELAY.createInstance(damageEvent.getAmount()), true).apply(game, source); return true; } @@ -102,7 +101,7 @@ class DelayingShieldReplacementEffect extends ReplacementEffectImpl { public boolean checksEventType(GameEvent event, Game game) { return event.getType() == EventType.DAMAGE_PLAYER; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { return event.getTargetId().equals(source.getControllerId()); @@ -115,30 +114,30 @@ class DelayingShieldReplacementEffect extends ReplacementEffectImpl { } class DelayingShieldUpkeepEffect extends OneShotEffect { - + DelayingShieldUpkeepEffect() { super(Outcome.Benefit); this.staticText = "remove all delay counters from {this}. For each delay counter removed this way, you lose 1 life unless you pay {1}{W}"; } - + DelayingShieldUpkeepEffect(final DelayingShieldUpkeepEffect effect) { super(effect); } - + @Override public DelayingShieldUpkeepEffect copy() { return new DelayingShieldUpkeepEffect(this); } - + @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); + Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); - if (player != null && permanent != null) { + if (controller != null && permanent != null) { int numCounters = permanent.getCounters().getCount(CounterType.DELAY); - permanent.removeCounters(CounterType.DELAY.createInstance(), game); + permanent.removeCounters(CounterType.DELAY.createInstance(numCounters), game); for (int i = numCounters; i > 0; i--) { - if (player.chooseUse(Outcome.Benefit, "Pay {1}{W}? (" + i + " counters left to pay)", source, game)) { + if (controller.chooseUse(Outcome.Benefit, "Pay {1}{W}? (" + i + " counters left to pay)", source, game)) { Cost cost = new ManaCostsImpl<>("{1}{W}"); if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false)) { continue; From 7b4f2dd33a1e372e92a87f98a0ef0598e9f69e3d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 21:53:28 +0200 Subject: [PATCH 4/6] * Added a bestow test. --- .../cards/abilities/keywords/BestowTest.java | 170 +++++++++++------- 1 file changed, 109 insertions(+), 61 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java index b2a1690abd..584008d440 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/BestowTest.java @@ -25,7 +25,6 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package org.mage.test.cards.abilities.keywords; import mage.constants.CardType; @@ -44,9 +43,9 @@ import org.mage.test.serverside.base.CardTestPlayerBase; public class BestowTest extends CardTestPlayerBase { /** - * Tests that if from bestow permanent targeted creature - * gets protection from the color of the bestow permanent, - * the bestow permanent becomes a creature on the battlefield. + * Tests that if from bestow permanent targeted creature gets protection + * from the color of the bestow permanent, the bestow permanent becomes a + * creature on the battlefield. * */ @@ -67,7 +66,6 @@ public class BestowTest extends CardTestPlayerBase { * Scry 1. (Look at the top card of your library. You may put that card on the bottom of your library.) * */ - @Test public void bestowEnchantmentToCreature() { addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); @@ -97,7 +95,7 @@ public class BestowTest extends CardTestPlayerBase { addCard(Zone.BATTLEFIELD, playerA, "Forest", 6); // Creature - Giant 3/5 addCard(Zone.BATTLEFIELD, playerA, "Silent Artisan"); - + addCard(Zone.HAND, playerA, "Experiment One"); // Enchanted creature gets +4/+2. addCard(Zone.HAND, playerA, "Boon Satyr"); @@ -111,26 +109,27 @@ public class BestowTest extends CardTestPlayerBase { // because Boon Satyr is no creature on the battlefield, evolve may not trigger assertPermanentCount(playerA, "Boon Satyr", 1); Permanent boonSatyr = getPermanent("Boon Satyr", playerA); - Assert.assertTrue("Boon Satyr may not be a creature",!boonSatyr.getCardType().contains(CardType.CREATURE)); + Assert.assertTrue("Boon Satyr may not be a creature", !boonSatyr.getCardType().contains(CardType.CREATURE)); assertPermanentCount(playerA, "Silent Artisan", 1); assertPermanentCount(playerA, "Experiment One", 1); assertPowerToughness(playerA, "Experiment One", 1, 1); - assertPowerToughness(playerA, "Silent Artisan", 7, 7); - + assertPowerToughness(playerA, "Silent Artisan", 7, 7); + } - + /** - * Test that the bestow enchantment becomes a creature if the enchanted creature dies + * Test that the bestow enchantment becomes a creature if the enchanted + * creature dies */ @Test public void bestowEnchantmentBecomesCreature() { addCard(Zone.BATTLEFIELD, playerA, "Plains", 4); - addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); addCard(Zone.HAND, playerA, "Hopeful Eidolon"); - + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); addCard(Zone.HAND, playerB, "Lightning Bolt"); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Hopeful Eidolon using bestow", "Silvercoat Lion"); castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Silvercoat Lion"); @@ -140,7 +139,7 @@ public class BestowTest extends CardTestPlayerBase { // because Boon Satyr is no creature on the battlefield, evolve may not trigger assertLife(playerA, 20); assertLife(playerB, 20); - + assertPermanentCount(playerA, "Silvercoat Lion", 0); assertPermanentCount(playerA, "Hopeful Eidolon", 1); assertPowerToughness(playerA, "Hopeful Eidolon", 1, 1); @@ -149,23 +148,23 @@ public class BestowTest extends CardTestPlayerBase { Assert.assertTrue("Hopeful Eidolon has to be a creature but is not", hopefulEidolon.getCardType().contains(CardType.CREATURE)); Assert.assertTrue("Hopeful Eidolon has to be an enchantment but is not", hopefulEidolon.getCardType().contains(CardType.ENCHANTMENT)); - } - + /** - * Test that card cast with bestow will not be tapped, if creatures come into play tapped + * Test that card cast with bestow will not be tapped, if creatures come + * into play tapped */ @Test public void bestowEnchantmentWillNotBeTapped() { addCard(Zone.BATTLEFIELD, playerA, "Forest", 6); addCard(Zone.BATTLEFIELD, playerA, "Silent Artisan"); - + addCard(Zone.HAND, playerA, "Boon Satyr"); - + // Enchantment {1}{W} // Creatures your opponents control enter the battlefield tapped. addCard(Zone.BATTLEFIELD, playerB, "Imposing Sovereign"); - + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Boon Satyr using bestow", "Silent Artisan"); setStopAt(1, PhaseStep.END_TURN); @@ -176,34 +175,32 @@ public class BestowTest extends CardTestPlayerBase { assertPowerToughness(playerA, "Silent Artisan", 7, 7); // because cast with bestow, Boon Satyr may not be tapped assertTapped("Boon Satyr", false); - - } - + + } + /** - * If I have a bestowed creature on the battlefield and my opponent uses Far // Away casting - * both sides, will the creature that has bestow come in time for it to be sacrificed or does - * it fully resolve before the creature comes in? - * + * If I have a bestowed creature on the battlefield and my opponent uses Far + * // Away casting both sides, will the creature that has bestow come in + * time for it to be sacrificed or does it fully resolve before the creature + * comes in? + * * Bestowed creature can be used to sacrifice a creature for the Away part. * http://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/513828-bestow-far-away - */ + */ @Test @Ignore // Handling of targets of Fused spells is not handled yet in TestPlayer class public void bestowWithFusedSpell() { addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); /** - * Cyclops of One-Eyed Pass {2}{R}{R} - * Creature - Cyclops - * 5/2 + * Cyclops of One-Eyed Pass {2}{R}{R} Creature - Cyclops 5/2 */ addCard(Zone.BATTLEFIELD, playerA, "Cyclops of One-Eyed Pass"); - + /** - * Nyxborn Rollicker {R} - * Enchantment Creature - Satyr - * 1/1 - * Bestow {1}{R} (If you cast this card for its bestow cost, it's an Aura spell with enchant creature. It becomes a creature again if it's not attached to a creature.) - * Enchanted creature gets +1/+1. + * Nyxborn Rollicker {R} Enchantment Creature - Satyr 1/1 Bestow {1}{R} + * (If you cast this card for its bestow cost, it's an Aura spell with + * enchant creature. It becomes a creature again if it's not attached to + * a creature.) Enchanted creature gets +1/+1. */ addCard(Zone.HAND, playerA, "Nyxborn Rollicker"); @@ -211,18 +208,14 @@ public class BestowTest extends CardTestPlayerBase { addCard(Zone.BATTLEFIELD, playerB, "Island", 2); /** - * Far {1}{U} - * Instant - * Return target creature to its owner's hand. - * Away {2}{B} - * Instant - * Target player sacrifices a creature. - * Fuse (You may cast one or both halves of this card from your hand.) - */ + * Far {1}{U} Instant Return target creature to its owner's hand. Away + * {2}{B} Instant Target player sacrifices a creature. Fuse (You may + * cast one or both halves of this card from your hand.) + */ addCard(Zone.HAND, playerB, "Far // Away"); - + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nyxborn Rollicker using bestow", "Cyclops of One-Eyed Pass"); - + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "fused Far // Away", "Cyclops of One-Eyed Pass^targetPlayer=PlayerA"); playerA.addTarget("Nyxborn Rollicker"); @@ -231,18 +224,18 @@ public class BestowTest extends CardTestPlayerBase { assertHandCount(playerA, 0); assertHandCount(playerB, 0); - + assertGraveyardCount(playerB, "Far // Away", 1); - + assertPermanentCount(playerA, "Nyxborn Rollicker", 0); assertGraveyardCount(playerA, "Nyxborn Rollicker", 1); - + } /** - * Test that CMC of a spell cast with bestowed is correct - * Disdainful Stroke doesn't check converted mana cost correctly. Opponent was - * able to use it to counter a Hypnotic Siren cast with Bestow. + * Test that CMC of a spell cast with bestowed is correct Disdainful Stroke + * doesn't check converted mana cost correctly. Opponent was able to use it + * to counter a Hypnotic Siren cast with Bestow. */ @Test public void bestowCheckForCorrectCMC() { @@ -275,14 +268,14 @@ public class BestowTest extends CardTestPlayerBase { // because cast with bestow, Boon Satyr may not be tapped assertPermanentCount(playerA, "Silvercoat Lion", 1); - assertPowerToughness(playerA, "Silvercoat Lion", 3,3); + assertPowerToughness(playerA, "Silvercoat Lion", 3, 3); } - - /** - * - * - * + + /** + * + * + * */ @Test public void bestowMogissWarhound() { @@ -311,5 +304,60 @@ public class BestowTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Mogis's Warhound", 1); assertGraveyardCount(playerA, "Silvercoat Lion", 1); - } + } + + /* + * Bug with the Nighthowler Card. Card does sometimes not get a creature + * after Bestow. + + Steps: + 1) Cast any creature + 2) Cast Nightowler using Bestow on that creature + 3) Make sure creature is tapped + 4) Opponent uses any spell that kills creature which is bestowed by nighthowler + 5) Result: Nighthowler is still on the field, but is no creature (no Power/Toughness) + + Expected:Nighthowler gets on field as a creature + + Important: This happens ONLY if the creature is killed with a spell when + its TAPPED! + + */ + @Test + public void bestowNighthowlerTest() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4); + // Instant - {2}{R}{R} + // Chandra's Outrage deals 4 damage to target creature and 2 damage to that creature's controller. + addCard(Zone.HAND, playerA, "Chandra's Outrage"); + + // Enchantment Creature — Horror + // 0/0 + // Bestow {2}{B}{B} + // Nighthowler and enchanted creature each get +X/+X, where X is the number of creature cards in all graveyards. + addCard(Zone.HAND, playerB, "Nighthowler"); + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 4); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + addCard(Zone.GRAVEYARD, playerB, "Pillarfield Ox"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Nighthowler using bestow", "Silvercoat Lion"); + + attack(2, playerB, "Silvercoat Lion"); + + castSpell(2, PhaseStep.POSTCOMBAT_MAIN, playerA, "Chandra's Outrage", "Silvercoat Lion"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertLife(playerB, 18); // -2 from Chandra's Outrage + assertLife(playerA, 17); // -3 from attack Nighthowler + + assertGraveyardCount(playerA, "Chandra's Outrage", 1); + assertGraveyardCount(playerB, "Silvercoat Lion", 1); + assertPermanentCount(playerB, "Nighthowler", 1); + assertPowerToughness(playerB, "Nighthowler", 2, 2); + Permanent nighthowler = getPermanent("Nighthowler", playerB); + + Assert.assertEquals("Nighthowler has to be a creature", true, nighthowler.getCardType().contains(CardType.CREATURE)); + + } } From 1a458a083742d323374737a7473f55c962657327 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 22:33:40 +0200 Subject: [PATCH 5/6] * Gilded Drake - Fixed that the Drake had not to be sacrificed if the control did not happen. --- .../src/mage/sets/urzassaga/GildedDrake.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java b/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java index 1526087944..e499027f15 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java +++ b/Mage.Sets/src/mage/sets/urzassaga/GildedDrake.java @@ -55,11 +55,11 @@ import mage.target.common.TargetCreaturePermanent; public class GildedDrake extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature an opponent controls"); - + static { filter.add(new ControllerPredicate(TargetController.OPPONENT)); } - + public GildedDrake(UUID ownerId) { super(ownerId, 76, "Gilded Drake", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{U}"); this.expansionSetCode = "USG"; @@ -72,8 +72,8 @@ public class GildedDrake extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // When Gilded Drake enters the battlefield, exchange control of Gilded Drake and up to one target creature an opponent controls. If you don't make an exchange, sacrifice Gilded Drake. This ability can't be countered except by spells and abilities. Ability ability = new EntersBattlefieldTriggeredAbility(new GildedDrakeEffect()); - ability.addTarget(new TargetCreaturePermanent(0,1,filter, false)); - this.addAbility(ability); + ability.addTarget(new TargetCreaturePermanent(0, 1, filter, false)); + this.addAbility(ability); } public GildedDrake(final GildedDrake card) { @@ -87,21 +87,21 @@ public class GildedDrake extends CardImpl { } class GildedDrakeEffect extends OneShotEffect { - + public GildedDrakeEffect() { super(Outcome.GainControl); this.staticText = "exchange control of {this} and up to one target creature an opponent controls. If you don't make an exchange, sacrifice {this}. This ability can't be countered except by spells and abilities"; } - + public GildedDrakeEffect(final GildedDrakeEffect effect) { super(effect); } - + @Override public GildedDrakeEffect copy() { return new GildedDrakeEffect(this); } - + @Override public boolean apply(Game game, Ability source) { Permanent sourceObject = game.getPermanent(source.getSourceId()); @@ -111,13 +111,13 @@ class GildedDrakeEffect extends OneShotEffect { if (targetPointer.getFirst(game, source) != null) { targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); if (targetPermanent != null) { - ContinuousEffect effect = new ExchangeControlTargetEffect(Duration.EndOfGame, "", true); + ContinuousEffect effect = new ExchangeControlTargetEffect(Duration.EndOfGame, "", true); effect.setTargetPointer(targetPointer); game.addEffect(effect, source); - } else { - sourceObject.sacrifice(source.getSourceId(), game); + return true; } } + sourceObject.sacrifice(source.getSourceId(), game); return true; } return false; From 4aebcd23990ab8ac539370cf7f6f63ec4e852ab4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 2 Jul 2015 23:38:37 +0200 Subject: [PATCH 6/6] * Savage Summoning - Fixed that it did not work to cast a commander from command zone. --- .../mage/sets/magic2014/SavageSummoning.java | 76 +++++++++-------- Mage.Tests/Power Hungry.dck | 84 +++++++++++++++++++ .../commander/duel/CastBRGCommanderTest.java | 72 ++++++++++++++++ 3 files changed, 199 insertions(+), 33 deletions(-) create mode 100644 Mage.Tests/Power Hungry.dck create mode 100644 Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java diff --git a/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java b/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java index 6e1407ba2d..fc7db630f2 100644 --- a/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java +++ b/Mage.Sets/src/mage/sets/magic2014/SavageSummoning.java @@ -49,6 +49,7 @@ import mage.constants.Rarity; import mage.constants.WatcherScope; import mage.counters.CounterType; import mage.game.Game; +import mage.game.command.Commander; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; @@ -65,13 +66,12 @@ public class SavageSummoning extends CardImpl { super(ownerId, 194, "Savage Summoning", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{G}"); this.expansionSetCode = "M14"; - // Savage Summoning can't be countered. Ability ability = new CantBeCounteredAbility(); ability.setRuleAtTheTop(true); this.addAbility(ability); - // The next creature card you cast this turn can be cast as though it had flash. + // The next creature card you cast this turn can be cast as though it had flash. // That spell can't be countered. That creature enters the battlefield with an additional +1/+1 counter on it. this.getSpellAbility().addEffect(new SavageSummoningAsThoughEffect()); this.getSpellAbility().addEffect(new SavageSummoningCantCounterEffect()); @@ -91,6 +91,7 @@ public class SavageSummoning extends CardImpl { } class SavageSummoningAsThoughEffect extends AsThoughEffectImpl { + private SavageSummoningWatcher watcher; private int zoneChangeCounter; @@ -107,13 +108,13 @@ class SavageSummoningAsThoughEffect extends AsThoughEffectImpl { @Override public void init(Ability source, Game game) { - watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); - Card card = game.getCard(source.getSourceId()); - if (watcher != null && card != null) { - watcher.setSavageSummoningSpellActive(card, game); - } else { - throw new IllegalArgumentException("Consume Savage watcher could not be found"); - } + watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); + Card card = game.getCard(source.getSourceId()); + if (watcher != null && card != null) { + watcher.setSavageSummoningSpellActive(card, game); + } else { + throw new IllegalArgumentException("Consume Savage watcher could not be found"); + } } @Override @@ -126,13 +127,20 @@ class SavageSummoningAsThoughEffect extends AsThoughEffectImpl { return new SavageSummoningAsThoughEffect(this); } - @Override - public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { + public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { if (watcher.isSavageSummoningSpellActive()) { - Card card = game.getCard(sourceId); - if (card != null && card.getCardType().contains(CardType.CREATURE) && card.getOwnerId().equals(source.getControllerId())) { - return card.getSpellAbility().isInUseableZone(game, card, null); + MageObject mageObject = game.getBaseObject(objectId); + if (mageObject instanceof Commander) { + Commander commander = (Commander) mageObject; + if (commander.getCardType().contains(CardType.CREATURE) && commander.getControllerId().equals(source.getControllerId())) { + return true; + } + } else if (mageObject != null && mageObject instanceof Card) { + Card card = (Card) mageObject; + if (card.getCardType().contains(CardType.CREATURE) && card.getOwnerId().equals(source.getControllerId())) { + return true; + } } } return false; @@ -140,10 +148,10 @@ class SavageSummoningAsThoughEffect extends AsThoughEffectImpl { } - class SavageSummoningWatcher extends Watcher { - private Set savageSummoningSpells = new HashSet<>();; + private Set savageSummoningSpells = new HashSet<>(); + ; private Map> spellsCastWithSavageSummoning = new LinkedHashMap<>(); private Map> cardsCastWithSavageSummoning = new LinkedHashMap<>(); @@ -154,10 +162,10 @@ class SavageSummoningWatcher extends Watcher { public SavageSummoningWatcher(final SavageSummoningWatcher watcher) { super(watcher); this.savageSummoningSpells.addAll(watcher.savageSummoningSpells); - for (Entry> entry :watcher.spellsCastWithSavageSummoning.entrySet()) { + for (Entry> entry : watcher.spellsCastWithSavageSummoning.entrySet()) { this.spellsCastWithSavageSummoning.put(entry.getKey(), entry.getValue()); } - for (Entry> entry :watcher.cardsCastWithSavageSummoning.entrySet()) { + for (Entry> entry : watcher.cardsCastWithSavageSummoning.entrySet()) { this.cardsCastWithSavageSummoning.put(entry.getKey(), entry.getValue()); } } @@ -172,7 +180,7 @@ class SavageSummoningWatcher extends Watcher { if (event.getType() == GameEvent.EventType.SPELL_CAST) { if (isSavageSummoningSpellActive() && event.getPlayerId().equals(getControllerId())) { Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && spell.getCardType().contains(CardType.CREATURE)) { + if (spell != null && spell.getCardType().contains(CardType.CREATURE)) { spellsCastWithSavageSummoning.put(spell.getId(), new HashSet<>(savageSummoningSpells)); String cardKey = new StringBuilder(spell.getCard().getId().toString()).append("_").append(spell.getCard().getZoneChangeCounter(game)).toString(); cardsCastWithSavageSummoning.put(cardKey, new HashSet<>(savageSummoningSpells)); @@ -198,7 +206,7 @@ class SavageSummoningWatcher extends Watcher { } public boolean isCardCastWithThisSavageSummoning(Card card, UUID cardId, int zoneChangeCounter, Game game) { - String creatureCardKey = new StringBuilder(card.getId().toString()).append("_").append(card.getZoneChangeCounter(game)-1).toString(); + String creatureCardKey = new StringBuilder(card.getId().toString()).append("_").append(card.getZoneChangeCounter(game) - 1).toString(); // add one because card is now gone to battlefield as creature String cardKey = new StringBuilder(cardId.toString()).append("_").append(zoneChangeCounter).toString(); HashSet savageSpells = (HashSet) cardsCastWithSavageSummoning.get(creatureCardKey); @@ -216,6 +224,7 @@ class SavageSummoningWatcher extends Watcher { } class SavageSummoningCantCounterEffect extends ContinuousRuleModifyingEffectImpl { + private SavageSummoningWatcher watcher; private int zoneChangeCounter; @@ -232,12 +241,12 @@ class SavageSummoningCantCounterEffect extends ContinuousRuleModifyingEffectImpl @Override public void init(Ability source, Game game) { - watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); - Card card = game.getCard(source.getSourceId()); - if (watcher == null || card == null) { - throw new IllegalArgumentException("Consume Savage watcher or card could not be found"); - } - this.zoneChangeCounter = card.getZoneChangeCounter(game); + watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); + Card card = game.getCard(source.getSourceId()); + if (watcher == null || card == null) { + throw new IllegalArgumentException("Consume Savage watcher or card could not be found"); + } + this.zoneChangeCounter = card.getZoneChangeCounter(game); } @Override @@ -273,6 +282,7 @@ class SavageSummoningCantCounterEffect extends ContinuousRuleModifyingEffectImpl } class SavageSummoningEntersBattlefieldEffect extends ReplacementEffectImpl { + private SavageSummoningWatcher watcher; private int zoneChangeCounter; @@ -289,12 +299,12 @@ class SavageSummoningEntersBattlefieldEffect extends ReplacementEffectImpl { @Override public void init(Ability source, Game game) { - watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); - Card card = game.getCard(source.getSourceId()); - if (watcher == null || card == null) { - throw new IllegalArgumentException("Consume Savage watcher or card could not be found"); - } - this.zoneChangeCounter = card.getZoneChangeCounter(game); + watcher = (SavageSummoningWatcher) game.getState().getWatchers().get("consumeSavageSummoningWatcher", source.getControllerId()); + Card card = game.getCard(source.getSourceId()); + if (watcher == null || card == null) { + throw new IllegalArgumentException("Consume Savage watcher or card could not be found"); + } + this.zoneChangeCounter = card.getZoneChangeCounter(game); } @Override @@ -316,7 +326,7 @@ class SavageSummoningEntersBattlefieldEffect extends ReplacementEffectImpl { public boolean checksEventType(GameEvent event, Game game) { return event.getType() == EventType.ENTERS_THE_BATTLEFIELD; } - + @Override public boolean applies(GameEvent event, Ability source, Game game) { Card card = game.getCard(event.getTargetId()); diff --git a/Mage.Tests/Power Hungry.dck b/Mage.Tests/Power Hungry.dck new file mode 100644 index 0000000000..ddabd22311 --- /dev/null +++ b/Mage.Tests/Power Hungry.dck @@ -0,0 +1,84 @@ +NAME:Power Hungry +7 [THS:246] Forest +1 [C13:78] Fell Shepherd +1 [C13:76] Endrek Sahr, Master Breeder +1 [C13:75] Endless Cockroaches +7 [THS:242] Mountain +1 [C13:73] Dirge of Dread +1 [C13:219] Sprouting Thrinax +1 [C13:259] Sol Ring +1 [C13:138] Brooding Saurian +1 [C13:335] Vivid Grove +1 [C13:213] Shattergang Brothers +1 [C13:254] Plague Boiler +1 [C13:210] Sek'Kuar, Deathkeeper +1 [C13:298] Jund Panorama +1 [C13:252] Obelisk of Jund +1 [C13:175] Walker of the Grove +1 [C13:131] Widespread Panic +1 [C13:294] Gruul Guildgate +1 [C13:172] Spoils of Victory +1 [C13:292] Grim Backwoods +1 [C13:291] Golgari Rot Farm +1 [C13:80] Hooded Horror +1 [C13:290] Golgari Guildgate +1 [C13:84] Ophiomancer +1 [C13:109] Furnace Celebration +1 [C13:229] Golgari Guildmage +6 [THS:238] Swamp +1 [C13:304] Llanowar Reborn +1 [C13:149] Hua Tuo, Honored Physician +1 [C13:105] Curse of Chaos +1 [C13:303] Kher Keep +1 [C13:302] Khalni Garden +1 [C13:301] Kazandu Refuge +1 [C13:102] Capricious Efreet +1 [C13:146] Foster +1 [C13:101] Blood Rites +1 [C13:145] Fecundity +1 [C13:100] Wight of Precinct Six +1 [C13:143] Elvish Skysweeper +1 [C13:263] Swiftfoot Boots +1 [C13:185] Deepfire Elemental +1 [C13:184] Deathbringer Thoctar +1 [C13:140] Curse of Predation +1 [C13:260] Spine of Ish Sah +1 [C13:93] Stronghold Assassin +1 [C13:180] Charnelhoard Wurm +1 [C13:90] Quagmire Druid +1 [C13:99] Viscera Seer +1 [C13:98] Vile Requiem +1 [C13:317] Savage Lands +1 [C13:118] Rough // Tumble +1 [C13:315] Rupture Spire +1 [C13:238] Carnage Altar +1 [C13:314] Rakdos Guildgate +1 [C13:116] Mass Mutiny +1 [C13:235] Armillary Sphere +1 [C13:114] Inferno Titan +1 [C13:158] Night Soil +1 [C13:310] Opal Palace +1 [C13:111] Goblin Sharpshooter +1 [C13:110] Goblin Bombardment +1 [C13:272] Akoum Refuge +1 [C13:195] Jund Charm +1 [C13:151] Jade Mage +1 [C13:150] Hunted Troll +1 [C13:209] Scarland Thrinax +1 [C13:328] Terramorphic Expanse +1 [C13:327] Temple of the False God +1 [C13:127] Tooth and Claw +1 [C13:126] Terra Ravager +1 [C13:125] Tempt with Vengeance +1 [C13:169] Silklash Spider +1 [C13:124] Sudden Demise +1 [C13:168] Sakura-Tribe Elder +1 [C13:167] Restore +1 [C13:244] Jar of Eyeballs +1 [C13:166] Reincarnation +1 [C13:287] Evolving Wilds +1 [C13:121] Stalking Vengeance +1 [C13:162] Primal Vigor +1 [C13:71] Curse of Shallow Graves +1 [C13:281] Command Tower +SB: 1 [C13:204] Prossh, Skyraider of Kher diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java new file mode 100644 index 0000000000..b7732e593b --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java @@ -0,0 +1,72 @@ +/* + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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 org.mage.test.commander.duel; + +import java.io.FileNotFoundException; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.GameException; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestCommanderDuelBase; + +/** + * + * @author LevelX2 + */ +public class CastBRGCommanderTest extends CardTestCommanderDuelBase { + + @Override + protected Game createNewGameAndPlayers() throws GameException, FileNotFoundException { + // Flying + // When you cast Prossh, Skyraider of Kher, put X 0/1 red Kobold creature tokens named Kobolds of Kher Keep onto the battlefield, where X is the amount of mana spent to cast Prossh. + // Sacrifice another creature: Prossh gets +1/+0 until end of turn. + setDecknamePlayerA("Power Hungry.dck"); // Commander = Prosssh, Skyrider of Kher {3}{B}{R}{G} + return super.createNewGameAndPlayers(); + } + + @Test + public void castCommanderWithFlash() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerA, "Forest", 5); + + addCard(Zone.HAND, playerA, "Savage Summoning"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Savage Summoning"); + castSpell(1, PhaseStep.BEGIN_COMBAT, playerA, "Prossh, Skyraider of Kher"); + setStopAt(1, PhaseStep.END_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Savage Summoning", 1); + assertPermanentCount(playerA, "Prossh, Skyraider of Kher", 1); + assertPermanentCount(playerA, "Kobolds of Kher Keep", 6); + + } + +}