Implemented World Rule state based action.

This commit is contained in:
LevelX2 2015-05-27 00:53:29 +02:00
parent 0f3fc99943
commit ccae89e181
5 changed files with 107 additions and 3 deletions

View file

@ -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));
}

View file

@ -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);
}
}

View file

@ -1492,6 +1492,7 @@ public abstract class GameImpl implements Game, Serializable {
List<Permanent> planeswalkers = new ArrayList<>();
List<Permanent> legendary = new ArrayList<>();
List<Permanent> 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;

View file

@ -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();
}

View file

@ -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<Counter> markedDamage;
protected int timesLoyaltyUsed = 0;
protected Map<String, String> info;
protected Date createDate;
private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>());
@ -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;
}
}