* Fixed a bug of colorless mana (e.g. caused Heartbeat of Spring not working with Urza's lands).

This commit is contained in:
LevelX2 2016-02-16 17:15:47 +01:00
parent bf934137e8
commit f54c675c4b
15 changed files with 203 additions and 97 deletions

View file

@ -347,14 +347,17 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
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");

View file

@ -426,10 +426,10 @@ public abstract class AbilityImpl implements Ability {
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);

View file

@ -85,7 +85,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
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;
}
@ -129,22 +129,18 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
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 ");
}
}
@ -191,12 +187,10 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
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());
}
}

View file

@ -83,7 +83,7 @@ import org.apache.log4j.Logger;
*/
public class ContinuousEffects implements Serializable {
private static final Logger LOGGER = Logger.getLogger(ContinuousEffects.class);
private static final Logger logger = Logger.getLogger(ContinuousEffects.class);
private long order = 0;
@ -227,7 +227,7 @@ public class ContinuousEffects implements Serializable {
}
}
} else {
LOGGER.error("No abilities for continuous effect: " + effect.toString());
logger.error("No abilities for continuous effect: " + effect.toString());
}
break;
default:
@ -1095,10 +1095,10 @@ public class ContinuousEffects implements Serializable {
public void addEffect(ContinuousEffect effect, Ability source) {
if (effect == null) {
LOGGER.error("Effect is null: " + source.toString());
logger.error("Effect is null: " + source.toString());
return;
} else if (source == null) {
LOGGER.warn("Adding effect without ability : " + effect.toString());
logger.warn("Adding effect without ability : " + effect.toString());
}
switch (effect.getEffectType()) {
case REPLACEMENT:
@ -1165,7 +1165,7 @@ public class ContinuousEffects implements Serializable {
ability.setControllerId(controllerId);
}
} else if (!ability.getZone().equals(Zone.COMMAND)) {
LOGGER.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
logger.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
}
}
}
@ -1236,7 +1236,7 @@ public class ContinuousEffects implements Serializable {
}
}
} else {
LOGGER.error("Replacement effect without ability: " + entry.getKey().toString());
logger.error("Replacement effect without ability: " + entry.getKey().toString());
}
}
return texts;
@ -1274,7 +1274,7 @@ public class ContinuousEffects implements Serializable {
}
}
} else {
LOGGER.warn("Ability without sourceId:" + ability.getRule());
logger.warn("Ability without sourceId:" + ability.getRule());
}
}
}

View file

