Merge origin/master

This commit is contained in:
fireshoes 2015-08-25 22:27:04 -05:00
commit 0bc3ed1cbc
20 changed files with 339 additions and 146 deletions

View file

@ -89,6 +89,9 @@ public class CardsView extends LinkedHashMap<UUID, CardView> {
case EXILED:
case GRAVEYARD:
sourceObject = game.getCard(ability.getSourceId());
if (sourceObject == null) {
sourceObject = game.getPermanent(ability.getSourceId());
}
isCard = true;
break;
case BATTLEFIELD:

View file

@ -846,7 +846,8 @@ public class GameController implements GameCallback {
perform(playerId, new Command() {
@Override
public void execute(UUID playerId) {
getGameSession(playerId).target(question, new CardsView(abilities, game), null, required, options);
CardsView cardsView = new CardsView(abilities, game);
getGameSession(playerId).target(question, cardsView, null, required, options);
}
});
}

View file

@ -108,15 +108,16 @@ class FelhideSpiritbinderEffect extends OneShotEffect {
if (permanent != null) {
PutTokenOntoBattlefieldCopyTargetEffect effect = new PutTokenOntoBattlefieldCopyTargetEffect(null, CardType.ENCHANTMENT, true);
effect.setTargetPointer(getTargetPointer());
if (effect.apply(game, source) && effect.getAddedPermanent() != null) {
if (effect.apply(game, source)) {
for (Permanent tokenPermanent : effect.getAddedPermanent()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(effect.getAddedPermanent().getId()));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
return true;
}
}

View file

@ -35,9 +35,10 @@ import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.ExileSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlSourceEffect;
import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect;
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.FlyingAbility;
@ -51,6 +52,7 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
import mage.target.targetpointer.FixedTarget;
@ -108,12 +110,19 @@ class TatsumaTheDragonsFangEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
CreateTokenEffect effect = new CreateTokenEffect(new TatsumaDragonToken());
effect.apply(game, source);
FixedTarget fixedTarget = new FixedTarget(effect.getLastAddedTokenId());
DelayedTriggeredAbility delayedAbility = new TatsumaTheDragonsFangTriggeredAbility(fixedTarget);
for (UUID tokenId : effect.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
FixedTarget fixedTarget = new FixedTarget(tokenPermanent, game);
Effect returnEffect = new ReturnToBattlefieldUnderOwnerControlTargetEffect();
returnEffect.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId())));
DelayedTriggeredAbility delayedAbility = new TatsumaTheDragonsFangTriggeredAbility(fixedTarget, returnEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
}
return true;
}
@ -123,8 +132,8 @@ class TatsumaTheDragonsFangTriggeredAbility extends DelayedTriggeredAbility {
protected FixedTarget fixedTarget;
public TatsumaTheDragonsFangTriggeredAbility(FixedTarget fixedTarget) {
super(new ReturnToBattlefieldUnderYourControlSourceEffect(), Duration.OneUse);
public TatsumaTheDragonsFangTriggeredAbility(FixedTarget fixedTarget, Effect effect) {
super(effect, Duration.OneUse);
this.fixedTarget = fixedTarget;
}
@ -160,6 +169,7 @@ class TatsumaTheDragonsFangTriggeredAbility extends DelayedTriggeredAbility {
}
class TatsumaDragonToken extends Token {
public TatsumaDragonToken() {
super("Dragon Spirit", "5/5 blue Dragon Spirit creature token with flying");
cardType.add(CardType.CREATURE);

View file

@ -43,6 +43,7 @@ import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard;
@ -59,7 +60,6 @@ public class Seance extends CardImpl {
super(ownerId, 20, "Seance", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{W}");
this.expansionSetCode = "DKA";
// At the beginning of each upkeep, you may exile target creature card from your graveyard. If you do, put a token onto the battlefield that's a copy of that card except it's a Spirit in addition to its other types. Exile it at the beginning of the next end step.
Ability ability = new BeginningOfUpkeepTriggeredAbility(new SeanceEffect(), TargetController.ANY, true);
ability.addTarget(new TargetCardInYourGraveyard(new FilterCreatureCard()));
@ -105,15 +105,19 @@ class SeanceEffect extends OneShotEffect {
token.getSubtype().add("Spirit");
}
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(token.getLastAddedToken()));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
}
}
return true;
}

View file

@ -110,13 +110,18 @@ class MirrorMockeryEffect extends OneShotEffect {
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(token.getLastAddedToken()));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
}
return true;
}
return false;

