mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 12:52:06 -08:00
* Commander format - Fixed that the commanders color identity was not correctly set for the mana replacement effect. Mana symbols from the rule text were not taken into account.
This commit is contained in:
parent
4127d2b358
commit
de92c50944
4 changed files with 57 additions and 58 deletions
|
|
@ -27,17 +27,16 @@
|
|||
*/
|
||||
package mage.abilities.effects.common.continious;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ManaEvent;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -52,9 +51,9 @@ import org.apache.log4j.Logger;
|
|||
public class CommanderManaReplacementEffect extends ReplacementEffectImpl {
|
||||
|
||||
private final UUID playerId;
|
||||
private final Mana commanderMana;
|
||||
private final FilterMana commanderMana;
|
||||
|
||||
public CommanderManaReplacementEffect(UUID playerId, Mana commanderMana) {
|
||||
public CommanderManaReplacementEffect(UUID playerId, FilterMana commanderMana) {
|
||||
super(Duration.EndOfGame, Outcome.Neutral);
|
||||
staticText = "If mana would be added to a player's mana pool of a color that isn't in the color identity of that player's commander, that amount of colorless mana is added to that player's mana pool instead.";
|
||||
this.playerId = playerId;
|
||||
|
|
@ -80,31 +79,31 @@ public class CommanderManaReplacementEffect extends ReplacementEffectImpl {
|
|||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
Mana mana = ((ManaEvent) event).getMana();
|
||||
if (mana.getBlack() > 0 && commanderMana.getBlack() == 0) {
|
||||
if (mana.getBlack() > 0 && !commanderMana.isBlack()) {
|
||||
for (int i = 0; i < mana.getBlack(); i++) {
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setBlack(0);
|
||||
}
|
||||
if (mana.getBlue() > 0 && commanderMana.getBlue() == 0) {
|
||||
if (mana.getBlue() > 0 && !commanderMana.isBlue()) {
|
||||
for (int i = 0; i < mana.getBlue(); i++) {
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setBlue(0);
|
||||
}
|
||||
if (mana.getGreen() > 0 && commanderMana.getGreen() == 0) {
|
||||
if (mana.getGreen() > 0 && !commanderMana.isGreen()) {
|
||||
for (int i = 0; i < mana.getGreen(); i++) {
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setGreen(0);
|
||||
}
|
||||
if (mana.getRed() > 0 && commanderMana.getRed() == 0) {
|
||||
if (mana.getRed() > 0 && !commanderMana.isRed()) {
|
||||
for (int i = 0; i < mana.getRed(); i++) {
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setRed(0);
|
||||
}
|
||||
if (mana.getWhite() > 0 && commanderMana.getWhite()== 0) {
|
||||
if (mana.getWhite() > 0 && !commanderMana.isWhite()) {
|
||||
for (int i = 0; i < mana.getWhite(); i++) {
|
||||
mana.addColorless();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EmptyEffect;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
|
|
@ -52,8 +51,8 @@ import mage.filter.FilterCard;
|
|||
import mage.game.turn.TurnMod;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.util.CardUtil;
|
||||
import mage.watchers.common.CommanderCombatDamageWatcher;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public abstract class GameCommanderImpl extends GameImpl {
|
||||
|
||||
|
|
@ -87,14 +86,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
commander.moveToZone(Zone.COMMAND, null, this, true);
|
||||
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoLibrary));
|
||||
ability.addEffect(new CommanderCostModification(commander.getId()));
|
||||
Mana commanderMana;
|
||||
if (commander.getSpellAbility().getManaCosts() == null) {
|
||||
Logger.getLogger(GameCommanderImpl.class).warn("Got commander without Mana costs: " + commander.getName());
|
||||
commanderMana = new Mana();
|
||||
} else {
|
||||
commanderMana = commander.getSpellAbility().getManaCosts().getMana();
|
||||
}
|
||||
ability.addEffect(new CommanderManaReplacementEffect(player.getId(), commanderMana));
|
||||
ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
|
||||
getState().setValue(commander.getId() + "_castCount", 0);
|
||||
CommanderCombatDamageWatcher watcher = new CommanderCombatDamageWatcher(commander.getId());
|
||||
getState().getWatchers().add(watcher);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
|
|
@ -51,6 +50,7 @@ import mage.abilities.keyword.ChangelingAbility;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.CardType;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.token.Token;
|
||||
import mage.game.stack.Spell;
|
||||
|
|
@ -58,12 +58,17 @@ import mage.util.functions.CopyFunction;
|
|||
import mage.util.functions.CopyTokenFunction;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class CardUtil {
|
||||
|
||||
private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
|
||||
private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
|
||||
private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
|
||||
private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
|
||||
private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
|
||||
|
||||
static String numberStrings[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
|
||||
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "ninteen", "twenty"};
|
||||
|
||||
|
|
@ -556,4 +561,41 @@ public class CardUtil {
|
|||
}
|
||||
return cmcObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the colors that are in the casting cost but also in the rules text
|
||||
* as far as not included in reminder text.
|
||||
*
|
||||
* @param card
|
||||
* @return
|
||||
*/
|
||||
public static FilterMana getColorIdentity(Card card) {
|
||||
FilterMana mana = new FilterMana();
|
||||
mana.setBlack(card.getManaCost().getText().matches(regexBlack));
|
||||
mana.setBlue(card.getManaCost().getText().matches(regexBlue));
|
||||
mana.setGreen(card.getManaCost().getText().matches(regexGreen));
|
||||
mana.setRed(card.getManaCost().getText().matches(regexRed));
|
||||
mana.setWhite(card.getManaCost().getText().matches(regexWhite));
|
||||
|
||||
for (String rule : card.getRules()) {
|
||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||
if (rule.matches(regexBlack)) {
|
||||
mana.setBlack(true);
|
||||
}
|
||||
if (rule.matches(regexBlue)) {
|
||||
mana.setBlue(true);
|
||||
}
|
||||
if (rule.matches(regexGreen)) {
|
||||
mana.setGreen(true);
|
||||
}
|
||||
if (rule.matches(regexRed)) {
|
||||
mana.setRed(true);
|
||||
}
|
||||
if (rule.matches(regexWhite)) {
|
||||
mana.setWhite(true);
|
||||
}
|
||||
}
|
||||
return mana;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue