* Drain Power - Improved conditonal mana handling.

This commit is contained in:
LevelX2 2018-05-01 00:55:46 +02:00
parent 940fe603c6
commit 0ceb5fc88f
4 changed files with 35 additions and 70 deletions

View file

@ -32,7 +32,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbility; import mage.abilities.ActivatedAbility;
import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCost;
@ -42,11 +41,13 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.AbilityType; import mage.constants.AbilityType;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.filter.common.FilterLandPermanent; import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.PermanentInListPredicate; import mage.filter.predicate.permanent.PermanentInListPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.ManaPoolItem;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
@ -58,7 +59,7 @@ import mage.target.TargetPlayer;
public class DrainPower extends CardImpl { public class DrainPower extends CardImpl {
public DrainPower(UUID ownerId, CardSetInfo setInfo) { public DrainPower(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{U}{U}"); super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{U}{U}");
// Target player activates a mana ability of each land they control. Then that player loses all unspent mana and you add the mana lost this way. // Target player activates a mana ability of each land they control. Then that player loses all unspent mana and you add the mana lost this way.
this.getSpellAbility().addEffect(new DrainPowerEffect()); this.getSpellAbility().addEffect(new DrainPowerEffect());
@ -76,11 +77,11 @@ public class DrainPower extends CardImpl {
} }
class DrainPowerEffect extends OneShotEffect { class DrainPowerEffect extends OneShotEffect {
private static final FilterLandPermanent filter = new FilterLandPermanent(); private static final FilterLandPermanent filter = new FilterLandPermanent();
public DrainPowerEffect() { public DrainPowerEffect() {
super(Outcome.Tap); super(Outcome.PutManaInPool);
this.staticText = "Target player activates a mana ability of each land they control. Then that player loses all unspent mana and you add the mana lost this way"; this.staticText = "Target player activates a mana ability of each land they control. Then that player loses all unspent mana and you add the mana lost this way";
} }
@ -100,7 +101,7 @@ class DrainPowerEffect extends OneShotEffect {
if (targetPlayer != null) { if (targetPlayer != null) {
List<Permanent> ignorePermanents = new ArrayList<>(); List<Permanent> ignorePermanents = new ArrayList<>();
TargetPermanent target = null; TargetPermanent target = null;
while (true) { while (true) {
Map<Permanent, List<ActivatedManaAbilityImpl>> manaAbilitiesMap = new HashMap<>(); Map<Permanent, List<ActivatedManaAbilityImpl>> manaAbilitiesMap = new HashMap<>();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, targetPlayer.getId(), game)) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, targetPlayer.getId(), game)) {
@ -131,9 +132,9 @@ class DrainPowerEffect extends OneShotEffect {
if (manaAbilitiesMap.isEmpty()) { if (manaAbilitiesMap.isEmpty()) {
break; break;
} }
List<Permanent> permList = new ArrayList<Permanent>(manaAbilitiesMap.keySet()); List<Permanent> permList = new ArrayList<>(manaAbilitiesMap.keySet());
Permanent permanent = null; Permanent permanent;
if (permList.size() > 1 || target != null) { if (permList.size() > 1 || target != null) {
FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')'); FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
filter2.add(new PermanentInListPredicate(permList)); filter2.add(new PermanentInListPredicate(permList));
@ -149,9 +150,9 @@ class DrainPowerEffect extends OneShotEffect {
int i = 0; int i = 0;
for (ActivatedManaAbilityImpl manaAbility : manaAbilitiesMap.get(permanent)) { for (ActivatedManaAbilityImpl manaAbility : manaAbilitiesMap.get(permanent)) {
i++; i++;
if (manaAbilitiesMap.get(permanent).size() <= i if (manaAbilitiesMap.get(permanent).size() <= i
|| targetPlayer.chooseUse(Outcome.Neutral, "Activate mana ability \"" + manaAbility.getRule() + "\" of " + permanent.getLogName() || targetPlayer.chooseUse(Outcome.Neutral, "Activate mana ability \"" + manaAbility.getRule() + "\" of " + permanent.getLogName()
+ "? (Choose \"no\" to activate next mana ability)", source, game)) { + "? (Choose \"no\" to activate next mana ability)", source, game)) {
boolean originalCanUndo = manaAbility.isUndoPossible(); boolean originalCanUndo = manaAbility.isUndoPossible();
manaAbility.setUndoPossible(false); // prevents being able to undo Drain Power manaAbility.setUndoPossible(false); // prevents being able to undo Drain Power
if (targetPlayer.activateAbility(manaAbility, game)) { if (targetPlayer.activateAbility(manaAbility, game)) {
@ -163,14 +164,18 @@ class DrainPowerEffect extends OneShotEffect {
} }
} }
} }
// 106.12. One card (Drain Power) causes one player to lose unspent mana and another to add the mana lost this way. (Note that these may be the same player.) // 106.12. One card (Drain Power) causes one player to lose unspent mana and another to add the mana lost this way. (Note that these may be the same player.)
// This empties the former players mana pool and causes the mana emptied this way to be put into the latter players mana pool. Which permanents, spells, and/or // This empties the former players mana pool and causes the mana emptied this way to be put into the latter players mana pool. Which permanents, spells, and/or
// abilities produced that mana are unchanged, as are any restrictions or additional effects associated with any of that mana. // abilities produced that mana are unchanged, as are any restrictions or additional effects associated with any of that mana.
// TODO: retain riders associated with drained mana // TODO: retain riders associated with drained mana
Mana mana = targetPlayer.getManaPool().getMana(); List<ManaPoolItem> manaItems = targetPlayer.getManaPool().getManaItems();
targetPlayer.getManaPool().emptyPool(game); targetPlayer.getManaPool().emptyPool(game);
controller.getManaPool().addMana(mana, game, source); for (ManaPoolItem manaPoolItem : manaItems) {
controller.getManaPool().addMana(
manaPoolItem.isConditional() ? manaPoolItem.getConditionalMana() : manaPoolItem.getMana(),
game, source, Duration.EndOfTurn.equals(manaPoolItem.getDuration()));
}
return true; return true;
} }
return false; return false;

View file

@ -90,56 +90,6 @@ public class TorgaarFamineIncarnate extends CardImpl {
} }
} }
//class TorgaarFamineIncarnateSacrificeCost extends CostImpl {
//
// int numbSacrificed = 0;
//
// public TorgaarFamineIncarnateSacrificeCost() {
// this.text = "sacrifice any number of creatures";
//
// }
//
// public TorgaarFamineIncarnateSacrificeCost(final TorgaarFamineIncarnateSacrificeCost cost) {
// super(cost);
// this.numbSacrificed = cost.numbSacrificed;
// }
//
// @Override
// public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
// return true;
// }
//
// @Override
// public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
// TargetControlledCreaturePermanent target
// = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE,
// new FilterControlledCreaturePermanent("select any number of creatures to sacrifice. "
// + "This spell costs {2} less to cast for each creature sacrificed this way"), true);
// Player player = game.getPlayer(controllerId);
// if (player != null) {
// player.chooseTarget(Outcome.Benefit, target, ability, game);
// for (UUID creatureId : target.getTargets()) {
// Permanent creature = game.getPermanent(creatureId);
// if (creature != null) {
// if (creature.sacrifice(sourceId, game)) {
// numbSacrificed++;
// }
// }
// }
// }
// this.paid = true;
// return paid;
// }
//
// public int getNumbSacrificed() {
// return numbSacrificed;
// }
//
// @Override
// public TorgaarFamineIncarnateSacrificeCost copy() {
// return new TorgaarFamineIncarnateSacrificeCost(this);
// }
//}
class TorgaarFamineIncarnateEffect extends OneShotEffect { class TorgaarFamineIncarnateEffect extends OneShotEffect {
public TorgaarFamineIncarnateEffect() { public TorgaarFamineIncarnateEffect() {

View file

@ -63,9 +63,9 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
staticText = "Add " staticText = "Add "
+ (amount instanceof StaticValue ? (CardUtil.numberToText(((StaticValue) amount).toString())) : "") + (amount instanceof StaticValue ? (CardUtil.numberToText(((StaticValue) amount).toString())) : "")
+ " mana " + " mana "
+ (oneChoice ? "of any" + (oneChoice || (amount instanceof StaticValue && (((StaticValue) amount).toString()).equals("1"))
+ (amount instanceof StaticValue && (((StaticValue) amount).toString()).equals("1") ? "" : " one") ? "of any" + (amount instanceof StaticValue && (((StaticValue) amount).toString()).equals("1") ? "" : " one") + " color"
+ " color" : "in any combination of colors") : "in any combination of colors")
+ ". " + manaBuilder.getRule(); + ". " + manaBuilder.getRule();
} }

View file

@ -395,7 +395,8 @@ public class ManaPool implements Serializable {
Mana mana = manaToAdd.copy(); Mana mana = manaToAdd.copy();
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) { if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) {
if (mana instanceof ConditionalMana) { if (mana instanceof ConditionalMana) {
ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game), source.getOriginalId()); ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game),
((ConditionalMana) mana).getManaProducerOriginalId() != null ? ((ConditionalMana) mana).getManaProducerOriginalId() : source.getOriginalId());
if (emptyOnTurnsEnd) { if (emptyOnTurnsEnd) {
item.setDuration(Duration.EndOfTurn); item.setDuration(Duration.EndOfTurn);
} }
@ -505,4 +506,13 @@ public class ManaPool implements Serializable {
public boolean isEmpty() { public boolean isEmpty() {
return count() == 0; return count() == 0;
} }
public List<ManaPoolItem> getManaItems() {
List<ManaPoolItem> itemsCopy = new ArrayList<>();
for (ManaPoolItem manaItem : manaItems) {
itemsCopy.add(manaItem.copy());
}
return itemsCopy;
}
} }