From 1567c4efe9594845fa47e68c1c8e78793ff19087 Mon Sep 17 00:00:00 2001 From: glerman Date: Sun, 21 Jun 2015 10:10:08 +0300 Subject: [PATCH 01/14] Adding Chronozoa card impl --- Mage.Server/config/init.txt.example | 20 ----- .../src/mage/sets/planarchaos/Chronozoa.java | 83 +++++++++++++++++++ .../mage/sets/returntoravnica/PackRat.java | 44 +--------- .../mage/sets/planarchaos/ChronozoaTest.java | 17 ++++ .../LastTimeCounterRemovedCondition.java | 27 ++++++ .../abilities/effects/CopyCardAffect.java | 51 ++++++++++++ 6 files changed, 180 insertions(+), 62 deletions(-) delete mode 100644 Mage.Server/config/init.txt.example create mode 100644 Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java create mode 100644 Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java create mode 100644 Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java create mode 100644 Mage/src/mage/abilities/effects/CopyCardAffect.java diff --git a/Mage.Server/config/init.txt.example b/Mage.Server/config/init.txt.example deleted file mode 100644 index 8203963155a..00000000000 --- a/Mage.Server/config/init.txt.example +++ /dev/null @@ -1,20 +0,0 @@ -# -# Rename this file to init.txt if you want to start using it -# - -# You may add any card to any zone here -# -# Format: ::: -# -# zone ::= hand | battlefield | graveyard | library -# nickname - Player's name you connect to the game with -# -# -battlefield:player:Forest:3 -graveyard:player:Plains:1 -battlefield:player:Snapsail Glider:1 -battlefield:computer:Island:2 -battlefield:player:Plains:3 -hand:player:Whispersilk Cloak:1 -hand:computer:Lightning Bolt:1 -library:player:Shock:2 diff --git a/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java new file mode 100644 index 00000000000..9824913de3a --- /dev/null +++ b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java @@ -0,0 +1,83 @@ +/* + * 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 mage.sets.planarchaos; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.common.DiesCreatureTriggeredAbility; +import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.condition.common.LastTimeCounterRemovedCondition; +import mage.abilities.decorator.ConditionalTriggeredAbility; +import mage.abilities.effects.CopyCardAffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.abilities.keyword.FlyingAbility; +import mage.abilities.keyword.VanishingSacrificeAbility; +import mage.abilities.keyword.VanishingUpkeepAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.counters.CounterType; + +/** + * + * @author Gal Lerman + + */ +public class Chronozoa extends CardImpl { + + private static final int timeCounters = 3; + private static final int numCopies = 2; + + public Chronozoa(UUID ownerId) { + super(ownerId, 37, "Chronozoa", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{3}{U}"); + this.expansionSetCode = "PLC"; + this.subtype.add("Illusion"); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // Flying + this.addAbility(FlyingAbility.getInstance()); + // Vanishing 3 + this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.TIME.createInstance(timeCounters)))); + this.addAbility(new VanishingUpkeepAbility(timeCounters)); + this.addAbility(new VanishingSacrificeAbility()); + // When Chronozoa is put into a graveyard from play, if it had no time counters on it, put two tokens into play that are copies of it. + this.addAbility(new ConditionalTriggeredAbility(new DiesCreatureTriggeredAbility(new CopyCardAffect(this, numCopies), false), + new LastTimeCounterRemovedCondition(), + "When Chronozoa is put into a graveyard from play, if it had no time counters on it, put two tokens into play that are copies of it.")); + } + + public Chronozoa(final Chronozoa card) { + super(card); + } + + @Override + public Chronozoa copy() { + return new Chronozoa(this); + } +} diff --git a/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java b/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java index 451cc8df37c..e5f6e9953da 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java @@ -29,6 +29,7 @@ package mage.sets.returntoravnica; import java.util.UUID; +import mage.abilities.effects.CopyCardAffect; import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.Zone; @@ -39,18 +40,11 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.DiscardCardCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.Duration; -import mage.constants.Outcome; import mage.filter.common.FilterControlledPermanent; import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.game.permanent.token.EmptyToken; -import mage.util.CardUtil; /** * @@ -89,7 +83,7 @@ public class PackRat extends CardImpl { // Pack Rat's power and toughness are each equal to the number of Rats you control. this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetPowerToughnessSourceEffect(new PermanentsOnBattlefieldCount(filter), Duration.EndOfGame))); // {2}{B}, Discard a card: Put a token onto the battlefield that's a copy of Pack Rat. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PackRatEffect(this), new ManaCostsImpl("{2}{B}")); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CopyCardAffect(this, 1), new ManaCostsImpl("{2}{B}")); ability.addCost(new DiscardCardCost()); this.addAbility(ability); } @@ -104,37 +98,3 @@ public class PackRat extends CardImpl { } } -class PackRatEffect extends OneShotEffect { - - private Card card; - - public PackRatEffect(Card card) { - super(Outcome.PutCreatureInPlay); - this.card = card; - staticText = "Put a token onto the battlefield that's a copy of {this}"; - } - - public PackRatEffect(final PackRatEffect effect) { - super(effect); - this.card = effect.card; - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent == null) { - permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - if (permanent != null) { - EmptyToken newToken = new EmptyToken(); - CardUtil.copyTo(newToken).from(permanent); - return newToken.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId()); - } - return false; - } - - @Override - public PackRatEffect copy() { - return new PackRatEffect(this); - } -} diff --git a/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java b/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java new file mode 100644 index 00000000000..e938700073f --- /dev/null +++ b/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java @@ -0,0 +1,17 @@ +package mage.sets.planarchaos; + +import mage.abilities.condition.common.LastTimeCounterRemovedCondition; +import org.junit.Test; + +import java.util.UUID; + +public class ChronozoaTest { + + @Test + public void test() throws Exception { + final Chronozoa chronozoa = new Chronozoa(UUID.randomUUID()); + + final LastTimeCounterRemovedCondition cond = new LastTimeCounterRemovedCondition(); + + } +} diff --git a/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java b/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java new file mode 100644 index 00000000000..b214b86a8e5 --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java @@ -0,0 +1,27 @@ +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * Created by glerman on 20/6/15. + */ +public class LastTimeCounterRemovedCondition implements Condition{ + + + private static final LastTimeCounterRemovedCondition fInstance = new LastTimeCounterRemovedCondition(); + + public static LastTimeCounterRemovedCondition getInstance() { + return fInstance; + } + + @Override + public boolean apply(Game game, Ability source) { + final Permanent p = game.getPermanent(source.getSourceId()); + final int timeCounters = p.getCounters().getCount(CounterType.TIME); + return timeCounters == 0; + } +} diff --git a/Mage/src/mage/abilities/effects/CopyCardAffect.java b/Mage/src/mage/abilities/effects/CopyCardAffect.java new file mode 100644 index 00000000000..9ac38a405f2 --- /dev/null +++ b/Mage/src/mage/abilities/effects/CopyCardAffect.java @@ -0,0 +1,51 @@ +package mage.abilities.effects; + +import mage.abilities.Ability; +import mage.cards.Card; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.EmptyToken; +import mage.util.CardUtil; + +/** + * Created by glerman on 20/6/15. + */ +public class CopyCardAffect extends OneShotEffect { + + private final Card card; + private final int copies; + + public CopyCardAffect(Card card, int copies) { + super(Outcome.PutCreatureInPlay); + this.card = card; + this.copies = copies; + staticText = "Put a token onto the battlefield that's a copy of {this}"; + } + + public CopyCardAffect(final CopyCardAffect effect) { + super(effect); + this.card = effect.card; + this.copies = effect.copies; + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); + } + if (permanent != null) { + EmptyToken newToken = new EmptyToken(); + CardUtil.copyTo(newToken).from(permanent); + return newToken.putOntoBattlefield(copies, game, source.getSourceId(), source.getControllerId()); + } + return false; + } + + @Override + public CopyCardAffect copy() { + return new CopyCardAffect(this); + } +} From 15e3101bf479b9412af9e951dd0a1e7521b30476 Mon Sep 17 00:00:00 2001 From: glerman Date: Sun, 21 Jun 2015 12:26:39 +0300 Subject: [PATCH 02/14] fixed typo --- Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java | 4 ++-- Mage.Sets/src/mage/sets/returntoravnica/PackRat.java | 4 ++-- .../{CopyCardAffect.java => CopyCardEffect.java} | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) rename Mage/src/mage/abilities/effects/{CopyCardAffect.java => CopyCardEffect.java} (84%) diff --git a/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java index 9824913de3a..e8f7e5bfd2d 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java +++ b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java @@ -33,7 +33,7 @@ import mage.abilities.common.DiesCreatureTriggeredAbility; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.condition.common.LastTimeCounterRemovedCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; -import mage.abilities.effects.CopyCardAffect; +import mage.abilities.effects.CopyCardEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.VanishingSacrificeAbility; @@ -67,7 +67,7 @@ public class Chronozoa extends CardImpl { this.addAbility(new VanishingUpkeepAbility(timeCounters)); this.addAbility(new VanishingSacrificeAbility()); // When Chronozoa is put into a graveyard from play, if it had no time counters on it, put two tokens into play that are copies of it. - this.addAbility(new ConditionalTriggeredAbility(new DiesCreatureTriggeredAbility(new CopyCardAffect(this, numCopies), false), + this.addAbility(new ConditionalTriggeredAbility(new DiesCreatureTriggeredAbility(new CopyCardEffect(this, numCopies), false), new LastTimeCounterRemovedCondition(), "When Chronozoa is put into a graveyard from play, if it had no time counters on it, put two tokens into play that are copies of it.")); } diff --git a/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java b/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java index e5f6e9953da..266521195b0 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/PackRat.java @@ -29,7 +29,7 @@ package mage.sets.returntoravnica; import java.util.UUID; -import mage.abilities.effects.CopyCardAffect; +import mage.abilities.effects.CopyCardEffect; import mage.constants.CardType; import mage.constants.Rarity; import mage.constants.Zone; @@ -83,7 +83,7 @@ public class PackRat extends CardImpl { // Pack Rat's power and toughness are each equal to the number of Rats you control. this.addAbility(new SimpleStaticAbility(Zone.ALL, new SetPowerToughnessSourceEffect(new PermanentsOnBattlefieldCount(filter), Duration.EndOfGame))); // {2}{B}, Discard a card: Put a token onto the battlefield that's a copy of Pack Rat. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CopyCardAffect(this, 1), new ManaCostsImpl("{2}{B}")); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CopyCardEffect(this, 1), new ManaCostsImpl("{2}{B}")); ability.addCost(new DiscardCardCost()); this.addAbility(ability); } diff --git a/Mage/src/mage/abilities/effects/CopyCardAffect.java b/Mage/src/mage/abilities/effects/CopyCardEffect.java similarity index 84% rename from Mage/src/mage/abilities/effects/CopyCardAffect.java rename to Mage/src/mage/abilities/effects/CopyCardEffect.java index 9ac38a405f2..3435e707673 100644 --- a/Mage/src/mage/abilities/effects/CopyCardAffect.java +++ b/Mage/src/mage/abilities/effects/CopyCardEffect.java @@ -12,19 +12,19 @@ import mage.util.CardUtil; /** * Created by glerman on 20/6/15. */ -public class CopyCardAffect extends OneShotEffect { +public class CopyCardEffect extends OneShotEffect { private final Card card; private final int copies; - public CopyCardAffect(Card card, int copies) { + public CopyCardEffect(Card card, int copies) { super(Outcome.PutCreatureInPlay); this.card = card; this.copies = copies; staticText = "Put a token onto the battlefield that's a copy of {this}"; } - public CopyCardAffect(final CopyCardAffect effect) { + public CopyCardEffect(final CopyCardEffect effect) { super(effect); this.card = effect.card; this.copies = effect.copies; @@ -45,7 +45,7 @@ public class CopyCardAffect extends OneShotEffect { } @Override - public CopyCardAffect copy() { - return new CopyCardAffect(this); + public CopyCardEffect copy() { + return new CopyCardEffect(this); } } From 9b44c9a0879b09e35c4d4e3c2aa97cee436b9cd0 Mon Sep 17 00:00:00 2001 From: glerman Date: Wed, 24 Jun 2015 12:20:38 +0300 Subject: [PATCH 03/14] fixed the LastTimeCounterRemovedCondition, moved the Chronozoa test to fit the package convention, added a test case --- .../src/mage/sets/planarchaos/Chronozoa.java | 1 + .../mage/sets/planarchaos/ChronozoaTest.java | 17 ---- .../mage/test/cards/single/ChronozoaTest.java | 79 +++++++++++++++++++ .../LastTimeCounterRemovedCondition.java | 14 +++- 4 files changed, 91 insertions(+), 20 deletions(-) delete mode 100644 Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java diff --git a/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java index e8f7e5bfd2d..008b1dd77b0 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java +++ b/Mage.Sets/src/mage/sets/planarchaos/Chronozoa.java @@ -28,6 +28,7 @@ package mage.sets.planarchaos; import java.util.UUID; + import mage.MageInt; import mage.abilities.common.DiesCreatureTriggeredAbility; import mage.abilities.common.EntersBattlefieldAbility; diff --git a/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java b/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java deleted file mode 100644 index e938700073f..00000000000 --- a/Mage.Tests/src/test/java/mage/sets/planarchaos/ChronozoaTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package mage.sets.planarchaos; - -import mage.abilities.condition.common.LastTimeCounterRemovedCondition; -import org.junit.Test; - -import java.util.UUID; - -public class ChronozoaTest { - - @Test - public void test() throws Exception { - final Chronozoa chronozoa = new Chronozoa(UUID.randomUUID()); - - final LastTimeCounterRemovedCondition cond = new LastTimeCounterRemovedCondition(); - - } -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java new file mode 100644 index 00000000000..a2b4514994a --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java @@ -0,0 +1,79 @@ +package org.mage.test.cards.single; + +import java.util.List; + +import mage.constants.CardType; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.Counter; +import mage.counters.CounterType; +import mage.counters.Counters; +import mage.game.permanent.Permanent; +import mage.game.permanent.PermanentToken; + +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Created by glerman on 22/6/15. + */ +public class ChronozoaTest extends CardTestPlayerBase { + + /** + * Test that time counters are removed before the draw phase + */ + @Test + public void testVanishing() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + // Flying + // Vanishing 3 + // When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield. + addCard(Zone.HAND, playerA, "Chronozoa"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); + + setStopAt(5, PhaseStep.DRAW); + execute(); + + // Make sure one time counter was removed at beginning of playerA turn num 3 + assertCounterCount("Chronozoa", CounterType.TIME, 1); + } + + /** + * Test that the tokens are put to battlefield if the last time counter is removed + */ + @Test + public void testDuplicationEffect() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + // Flying + // Vanishing 3 + // When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield. + addCard(Zone.HAND, playerA, "Chronozoa"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); + + setStopAt(9, PhaseStep.PRECOMBAT_MAIN); + execute(); + + // The original Chronozoa card should be in graveyard + assertGraveyardCount(playerA, 1); + + final List creatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); + Assert.assertEquals(2, creatures.size()); + + for (final Permanent creature : creatures) { + // Make sure the creatures are Chronozoa tokens + Assert.assertEquals("Chronozoa", creature.getName()); + Assert.assertEquals("Chronozoa has to be a token", true, creature instanceof PermanentToken); + + // Make sure each token has 2 time counters + final Counters counters = creature.getCounters(); + Assert.assertEquals(1, counters.size()); + for(final Counter counter : counters.values()) { + Assert.assertEquals(CounterType.TIME.getName(), counter.getName()); + Assert.assertEquals(2, counter.getCount()); + } + } + } +} diff --git a/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java b/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java index b214b86a8e5..0c47125c9ca 100644 --- a/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java +++ b/Mage/src/mage/abilities/condition/common/LastTimeCounterRemovedCondition.java @@ -2,6 +2,7 @@ package mage.abilities.condition.common; import mage.abilities.Ability; import mage.abilities.condition.Condition; +import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.Permanent; @@ -20,8 +21,15 @@ public class LastTimeCounterRemovedCondition implements Condition{ @Override public boolean apply(Game game, Ability source) { - final Permanent p = game.getPermanent(source.getSourceId()); - final int timeCounters = p.getCounters().getCount(CounterType.TIME); - return timeCounters == 0; + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent == null) { + permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); + } + if (permanent != null) { + final int timeCounters = permanent.getCounters().getCount(CounterType.TIME); + return timeCounters == 0; + } else { + return false; + } } } From 5ebfacecb573bb05c2ae0fe79e2c8d0b29eef4ec Mon Sep 17 00:00:00 2001 From: glerman Date: Wed, 24 Jun 2015 14:28:41 +0300 Subject: [PATCH 04/14] added test case of Chronozoa being destroyed with time counters on it (end case) --- .../mage/test/cards/single/ChronozoaTest.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java index a2b4514994a..7125bdce733 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/ChronozoaTest.java @@ -19,6 +19,9 @@ import org.mage.test.serverside.base.CardTestPlayerBase; * Created by glerman on 22/6/15. */ public class ChronozoaTest extends CardTestPlayerBase { + // Flying + // Vanishing 3 + // When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield. /** * Test that time counters are removed before the draw phase @@ -26,9 +29,6 @@ public class ChronozoaTest extends CardTestPlayerBase { @Test public void testVanishing() { addCard(Zone.BATTLEFIELD, playerA, "Island", 4); - // Flying - // Vanishing 3 - // When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield. addCard(Zone.HAND, playerA, "Chronozoa"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); @@ -46,9 +46,6 @@ public class ChronozoaTest extends CardTestPlayerBase { @Test public void testDuplicationEffect() { addCard(Zone.BATTLEFIELD, playerA, "Island", 4); - // Flying - // Vanishing 3 - // When Chronozoa dies, if it had no time counters on it, put two tokens that are copies of it onto the battlefield. addCard(Zone.HAND, playerA, "Chronozoa"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); @@ -76,4 +73,29 @@ public class ChronozoaTest extends CardTestPlayerBase { } } } + + @Test + public void testChronozoaDestroyedWithTimeCounters() throws Exception { + addCard(Zone.BATTLEFIELD, playerA, "Island", 4); + addCard(Zone.HAND, playerA, "Chronozoa"); + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); + addCard(Zone.HAND, playerB, "Lightning Bolt"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); + // Destroy Chronozoa the same phase it should duplicate -> due to stack Chronozoa is destroyed before duplication + castSpell(7, PhaseStep.UPKEEP, playerB, "Lightning Bolt", "Chronozoa"); + + setStopAt(7, PhaseStep.PRECOMBAT_MAIN); + execute(); + + // Chronozoa in gy + assertGraveyardCount(playerA, 1); + // Lightning Bolt in gt + assertGraveyardCount(playerB, 1); + + // Chronozoa shouldn't duplicate + final List creatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); + Assert.assertTrue(creatures.isEmpty()); + + } } From 0a293063cf88e41e647060c0bfe261f0856d2db5 Mon Sep 17 00:00:00 2001 From: glerman Date: Wed, 24 Jun 2015 19:48:28 +0300 Subject: [PATCH 05/14] added test for NornsAnnex still in progress, dur to friends bug --- .../test/cards/single/NornsAnnexTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/NornsAnnexTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/NornsAnnexTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/NornsAnnexTest.java new file mode 100644 index 00000000000..2336b6aa895 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/NornsAnnexTest.java @@ -0,0 +1,27 @@ +package org.mage.test.cards.single; + +import mage.constants.PhaseStep; +import mage.constants.Zone; + +import org.junit.Ignore; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Created by glerman on 23/6/15. + */ +@Ignore +public class NornsAnnexTest extends CardTestPlayerBase{ + @Test + @Ignore + public void testNornsAnnex() { + addCard(Zone.BATTLEFIELD, playerA, "Norn's Annex"); + addCard(Zone.BATTLEFIELD, playerB, "Brindle Boar"); + attack(2, playerB, "Brindle Boar", playerA); + setStopAt(2, PhaseStep.END_TURN); + execute(); + + + + } +} From 049f76ffe6d326cd284e440501afe64e72931dee Mon Sep 17 00:00:00 2001 From: glerman Date: Mon, 29 Jun 2015 01:23:12 +0300 Subject: [PATCH 06/14] added DustOfMoments and it's ability --- .../mage/sets/futuresight/DustOfMoments.java | 79 +++++++++++ ...AddRemoveAllTimeSuspentCountersEffect.java | 125 ++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java create mode 100644 Mage/src/mage/abilities/effects/common/counter/AddRemoveAllTimeSuspentCountersEffect.java diff --git a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java new file mode 100644 index 00000000000..507a0d7e665 --- /dev/null +++ b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java @@ -0,0 +1,79 @@ +/* + * 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 mage.sets.futuresight; + +import java.util.UUID; + +import mage.abilities.Mode; +import mage.abilities.effects.common.counter.AddRemoveAllTimeSuspentCountersEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.counters.Counter; +import mage.counters.CounterType; +import mage.filter.Filter; +import mage.filter.FilterCard; +import mage.filter.predicate.permanent.CounterPredicate; + +/** + * + * @author Gal Lerman + + */ +public class DustOfMoments extends CardImpl { + + private static final Filter filter = new FilterCard("Has Time Counter Filter"); + + static { + filter.add(new CounterPredicate(CounterType.TIME)); + } + + public DustOfMoments(UUID ownerId) { + super(ownerId, 5, "Dust of Moments", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{W}"); + this.expansionSetCode = "FUT"; + + // Choose one + // Remove two time counters from each permanent and each suspended card + final Counter counter = new Counter(CounterType.TIME.getName(), 2); + this.getSpellAbility().addEffect(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, true)); + // Or put two time counters on each permanent with a time counter on it and each suspended card + Mode mode = new Mode(); + mode.getEffects().add(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, false)); + this.getSpellAbility().getModes().addMode(mode); + } + + public DustOfMoments(final DustOfMoments card) { + super(card); + } + + @Override + public DustOfMoments copy() { + return new DustOfMoments(this); + } +} diff --git a/Mage/src/mage/abilities/effects/common/counter/AddRemoveAllTimeSuspentCountersEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddRemoveAllTimeSuspentCountersEffect.java new file mode 100644 index 00000000000..6c1e8525bcb --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/counter/AddRemoveAllTimeSuspentCountersEffect.java @@ -0,0 +1,125 @@ +/* + * 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 mage.abilities.effects.common.counter; + +import java.util.ArrayList; +import java.util.List; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.constants.Outcome; +import mage.counters.Counter; +import mage.filter.Filter; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author Gal Lerman + */ +public class AddRemoveAllTimeSuspentCountersEffect extends OneShotEffect { + + private final Counter counter; + private final Filter filter; + private final boolean removeCounter; + private final String actionStr; + + public AddRemoveAllTimeSuspentCountersEffect(Counter counter, Filter filter, boolean removeCounter) { + super(Outcome.Benefit); + this.counter = counter; + this.filter = filter; + this.removeCounter= removeCounter; + actionStr = removeCounter ? " removes " : " puts "; + setText(); + } + + public AddRemoveAllTimeSuspentCountersEffect(final AddRemoveAllTimeSuspentCountersEffect effect) { + super(effect); + this.counter = effect.counter.copy(); + this.filter = effect.filter.copy(); + this.removeCounter = effect.removeCounter; + this.actionStr = effect.actionStr; + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller != null && sourceObject != null) { + if (counter != null) { + List permanents = new ArrayList(game.getBattlefield().getAllActivePermanents()); + execute(game, controller, sourceObject, permanents, removeCounter); + final List exiledCards = game.getExile().getAllCards(game); + execute(game, controller, sourceObject, exiledCards, removeCounter); + } + return true; + } + return false; + } + + private void execute(final Game game, final Player controller, final MageObject sourceObject, final List cards, final boolean removeCounter) { + for (Card card : cards) { + if (filter.match(card, game)) { + final String counterName = counter.getName(); + if (removeCounter) { + final Counter existingCounterOfSameType = card.getCounters(game).get(counterName); + final int countersToRemove = Math.min(existingCounterOfSameType.getCount(), counter.getCount()); + final Counter modifiedCounter = new Counter(counterName, countersToRemove); + card.removeCounters(modifiedCounter, game); + } else { + card.addCounters(counter, game); + } + if (!game.isSimulation()) + game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ") + .append(controller.getLogName()).append(actionStr) + .append(counter.getCount()).append(" ").append(counterName.toLowerCase()) + .append(" counter on ").append(card.getName()).toString()); + } + } + } + + private void setText() { + StringBuilder sb = new StringBuilder(); + final String actionsStr2 = removeCounter ? "remove " : " put "; + sb.append(actionsStr2); + if (counter.getCount() > 1) { + sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName().toLowerCase()).append(" counters on each "); + } else { + sb.append("a ").append(counter.getName().toLowerCase()).append(" counter on each "); + } + sb.append(filter.getMessage()); + staticText = sb.toString(); + } + + @Override + public AddRemoveAllTimeSuspentCountersEffect copy() { + return new AddRemoveAllTimeSuspentCountersEffect(this); + } +} From 9e4a7aad8ac1506a277d0b69503e13f81a695741 Mon Sep 17 00:00:00 2001 From: glerman Date: Mon, 29 Jun 2015 01:24:21 +0300 Subject: [PATCH 07/14] added empty test for DustOfMoments --- .../org/mage/test/cards/single/DustOfMomentsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java new file mode 100644 index 00000000000..44e03630cac --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -0,0 +1,9 @@ +package org.mage.test.cards.single; + +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Created by glerman on 29/6/15. + */ +public class DustOfMomentsTest extends CardTestPlayerBase{ +} From 45e269de770e9ab9cbfdbc78ad3f3fdaf6c9ea7e Mon Sep 17 00:00:00 2001 From: glerman Date: Mon, 29 Jun 2015 02:09:56 +0300 Subject: [PATCH 08/14] added empty test for DustOfMoments --- .../mage/sets/futuresight/DustOfMoments.java | 6 ++- .../test/cards/single/DustOfMomentsTest.java | 44 ++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java index 507a0d7e665..941cf8398b0 100644 --- a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java +++ b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java @@ -58,14 +58,16 @@ public class DustOfMoments extends CardImpl { super(ownerId, 5, "Dust of Moments", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{W}"); this.expansionSetCode = "FUT"; - // Choose one - // Remove two time counters from each permanent and each suspended card + // Choose one - Remove two time counters from each permanent and each suspended card final Counter counter = new Counter(CounterType.TIME.getName(), 2); this.getSpellAbility().addEffect(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, true)); + // Or put two time counters on each permanent with a time counter on it and each suspended card Mode mode = new Mode(); mode.getEffects().add(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, false)); this.getSpellAbility().getModes().addMode(mode); + this.getSpellAbility().getModes().setMaxModes(1); + this.getSpellAbility().getModes().setMinModes(1); } public DustOfMoments(final DustOfMoments card) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java index 44e03630cac..f2fb41c9d8a 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -1,9 +1,51 @@ package org.mage.test.cards.single; +import java.util.List; + +import mage.cards.Card; +import mage.constants.CardType; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.permanent.Permanent; + +import org.junit.Assert; +import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; /** * Created by glerman on 29/6/15. */ -public class DustOfMomentsTest extends CardTestPlayerBase{ +public class DustOfMomentsTest extends CardTestPlayerBase { + + @Test + public void test() throws Exception { + addCard(Zone.BATTLEFIELD, playerA, "Island", 7); + addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); + addCard(Zone.HAND, playerA, "Chronozoa"); + addCard(Zone.HAND, playerA, "Deep-Sea Kraken"); + addCard(Zone.HAND, playerA, "Dust of Moments"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Deep-Sea Kraken"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dust Of Moments"); + + setModeChoice(playerA, "1"); + + setStopAt(3, PhaseStep.PRECOMBAT_MAIN); + execute(); + + final List activeCreatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); + Assert.assertEquals(2, activeCreatures.size()); + + for (final Permanent creature : activeCreatures) { + Assert.assertEquals("Chronozoa", creature.getName()); + } + final List exiledCards = currentGame.getExile().getAllCards(currentGame); + Assert.assertEquals(1, exiledCards.size()); + + final Card kraken = exiledCards.get(0); + final int krakenCounters = kraken.getCounters(currentGame).getCount(CounterType.TIME); + Assert.assertEquals(6, krakenCounters); + } } From afe9c27aa539ea0bf3b7466c4ee4720e56fbc85f Mon Sep 17 00:00:00 2001 From: glerman Date: Fri, 3 Jul 2015 02:10:06 +0300 Subject: [PATCH 09/14] finally made DustOfMoments to work, CounterPredicate didn't see counters for Chronozoa (permanent). why the hell is PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same card --- .../mage/sets/futuresight/DustOfMoments.java | 195 ++++++++++++++++-- .../test/cards/single/DustOfMomentsTest.java | 12 +- .../permanent/CardCounterPredicate.java | 36 ++++ 3 files changed, 225 insertions(+), 18 deletions(-) create mode 100644 Mage/src/mage/filter/predicate/permanent/CardCounterPredicate.java diff --git a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java index 941cf8398b0..99284d91a50 100644 --- a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java +++ b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java @@ -27,19 +27,28 @@ */ package mage.sets.futuresight; +import java.util.List; import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; import mage.abilities.Mode; -import mage.abilities.effects.common.counter.AddRemoveAllTimeSuspentCountersEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.Rarity; import mage.counters.Counter; import mage.counters.CounterType; import mage.filter.Filter; import mage.filter.FilterCard; +import mage.filter.predicate.permanent.CardCounterPredicate; import mage.filter.predicate.permanent.CounterPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -48,26 +57,17 @@ import mage.filter.predicate.permanent.CounterPredicate; */ public class DustOfMoments extends CardImpl { - private static final Filter filter = new FilterCard("Has Time Counter Filter"); - - static { - filter.add(new CounterPredicate(CounterType.TIME)); - } - public DustOfMoments(UUID ownerId) { super(ownerId, 5, "Dust of Moments", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{W}"); this.expansionSetCode = "FUT"; - // Choose one - Remove two time counters from each permanent and each suspended card - final Counter counter = new Counter(CounterType.TIME.getName(), 2); - this.getSpellAbility().addEffect(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, true)); + // Choose one - Remove two time counters from each permanent and each suspended card with time counter + this.getSpellAbility().addEffect(new RemoveCountersEffect()); - // Or put two time counters on each permanent with a time counter on it and each suspended card + // Or put two time counters on each permanent with a time counter on it and each suspended card with time counter Mode mode = new Mode(); - mode.getEffects().add(new AddRemoveAllTimeSuspentCountersEffect(counter, filter, false)); - this.getSpellAbility().getModes().addMode(mode); - this.getSpellAbility().getModes().setMaxModes(1); - this.getSpellAbility().getModes().setMinModes(1); + mode.getEffects().add(new AddCountersEffect()); + this.getSpellAbility().addMode(mode); } public DustOfMoments(final DustOfMoments card) { @@ -78,4 +78,169 @@ public class DustOfMoments extends CardImpl { public DustOfMoments copy() { return new DustOfMoments(this); } + + + + public abstract static class DustOfMomentsEffect extends OneShotEffect { + + private final Counter counter; + private final Filter permFilter; + private final Filter exiledFilter; + + public DustOfMomentsEffect() { + super(Outcome.Benefit); + this.counter = new Counter(CounterType.TIME.getName(), 2); + this.permFilter = new FilterCard("permanent and each suspended card with time counter"); + permFilter.add(new CounterPredicate(CounterType.TIME)); + + this.exiledFilter = new FilterCard("permanent and each suspended card with time counter"); + exiledFilter.add(new CardCounterPredicate(CounterType.TIME)); + setText(); + } + + public DustOfMomentsEffect(final DustOfMomentsEffect effect) { + super(effect); + this.counter = effect.counter.copy(); + this.permFilter = effect.permFilter.copy(); + this.exiledFilter = effect.exiledFilter.copy(); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (controller != null && sourceObject != null) { + updatePermanents(game, controller, sourceObject); + updateSuspended(game, controller, sourceObject); + return true; + } + return false; + } + + private void updateSuspended(final Game game, final Player controller, final MageObject sourceObject) { + final List exiledCards = game.getExile().getAllCards(game); + execute(game, controller, sourceObject, exiledCards); + } + + private void updatePermanents(final Game game, final Player controller, final MageObject sourceObject) { + List permanents = game.getBattlefield().getAllActivePermanents(); + executeP(game, controller, sourceObject, permanents); + } + + private void executeP(final Game game, final Player controller, final MageObject sourceObject, final List cards) { + if (cards == null || cards.isEmpty()) { + return; + } + for (Permanent card : cards) { + if (permFilter.match(card, game)) { + final String counterName = counter.getName(); + if (shouldRemoveCounters()) { + final Counter existingCounterOfSameType = card.getCounters().get(counterName); + final int countersToRemove = Math.min(existingCounterOfSameType.getCount(), counter.getCount()); + final Counter modifiedCounter = new Counter(counterName, countersToRemove); + card.removeCounters(modifiedCounter, game); + } else { + card.addCounters(counter, game); + } + if (!game.isSimulation()) + game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ") + .append(controller.getLogName()).append(getActionStr()).append("s") + .append(counter.getCount()).append(" ").append(counterName.toLowerCase()) + .append(" counter on ").append(card.getName()).toString()); + } + } + } + + private void execute(final Game game, final Player controller, final MageObject sourceObject, final List cards) { + if (cards == null || cards.isEmpty()) { + return; + } + for (Card card : cards) { + if (exiledFilter.match(card, game)) { + final String counterName = counter.getName(); + if (shouldRemoveCounters()) { + final Counter existingCounterOfSameType = card.getCounters(game).get(counterName); + final int countersToRemove = Math.min(existingCounterOfSameType.getCount(), counter.getCount()); + final Counter modifiedCounter = new Counter(counterName, countersToRemove); + card.removeCounters(modifiedCounter, game); + } else { + card.addCounters(counter, game); + } + if (!game.isSimulation()) + game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ") + .append(controller.getLogName()).append(getActionStr()).append("s") + .append(counter.getCount()).append(" ").append(counterName.toLowerCase()) + .append(" counter on ").append(card.getName()).toString()); + } + } + } + + protected abstract boolean shouldRemoveCounters(); + + protected abstract String getActionStr(); + + private void setText() { + StringBuilder sb = new StringBuilder(); + sb.append(getActionStr()); + if (counter.getCount() > 1) { + sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName().toLowerCase()).append(" counters on each "); + } else { + sb.append("a ").append(counter.getName().toLowerCase()).append(" counter on each "); + } + sb.append(permFilter.getMessage()); + staticText = sb.toString(); + } + } + + public static class AddCountersEffect extends DustOfMomentsEffect { + + public AddCountersEffect() { + super(); + } + + public AddCountersEffect(final DustOfMomentsEffect effect) { + super(effect); + } + + @Override + protected boolean shouldRemoveCounters() { + return false; + } + + @Override + protected String getActionStr() { + return "add"; + } + + @Override + public Effect copy() { + return new AddCountersEffect(this); + } + } + + public static class RemoveCountersEffect extends DustOfMomentsEffect { + + public RemoveCountersEffect() { + super(); + } + + public RemoveCountersEffect(final DustOfMomentsEffect effect) { + super(effect); + } + + @Override + protected boolean shouldRemoveCounters() { + return true; + } + + @Override + protected String getActionStr() { + return "remove"; + } + + @Override + public Effect copy() { + return new RemoveCountersEffect(this); + } + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java index f2fb41c9d8a..7859f6945e7 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -18,6 +18,8 @@ import org.mage.test.serverside.base.CardTestPlayerBase; */ public class DustOfMomentsTest extends CardTestPlayerBase { + //TODO: why the hell is PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same card??? + @Test public void test() throws Exception { addCard(Zone.BATTLEFIELD, playerA, "Island", 7); @@ -27,20 +29,24 @@ public class DustOfMomentsTest extends CardTestPlayerBase { addCard(Zone.HAND, playerA, "Dust of Moments"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); - castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Deep-Sea Kraken"); - castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dust Of Moments"); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Suspend"); // Casts Deep-Sea Kraken as Suspend + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dust of Moments"); setModeChoice(playerA, "1"); - setStopAt(3, PhaseStep.PRECOMBAT_MAIN); + setStopAt(3, PhaseStep.END_TURN); execute(); +// Chronozoa should have duplicated final List activeCreatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); Assert.assertEquals(2, activeCreatures.size()); for (final Permanent creature : activeCreatures) { Assert.assertEquals("Chronozoa", creature.getName()); + Assert.assertEquals(3, creature.getCounters().getCount(CounterType.TIME)); } + + // Check time counters on kraken final List exiledCards = currentGame.getExile().getAllCards(currentGame); Assert.assertEquals(1, exiledCards.size()); diff --git a/Mage/src/mage/filter/predicate/permanent/CardCounterPredicate.java b/Mage/src/mage/filter/predicate/permanent/CardCounterPredicate.java new file mode 100644 index 00000000000..04fa0123400 --- /dev/null +++ b/Mage/src/mage/filter/predicate/permanent/CardCounterPredicate.java @@ -0,0 +1,36 @@ +package mage.filter.predicate.permanent; + +import mage.cards.Card; +import mage.counters.CounterType; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * Created by glerman on 3/7/15. + */ +public class CardCounterPredicate implements Predicate{ + + private final CounterType counter; + + /** + * + * @param counter if null any counter selects the permanent + */ + public CardCounterPredicate(CounterType counter) { + this.counter = counter; + } + + @Override + public boolean apply(Card input, Game game) { + if (counter == null) { + return !input.getCounters(game).keySet().isEmpty(); + } else { + return input.getCounters(game).containsKey(counter); + } + } + + @Override + public String toString() { + return "CounterType(" + counter.getName() + ')'; + } +} From 6aa23b0b2ef420ae8a565d8b84c1f872795c11dd Mon Sep 17 00:00:00 2001 From: glerman Date: Fri, 3 Jul 2015 02:27:49 +0300 Subject: [PATCH 10/14] added DustOfMoments counter addition test --- .../test/cards/single/DustOfMomentsTest.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java index 7859f6945e7..d12b8e600e0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -2,7 +2,6 @@ package org.mage.test.cards.single; import java.util.List; -import mage.cards.Card; import mage.constants.CardType; import mage.constants.PhaseStep; import mage.constants.Zone; @@ -21,7 +20,36 @@ public class DustOfMomentsTest extends CardTestPlayerBase { //TODO: why the hell is PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same card??? @Test - public void test() throws Exception { + public void testRemoveCounters() throws Exception { + initGame(); + setModeChoice(playerA, "1"); // Chose the remove 2 time counters option + setStopAt(3, PhaseStep.END_TURN); + execute(); + + // Chronozoa should have duplicated + final List activeCreatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); + Assert.assertEquals(2, activeCreatures.size()); + + for (final Permanent creature : activeCreatures) { + Assert.assertEquals("Chronozoa", creature.getName()); + Assert.assertEquals(3, creature.getCounters().getCount(CounterType.TIME)); + } + // Check time counters on kraken + assertCounterOnExiledCardCount("Deep-Sea Kraken", CounterType.TIME, 6); + } + + @Test + public void testAddCounters() throws Exception { + initGame(); + setModeChoice(playerA, "2"); // Chose the add 2 time counters option + setStopAt(3, PhaseStep.END_TURN); + execute(); + + assertCounterCount("Chronozoa", CounterType.TIME, 4); + assertCounterOnExiledCardCount("Deep-Sea Kraken", CounterType.TIME, 10); + } + + private void initGame() { addCard(Zone.BATTLEFIELD, playerA, "Island", 7); addCard(Zone.BATTLEFIELD, playerA, "Plains", 1); addCard(Zone.HAND, playerA, "Chronozoa"); @@ -31,27 +59,5 @@ public class DustOfMomentsTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa"); activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Suspend"); // Casts Deep-Sea Kraken as Suspend castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Dust of Moments"); - - setModeChoice(playerA, "1"); - - setStopAt(3, PhaseStep.END_TURN); - execute(); - -// Chronozoa should have duplicated - final List activeCreatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE); - Assert.assertEquals(2, activeCreatures.size()); - - for (final Permanent creature : activeCreatures) { - Assert.assertEquals("Chronozoa", creature.getName()); - Assert.assertEquals(3, creature.getCounters().getCount(CounterType.TIME)); - } - - // Check time counters on kraken - final List exiledCards = currentGame.getExile().getAllCards(currentGame); - Assert.assertEquals(1, exiledCards.size()); - - final Card kraken = exiledCards.get(0); - final int krakenCounters = kraken.getCounters(currentGame).getCount(CounterType.TIME); - Assert.assertEquals(6, krakenCounters); } } From 27a9e80de153f23a8b0f4460504c2b6e71edad86 Mon Sep 17 00:00:00 2001 From: glerman Date: Fri, 3 Jul 2015 02:28:48 +0300 Subject: [PATCH 11/14] added a script to clean cards.h2* from Server, Client and Test envs --- clean_dbs.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 clean_dbs.sh diff --git a/clean_dbs.sh b/clean_dbs.sh new file mode 100644 index 00000000000..c091f9f7613 --- /dev/null +++ b/clean_dbs.sh @@ -0,0 +1,2 @@ +# Cleans the DB from Server, Client and Test modules +find . -type f | grep -i cards.h2*.db | xargs rm -v \ No newline at end of file From 638174add2a5837a50ffdbaa318622a84dcb8cab Mon Sep 17 00:00:00 2001 From: glerman Date: Fri, 3 Jul 2015 02:44:24 +0300 Subject: [PATCH 12/14] fixed tooltip a little --- Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java index 99284d91a50..5a543e83fea 100644 --- a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java +++ b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java @@ -61,10 +61,10 @@ public class DustOfMoments extends CardImpl { super(ownerId, 5, "Dust of Moments", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{W}"); this.expansionSetCode = "FUT"; - // Choose one - Remove two time counters from each permanent and each suspended card with time counter + // Choose one - Remove two time counters from each permanent and each suspended card this.getSpellAbility().addEffect(new RemoveCountersEffect()); - // Or put two time counters on each permanent with a time counter on it and each suspended card with time counter + // Or put two time counters on each permanent with a time counter on it and each suspended card Mode mode = new Mode(); mode.getEffects().add(new AddCountersEffect()); this.getSpellAbility().addMode(mode); @@ -90,10 +90,10 @@ public class DustOfMoments extends CardImpl { public DustOfMomentsEffect() { super(Outcome.Benefit); this.counter = new Counter(CounterType.TIME.getName(), 2); - this.permFilter = new FilterCard("permanent and each suspended card with time counter"); + this.permFilter = new FilterCard("permanent and each suspended card"); permFilter.add(new CounterPredicate(CounterType.TIME)); - this.exiledFilter = new FilterCard("permanent and each suspended card with time counter"); + this.exiledFilter = new FilterCard("permanent and each suspended card"); exiledFilter.add(new CardCounterPredicate(CounterType.TIME)); setText(); } @@ -168,7 +168,7 @@ public class DustOfMoments extends CardImpl { } if (!game.isSimulation()) game.informPlayers(new StringBuilder(sourceObject.getName()).append(": ") - .append(controller.getLogName()).append(getActionStr()).append("s") + .append(controller.getLogName()).append(getActionStr()).append("s ") .append(counter.getCount()).append(" ").append(counterName.toLowerCase()) .append(" counter on ").append(card.getName()).toString()); } From cb892303273f5802aad3371614982da8f6a35b9a Mon Sep 17 00:00:00 2001 From: glerman Date: Fri, 3 Jul 2015 17:35:28 +0300 Subject: [PATCH 13/14] added todos --- .../test/java/org/mage/test/cards/single/DustOfMomentsTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java index d12b8e600e0..b89d8f45c26 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -18,6 +18,8 @@ import org.mage.test.serverside.base.CardTestPlayerBase; public class DustOfMomentsTest extends CardTestPlayerBase { //TODO: why the hell is PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same card??? + //TODO: fix tooltip + //TODO: refactor effect code @Test public void testRemoveCounters() throws Exception { From 584e7fb394e96a12f16db56403891845e9a02be7 Mon Sep 17 00:00:00 2001 From: Gal Lerman Date: Mon, 6 Jul 2015 23:49:03 +0300 Subject: [PATCH 14/14] edited TODOs and comment header in clean_dbs.sh --- Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java | 5 ++++- .../java/org/mage/test/cards/single/DustOfMomentsTest.java | 4 ---- clean_dbs.sh | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java index 5a543e83fea..1736ded2689 100644 --- a/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java +++ b/Mage.Sets/src/mage/sets/futuresight/DustOfMoments.java @@ -80,7 +80,10 @@ public class DustOfMoments extends CardImpl { } - + //TODO: PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same Card + //TODO: This means I can't use a Card generic for Permanents and Exiled cards and use Card.getCounters(game) + //TODO: This is the reason i've copy pasted some logic in DustOfMomentsEffect + //TODO: After this issue is fixed/explained i'll refactor the code public abstract static class DustOfMomentsEffect extends OneShotEffect { private final Counter counter; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java index b89d8f45c26..bd0af195e47 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/DustOfMomentsTest.java @@ -17,10 +17,6 @@ import org.mage.test.serverside.base.CardTestPlayerBase; */ public class DustOfMomentsTest extends CardTestPlayerBase { - //TODO: why the hell is PermanentImpl.getCounters() and CardImpl.getCounters(game) don't return the same value for the same card??? - //TODO: fix tooltip - //TODO: refactor effect code - @Test public void testRemoveCounters() throws Exception { initGame(); diff --git a/clean_dbs.sh b/clean_dbs.sh index c091f9f7613..9ccf51fd6d2 100644 --- a/clean_dbs.sh +++ b/clean_dbs.sh @@ -1,2 +1,3 @@ +#!/usr/bin/env bash # Cleans the DB from Server, Client and Test modules find . -type f | grep -i cards.h2*.db | xargs rm -v \ No newline at end of file