Implemented [DOM] Mox Amber (#4622)

This commit is contained in:
CountAndromalius 2018-03-16 16:09:35 -03:00 committed by Jeff Wadsworth
parent 1405bc87ae
commit d7458c5e35
2 changed files with 287 additions and 0 deletions

View file

@ -0,0 +1,72 @@
/*
* 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.cards.m;
import java.util.UUID;
import mage.abilities.mana.AnyColorPermanentTypesManaAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SuperType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SupertypePredicate;
/**
*
* @author CountAndromalius
*/
public class MoxAmber extends CardImpl {
public MoxAmber(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{0}");
addSuperType(SuperType.LEGENDARY);
// {tap}: Add one mana pool of any color among legendary creatures or planeswalkers you control.
FilterPermanent filter = new FilterPermanent("legendary creatures or planeswalkers");
filter.add(Predicates.or(
Predicates.and(
new CardTypePredicate(CardType.CREATURE),
new SupertypePredicate(SuperType.LEGENDARY)
),
new CardTypePredicate(CardType.PLANESWALKER))
);
this.addAbility(new AnyColorPermanentTypesManaAbility(TargetController.YOU, false, filter));
}
public MoxAmber(final MoxAmber card) {
super(card);
}
@Override
public MoxAmber copy() {
return new MoxAmber(this);
}
}

View file

@ -0,0 +1,215 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.mana;
import java.util.ArrayList;
import java.util.List;
import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.ColoredManaSymbol;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
* @author CountAndromalius
*/
public class AnyColorPermanentTypesManaAbility extends ActivatedManaAbilityImpl {
public AnyColorPermanentTypesManaAbility(TargetController targetController, FilterPermanent permanentTypes) {
this(targetController, true, permanentTypes);
}
public AnyColorPermanentTypesManaAbility(TargetController targetController, boolean onlyColors, FilterPermanent permanentTypes) {
super(Zone.BATTLEFIELD, new AnyColorPermanentTypesManaEffect(targetController, onlyColors, permanentTypes), new TapSourceCost());
}
public AnyColorPermanentTypesManaAbility(final AnyColorPermanentTypesManaAbility ability) {
super(ability);
}
@Override
public AnyColorPermanentTypesManaAbility copy() {
return new AnyColorPermanentTypesManaAbility(this);
}
@Override
public List<Mana> getNetMana(Game game) {
return ((AnyColorPermanentTypesManaEffect) getEffects().get(0)).getNetMana(game, this);
}
@Override
public boolean definesMana(Game game) {
return true;
}
}
class AnyColorPermanentTypesManaEffect extends ManaEffect {
private final FilterPermanent filter;
private final boolean onlyColors; // false if mana types can be produced (also Colorless mana), if false only colors can be produced (no Colorless mana).
private boolean inManaTypeCalculation = false;
public AnyColorPermanentTypesManaEffect(TargetController targetController, boolean onlyColors, FilterPermanent permanentTypes) {
super();
filter = permanentTypes;
this.onlyColors = onlyColors;
filter.add(new ControllerPredicate(targetController));
String text = targetController == TargetController.OPPONENT ? "an opponent controls." : "you control.";
staticText = "Add one mana of any " + (this.onlyColors ? "color" : "type") + " among " + permanentTypes.getMessage() + " " + text;
}
public AnyColorPermanentTypesManaEffect(final AnyColorPermanentTypesManaEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.onlyColors = effect.onlyColors;
}
@Override
public boolean apply(Game game, Ability source) {
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (!onlyColors && types.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
if (!onlyColors) {
choice.getChoices().add("Colorless");
}
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
return false;
}
}
if (choice.getChoice() != null) {
Mana mana = new Mana();
switch (choice.getChoice()) {
case "Black":
mana.setBlack(1);
break;
case "Blue":
mana.setBlue(1);
break;
case "Red":
mana.setRed(1);
break;
case "Green":
mana.setGreen(1);
break;
case "White":
mana.setWhite(1);
break;
case "Colorless":
mana.setColorless(1);
break;
}
checkToFirePossibleEvents(mana, game, source);
player.getManaPool().addMana(mana, game, source);
}
}
return true;
}
@Override
public Mana getMana(Game game, Ability source) {
return null;
}
private Mana getManaTypes(Game game, Ability source) {
Mana types = new Mana();
if (game == null || game.getPhase() == null) {
return types;
}
if (inManaTypeCalculation) {
return types;
}
inManaTypeCalculation = true;
List<ObjectColor> permanentColors;
// Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "needed to identify endless loop causing cards: {0}", source.getSourceObject(game).getName());
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : permanents) {
permanentColors = permanent.getColor(game).getColors();
for (ObjectColor color : permanentColors){
types.add(new Mana(color.getColoredManaSymbol()));
}
}
inManaTypeCalculation = false;
return types;
}
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netManas = new ArrayList<>();
Mana types = getManaTypes(game, source);
if (types.getBlack() > 0) {
netManas.add(new Mana(ColoredManaSymbol.B));
}
if (types.getRed() > 0) {
netManas.add(new Mana(ColoredManaSymbol.R));
}
if (types.getBlue() > 0) {
netManas.add(new Mana(ColoredManaSymbol.U));
}
if (types.getGreen() > 0) {
netManas.add(new Mana(ColoredManaSymbol.G));
}
if (types.getWhite() > 0) {
netManas.add(new Mana(ColoredManaSymbol.W));
}
if (types.getColorless() > 0) {
netManas.add(Mana.ColorlessMana(1));
}
if (types.getAny() > 0) {
netManas.add(Mana.AnyMana(1));
}
return netManas;
}
@Override
public AnyColorPermanentTypesManaEffect copy() {
return new AnyColorPermanentTypesManaEffect(this);
}
}