Fixed world enchantment rule.

This commit is contained in:
LevelX2 2015-05-28 11:59:19 +02:00
parent 16ea49141f
commit 8d31a38d1d
6 changed files with 38 additions and 16 deletions

View file

@ -48,10 +48,14 @@ public class ChromaticStar extends CardImpl {
public ChromaticStar(UUID ownerId) { public ChromaticStar(UUID ownerId) {
super(ownerId, 314, "Chromatic Star", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{1}"); super(ownerId, 314, "Chromatic Star", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{1}");
this.expansionSetCode = "10E"; this.expansionSetCode = "10E";
// {1}, {T}, Sacrifice Chromatic Star: Add one mana of any color to your mana pool.
Ability ability = new AnyColorManaAbility(new GenericManaCost(1)); Ability ability = new AnyColorManaAbility(new GenericManaCost(1));
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeSourceCost()); ability.addCost(new SacrificeSourceCost());
this.addAbility(ability); this.addAbility(ability);
// When Chromatic Star is put into a graveyard from the battlefield, draw a card.
this.addAbility(new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new DrawCardSourceControllerEffect(1))); this.addAbility(new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new DrawCardSourceControllerEffect(1)));
} }

View file

@ -48,13 +48,16 @@ public class WorldEnchantmentsRuleTest extends CardTestPlayerBase {
*/ */
@Test @Test
public void TestTwoWorldEnchantsments() { public void TestTwoWorldEnchantsments() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.HAND, playerA, "Nether Void", 1); addCard(Zone.HAND, playerA, "Nether Void", 1);
addCard(Zone.HAND, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerB, "Swamp", 7); addCard(Zone.BATTLEFIELD, playerB, "Swamp", 7);
addCard(Zone.HAND, playerB, "Nether Void", 1); addCard(Zone.HAND, playerB, "Nether Void", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nether Void"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nether Void");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); // just needed to get different craete time to second Nether Void
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Nether Void"); castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Nether Void");
setStopAt(2, PhaseStep.END_TURN); setStopAt(2, PhaseStep.END_TURN);

View file

@ -30,6 +30,7 @@ package mage.game;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
@ -1278,6 +1279,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override @Override
public void addPermanent(Permanent permanent) { public void addPermanent(Permanent permanent) {
getBattlefield().addPermanent(permanent); getBattlefield().addPermanent(permanent);
permanent.setCreateOrder(getState().getNextPermanentOrderNumber());
} }
@Override @Override
@ -1735,17 +1737,17 @@ public abstract class GameImpl implements Game, Serializable {
} }
//704.5m - World Enchantments //704.5m - World Enchantments
if (worldEnchantment.size() > 1) { if (worldEnchantment.size() > 1) {
Date newestCard = null; int newestCard = -1;
Permanent newestPermanent = null; Permanent newestPermanent = null;
for (Permanent permanent :worldEnchantment) { for (Permanent permanent :worldEnchantment) {
if (newestCard == null) { if (newestCard == -1) {
newestCard = permanent.getCreateDate(); newestCard = permanent.getCreateOrder();
newestPermanent = permanent; newestPermanent = permanent;
} else if (newestCard.before(permanent.getCreateDate())) { } else if (newestCard < permanent.getCreateOrder()) {
newestCard = permanent.getCreateDate(); newestCard = permanent.getCreateOrder();
newestPermanent = permanent; newestPermanent = permanent;
} else if(newestCard.equals(permanent.getCreateDate())) { } else if(newestCard == permanent.getCreateOrder()) {
newestCard = null; newestPermanent = null;
} }
} }
for (Permanent permanent :worldEnchantment) { for (Permanent permanent :worldEnchantment) {

View file

@ -111,6 +111,7 @@ public class GameState implements Serializable, Copyable<GameState> {
private Map<UUID, CardState> cardState = new HashMap<>(); private Map<UUID, CardState> cardState = new HashMap<>();
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>(); private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
private Map<UUID, Card> copiedCards = new HashMap<>(); private Map<UUID, Card> copiedCards = new HashMap<>();
private int permanentOrderNumber;
public GameState() { public GameState() {
players = new Players(); players = new Players();
@ -169,6 +170,7 @@ public class GameState implements Serializable, Copyable<GameState> {
} }
this.zoneChangeCounter.putAll(state.zoneChangeCounter); this.zoneChangeCounter.putAll(state.zoneChangeCounter);
this.copiedCards.putAll(state.copiedCards); this.copiedCards.putAll(state.copiedCards);
this.permanentOrderNumber = state.permanentOrderNumber;
} }
@Override @Override
@ -575,6 +577,7 @@ public class GameState implements Serializable, Copyable<GameState> {
this.cardState = state.cardState; this.cardState = state.cardState;
this.zoneChangeCounter = state.zoneChangeCounter; this.zoneChangeCounter = state.zoneChangeCounter;
this.copiedCards = state.copiedCards; this.copiedCards = state.copiedCards;
this.permanentOrderNumber = state.permanentOrderNumber;
} }
public void addSimultaneousEvent(GameEvent event, Game game) { public void addSimultaneousEvent(GameEvent event, Game game) {
@ -837,6 +840,7 @@ public class GameState implements Serializable, Copyable<GameState> {
values.clear(); values.clear();
zones.clear(); zones.clear();
simultaneousEvents.clear(); simultaneousEvents.clear();
permanentOrderNumber = 0;
} }
public void pause() { public void pause() {
@ -925,4 +929,8 @@ public class GameState implements Serializable, Copyable<GameState> {
} }
return copiedCard; return copiedCard;
} }
public int getNextPermanentOrderNumber() {
return permanentOrderNumber++;
} }
}

View file

@ -29,7 +29,6 @@
package mage.game.permanent; package mage.game.permanent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -275,5 +274,8 @@ public interface Permanent extends Card, Controllable {
@Override @Override
Permanent copy(); Permanent copy();
Date getCreateDate(); // Simple int counter to set a timewise create order , the lower the number the earlier the object was created
// if objects enter the battlefield at the same time they can get (and should) get the same number.
int getCreateOrder();
void setCreateOrder(int createOrder);
} }

View file

@ -120,7 +120,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
protected List<Counter> markedDamage; protected List<Counter> markedDamage;
protected int timesLoyaltyUsed = 0; protected int timesLoyaltyUsed = 0;
protected Map<String, String> info; protected Map<String, String> info;
protected Date createDate; protected int createOrder;
private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>()); private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>());
@ -129,7 +129,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.originalControllerId = controllerId; this.originalControllerId = controllerId;
this.controllerId = 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) { public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) {
@ -137,7 +136,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.originalControllerId = controllerId; this.originalControllerId = controllerId;
this.controllerId = controllerId; this.controllerId = controllerId;
this.counters = new Counters(); this.counters = new Counters();
this.createDate = new Date();
} }
public PermanentImpl(final PermanentImpl permanent) { public PermanentImpl(final PermanentImpl permanent) {
@ -183,7 +181,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.morphed = permanent.morphed; this.morphed = permanent.morphed;
this.manifested = permanent.manifested; this.manifested = permanent.manifested;
this.createDate = permanent.createDate; this.createOrder = permanent.createOrder;
} }
@Override @Override
@ -1354,8 +1352,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
} }
@Override @Override
public Date getCreateDate() { public int getCreateOrder() {
return createDate; return createOrder;
}
@Override
public void setCreateOrder(int createOrder) {
this.createOrder = createOrder;
} }
} }