@ -138,6 +138,8 @@ public class DynamicManaEffect extends BasicManaEffect {
computedMana.setRed(count);
} else if (mana.getWhite() > 0) {
computedMana.setWhite(count);
} else if (mana.getColorless() > 0) {
computedMana.setColorless(count);
} else if (mana.getAny() > 0) {
if (netMana) {
computedMana.setAny(count);

View file

@ -1,4 +1,4 @@
/*
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
@ -132,20 +132,18 @@ public class ManaOptions extends ArrayList<Mana> {
}
}
}
} else // the ability has mana costs
if (netManas.size() == 1) {
subtractCostAddMana(ability.getManaCosts().getMana(), netManas.get(0), ability.getCosts().isEmpty());
} else {
// the ability has mana costs
if (netManas.size() == 1) {
subtractCostAddMana(ability.getManaCosts().getMana(), netManas.get(0), ability.getCosts().isEmpty());
} else {
List<Mana> copy = copy();
this.clear();
for (Mana netMana : netManas) {
for (Mana mana : copy) {
Mana newMana = new Mana();
newMana.add(mana);
newMana.add(netMana);
subtractCostAddMana(ability.getManaCosts().getMana(), netMana, ability.getCosts().isEmpty());
}
List<Mana> copy = copy();
this.clear();
for (Mana netMana : netManas) {
for (Mana mana : copy) {
Mana newMana = new Mana();
newMana.add(mana);
newMana.add(netMana);
subtractCostAddMana(ability.getManaCosts().getMana(), netMana, ability.getCosts().isEmpty());
}
}
}
@ -248,7 +246,7 @@ public class ManaOptions extends ArrayList<Mana> {
Mana oldMan = mana.copy();
if (mana.includesMana(cost)) {
// colorless costs can be paid with different colored mana, can lead to different color combinations
if (cost.getGeneric() > 0 && cost.getGeneric() > mana.getGeneric()) {
if (cost.getGeneric() > 0 && cost.getGeneric() > (mana.getGeneric() + mana.getColorless())) {
Mana coloredCost = cost.copy();
coloredCost.setGeneric(0);
mana.subtract(coloredCost);

View file

@ -138,7 +138,7 @@ public abstract class GameImpl implements Game, Serializable {
private static final int ROLLBACK_TURNS_MAX = 4;
private static final Logger LOGGER = Logger.getLogger(GameImpl.class);
private static final Logger logger = Logger.getLogger(GameImpl.class);
private static final FilterPermanent FILTER_AURA = new FilterPermanent();
private static final FilterPermanent FILTER_EQUIPMENT = new FilterPermanent();
@ -230,7 +230,7 @@ public abstract class GameImpl implements Game, Serializable {
public GameImpl(final GameImpl game) {
long t1 = 0;
if (LOGGER.isDebugEnabled()) {
if (logger.isDebugEnabled()) {
t1 = System.currentTimeMillis();
}
this.id = game.id;
@ -248,7 +248,7 @@ public abstract class GameImpl implements Game, Serializable {
this.lkiExtended.putAll(game.lkiExtended);
this.shortLivingLKI.putAll(game.shortLivingLKI);
this.permanentsEntering.putAll(game.permanentsEntering);
if (LOGGER.isDebugEnabled()) {
if (logger.isDebugEnabled()) {
copyCount++;
copyTime += (System.currentTimeMillis() - t1);
}
@ -577,7 +577,7 @@ public abstract class GameImpl implements Game, Serializable {
boolean result = checkIfGameIsOver();
return result;
} else {
LOGGER.debug("Game over for player Id: " + playerId + " gameId " + getId());
logger.debug("Game over for player Id: " + playerId + " gameId " + getId());
leave(playerId);
return true;
}
@ -599,15 +599,15 @@ public abstract class GameImpl implements Game, Serializable {
}
if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) {
end();
if (remainingPlayers == 0 && LOGGER.isDebugEnabled()) {
LOGGER.debug("DRAW for gameId: " + getId());
if (remainingPlayers == 0 && logger.isDebugEnabled()) {
logger.debug("DRAW for gameId: " + getId());
for (Player player : state.getPlayers().values()) {
LOGGER.debug("-- " + player.getName() + " left: " + (player.hasLeft() ? "Y" : "N") + " lost: " + (player.hasLost() ? "Y" : "N"));
logger.debug("-- " + player.getName() + " left: " + (player.hasLeft() ? "Y" : "N") + " lost: " + (player.hasLost() ? "Y" : "N"));
}
}
for (Player player : state.getPlayers().values()) {
if (!player.hasLeft() && !player.hasLost()) {
LOGGER.debug(new StringBuilder("Player ").append(player.getName()).append(" has won gameId: ").append(this.getId()));
logger.debug(new StringBuilder("Player ").append(player.getName()).append(" has won gameId: ").append(this.getId()));
player.won(this);
}
}
@ -643,8 +643,8 @@ public abstract class GameImpl implements Game, Serializable {
public int bookmarkState() {
if (!simulation) {
saveState(true);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Bookmarking state: " + gameStates.getSize());
if (logger.isTraceEnabled()) {
logger.trace("Bookmarking state: " + gameStates.getSize());
}
savedStates.push(gameStates.getSize() - 1);
return savedStates.size();
@ -772,7 +772,7 @@ public abstract class GameImpl implements Game, Serializable {
sb.append("]");
count++;
}
LOGGER.info(sb.toString());
logger.info(sb.toString());
}
}
@ -926,7 +926,7 @@ public abstract class GameImpl implements Game, Serializable {
}
Player startingPlayer = state.getPlayer(startingPlayerId);
if (startingPlayer == null) {
LOGGER.debug("Starting player not found. playerId:" + startingPlayerId);
logger.debug("Starting player not found. playerId:" + startingPlayerId);
return;
}
StringBuilder message = new StringBuilder(choosingPlayer.getLogName()).append(" chooses that ");
@ -1052,12 +1052,12 @@ public abstract class GameImpl implements Game, Serializable {
UUID winnerIdFound = null;
for (Player player : state.getPlayers().values()) {
if (player.hasWon()) {
LOGGER.debug(player.getName() + " has won gameId: " + getId());
logger.debug(player.getName() + " has won gameId: " + getId());
winnerIdFound = player.getId();
break;
}
if (!player.hasLost() && !player.hasLeft()) {
LOGGER.debug(player.getName() + " has not lost so he won gameId: " + this.getId());
logger.debug(player.getName() + " has not lost so he won gameId: " + this.getId());
player.won(this);
winnerIdFound = player.getId();
break;
@ -1089,7 +1089,7 @@ public abstract class GameImpl implements Game, Serializable {
return player.getId();
}
}
LOGGER.debug("Game was not possible to pick a choosing player. GameId:" + getId());
logger.debug("Game was not possible to pick a choosing player. GameId:" + getId());
return null;
}
@ -1106,7 +1106,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override
public void end() {
if (!state.isGameOver()) {
LOGGER.debug("END of gameId: " + this.getId());
logger.debug("END of gameId: " + this.getId());
endTime = new Date();
state.endGame();
for (Player player : state.getPlayers().values()) {
@ -1175,7 +1175,7 @@ public abstract class GameImpl implements Game, Serializable {
if (player != null) {
player.timerTimeout(this);
} else {
LOGGER.error(new StringBuilder("timerTimeout - player not found - playerId: ").append(playerId));
logger.error(new StringBuilder("timerTimeout - player not found - playerId: ").append(playerId));
}
}
@ -1185,7 +1185,7 @@ public abstract class GameImpl implements Game, Serializable {
if (player != null) {
player.idleTimeout(this);
} else {
LOGGER.error(new StringBuilder("idleTimeout - player not found - playerId: ").append(playerId));
logger.error(new StringBuilder("idleTimeout - player not found - playerId: ").append(playerId));
}
}
@ -1193,7 +1193,7 @@ public abstract class GameImpl implements Game, Serializable {
public synchronized void concede(UUID playerId) {
Player player = state.getPlayer(playerId);
if (player != null) {
LOGGER.debug("Player " + player.getName() + " concedes game " + this.getId());
logger.debug("Player " + player.getName() + " concedes game " + this.getId());
fireInformEvent(player.getLogName() + " has conceded.");
player.concede(this);
}
@ -1306,10 +1306,10 @@ public abstract class GameImpl implements Game, Serializable {
}
}
} catch (Exception ex) {
LOGGER.fatal("Game exception gameId: " + getId(), ex);
logger.fatal("Game exception gameId: " + getId(), ex);
if ((ex instanceof NullPointerException)
&& errorContinueCounter == 1 && ex.getStackTrace() != null) {
LOGGER.fatal(ex.getStackTrace());
logger.fatal(ex.getStackTrace());
}
this.fireErrorEvent("Game exception occurred: ", ex);
restoreState(bookmark, "");
@ -1329,7 +1329,7 @@ public abstract class GameImpl implements Game, Serializable {
}
}
} catch (Exception ex) {
LOGGER.fatal("Game exception ", ex);
logger.fatal("Game exception ", ex);
this.fireErrorEvent("Game exception occurred: ", ex);
this.end();
} finally {
@ -1736,7 +1736,7 @@ public abstract class GameImpl implements Game, Serializable {
}
if (spellAbility.getTargets().isEmpty()) {
Permanent enchanted = this.getPermanent(perm.getAttachedTo());
LOGGER.error("Aura without target: " + perm.getName() + " attached to " + (enchanted == null ? " null" : enchanted.getName()));
logger.error("Aura without target: " + perm.getName() + " attached to " + (enchanted == null ? " null" : enchanted.getName()));
} else {
Target target = spellAbility.getTargets().get(0);
if (target instanceof TargetPermanent) {
@ -2091,7 +2091,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override
public void debugMessage(String message) {
LOGGER.warn(message);
logger.warn(message);
}
@Override
@ -2115,7 +2115,7 @@ public abstract class GameImpl implements Game, Serializable {
if (simulation) {
return;
}
LOGGER.trace("fireUpdatePlayersEvent");
logger.trace("fireUpdatePlayersEvent");
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
getState().clearLookedAt();
getState().clearRevealed();
@ -2126,7 +2126,7 @@ public abstract class GameImpl implements Game, Serializable {
if (simulation) {
return;
}
LOGGER.trace("fireGameEndIfo");
logger.trace("fireGameEndIfo");
tableEventSource.fireTableEvent(EventType.END_GAME_INFO, null, this);
}
@ -2212,10 +2212,10 @@ public abstract class GameImpl implements Game, Serializable {
Player player = getPlayer(playerId);
if (player == null || player.hasLeft()) {
LOGGER.debug("Player already left " + (player != null ? player.getName() : playerId));
logger.debug("Player already left " + (player != null ? player.getName() : playerId));
return;
}
LOGGER.debug("Start leave game: " + player.getName());
logger.debug("Start leave game: " + player.getName());
player.leave();
if (checkIfGameIsOver()) {
// no need to remove objects if only one player is left so the game is over
@ -2530,9 +2530,9 @@ public abstract class GameImpl implements Game, Serializable {
try {
Integer amount = Integer.parseInt(s[1]);
player.setLife(amount, this);
LOGGER.info("Setting player's life: ");
logger.info("Setting player's life: ");
} catch (NumberFormatException e) {
LOGGER.fatal("error setting life", e);
logger.fatal("error setting life", e);
}
}