Skip to content

Commit

Permalink
* Fixed a bug of colorless mana (e.g. caused Heartbeat of Spring not …
Browse files Browse the repository at this point in the history
…working with Urza's lands).
  • Loading branch information
LevelX2 committed Feb 16, 2016
1 parent bf93413 commit f54c675
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
*/
public class DeckEditorPanel extends javax.swing.JPanel {

private static final Logger LOGGER = Logger.getLogger(DeckEditorPanel.class);
private static final Logger logger = Logger.getLogger(DeckEditorPanel.class);
private final JFileChooser fcSelectDeck;
private final JFileChooser fcImportDeck;
private Deck deck = new Deck();
Expand Down Expand Up @@ -690,7 +690,7 @@ private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
} catch (GameException ex) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
} catch (Exception ex) {
LOGGER.fatal(ex);
logger.fatal(ex);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
Expand Down Expand Up @@ -722,7 +722,7 @@ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
setCursor(new Cursor(Cursor.WAIT_CURSOR));
Sets.saveDeck(fileName, deck.getDeckCardLists());
} catch (Exception ex) {
LOGGER.fatal(ex);
logger.fatal(ex);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
Expand Down Expand Up @@ -771,7 +771,7 @@ private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Unknown deck format", "Error importing deck", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
LOGGER.fatal(ex);
logger.fatal(ex);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
Expand Down Expand Up @@ -877,7 +877,7 @@ public String getDescription() {

class UpdateDeckTask extends SwingWorker<Void, Void> {

private static final Logger LOGGER = Logger.getLogger(UpdateDeckTask.class);
private static final Logger logger = Logger.getLogger(UpdateDeckTask.class);
private final Session session;
private final UUID tableId;
private final Deck deck;
Expand All @@ -902,7 +902,7 @@ protected void done() {
try {
get();
} catch (InterruptedException | ExecutionException ex) {
LOGGER.fatal("Update Matches Task error", ex);
logger.fatal("Update Matches Task error", ex);
} catch (CancellationException ex) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UpdateMemUsageTask extends SwingWorker<Void, Float> {

private final JLabel jLabelToDisplayInfo;

private static final Logger LOGGER = Logger.getLogger(UpdateMemUsageTask.class);
private static final Logger logger = Logger.getLogger(UpdateMemUsageTask.class);

public UpdateMemUsageTask(JLabel jLabelToDisplayInfo) {
this.jLabelToDisplayInfo = jLabelToDisplayInfo;
Expand Down Expand Up @@ -51,7 +51,7 @@ protected void done() {
try {
get();
} catch (InterruptedException | ExecutionException ex) {
LOGGER.fatal("Update Memory Usage error", ex);
logger.fatal("Update Memory Usage error", ex);
} catch (CancellationException ex) {
}
}
Expand Down
4 changes: 2 additions & 2 deletions Mage.Sets/src/mage/sets/magicorigins/MageRingNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public MageRingNetwork(UUID ownerId) {
new ManaCostsImpl("{1}"));
ability.addCost(new TapSourceCost());
this.addAbility(ability);
// {T}, Remove X storage counters from Mage-Ring Network: Add {x} to your mana pool.
// {T}, Remove any number of storage counters from Mage-Ring Network: Add {C} to your mana pool for each storage counter removed this way.
ability = new DynamicManaAbility(
Mana.ColorlessMana(1),
new RemovedCountersForCostValue(),
new TapSourceCost(),
"Add {X} to your mana pool",
"Add {C} to your mana pool for each storage counter removed this way",
true, new CountersCount(CounterType.STORAGE));
ability.addCost(new RemoveVariableCountersSourceCost(CounterType.STORAGE.createInstance(),
"Remove X storage counters from {this}"));
Expand Down
12 changes: 6 additions & 6 deletions Mage.Sets/src/mage/sets/scarsofmirrodin/LeoninArbiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
*/
public class LeoninArbiter extends CardImpl {

private static final String keyString = "_ignoreEffectForTurn";
private static final String KEY_STRING = "_ignoreEffectForTurn";

public LeoninArbiter(UUID ownerId) {
super(ownerId, 14, "Leonin Arbiter", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{W}");
Expand All @@ -69,10 +69,10 @@ public LeoninArbiter(UUID ownerId) {
this.toughness = new MageInt(2);

// Players can't search libraries.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new LeoninArbiterCantSearchEffect(keyString)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new LeoninArbiterCantSearchEffect(KEY_STRING)));

// Any player may pay {2} for that player to ignore this effect until end of turn.
this.addAbility(new LeoninArbiterSpecialAction(keyString));
this.addAbility(new LeoninArbiterSpecialAction(KEY_STRING));
}

public LeoninArbiter(final LeoninArbiter card) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public boolean apply(Game game, Ability source) {
// Using a Map.Entry since there is no pair class
long zoneChangeCount = permanent.getZoneChangeCounter(game);
long turnNum = game.getTurnNum();
Long activationState = zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;
Long activationState = zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;

Map.Entry<Long, Set<UUID>> turnIgnoringPlayersPair = (Map.Entry<Long, Set<UUID>>) game.getState().getValue(key);
if (turnIgnoringPlayersPair == null || !activationState.equals(turnIgnoringPlayersPair.getKey())) {
Expand Down Expand Up @@ -169,13 +169,13 @@ public boolean checksEventType(GameEvent event, Game game) {
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
boolean applies = true;
boolean applies = true;
String key = permanent.getId() + keyString;
Map.Entry<Long, Set<UUID>> turnIgnoringPlayersPair = (Map.Entry<Long, Set<UUID>>) game.getState().getValue(key);
if (turnIgnoringPlayersPair != null) {
long zoneChangeCount = permanent.getZoneChangeCounter(game);
long turnNum = game.getTurnNum();
Long activationState = zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;
Long activationState = zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;
if (activationState.equals(turnIgnoringPlayersPair.getKey())) {
applies = !turnIgnoringPlayersPair.getValue().contains(event.getPlayerId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,47 @@ public void EdricSpymasterOfTrestTest() {
assertHandCount(playerA, 4); // 2 * 2 from Sphinx = 4

}

/**
* two consecrated sphinxes do not work properly, only gives one player
* additional draw
*
*/
@Test
public void TwoConsecratedSphinxDifferentPlayers() {
// Flying
// Whenever an opponent draws a card, you may draw two cards.
addCard(Zone.BATTLEFIELD, playerA, "Consecrated Sphinx", 1);

// Flying
// Whenever an opponent draws a card, you may draw two cards.
addCard(Zone.BATTLEFIELD, playerB, "Consecrated Sphinx", 1);

setChoice(playerA, "Yes");
setChoice(playerA, "No");
setChoice(playerA, "No");

setChoice(playerB, "Yes");
setChoice(playerB, "No");
setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
execute();

assertHandCount(playerB, 3); // 1 from start of turn 1 and 4 from Opponents draw of 2 cards
assertHandCount(playerA, 2); // 2 from Sphinx triggered by the normal draw

}

@Test
public void TwoConsecratedSphinxSamePlayer() {
// Flying
// Whenever an opponent draws a card, you may draw two cards.
addCard(Zone.BATTLEFIELD, playerA, "Consecrated Sphinx", 2);

setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
execute();

assertHandCount(playerB, 1); // 1 from start of turn 1 and 4 from Opponents draw of 2 cards
assertHandCount(playerA, 4); // 2 from Sphinx triggered by the normal draw

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.triggers;

import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;

/**
*
* @author LevelX2
*/
public class HeartbeatOfSpringTest extends CardTestPlayerBase {

/**
* Heartbeat of Spring does not function on urza's
*/
@Test
public void testWorksForUrzasLand() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
// {T}: Add {C} to your mana pool. If you control an Urza's Power-Plant and an Urza's Tower, add {C}{C} to your mana pool instead.
addCard(Zone.HAND, playerA, "Urza's Mine", 1);
// Whenever a player taps a land for mana, that player adds one mana to his or her mana pool of any type that land produced.
addCard(Zone.HAND, playerA, "Heartbeat of Spring"); // {2}{G}
// Whenever a player casts a white spell, you may gain 1 life.
addCard(Zone.HAND, playerA, "Angel's Feather"); // {2}

castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Heartbeat of Spring");
playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Urza's Mine");

activateManaAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "{T}:");
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Angel's Feather");

setStopAt(1, PhaseStep.END_TURN);
execute();

assertPermanentCount(playerA, "Heartbeat of Spring", 1);
assertPermanentCount(playerA, "Angel's Feather", 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ public boolean priority(Game game) {
command = command.substring(command.indexOf("manaActivate:") + 13);
String[] groups = command.split("\\$");
List<MageObject> manaObjects = computerPlayer.getAvailableManaProducers(game);

for (MageObject mageObject : manaObjects) {
if (mageObject instanceof Permanent) {
for (Ability manaAbility : ((Permanent) mageObject).getAbilities(game).getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public void testMageRingNetwork() {
public void testMageRingNetwork2() {
// {T}: Add {C} to your mana pool.
// {T}, {1} : Put a storage counter on Mage-Ring Network.
// {T}, Remove X storage counters from Mage-Ring Network: Add {X} to your mana pool.
// {T}, Remove any number of storage counters from Mage-Ring Network: Add {C} to your mana pool for each storage counter removed this way.
addCard(Zone.BATTLEFIELD, playerA, "Mage-Ring Network", 1);
addCounters(1, PhaseStep.UPKEEP, playerA, "Mage-Ring Network", CounterType.STORAGE, 4);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
Expand All @@ -332,9 +332,8 @@ public void testMageRingNetwork2() {

ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);

Assert.assertEquals("mana variations don't fit", 2, manaOptions.size());
Assert.assertEquals("{C}{W}{B}", getManaOption(0, manaOptions));
Assert.assertEquals("{4}{W}{B}", getManaOption(1, manaOptions));
Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{C}{C}{C}{C}{W}{B}", getManaOption(0, manaOptions));
}

@Test
Expand Down
3 changes: 3 additions & 0 deletions Mage/src/main/java/mage/Mana.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,17 @@ public void subtractCost(final Mana mana) throws ArithmeticException {
if (black > 0) {
black--;
generic++;
continue;
}
if (colorless > 0) {
colorless--;
generic++;
continue;
}
if (any > 0) {
any--;
generic++;
continue;
}
if (oldColorless == generic) {
throw new ArithmeticException("Not enough mana to pay colorless");
Expand Down
6 changes: 3 additions & 3 deletions Mage/src/main/java/mage/abilities/AbilityImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@ public boolean activate(Game game, boolean noMana) {
if (cost instanceof TapSourceCost) {
Mana mana = null;
Effect effect = getEffects().get(0);
if (effect instanceof BasicManaEffect) {
mana = ((BasicManaEffect) effect).getMana(game, this);
} else if (effect instanceof DynamicManaEffect) {
if (effect instanceof DynamicManaEffect) {
mana = ((DynamicManaEffect) effect).getMana(game, this);
} else if (effect instanceof BasicManaEffect) {
mana = ((BasicManaEffect) effect).getMana(game, this);
}
if (mana != null && mana.getAny() == 0) { // if mana == null or Any > 0 the event has to be fired in the mana effect to know which mana was produced
ManaEvent event = new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId, mana);
Expand Down
38 changes: 16 additions & 22 deletions Mage/src/main/java/mage/abilities/TriggeredAbilityImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean resolve(Game game) {
if (isOptional()) {
MageObject object = game.getObject(getSourceId());
Player player = game.getPlayer(this.getControllerId());
if (player != null) {
if (player != null && object != null) {
if (!player.chooseUse(getEffects().get(0).getOutcome(), (object != null ? this.getRule(object.getLogName()) : this.getRule()), this, game)) {
return false;
}
Expand Down Expand Up @@ -129,22 +129,18 @@ public String getRule() {
newRule.insert(4, "may ");
superRule = newRule.toString();
}
} else {
if (this.getTargets().isEmpty()
|| ruleLow.startsWith("exile")
|| ruleLow.startsWith("destroy")
|| ruleLow.startsWith("return")
|| ruleLow.startsWith("tap")
|| ruleLow.startsWith("untap")
|| ruleLow.startsWith("put")
|| ruleLow.startsWith("remove")
|| ruleLow.startsWith("counter")) {
sb.append("you may ");
} else {
if (!ruleLow.startsWith("its controller may")) {
sb.append("you may have ");
}
}
} else if (this.getTargets().isEmpty()
|| ruleLow.startsWith("exile")
|| ruleLow.startsWith("destroy")
|| ruleLow.startsWith("return")
|| ruleLow.startsWith("tap")
|| ruleLow.startsWith("untap")
|| ruleLow.startsWith("put")
|| ruleLow.startsWith("remove")
|| ruleLow.startsWith("counter")) {
sb.append("you may ");
} else if (!ruleLow.startsWith("its controller may")) {
sb.append("you may have ");
}

}
Expand Down Expand Up @@ -191,12 +187,10 @@ public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
if (isLeavesTheBattlefieldTrigger()) {
if (event.getType().equals(EventType.DESTROYED_PERMANENT)) {
source = game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
} else if (((ZoneChangeEvent) event).getTarget() != null) {
source = ((ZoneChangeEvent) event).getTarget();
} else {
if (((ZoneChangeEvent) event).getTarget() != null) {
source = ((ZoneChangeEvent) event).getTarget();
} else {
source = game.getLastKnownInformation(getSourceId(), ((ZoneChangeEvent) event).getZone());
}
source = game.getLastKnownInformation(getSourceId(), ((ZoneChangeEvent) event).getZone());
}
}

Expand Down
Loading

0 comments on commit f54c675

Please sign in to comment.