From ccae89e181423694b0643f4592cf311388618c11 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 27 May 2015 00:53:29 +0200 Subject: [PATCH] Implemented World Rule state based action. --- .../src/mage/sets/legends/NetherVoid.java | 1 - .../rules/WorldEnchantmentsRuleTest.java | 67 +++++++++++++++++++ Mage/src/mage/game/GameImpl.java | 27 +++++++- Mage/src/mage/game/permanent/Permanent.java | 2 + .../mage/game/permanent/PermanentImpl.java | 13 +++- 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/rules/WorldEnchantmentsRuleTest.java diff --git a/Mage.Sets/src/mage/sets/legends/NetherVoid.java b/Mage.Sets/src/mage/sets/legends/NetherVoid.java index b99ccca8498..9899b75a2d5 100644 --- a/Mage.Sets/src/mage/sets/legends/NetherVoid.java +++ b/Mage.Sets/src/mage/sets/legends/NetherVoid.java @@ -47,7 +47,6 @@ public class NetherVoid extends CardImpl { this.expansionSetCode = "LEG"; this.supertype.add("World"); - // Whenever a player casts a spell, counter it unless that player pays {3}. this.addAbility(new SpellCastAllTriggeredAbility(new CounterUnlessPaysEffect(new GenericManaCost(3)), new FilterSpell("a spell"), false, true)); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/rules/WorldEnchantmentsRuleTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/rules/WorldEnchantmentsRuleTest.java new file mode 100644 index 00000000000..09d210b6a76 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/rules/WorldEnchantmentsRuleTest.java @@ -0,0 +1,67 @@ +/* + * 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.cards.rules; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class WorldEnchantmentsRuleTest extends CardTestPlayerBase { + + /** + * 704.5m If two or more permanents have the supertype world, all except the one that has had + * the world supertype for the shortest amount of time are put into their owners’ graveyards. + * In the event of a tie for the shortest amount of time, all are put into their owners’ graveyards. + * This is called the “world rule. + * + */ + @Test + public void TestTwoWorldEnchantsments() { + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); + addCard(Zone.HAND, playerA, "Nether Void", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 7); + addCard(Zone.HAND, playerB, "Nether Void", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nether Void"); + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Nether Void"); + + setStopAt(2, PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, "Nether Void", 0); + assertPermanentCount(playerB, "Nether Void", 1); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 28c823f6446..a5dde0e6ca3 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1492,6 +1492,7 @@ public abstract class GameImpl implements Game, Serializable { List planeswalkers = new ArrayList<>(); List legendary = new ArrayList<>(); + List worldEnchantment = new ArrayList<>(); for (Permanent perm: getBattlefield().getAllActivePermanents()) { if (perm.getCardType().contains(CardType.CREATURE)) { //20091005 - 704.5f @@ -1539,6 +1540,9 @@ public abstract class GameImpl implements Game, Serializable { } planeswalkers.add(perm); } + if (perm.getSupertype().contains("World")) { + worldEnchantment.add(perm); + } if (filterAura.match(perm, this)) { //20091005 - 704.5n, 702.14c if (perm.getAttachedTo() == null) { @@ -1729,7 +1733,28 @@ public abstract class GameImpl implements Game, Serializable { } } } - + //704.5m - World Enchantments + if (worldEnchantment.size() > 1) { + Date newestCard = null; + Permanent newestPermanent = null; + for (Permanent permanent :worldEnchantment) { + if (newestCard == null) { + newestCard = permanent.getCreateDate(); + newestPermanent = permanent; + } else if (newestCard.before(permanent.getCreateDate())) { + newestCard = permanent.getCreateDate(); + newestPermanent = permanent; + } else if(newestCard.equals(permanent.getCreateDate())) { + newestCard = null; + } + } + for (Permanent permanent :worldEnchantment) { + if (newestPermanent != permanent) { + movePermanentToGraveyardWithInfo(permanent); + somethingHappened = true; + } + } + } //TODO: implement the rest return somethingHappened; diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 49210d311f0..0123c191414 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -29,6 +29,7 @@ package mage.game.permanent; import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.UUID; @@ -274,4 +275,5 @@ public interface Permanent extends Card, Controllable { @Override Permanent copy(); + Date getCreateDate(); } diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index c443897bc24..98899b343c3 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -30,6 +30,7 @@ package mage.game.permanent; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -119,6 +120,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { protected List markedDamage; protected int timesLoyaltyUsed = 0; protected Map info; + protected Date createDate; private static final List emptyList = Collections.unmodifiableList(new ArrayList()); @@ -126,7 +128,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { super(ownerId, name); this.originalControllerId = controllerId; this.controllerId = controllerId; - this.counters = new Counters(); + this.counters = new Counters(); + this.createDate = new Date(); } public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) { @@ -134,6 +137,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.originalControllerId = controllerId; this.controllerId = controllerId; this.counters = new Counters(); + this.createDate = new Date(); } public PermanentImpl(final PermanentImpl permanent) { @@ -179,6 +183,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { this.morphed = permanent.morphed; this.manifested = permanent.manifested; + this.createDate = permanent.createDate; } @Override @@ -1347,4 +1352,10 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { fightTarget.damage(getPower().getValue(), getId(), game, false, true); return true; } + + @Override + public Date getCreateDate() { + return createDate; } + +}