* Reworked TAPPED_FOR_MANA event handling to include the produced mana in the event.

This commit is contained in:
LevelX2 2014-12-05 20:15:56 +01:00
parent c5bc99b8de
commit d26c1000f2
17 changed files with 475 additions and 69 deletions

View file

@ -54,8 +54,12 @@ import org.apache.log4j.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.BasicManaEffect;
import mage.abilities.effects.common.DynamicManaEffect;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
/** /**
@ -346,7 +350,16 @@ public abstract class AbilityImpl implements Ability {
if (this.getAbilityType().equals(AbilityType.MANA)) { if (this.getAbilityType().equals(AbilityType.MANA)) {
for (Cost cost: costs) { for (Cost cost: costs) {
if (cost instanceof TapSourceCost) { if (cost instanceof TapSourceCost) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId)); Mana mana = null;
Effect effect = getEffects().get(0);
if (effect instanceof BasicManaEffect) {
mana = ((BasicManaEffect)effect).getMana(game, this);
} else if (effect instanceof DynamicManaEffect) {
mana = ((DynamicManaEffect)effect).getMana(game, this);
}
if (mana != null) { // if mana == null the event has to be fires in the mana effect
game.fireEvent(new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId, mana));
}
break; break;
} }
} }

View file

@ -0,0 +1,95 @@
/*
* 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 mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.SetTargetPointer;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class TapForManaAllTriggeredAbility extends TriggeredAbilityImpl {
private final FilterPermanent filter;
private final SetTargetPointer setTargetPointer;
public TapForManaAllTriggeredAbility(Effect effect, FilterPermanent filter, SetTargetPointer setTargetPointer) {
super(Zone.BATTLEFIELD, effect);
this.filter = filter;
this.setTargetPointer = setTargetPointer;
}
public TapForManaAllTriggeredAbility(TapForManaAllTriggeredAbility ability) {
super(ability);
this.filter = ability.filter.copy();
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.TAPPED_FOR_MANA) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) {
ManaEvent mEvent = (ManaEvent) event;
for(Effect effect:getEffects()) {
effect.setValue("mana", mEvent.getMana());
}
switch(setTargetPointer) {
case PERMANENT:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId()));
break;
case PLAYER:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
}
return true;
}
}
return false;
}
@Override
public TapForManaAllTriggeredAbility copy() {
return new TapForManaAllTriggeredAbility(this);
}
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " for mana, " + super.getRule();
}
}

View file

@ -0,0 +1,97 @@
/*
* 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 mage.abilities.common;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.TriggeredManaAbility;
import mage.constants.SetTargetPointer;
import static mage.constants.SetTargetPointer.PERMANENT;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class TapForManaAllTriggeredManaAbility extends TriggeredManaAbility {
private final FilterPermanent filter;
private final SetTargetPointer setTargetPointer;
public TapForManaAllTriggeredManaAbility(ManaEffect effect, FilterPermanent filter, SetTargetPointer setTargetPointer) {
super(Zone.BATTLEFIELD, effect);
this.filter = filter;
this.setTargetPointer = setTargetPointer;
}
public TapForManaAllTriggeredManaAbility(TapForManaAllTriggeredManaAbility ability) {
super(ability);
this.filter = ability.filter.copy();
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.TAPPED_FOR_MANA) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) {
ManaEvent mEvent = (ManaEvent) event;
for(Effect effect:getEffects()) {
effect.setValue("mana", mEvent.getMana());
}
switch(setTargetPointer) {
case PERMANENT:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getId()));
break;
case PLAYER:
getEffects().get(0).setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
}
return true;
}
}
return false;
}
@Override
public TapForManaAllTriggeredManaAbility copy() {
return new TapForManaAllTriggeredManaAbility(this);
}
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " for mana, " + super.getRule();
}
}

View file

@ -44,9 +44,14 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build(), game, source); player.getManaPool().addMana(getMana(game, source), game, source);
return true; return true;
} }
return false; return false;
} }
@Override
public Mana getMana(Game game, Ability source) {
return manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build();
}
} }

View file

@ -88,8 +88,16 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);
result = true; result = true;
} }
} }
return result; return result;
} }
@Override
public Mana getMana(Game game, Ability source) {
//TODO: TAP_FOR_MANA Event does not support currently to get an amount > 1 of conditional mana
return null;
}
} }

View file

@ -0,0 +1,101 @@
/*
* 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 mage.abilities.effects.common;
import mage.Mana;
import mage.abilities.Ability;
import mage.choices.ChoiceColor;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
public AddManaAnyColorAttachedControllerEffect() {
super();
staticText = "its controller adds one mana of any color to his or her mana pool";
}
public AddManaAnyColorAttachedControllerEffect(final AddManaAnyColorAttachedControllerEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) {
Permanent land = game.getPermanent(enchantment.getAttachedTo());
if (land != null) {
Player player = game.getPlayer(land.getControllerId());
if (player != null) {
ChoiceColor choice = new ChoiceColor();
while (!player.choose(outcome, choice, game)) {
if (!player.isInGame()) {
return false;
}
}
int amount = 1;
Mana mana = null;
if (choice.getColor().isBlack()) {
mana = Mana.BlackMana(amount);
} else if (choice.getColor().isBlue()) {
mana = Mana.BlueMana(amount);
} else if (choice.getColor().isRed()) {
mana = Mana.RedMana(amount);
} else if (choice.getColor().isGreen()) {
mana = Mana.GreenMana(amount);
} else if (choice.getColor().isWhite()) {
mana = Mana.WhiteMana(amount);
}
if (mana != null) {
checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source);
return true;
}
}
}
}
return false;
}
@Override
public AddManaAnyColorAttachedControllerEffect copy() {
return new AddManaAnyColorAttachedControllerEffect(this);
}
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
}

View file

@ -21,31 +21,35 @@ import mage.util.CardUtil;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class ManaInAnyCombinationEffect extends ManaEffect { public class AddManaInAnyCombinationEffect extends ManaEffect {
private ArrayList<ColoredManaSymbol> manaSymbols = new ArrayList<>(); private ArrayList<ColoredManaSymbol> manaSymbols = new ArrayList<>();
private final DynamicValue amount; private final DynamicValue amount;
public ManaInAnyCombinationEffect(int amount, ColoredManaSymbol... coloredManaSymbols) { public AddManaInAnyCombinationEffect(int amount) {
this(new StaticValue(amount), ColoredManaSymbol.B, ColoredManaSymbol.U, ColoredManaSymbol.R, ColoredManaSymbol.W, ColoredManaSymbol.G);
}
public AddManaInAnyCombinationEffect(int amount, ColoredManaSymbol... coloredManaSymbols) {
this(new StaticValue(amount), coloredManaSymbols); this(new StaticValue(amount), coloredManaSymbols);
} }
public ManaInAnyCombinationEffect(DynamicValue amount, ColoredManaSymbol... coloredManaSymbols) { public AddManaInAnyCombinationEffect(DynamicValue amount, ColoredManaSymbol... coloredManaSymbols) {
super(); super();
this.manaSymbols.addAll(Arrays.asList(coloredManaSymbols)); this.manaSymbols.addAll(Arrays.asList(coloredManaSymbols));
this.amount = amount; this.amount = amount;
this.staticText = setText(); this.staticText = setText();
} }
public ManaInAnyCombinationEffect(final ManaInAnyCombinationEffect effect) { public AddManaInAnyCombinationEffect(final AddManaInAnyCombinationEffect effect) {
super(effect); super(effect);
this.manaSymbols = effect.manaSymbols; this.manaSymbols = effect.manaSymbols;
this.amount = effect.amount; this.amount = effect.amount;
} }
@Override @Override
public ManaInAnyCombinationEffect copy() { public AddManaInAnyCombinationEffect copy() {
return new ManaInAnyCombinationEffect(this); return new AddManaInAnyCombinationEffect(this);
} }
@Override @Override
@ -69,16 +73,25 @@ public class ManaInAnyCombinationEffect extends ManaEffect {
} }
} }
} }
checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);
return true; return true;
} }
return false; return false;
} }
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
private String setText() { private String setText() {
StringBuilder sb = new StringBuilder("Add "); StringBuilder sb = new StringBuilder("Add ");
sb.append(CardUtil.numberToText(amount.toString())); sb.append(CardUtil.numberToText(amount.toString()));
sb.append(" mana in any combination of "); sb.append(" mana in any combination of ");
if (manaSymbols.size() == 5) {
sb.append("of colors");
} else {
int i = 0; int i = 0;
for (ColoredManaSymbol coloredManaSymbol: manaSymbols) { for (ColoredManaSymbol coloredManaSymbol: manaSymbols) {
i++; i++;
@ -87,6 +100,7 @@ public class ManaInAnyCombinationEffect extends ManaEffect {
} }
sb.append("{").append(coloredManaSymbol.toString()).append("}"); sb.append("{").append(coloredManaSymbol.toString()).append("}");
} }
}
sb.append(" to your mana pool"); sb.append(" to your mana pool");
return sb.toString(); return sb.toString();
} }

View file

@ -57,8 +57,9 @@ public class AddManaOfAnyColorTargetCanProduceEffect extends ManaEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(this.targetPointer.getFirst(game, source)); Permanent permanent = game.getPermanent(this.targetPointer.getFirst(game, source));
if (permanent != null) { if (controller != null && permanent != null) {
Abilities<ManaAbility> mana = permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD); Abilities<ManaAbility> mana = permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
Mana types = new Mana(); Mana types = new Mana();
for (ManaAbility ability : mana) { for (ManaAbility ability : mana) {
@ -67,7 +68,7 @@ public class AddManaOfAnyColorTargetCanProduceEffect extends ManaEffect {
} }
} }
Choice choice = new ChoiceImpl(true); Choice choice = new ChoiceImpl(true);
choice.setMessage("Pick a mana color"); choice.setMessage("Pick the type of mana to produce");
if (types.getBlack() > 0) { if (types.getBlack() > 0) {
choice.getChoices().add("Black"); choice.getChoices().add("Black");
} }
@ -87,35 +88,37 @@ public class AddManaOfAnyColorTargetCanProduceEffect extends ManaEffect {
choice.getChoices().add("Colorless"); choice.getChoices().add("Colorless");
} }
if (choice.getChoices().size() > 0) { if (choice.getChoices().size() > 0) {
Player player = game.getPlayer(permanent.getControllerId());
if (choice.getChoices().size() == 1) { if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next()); choice.setChoice(choice.getChoices().iterator().next());
} else { } else {
player.choose(outcome, choice, game); controller.choose(outcome, choice, game);
} }
if (choice.getChoice() == null) { if (choice.getChoice() == null) {
return false; return false;
} }
Mana newMana = new Mana();
switch (choice.getChoice()) { switch (choice.getChoice()) {
case "Black": case "Black":
player.getManaPool().addMana(Mana.BlackMana, game, source); newMana.setBlack(1);
return true; return true;
case "Blue": case "Blue":
player.getManaPool().addMana(Mana.BlueMana, game, source); newMana.setBlue(1);
return true; return true;
case "Red": case "Red":
player.getManaPool().addMana(Mana.RedMana, game, source); newMana.setRed(1);
return true; return true;
case "Green": case "Green":
player.getManaPool().addMana(Mana.GreenMana, game, source); newMana.setGreen(1);
return true; return true;
case "White": case "White":
player.getManaPool().addMana(Mana.WhiteMana, game, source); newMana.setWhite(1);
return true; return true;
case "Colorless": case "Colorless":
player.getManaPool().addMana(Mana.ColorlessMana, game, source); newMana.setColorless(1);
return true; return true;
} }
controller.getManaPool().addMana(newMana, game, source);
checkToFirePossibleEvents(newMana, game, source);
} }
return true; return true;
} }
@ -126,4 +129,11 @@ public class AddManaOfAnyColorTargetCanProduceEffect extends ManaEffect {
public AddManaOfAnyColorTargetCanProduceEffect copy() { public AddManaOfAnyColorTargetCanProduceEffect copy() {
return new AddManaOfAnyColorTargetCanProduceEffect(this); return new AddManaOfAnyColorTargetCanProduceEffect(this);
} }
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
} }

View file

@ -17,24 +17,24 @@ import mage.players.Player;
* *
* @author magenoxx * @author magenoxx
*/ */
public class AddManaToControllersManaPoolEffect extends OneShotEffect { public class AddManaToManaPoolSourceControllerEffect extends OneShotEffect {
protected Mana mana; protected Mana mana;
public AddManaToControllersManaPoolEffect(Mana mana) { public AddManaToManaPoolSourceControllerEffect(Mana mana) {
super(Outcome.PutManaInPool); super(Outcome.PutManaInPool);
this.mana = mana; this.mana = mana;
this.staticText = "Add " + mana.toString() + " to your mana pool"; this.staticText = "Add " + mana.toString() + " to your mana pool";
} }
public AddManaToControllersManaPoolEffect(final AddManaToControllersManaPoolEffect effect) { public AddManaToManaPoolSourceControllerEffect(final AddManaToManaPoolSourceControllerEffect effect) {
super(effect); super(effect);
this.mana = effect.mana; this.mana = effect.mana;
} }
@Override @Override
public AddManaToControllersManaPoolEffect copy() { public AddManaToManaPoolSourceControllerEffect copy() {
return new AddManaToControllersManaPoolEffect(this); return new AddManaToManaPoolSourceControllerEffect(this);
} }
@Override @Override

View file

@ -18,12 +18,12 @@ import mage.players.Player;
* @author LevelX2 * @author LevelX2
*/ */
public class AddManaToManaPoolEffect extends OneShotEffect { public class AddManaToManaPoolTargetControllerEffect extends ManaEffect {
protected Mana mana; protected Mana mana;
protected boolean emptyOnlyOnTurnsEnd; protected boolean emptyOnlyOnTurnsEnd;
public AddManaToManaPoolEffect(Mana mana, String textManaPoolOwner) { public AddManaToManaPoolTargetControllerEffect(Mana mana, String textManaPoolOwner) {
this(mana, textManaPoolOwner, false); this(mana, textManaPoolOwner, false);
} }
/** /**
@ -34,22 +34,22 @@ public class AddManaToManaPoolEffect extends OneShotEffect {
* @param emptyOnTurnsEnd if set, the mana will empty only on end of turnstep * @param emptyOnTurnsEnd if set, the mana will empty only on end of turnstep
* *
*/ */
public AddManaToManaPoolEffect(Mana mana, String textManaPoolOwner, boolean emptyOnTurnsEnd) { public AddManaToManaPoolTargetControllerEffect(Mana mana, String textManaPoolOwner, boolean emptyOnTurnsEnd) {
super(Outcome.PutManaInPool); super();
this.mana = mana; this.mana = mana;
this.emptyOnlyOnTurnsEnd = emptyOnTurnsEnd; this.emptyOnlyOnTurnsEnd = emptyOnTurnsEnd;
this.staticText = "add " + mana.toString() + " to " + textManaPoolOwner + " mana pool"; this.staticText = (textManaPoolOwner.equals("his or her")?"that player adds":"add ") + mana.toString() + " to " + textManaPoolOwner + " mana pool";
} }
public AddManaToManaPoolEffect(final AddManaToManaPoolEffect effect) { public AddManaToManaPoolTargetControllerEffect(final AddManaToManaPoolTargetControllerEffect effect) {
super(effect); super(effect);
this.mana = effect.mana; this.mana = effect.mana;
this.emptyOnlyOnTurnsEnd = effect.emptyOnlyOnTurnsEnd; this.emptyOnlyOnTurnsEnd = effect.emptyOnlyOnTurnsEnd;
} }
@Override @Override
public AddManaToManaPoolEffect copy() { public AddManaToManaPoolTargetControllerEffect copy() {
return new AddManaToManaPoolEffect(this); return new AddManaToManaPoolTargetControllerEffect(this);
} }
@Override @Override
@ -61,4 +61,10 @@ public class AddManaToManaPoolEffect extends OneShotEffect {
} }
return false; return false;
} }
@Override
public Mana getMana(Game game, Ability source) {
return mana;
}
} }

View file

@ -39,4 +39,9 @@ public class BasicManaEffect extends ManaEffect {
public Mana getMana() { public Mana getMana() {
return mana; return mana;
} }
@Override
public Mana getMana(Game game, Ability source) {
return mana;
}
} }

View file

@ -58,17 +58,15 @@ public class ChooseColorEffect extends OneShotEffect {
if (controller != null && permanent != null) { if (controller != null && permanent != null) {
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();
while (!choice.isChosen()) { while (!choice.isChosen()) {
controller.choose(Outcome.PutManaInPool, choice, game); controller.choose(outcome, choice, game);
if (!controller.isInGame()) { if (!controller.isInGame()) {
return false; return false;
} }
} }
ChoiceColor colorChoice = new ChoiceColor(); game.informPlayers(new StringBuilder(permanent.getLogName()).append(": ").append(controller.getName()).append(" has chosen ").append(choice.getChoice()).toString());
if (controller.choose(outcome, colorChoice, game)) { game.getState().setValue(source.getSourceId() + "_color", choice.getColor());
game.informPlayers(new StringBuilder(permanent.getLogName()).append(": ").append(controller.getName()).append(" has chosen ").append(colorChoice.getChoice()).toString()); permanent.addInfo("chosen color", "<font color = 'blue'>Chosen color: " + choice.getColor().getDescription() + "</font>");
game.getState().setValue(source.getSourceId() + "_color", colorChoice.getColor()); return true;
permanent.addInfo("chosen color", "<font color = 'blue'>Chosen color: " + colorChoice.getColor().getDescription() + "</font>");
}
} }
return false; return false;
} }

View file

@ -56,7 +56,7 @@ public class CounterTargetEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
boolean countered = false; boolean countered = false;
for (UUID targetId : source.getTargets().get(0).getTargets()) { for (UUID targetId : getTargetPointer().getTargets(game, source)) {
if (game.getStack().counter(targetId, source.getSourceId(), game)) { if (game.getStack().counter(targetId, source.getSourceId(), game)) {
countered = true; countered = true;
} }

View file

@ -86,6 +86,11 @@ public class DynamicManaEffect extends BasicManaEffect {
return super.getText(mode) + " for each " + amount.getMessage(); return super.getText(mode) + " for each " + amount.getMessage();
} }
@Override
public Mana getMana(Game game, Ability source) {
return computeMana(false, game, source);
}
public Mana computeMana(boolean netMana ,Game game, Ability source){ public Mana computeMana(boolean netMana ,Game game, Ability source){
this.computedMana.clear(); this.computedMana.clear();
int count = amount.calculate(game, source, this); int count = amount.calculate(game, source, this);
@ -131,4 +136,5 @@ public class DynamicManaEffect extends BasicManaEffect {
} }
return computedMana; return computedMana;
} }
} }

View file

@ -28,8 +28,16 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.constants.AbilityType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
/** /**
* *
@ -45,4 +53,22 @@ public abstract class ManaEffect extends OneShotEffect {
super(effect); super(effect);
} }
public abstract Mana getMana(Game game, Ability source);
/**
* Only used for mana effects that decide which mana is produced during resolution of the effect.
*
* @param mana
* @param game
* @param source
*/
public void checkToFirePossibleEvents(Mana mana, Game game, Ability source) {
if (source.getAbilityType().equals(AbilityType.MANA)) {
for (Cost cost: source.getCosts()) {
if (cost instanceof TapSourceCost) {
game.fireEvent(new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, source.getSourceId(), source.getSourceId(), source.getControllerId(), mana));
}
}
}
}
} }

