* Monocolor hybrid mana - Fixed that the payment did not always try to pay the colored cost if possible.

This commit is contained in:
LevelX2 2015-09-20 19:13:18 +02:00
parent 8880e263f9
commit b2ff7ac380
7 changed files with 143 additions and 52 deletions

View file

@ -106,7 +106,9 @@ class OblivionSowerEffect extends OneShotEffect {
Cards exiledLands = new CardsImpl(); Cards exiledLands = new CardsImpl();
exiledLands.addAll(exiledCards.getCards(filter, source.getSourceId(), controller.getId(), game)); exiledLands.addAll(exiledCards.getCards(filter, source.getSourceId(), controller.getId(), game));
if (!exiledLands.isEmpty() && controller.chooseUse(outcome, "Put lands into play?", source, game)) { if (!exiledLands.isEmpty() && controller.chooseUse(outcome, "Put lands into play?", source, game)) {
FilterCard filterToPlay = new FilterCard("Lands owned by " + targetPlayer.getName() + " to put into play under your control"); FilterCard filterToPlay = new FilterCard("land"
+ (exiledLands.size() > 1 ? "s" : "") + " from exile owned by "
+ targetPlayer.getName() + " to put into play under your control");
TargetCard targetCards = new TargetCard(0, exiledLands.size(), Zone.EXILED, filterToPlay); TargetCard targetCards = new TargetCard(0, exiledLands.size(), Zone.EXILED, filterToPlay);
if (controller.chooseTarget(outcome, exiledLands, targetCards, source, game)) { if (controller.chooseTarget(outcome, exiledLands, targetCards, source, game)) {
controller.moveCards(new CardsImpl(targetCards.getTargets()), null, Zone.BATTLEFIELD, source, game); controller.moveCards(new CardsImpl(targetCards.getTargets()), null, Zone.BATTLEFIELD, source, game);

View file

@ -58,8 +58,8 @@ import mage.target.TargetSpell;
import mage.util.CardUtil; import mage.util.CardUtil;
/** /**
import mage.constants.Outcome; * import mage.constants.Outcome;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class Mindreaver extends CardImpl { public class Mindreaver extends CardImpl {
@ -77,10 +77,10 @@ public class Mindreaver extends CardImpl {
Ability ability = new HeroicAbility(new MindreaverExileEffect(), false); Ability ability = new HeroicAbility(new MindreaverExileEffect(), false);
ability.addTarget(new TargetPlayer()); ability.addTarget(new TargetPlayer());
this.addAbility(ability); this.addAbility(ability);
// {U}{U}, Sacrifice Mindreaver: Counter target spell with the same name as a card exiled with mindreaver. // {U}{U}, Sacrifice Mindreaver: Counter target spell with the same name as a card exiled with Mindreaver.
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CounterTargetEffect(), new ManaCostsImpl("{U}{U}")); ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CounterTargetEffect(), new ManaCostsImpl("{U}{U}"));
FilterSpell filter = new FilterSpell("spell with the same name as a card exiled with mindreaver"); FilterSpell filter = new FilterSpell("spell with the same name as a card exiled with {this}");
filter.add(new MindreaverNamePredicate(this.getId())); filter.add(new MindreaverNamePredicate(this.getId()));
ability.addTarget(new TargetSpell(filter)); ability.addTarget(new TargetSpell(filter));
ability.addCost(new SacrificeSourceCost()); ability.addCost(new SacrificeSourceCost());
@ -116,12 +116,13 @@ class MindreaverExileEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
UUID exileId = CardUtil.getCardExileZoneId(game, source); UUID exileId = CardUtil.getCardExileZoneId(game, source);
MageObject sourceObject = source.getSourceObject(game);
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source)); Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (opponent != null) { if (opponent != null && sourceObject != null) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Card card = opponent.getLibrary().getFromTop(game); Card card = opponent.getLibrary().getFromTop(game);
if (card != null) { if (card != null) {
card.moveToExile(exileId, "Mindreaver", source.getSourceId(), game); card.moveToExile(exileId, sourceObject.getIdName(), source.getSourceId(), game);
} }
} }
} }
@ -130,29 +131,29 @@ class MindreaverExileEffect extends OneShotEffect {
} }
class MindreaverNamePredicate implements Predicate<MageObject> { class MindreaverNamePredicate implements Predicate<MageObject> {
private final UUID sourceId; private final UUID sourceId;
public MindreaverNamePredicate(UUID sourceId) { public MindreaverNamePredicate(UUID sourceId) {
this.sourceId = sourceId; this.sourceId = sourceId;
} }
@Override @Override
public boolean apply(MageObject input, Game game) { public boolean apply(MageObject input, Game game) {
Set<String> cardNames = new HashSet<String>(); Set<String> cardNames = new HashSet<String>();
UUID exileId = CardUtil.getCardExileZoneId(game, sourceId); UUID exileId = CardUtil.getCardExileZoneId(game, sourceId);
ExileZone exileZone = game.getExile().getExileZone(exileId); ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null) { if (exileZone != null) {
for(Card card : exileZone.getCards(game)) { for (Card card : exileZone.getCards(game)) {
cardNames.add(card.getName()); cardNames.add(card.getName());
} }
} }
// If a player names a card, the player may name either half of a split card, but not both. // If a player names a card, the player may name either half of a split card, but not both.
// A split card has the chosen name if one of its two names matches the chosen name. // A split card has the chosen name if one of its two names matches the chosen name.
if (input instanceof SplitCard) { if (input instanceof SplitCard) {
return cardNames.contains(((SplitCard)input).getLeftHalfCard().getName()) || cardNames.contains(((SplitCard)input).getRightHalfCard().getName()); return cardNames.contains(((SplitCard) input).getLeftHalfCard().getName()) || cardNames.contains(((SplitCard) input).getRightHalfCard().getName());
} else if (input instanceof Spell && ((Spell)input).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)){ } else if (input instanceof Spell && ((Spell) input).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
SplitCard card = (SplitCard) ((Spell)input).getCard(); SplitCard card = (SplitCard) ((Spell) input).getCard();
return cardNames.contains(card.getLeftHalfCard().getName()) || cardNames.contains(card.getRightHalfCard().getName()); return cardNames.contains(card.getLeftHalfCard().getName()) || cardNames.contains(card.getRightHalfCard().getName());
} else { } else {
return cardNames.contains(input.getName()); return cardNames.contains(input.getName());
@ -163,4 +164,4 @@ class MindreaverNamePredicate implements Predicate<MageObject> {
public String toString() { public String toString() {
return "spell with the same name as a card exiled with {source}"; return "spell with the same name as a card exiled with {source}";
} }
} }

View file

@ -44,22 +44,21 @@ import mage.filter.predicate.permanent.ControllerPredicate;
* @author LevelX2 * @author LevelX2
*/ */
public class DictateOfErebos extends CardImpl { public class DictateOfErebos extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control"); private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature you control");
static { static {
filter.add(new ControllerPredicate(TargetController.YOU)); filter.add(new ControllerPredicate(TargetController.YOU));
} }
public DictateOfErebos(UUID ownerId) { public DictateOfErebos(UUID ownerId) {
super(ownerId, 65, "Dictate of Erebos", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}{B}"); super(ownerId, 65, "Dictate of Erebos", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}{B}");
this.expansionSetCode = "JOU"; this.expansionSetCode = "JOU";
// Flash // Flash
this.addAbility(FlashAbility.getInstance()); this.addAbility(FlashAbility.getInstance());
// Whenever a creature you control dies, each opponent sacrifices a creature. // Whenever a creature you control dies, each opponent sacrifices a creature.
this.addAbility(new DiesCreatureTriggeredAbility(new SacrificeOpponentsEffect(new FilterControlledCreaturePermanent("a creature")), false, filter)); this.addAbility(new DiesCreatureTriggeredAbility(new SacrificeOpponentsEffect(new FilterControlledCreaturePermanent("a creature")), false, filter));
} }
public DictateOfErebos(final DictateOfErebos card) { public DictateOfErebos(final DictateOfErebos card) {

View file

@ -74,7 +74,6 @@ public class ChandraPyromaster extends CardImpl {
this.expansionSetCode = "M14"; this.expansionSetCode = "M14";
this.subtype.add("Chandra"); this.subtype.add("Chandra");
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false)); this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(4)), false));
// +1: Chandra, Pyromaster deals 1 damage to target player and 1 damage to up to one target creature that player controls. That creature can't block this turn. // +1: Chandra, Pyromaster deals 1 damage to target player and 1 damage to up to one target creature that player controls. That creature can't block this turn.
@ -215,7 +214,7 @@ class ChandraPyromasterEffect2 extends OneShotEffect {
Card card = library.removeFromTop(game); Card card = library.removeFromTop(game);
if (card != null) { if (card != null) {
controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName() + " <this card may be played the turn it was exiled>", source.getSourceId(), game, Zone.LIBRARY, true); controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName() + " <this card may be played the turn it was exiled>", source.getSourceId(), game, Zone.LIBRARY, true);
ContinuousEffect effect = new ChandraPyromasterCastFromExileEffect(); ContinuousEffect effect = new ChandraPyromasterCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId())); effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source); game.addEffect(effect, source);
} }
@ -273,36 +272,31 @@ class ChandraPyromasterEffect3 extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (you == null) { MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false; return false;
} }
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
int max = Math.min(you.getLibrary().size(), 10); cards.addAll(controller.getLibrary().getTopCards(game, 10));
for (int i = 0; i < max; i++) { controller.moveCardsToExile(cards.getCards(game), source, game, true, source.getSourceId(), sourceObject.getIdName());
Card card = you.getLibrary().removeFromTop(game);
if (card != null) {
card.moveToExile(source.getSourceId(), "Chandra Pyromaster", source.getSourceId(), game);
cards.add(card);
}
}
if (cards.getCards(new FilterInstantOrSorceryCard(), game).size() > 0) { if (cards.getCards(new FilterInstantOrSorceryCard(), game).size() > 0) {
TargetCard target = new TargetCard(Zone.EXILED, new FilterInstantOrSorceryCard()); TargetCard target = new TargetCard(Zone.EXILED, new FilterInstantOrSorceryCard());
if (you.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) { if (controller.chooseTarget(Outcome.PlayForFree, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game); Card card = cards.get(target.getFirstTarget(), game);
if (card != null) { if (card != null) {
Card copy1 = card.copy(); if (controller.chooseUse(outcome, "Do you wish to cast copy 1 of " + card.getName(), source, game)) {
Card copy2 = card.copy(); Card copy1 = card.copy();
Card copy3 = card.copy(); controller.cast(copy1.getSpellAbility(), game, true);
if (copy1 != null && you.chooseUse(outcome, "Do you wish to cast copy 1 of " + card.getName(), source, game)) {
you.cast(copy1.getSpellAbility(), game, true);
} }
if (copy2 != null && you.chooseUse(outcome, "Do you wish to cast copy 2 of " + card.getName(), source, game)) { if (controller.chooseUse(outcome, "Do you wish to cast copy 2 of " + card.getName(), source, game)) {
you.cast(copy2.getSpellAbility(), game, true); Card copy2 = card.copy();
controller.cast(copy2.getSpellAbility(), game, true);
} }
if (copy3 != null && you.chooseUse(outcome, "Do you wish to cast copy 3 of " + card.getName(), source, game)) { if (controller.chooseUse(outcome, "Do you wish to cast copy 3 of " + card.getName(), source, game)) {
you.cast(copy3.getSpellAbility(), game, true); Card copy3 = card.copy();
controller.cast(copy3.getSpellAbility(), game, true);
} }
return true; return true;
} }

View file

@ -0,0 +1,62 @@
/*
* 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.mana;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class HybridManaTest extends CardTestPlayerBase {
@Test
public void testCastReaperKingMonoHybrid() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
// Other Scarecrow creatures you control get +1/+1.
// Whenever another Scarecrow enters the battlefield under your control, destroy target permanent.
addCard(Zone.HAND, playerA, "Reaper King", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Reaper King");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Reaper King", 1);
}
}

View file

@ -228,30 +228,62 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof ColoredManaCost) { if (!cost.isPaid() && cost instanceof ColoredManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof HybridManaCost) { if (!cost.isPaid() && cost instanceof HybridManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
} }
} }
// Mono Hybrid mana costs
// First try only to pay colored mana with the pool
for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof MonoHybridManaCost) {
if (((((MonoHybridManaCost) cost).containsColor(ColoredManaSymbol.W)) && pool.getWhite() > 0)
|| ((((MonoHybridManaCost) cost).containsColor(ColoredManaSymbol.B)) && pool.getBlack() > 0)
|| ((((MonoHybridManaCost) cost).containsColor(ColoredManaSymbol.R)) && pool.getRed() > 0)
|| ((((MonoHybridManaCost) cost).containsColor(ColoredManaSymbol.G)) && pool.getGreen() > 0)
|| ((((MonoHybridManaCost) cost).containsColor(ColoredManaSymbol.U)) && pool.getBlue() > 0)) {
cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
}
}
}
// if colored didn't fit pay colorless with the mana
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof MonoHybridManaCost) { if (!cost.isPaid() && cost instanceof MonoHybridManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof SnowManaCost) { if (!cost.isPaid() && cost instanceof SnowManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
} }
} }
for (ManaCost cost : this) { for (ManaCost cost : this) {
if (!cost.isPaid() && cost instanceof GenericManaCost) { if (!cost.isPaid() && cost instanceof GenericManaCost) {
cost.assignPayment(game, ability, pool); cost.assignPayment(game, ability, pool);
if (pool.count() == 0) {
return;
}
} }
} }

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,8 +45,7 @@ import mage.target.TargetPermanent;
import mage.util.CardUtil; import mage.util.CardUtil;
/** /**
* All opponents have to sacrifice [amount] permanents * All opponents have to sacrifice [amount] permanents that match the [filter].
* that match the [filter].
* *
* @author LevelX2 * @author LevelX2
*/ */
@ -59,6 +57,7 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
public SacrificeOpponentsEffect(FilterPermanent filter) { public SacrificeOpponentsEffect(FilterPermanent filter) {
this(1, filter); this(1, filter);
} }
public SacrificeOpponentsEffect(int amount, FilterPermanent filter) { public SacrificeOpponentsEffect(int amount, FilterPermanent filter) {
this(new StaticValue(amount), filter); this(new StaticValue(amount), filter);
} }
@ -87,12 +86,14 @@ public class SacrificeOpponentsEffect extends OneShotEffect {
filter.add(new ControllerPredicate(TargetController.YOU)); filter.add(new ControllerPredicate(TargetController.YOU));
for (UUID playerId : game.getOpponents(source.getControllerId())) { for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
int numTargets = Math.min(amount.calculate(game, source, this), game.getBattlefield().countAll(filter, player.getId(), game)); int numTargets = Math.min(amount.calculate(game, source, this), game.getBattlefield().countAll(filter, player.getId(), game));
TargetPermanent target = new TargetPermanent(numTargets, numTargets, filter, true); if (numTargets > 0) {
if (target.canChoose(player.getId(), game)) { TargetPermanent target = new TargetPermanent(numTargets, numTargets, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, source, game); if (target.canChoose(player.getId(), game)) {
perms.addAll(target.getTargets()); player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.addAll(target.getTargets());
}
} }
} }
} }