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) {
super(ownerId, 314, "Chromatic Star", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{1}");
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.addCost(new TapSourceCost());
ability.addCost(new SacrificeSourceCost());
this.addAbility(ability);
// When Chromatic Star is put into a graveyard from the battlefield, draw a card.
this.addAbility(new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new DrawCardSourceControllerEffect(1)));
}

View file

@ -48,13 +48,16 @@ public class WorldEnchantmentsRuleTest extends CardTestPlayerBase {
*/
@Test
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, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerB, "Swamp", 7);
addCard(Zone.HAND, playerB, "Nether Void", 1);
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");
setStopAt(2, PhaseStep.END_TURN);

View file

@ -30,6 +30,7 @@ package mage.game;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@ -1278,6 +1279,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override
public void addPermanent(Permanent permanent) {
getBattlefield().addPermanent(permanent);
permanent.setCreateOrder(getState().getNextPermanentOrderNumber());
}
@Override
@ -1735,17 +1737,17 @@ public abstract class GameImpl implements Game, Serializable {
}
//704.5m - World Enchantments
if (worldEnchantment.size() > 1) {
Date newestCard = null;
int newestCard = -1;
Permanent newestPermanent = null;
for (Permanent permanent :worldEnchantment) {
if (newestCard == null) {
newestCard = permanent.getCreateDate();
if (newestCard == -1) {
newestCard = permanent.getCreateOrder();
newestPermanent = permanent;
} else if (newestCard.before(permanent.getCreateDate())) {
newestCard = permanent.getCreateDate();
} else if (newestCard < permanent.getCreateOrder()) {
newestCard = permanent.getCreateOrder();
newestPermanent = permanent;
} else if(newestCard.equals(permanent.getCreateDate())) {
newestCard = null;
} else if(newestCard == permanent.getCreateOrder()) {
newestPermanent = null;
}
}
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, Integer> zoneChangeCounter = new HashMap<>();
private Map<UUID, Card> copiedCards = new HashMap<>();
private int permanentOrderNumber;
public GameState() {
players = new Players();
@ -169,6 +170,7 @@ public class GameState implements Serializable, Copyable<GameState> {
}
this.zoneChangeCounter.putAll(state.zoneChangeCounter);
this.copiedCards.putAll(state.copiedCards);
this.permanentOrderNumber = state.permanentOrderNumber;
}
@Override
@ -575,6 +577,7 @@ public class GameState implements Serializable, Copyable<GameState> {
this.cardState = state.cardState;
this.zoneChangeCounter = state.zoneChangeCounter;
this.copiedCards = state.copiedCards;
this.permanentOrderNumber = state.permanentOrderNumber;
}
public void addSimultaneousEvent(GameEvent event, Game game) {
@ -837,6 +840,7 @@ public class GameState implements Serializable, Copyable<GameState> {
values.clear();
zones.clear();
simultaneousEvents.clear();
permanentOrderNumber = 0;
}
public void pause() {
@ -925,4 +929,8 @@ public class GameState implements Serializable, Copyable<GameState> {
}
return copiedCard;
}
public int getNextPermanentOrderNumber() {
return permanentOrderNumber++;
}
}

View file

@ -29,7 +29,6 @@
package mage.game.permanent;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
@ -275,5 +274,8 @@ public interface Permanent extends Card, Controllable {
@Override
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 int timesLoyaltyUsed = 0;
protected Map<String, String> info;
protected Date createDate;
protected int createOrder;
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.controllerId = controllerId;
this.counters = new Counters();
this.createDate = new Date();
}
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.controllerId = controllerId;
this.counters = new Counters();
this.createDate = new Date();
}
public PermanentImpl(final PermanentImpl permanent) {
@ -183,7 +181,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.morphed = permanent.morphed;
this.manifested = permanent.manifested;
this.createDate = permanent.createDate;
this.createOrder = permanent.createOrder;
}
@Override
@ -1354,8 +1352,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
@Override
public Date getCreateDate() {
return createDate;
public int getCreateOrder() {
return createOrder;
}
@Override
public void setCreateOrder(int createOrder) {
this.createOrder = createOrder;
}
}