Fix omniscience effect for colorless mana.

Also unified the tests for omniscience into a single file, and
put the effect into a single class so that Tamiyo and Omniscience
can share implementations.
This commit is contained in:
Nathaniel Brandes 2017-03-04 23:04:11 -08:00
parent be82f3bf33
commit 1d3ebb749d
6 changed files with 179 additions and 231 deletions

View file

@ -0,0 +1,77 @@
package mage.abilities.effects.common.continuous;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.condition.CompoundCondition;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.SourceIsSpellCondition;
import mage.abilities.costs.AlternativeCostSourceAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.cards.SplitCardHalf;
import mage.constants.*;
import mage.filter.common.FilterNonlandCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import java.util.UUID;
public class CastFromHandWithoutPayingManaCostEffect extends ContinuousEffectImpl {
public CastFromHandWithoutPayingManaCostEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "You may cast nonland cards from your hand without paying their mana costs";
}
public CastFromHandWithoutPayingManaCostEffect(final CastFromHandWithoutPayingManaCostEffect effect) {
super(effect);
}
@Override
public CastFromHandWithoutPayingManaCostEffect copy() {
return new CastFromHandWithoutPayingManaCostEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.getAlternativeSourceCosts().add(new AlternativeCostSourceAbility(
null, new CompoundCondition(SourceIsSpellCondition.getInstance(), new IsBeingCastFromHandCondition()), null, new FilterNonlandCard(), true));
return true;
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
}
class IsBeingCastFromHandCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
MageObject object = game.getObject(source.getSourceId());
if (object instanceof SplitCardHalf) {
UUID splitCardId = ((Card) object).getMainCard().getId();
object = game.getObject(splitCardId);
}
if (object instanceof Spell) { // needed to check if it can be cast by alternate cost
Spell spell = (Spell) object;
return spell.getFromZone() == Zone.HAND;
}
if (object instanceof Card) { // needed for the check what's playable
Card card = (Card) object;
return game.getPlayer(card.getOwnerId()).getHand().get(card.getId(), game) != null;
}
return false;
}
}

View file

@ -31,6 +31,9 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Supplier;
import mage.MageObject;
import mage.Mana;
import mage.ObjectColor;
@ -271,12 +274,12 @@ public final class CardUtil {
reduceMana.add(manaCost.getMana());
}
}
ManaCosts<ManaCost> manaCostToCheckForColorless = new ManaCostsImpl<>();
// subtract colored mana
ManaCosts<ManaCost> manaCostToCheckForGeneric = new ManaCostsImpl<>();
// subtract non-generic mana
for (ManaCost newManaCost : previousCost) {
Mana mana = newManaCost.getMana();
if (!(newManaCost instanceof MonoHybridManaCost) && mana.getGeneric() > 0) {
manaCostToCheckForColorless.add(newManaCost);
manaCostToCheckForGeneric.add(newManaCost);
continue;
}
boolean hybridMana = newManaCost instanceof HybridManaCost;
@ -340,6 +343,17 @@ public final class CardUtil {
continue;
}
}
if(mana.getColorless() > 0 && reduceMana.getColorless() > 0) {
if(reduceMana.getColorless() > mana.getColorless()) {
reduceMana.setColorless(reduceMana.getColorless() - mana.getColorless());
mana.setColorless(0);
} else {
mana.setColorless(mana.getColorless() - reduceMana.getColorless());
reduceMana.setColorless(0);
}
}
if (mana.count() > 0) {
if (newManaCost instanceof MonoHybridManaCost) {
if (mana.count() == 2) {
@ -347,7 +361,7 @@ public final class CardUtil {
continue;
}
}
manaCostToCheckForColorless.add(newManaCost);
manaCostToCheckForGeneric.add(newManaCost);
}
}
@ -360,7 +374,7 @@ public final class CardUtil {
reduceAmount = reduceMana.getGeneric();
}
if (reduceAmount > 0) {
for (ManaCost newManaCost : manaCostToCheckForColorless) {
for (ManaCost newManaCost : manaCostToCheckForGeneric) {
Mana mana = newManaCost.getMana();
if (mana.getGeneric() == 0 || reduceAmount == 0) {
adjustedCost.add(newManaCost);
@ -387,7 +401,7 @@ public final class CardUtil {
}
}
} else {
adjustedCost.addAll(manaCostToCheckForColorless);
adjustedCost.addAll(manaCostToCheckForGeneric);
}
if (adjustedCost.isEmpty()) {
adjustedCost.add(new GenericManaCost(0)); // neede to check if cost was reduced to 0
@ -397,6 +411,10 @@ public final class CardUtil {
spellAbility.getManaCostsToPay().addAll(adjustedCost);
}
private void reduceMana(Mana mana, Mana reduceMana, Supplier<Integer> manaAmountSupplier, Consumer<Integer> manaAmountConsumer) {
}
/**
* Returns function that copies params\abilities from one card to
* {@link Token}.