View file

@ -116,9 +116,14 @@ class FlamerushRiderEffect extends OneShotEffect {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(permanent);
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId(), true, true);
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
Effect effect = new ExileTargetEffect();
effect.setTargetPointer(new FixedTarget(token.getLastAddedToken()));
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
new CreateDelayedTriggeredAbilityEffect(new AtTheEndOfCombatDelayedTriggeredAbility(effect), false).apply(game, source);
}
}
return true;
}
return false;

View file

@ -117,10 +117,7 @@ class HelmOfKaldraCondition implements Condition {
if (game.getBattlefield().count(HelmOfKaldra.filterShield, source.getSourceId(), source.getControllerId(), game) < 1) {
return false;
}
if (game.getBattlefield().count(HelmOfKaldra.filterShield, source.getSourceId(), source.getControllerId(), game) < 1) {
return false;
}
return true;
return game.getBattlefield().count(HelmOfKaldra.filterShield, source.getSourceId(), source.getControllerId(), game) >= 1;
}
}
@ -146,8 +143,8 @@ class HelmOfKaldraEffect extends OneShotEffect {
if (new HelmOfKaldraCondition().apply(game, source)) {
CreateTokenEffect effect = new CreateTokenEffect(new KaldraToken());
effect.apply(game, source);
UUID kaldraId = effect.getLastAddedTokenId();
Permanent kaldra = game.getPermanent(kaldraId);
for (UUID tokenId : effect.getLastAddedTokenIds()) {
Permanent kaldra = game.getPermanent(tokenId);
if (kaldra != null) {
// Attach helm to the token
for (Permanent kaldrasHelm : game.getBattlefield().getAllActivePermanents(HelmOfKaldra.filterHelm, source.getControllerId(), game)) {
@ -166,6 +163,8 @@ class HelmOfKaldraEffect extends OneShotEffect {
}
}
return true;
}
}
return false;
}

View file

@ -50,9 +50,9 @@ public class MirarisWake extends CardImpl {
super(ownerId, 139, "Mirari's Wake", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{G}{W}");
this.expansionSetCode = "JUD";
// Creatures you control get +1/+1.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield)));
// Whenever you tap a land for mana, add one mana to your mana pool of any type that land produced.
AddManaOfAnyTypeProducedEffect effect = new AddManaOfAnyTypeProducedEffect();
effect.setText("add one mana to your mana pool of any type that land produced");

View file

@ -104,15 +104,16 @@ class FlameshadowConjuringEffect extends OneShotEffect {
if (permanent != null) {
PutTokenOntoBattlefieldCopyTargetEffect effect = new PutTokenOntoBattlefieldCopyTargetEffect(null, null, true);
effect.setTargetPointer(getTargetPointer());
if (effect.apply(game, source) && effect.getAddedPermanent() != null) {
if (effect.apply(game, source)) {
for (Permanent tokenPermanent : effect.getAddedPermanent()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(effect.getAddedPermanent().getId()));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
return true;
}
}

View file

@ -62,7 +62,9 @@ public class VorinclexVoiceOfHunger extends CardImpl {
this.power = new MageInt(7);
this.toughness = new MageInt(6);
// Trample
this.addAbility(TrampleAbility.getInstance());
// Whenever you tap a land for mana, add one mana to your mana pool of any type that land produced.
ManaEffect effect = new AddManaOfAnyTypeProducedEffect();
effect.setText("add one mana to your mana pool of any type that land produced");

View file

@ -42,6 +42,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
@ -56,7 +57,6 @@ public class FeralLightning extends CardImpl {
super(ownerId, 97, "Feral Lightning", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{3}{R}{R}{R}");
this.expansionSetCode = "SOK";
// Put three 3/1 red Elemental creature tokens with haste onto the battlefield. Exile them at the beginning of the next end step.
this.getSpellAbility().addEffect(new FeralLightningEffect());
@ -95,14 +95,17 @@ class FeralLightningEffect extends OneShotEffect {
CreateTokenEffect effect = new CreateTokenEffect(new FeralLightningElementalToken(), 3);
effect.apply(game, source);
for (UUID tokenId : effect.getLastAddedTokenIds()) {
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(tokenId));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
}
return true;
}

View file

@ -210,13 +210,18 @@ class MimicVatCreateTokenEffect extends OneShotEffect {
token.addAbility(HasteAbility.getInstance());
token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(token.getLastAddedToken()));
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
}
return true;
}

View file

@ -28,12 +28,12 @@
package mage.sets.tenthedition;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.MageInt;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.GainLifeEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
/**
*
@ -50,6 +50,8 @@ public class VenerableMonk extends CardImpl {
this.power = new MageInt(2);
this.toughness = new MageInt(2);
// When Venerable Monk enters the battlefield, you gain 2 life.
this.addAbility(new EntersBattlefieldTriggeredAbility(new GainLifeEffect(2)));
}

View file

@ -28,16 +28,16 @@
package mage.sets.zendikar;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.condition.common.KickedCondition;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.KickerAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
@ -54,7 +54,6 @@ public class RiteOfReplication extends CardImpl {
super(ownerId, 61, "Rite of Replication", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{2}{U}{U}");
this.expansionSetCode = "ZEN";
// Kicker {5}
this.addAbility(new KickerAbility("{5}"));

View file

@ -0,0 +1,65 @@
/*
* 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 VorinclexVoiceOfHungerTest extends CardTestPlayerBase {
/**
* Vorinclex, Voice of Hunger is not mana doubling River of Tears.
*/
@Test
public void testRiverOfTears() {
// Trample
// Whenever you tap a land for mana, add one mana to your mana pool of any type that land produced.
// Whenever an opponent taps a land for mana, that land doesn't untap during its controller's next untap step.
addCard(Zone.BATTLEFIELD, playerA, "Vorinclex, Voice of Hunger", 1);
// {T}: Add {U} to your mana pool. If you played a land this turn, add {B} to your mana pool instead.
addCard(Zone.BATTLEFIELD, playerA, "River of Tears", 1);
addCard(Zone.HAND, playerA, "Vedalken Mastermind", 1);
// because available mana calculation does not work correctly with Vorinclex, Voice of Hunger we have to tap the land manually
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {U} to your mana pool");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Vedalken Mastermind");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Vedalken Mastermind", 1);
}
}

View file

@ -7,17 +7,19 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Doubling Season:
* If an effect would put one or more tokens onto the battlefield under your control, it puts twice that many of those tokens onto the battlefield instead.
* If an effect would place one or more counters on a permanent you control, it places twice that many of those counters on that permanent instead.
* Doubling Season: If an effect would put one or more tokens onto the
* battlefield under your control, it puts twice that many of those tokens onto
* the battlefield instead. If an effect would place one or more counters on a
* permanent you control, it places twice that many of those counters on that
* permanent instead.
*
* @author LevelX2
*/
public class DoublingSeasonTest extends CardTestPlayerBase {
/**
* Tests that instead of one spore counter there were two spore counters added to Pallid Mycoderm
* if Doubling Season is on the battlefield.
* Tests that instead of one spore counter there were two spore counters
* added to Pallid Mycoderm if Doubling Season is on the battlefield.
*/
@Test
public void testDoubleSporeCounter() {
@ -35,8 +37,9 @@ public class DoublingSeasonTest extends CardTestPlayerBase {
}
/**
* Tests if 3 damage are prevented with Test of Faith and Doubling Season is on
* the battlefield, that 6 +1/+1 counters are added to the target creature.
* Tests if 3 damage are prevented with Test of Faith and Doubling Season is
* on the battlefield, that 6 +1/+1 counters are added to the target
* creature.
*/
@Test
public void testDoubleP1P1Counter() {
@ -63,9 +66,10 @@ public class DoublingSeasonTest extends CardTestPlayerBase {
assertPowerToughness(playerA, "Silvercoat Lion", 8, 8);
}
/**
* Tests that 2 Saproling tokens are created instead of one if Doubling Season is on
* the battlefield.
* Tests that 2 Saproling tokens are created instead of one if Doubling
* Season is on the battlefield.
*/
@Test
public void testDoubleTokens() {
@ -89,4 +93,43 @@ public class DoublingSeasonTest extends CardTestPlayerBase {
}
/**
* Creatures with enter the battlefield triggers are causing a bug when
* multiple copies are made simultaneously (ie via Doubling Season +
* Kiki-Jiki, Mirror Breaker or Rite of Replication). After the tokens have
* entered the battlefield it asks their controller to choose the order that
* the triggered abilities on the stack but no window opens to select the
* triggers leaving no option to move the game forward (besides rollback and
* just not making the tokens). Several attempts with the different
* combinations make it *seem to be a general bug about duplicates entering
* at the same time and not related to the specific cards.
*/
@Test
public void testDoubleRiteOfReplication() {
/**
* If an effect would put one or more tokens onto the battlefield under
* your control, it puts twice that many of those tokens onto the
* battlefield instead. If an effect would place one or more counters on
* a permanent you control, it places twice that many of those counters
* on that permanent instead.
*/
addCard(Zone.BATTLEFIELD, playerA, "Doubling Season");
addCard(Zone.BATTLEFIELD, playerA, "Island", 9);
// Put a token that's a copy of target creature onto the battlefield. If Rite of Replication was kicked, put five of those tokens onto the battlefield instead.
addCard(Zone.HAND, playerA, "Rite of Replication");
// When Venerable Monk enters the battlefield, you gain 2 life.
addCard(Zone.BATTLEFIELD, playerB, "Venerable Monk", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Rite of Replication", "Venerable Monk");
setChoice(playerA, "Yes");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 40);
assertPermanentCount(playerA, "Venerable Monk", 10);
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.decorator;
import mage.Mana;
@ -33,14 +32,14 @@ import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.effects.common.BasicManaEffect;
import mage.abilities.effects.common.ManaEffect;
import mage.choices.ChoiceColor;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class ConditionalManaEffect extends ManaEffect {
private BasicManaEffect effect;
@ -70,14 +69,46 @@ public class ConditionalManaEffect extends ManaEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
if (condition.apply(game, source)) {
effect.setTargetPointer(this.targetPointer);
return effect.apply(game, source);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.apply(game, source);
}
return false;
Mana mana = getMana(game, source);
if (mana != null && mana.getAny() > 0) {
int amount = mana.getAny();
ChoiceColor choice = new ChoiceColor(true);
Mana createdMana = null;
if (controller.choose(outcome, choice, game)) {
if (choice.getColor() == null) {
return false; // it happens, don't know how
}
if (choice.getColor().isBlack()) {
createdMana = Mana.BlackMana(amount);
} else if (choice.getColor().isBlue()) {
createdMana = Mana.BlueMana(amount);
} else if (choice.getColor().isRed()) {
createdMana = Mana.RedMana(amount);
} else if (choice.getColor().isGreen()) {
createdMana = Mana.GreenMana(amount);
} else if (choice.getColor().isWhite()) {
createdMana = Mana.WhiteMana(amount);
}
}
mana = createdMana;
}
if (mana != null) {
controller.getManaPool().addMana(mana, game, source);
}
return true;
}
@Override
@ -85,12 +116,18 @@ public class ConditionalManaEffect extends ManaEffect {
return new ConditionalManaEffect(this);
}
public Mana getMana(Game game, Ability source) {
@Override
public Mana getMana(Game game, Ability source
) {
Mana mana = null;
if (condition.apply(game, source)) {
return effect.getMana();
mana = effect.getMana();
} else if (otherwiseEffect != null) {
return otherwiseEffect.getMana();
mana = otherwiseEffect.getMana();
}
return null;
if (mana != null) {
checkToFirePossibleEvents(mana, game, source);
}
return mana;
}
}

View file

@ -27,6 +27,8 @@
*/
package mage.abilities.effects.common;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
@ -57,13 +59,13 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
private final UUID playerId;
private final CardType additionalCardType;
private boolean gainsHaste;
private Permanent addedTokenPermanent;
private List<Permanent> addedTokenPermanents;
public PutTokenOntoBattlefieldCopyTargetEffect() {
super(Outcome.PutCreatureInPlay);
this.playerId = null;
this.additionalCardType = null;
this.addedTokenPermanent = null;
this.addedTokenPermanents = new ArrayList<>();
}
public PutTokenOntoBattlefieldCopyTargetEffect(UUID playerId) {
@ -75,7 +77,7 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
this.playerId = playerId;
this.additionalCardType = additionalCardType;
this.gainsHaste = gainsHaste;
this.addedTokenPermanent = null;
this.addedTokenPermanents = new ArrayList<>();
}
public PutTokenOntoBattlefieldCopyTargetEffect(final PutTokenOntoBattlefieldCopyTargetEffect effect) {
@ -83,7 +85,7 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
this.playerId = effect.playerId;
this.additionalCardType = effect.additionalCardType;
this.gainsHaste = effect.gainsHaste;
this.addedTokenPermanent = effect.addedTokenPermanent;
this.addedTokenPermanents.addAll(effect.addedTokenPermanents);
}
@Override
@ -118,22 +120,25 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
token.addAbility(HasteAbility.getInstance());
}
token.putOntoBattlefield(1, game, source.getSourceId(), playerId == null ? source.getControllerId() : playerId);
addedTokenPermanent = game.getPermanent(token.getLastAddedToken());
if (addedTokenPermanent != null) {
game.copyPermanent(copyFromPermanent, addedTokenPermanent, source, applier);
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
addedTokenPermanents.add(tokenPermanent);
game.copyPermanent(copyFromPermanent, tokenPermanent, source, applier);
if (additionalCardType != null) {
ContinuousEffect effect = new AddCardTypeTargetEffect(additionalCardType, Duration.Custom);
effect.setTargetPointer(new FixedTarget(addedTokenPermanent.getId()));
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
if (gainsHaste) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(addedTokenPermanent.getId()));
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
return true;
}
}
return true;
}
return false;
}
@ -153,7 +158,7 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
}
public Permanent getAddedPermanent() {
return addedTokenPermanent;
public List<Permanent> getAddedPermanent() {
return addedTokenPermanents;
}
}

View file

@ -29,10 +29,12 @@ package mage.abilities.mana;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.common.ManaEffect;
import mage.constants.AbilityType;
import mage.constants.Zone;
/**
* see 20110715 - 605.1b
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class TriggeredManaAbility extends TriggeredAbilityImpl {
@ -44,6 +46,7 @@ public abstract class TriggeredManaAbility extends TriggeredAbilityImpl {
public TriggeredManaAbility(Zone zone, ManaEffect effect, boolean optional) {
super(zone, effect, optional);
this.usesStack = false;
this.abilityType = AbilityType.MANA;
}
public TriggeredManaAbility(final TriggeredManaAbility ability) {