Fixed empty mana pool handling to handle multiple effects at the same time correctly (fixes #482). Added support for mana that empties only at end of turn.

This commit is contained in:
LevelX2 2014-10-20 17:49:40 +02:00
parent 59702e4867
commit f893503acd
10 changed files with 185 additions and 103 deletions

View file

@ -97,15 +97,6 @@ public class KruphixGodOfHorizons extends CardImpl {
class KruphixGodOfHorizonsEffect extends ReplacementEffectImpl {
private static final List<ManaType> manaTypes = new ArrayList<>();
static {
manaTypes.add(ManaType.BLACK);
manaTypes.add(ManaType.BLUE);
manaTypes.add(ManaType.RED);
manaTypes.add(ManaType.WHITE);
manaTypes.add(ManaType.GREEN);
}
public KruphixGodOfHorizonsEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = "If unused mana would empty from your mana pool, that mana becomes colorless instead";
@ -127,15 +118,7 @@ class KruphixGodOfHorizonsEffect extends ReplacementEffectImpl {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null){
ManaPool pool = player.getManaPool();
int coloredMana = pool.getGreen() + pool.getBlack() + pool.getBlue()+ pool.getWhite()+ pool.getRed();
player.getManaPool().emptyManaType(manaTypes);
pool.addMana(Mana.ColorlessMana(coloredMana), game, source);
return true;
}
return false;
return true;
}
@Override

View file

@ -30,15 +30,19 @@ package mage.sets.tenth;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.ManaPool;
import mage.players.Player;
/**
*
@ -53,7 +57,7 @@ public class Upwelling extends CardImpl {
this.color.setGreen(true);
// Mana pools don't empty as steps and phases end.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UpwellingReplacementEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new UpwellingRuleEffect()));
}
@ -67,20 +71,41 @@ public class Upwelling extends CardImpl {
}
}
class UpwellingReplacementEffect extends ReplacementEffectImpl {
class UpwellingRuleEffect extends ContinuousEffectImpl {
public UpwellingReplacementEffect() {
public UpwellingRuleEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "Mana pools don't empty as steps and phases end";
}
public UpwellingReplacementEffect(final UpwellingReplacementEffect effect) {
public UpwellingRuleEffect(final UpwellingRuleEffect effect) {
super(effect);
}
@Override
public UpwellingReplacementEffect copy() {
return new UpwellingReplacementEffect(this);
public UpwellingRuleEffect copy() {
return new UpwellingRuleEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId: controller.getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null){
ManaPool pool = player.getManaPool();
pool.addDoNotEmptyManaType(ManaType.WHITE);
pool.addDoNotEmptyManaType(ManaType.GREEN);
pool.addDoNotEmptyManaType(ManaType.BLUE);
pool.addDoNotEmptyManaType(ManaType.RED);
pool.addDoNotEmptyManaType(ManaType.BLACK);
pool.addDoNotEmptyManaType(ManaType.COLORLESS);
}
}
return true;
}
return false;
}
@Override
@ -89,15 +114,7 @@ class UpwellingReplacementEffect extends ReplacementEffectImpl {
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.EMPTY_MANA_POOLS) {
return true;
}
return false;
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
}

View file

@ -27,21 +27,24 @@
*/
package mage.sets.worldwake;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.constants.*;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.ManaTypeInManaPoolCount;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.continious.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
/**
@ -60,7 +63,7 @@ public class OmnathLocusOfMana extends CardImpl {
this.toughness = new MageInt(1);
// Green mana doesn't empty from your mana pool as steps and phases end.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OmnathReplacementEffect()));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OmnathRuleEffect()));
// Omnath, Locus of Mana gets +1/+1 for each green mana in your mana pool
DynamicValue boost = new ManaTypeInManaPoolCount(ManaType.GREEN);
@ -78,50 +81,37 @@ public class OmnathLocusOfMana extends CardImpl {
}
}
class OmnathReplacementEffect extends ReplacementEffectImpl {
private static final List<ManaType> manaTypes = new ArrayList<>();
static {
manaTypes.add(ManaType.BLACK);
manaTypes.add(ManaType.BLUE);
manaTypes.add(ManaType.RED);
manaTypes.add(ManaType.WHITE);
manaTypes.add(ManaType.COLORLESS);
}
class OmnathRuleEffect extends ContinuousEffectImpl {
public OmnathReplacementEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit);
public OmnathRuleEffect() {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
staticText = "Green mana doesn't empty from your mana pool as steps and phases end";
}
public OmnathReplacementEffect(final OmnathReplacementEffect effect) {
public OmnathRuleEffect(final OmnathRuleEffect effect) {
super(effect);
}
@Override
public OmnathReplacementEffect copy() {
return new OmnathReplacementEffect(this);
public OmnathRuleEffect copy() {
return new OmnathRuleEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player player = game.getPlayer(source.getControllerId());
if (player != null){
player.getManaPool().addDoNotEmptyManaType(ManaType.GREEN);
}
return false; }
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null){
player.getManaPool().emptyManaType(manaTypes);
}
return true;
public boolean hasLayer(Layer layer) {
return layer == Layer.RulesEffects;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.EMPTY_MANA_POOL && event.getPlayerId().equals(source.getControllerId())) {
return true;
}
return false;
}
}
}