View file

@ -122,27 +122,37 @@ class AnyColorOpponentLandsProduceManaEffect extends ManaEffect {
} else { } else {
player.choose(outcome, choice, game); player.choose(outcome, choice, game);
} }
if (choice.getChoice() != null) {
Mana mana = new Mana();
switch (choice.getChoice()) { switch (choice.getChoice()) {
case "Black": case "Black":
player.getManaPool().addMana(Mana.BlackMana, game, source); mana.setBlack(1);
break; break;
case "Blue": case "Blue":
player.getManaPool().addMana(Mana.BlueMana, game, source); mana.setBlue(1);
break; break;
case "Red": case "Red":
player.getManaPool().addMana(Mana.RedMana, game, source); mana.setRed(1);
break; break;
case "Green": case "Green":
player.getManaPool().addMana(Mana.GreenMana, game, source); mana.setGreen(1);
break; break;
case "White": case "White":
player.getManaPool().addMana(Mana.WhiteMana, game, source); mana.setWhite(1);
break; break;
} }
checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source);
}
} }
return true; return true;
} }
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
private Mana getManaTypes(Game game, Ability source) { private Mana getManaTypes(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana(); Mana types = new Mana();

View file

@ -30,14 +30,18 @@ package mage.abilities.mana;
import java.util.List; import java.util.List;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.choices.Choice; import mage.choices.Choice;
import mage.choices.ChoiceImpl; import mage.choices.ChoiceImpl;
import mage.constants.AbilityType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
import mage.players.Player; import mage.players.Player;
/** /**
@ -145,27 +149,35 @@ class CommanderIdentityManaEffect extends ManaEffect {
return false; return false;
} }
} }
Mana mana = new Mana();
switch (choice.getChoice()) { switch (choice.getChoice()) {
case "Black": case "Black":
controller.getManaPool().addMana(Mana.BlackMana, game, source); mana.setBlack(1);
break; break;
case "Blue": case "Blue":
controller.getManaPool().addMana(Mana.BlueMana, game, source); mana.setBlue(1);
break; break;
case "Red": case "Red":
controller.getManaPool().addMana(Mana.RedMana, game, source); mana.setRed(1);
break; break;
case "Green": case "Green":
controller.getManaPool().addMana(Mana.GreenMana, game, source); mana.setGreen(1);
break; break;
case "White": case "White":
controller.getManaPool().addMana(Mana.WhiteMana, game, source); mana.setWhite(1);
break; break;
} }
} checkToFirePossibleEvents(mana, game, source);
controller.getManaPool().addMana(mana, game, source);
return true; return true;
} }
} }
}
return false; return false;
} }
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
} }