Created a more generic ConditionalSpellManaBuilder. Replaced some custom mana builders (more to do).

This commit is contained in:
LevelX2 2015-09-17 16:18:39 +02:00
parent 74161c665d
commit afe352168c
8 changed files with 123 additions and 151 deletions

View file

@ -36,12 +36,14 @@ import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.ReturnToHandTargetEffect; import mage.abilities.effects.common.ReturnToHandTargetEffect;
import mage.abilities.mana.ColorlessManaAbility; import mage.abilities.mana.ColorlessManaAbility;
import mage.abilities.mana.ConditionalAnyColorManaAbility; import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.abilities.mana.builder.SubtypeCastManaBuilder; import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.ColorlessPredicate;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
/** /**
@ -50,6 +52,12 @@ import mage.target.common.TargetControlledCreaturePermanent;
*/ */
public class AllyEncampment extends CardImpl { public class AllyEncampment extends CardImpl {
private static final FilterSpell filter = new FilterSpell("an Ally spell");
static {
filter.add(new ColorlessPredicate());
}
public AllyEncampment(UUID ownerId) { public AllyEncampment(UUID ownerId) {
super(ownerId, 228, "Ally Encampment", Rarity.RARE, new CardType[]{CardType.LAND}, ""); super(ownerId, 228, "Ally Encampment", Rarity.RARE, new CardType[]{CardType.LAND}, "");
this.expansionSetCode = "BFZ"; this.expansionSetCode = "BFZ";
@ -58,7 +66,7 @@ public class AllyEncampment extends CardImpl {
this.addAbility(new ColorlessManaAbility()); this.addAbility(new ColorlessManaAbility());
// {T} Add one mana of any color to your mana pool. Spend this mana only to cast an Ally spell. // {T} Add one mana of any color to your mana pool. Spend this mana only to cast an Ally spell.
this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new SubtypeCastManaBuilder("Ally"), true)); this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new ConditionalSpellManaBuilder(filter), true));
// {1}, {T}, Sacrifice Ally Encampment: Return target Ally you control to its owner's hand. // {1}, {T}, Sacrifice Ally Encampment: Return target Ally you control to its owner's hand.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandTargetEffect(), new GenericManaCost(1)); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandTargetEffect(), new GenericManaCost(1));

View file

@ -28,19 +28,13 @@
package mage.sets.dissension; package mage.sets.dissension;
import java.util.UUID; import java.util.UUID;
import mage.ConditionalMana;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.condition.Condition;
import mage.abilities.mana.ConditionalAnyColorManaAbility; import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
import mage.abilities.mana.conditional.ManaCondition;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.game.Game; import mage.filter.FilterSpell;
import mage.filter.predicate.mageobject.MulticoloredPredicate;
/** /**
* *
@ -48,12 +42,18 @@ import mage.game.Game;
*/ */
public class PillarOfTheParuns extends CardImpl { public class PillarOfTheParuns extends CardImpl {
private static final FilterSpell filter = new FilterSpell("a multicolored spell");
static {
filter.add(new MulticoloredPredicate());
}
public PillarOfTheParuns(UUID ownerId) { public PillarOfTheParuns(UUID ownerId) {
super(ownerId, 176, "Pillar of the Paruns", Rarity.RARE, new CardType[]{CardType.LAND}, ""); super(ownerId, 176, "Pillar of the Paruns", Rarity.RARE, new CardType[]{CardType.LAND}, "");
this.expansionSetCode = "DIS"; this.expansionSetCode = "DIS";
// {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a multicolored spell. // {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a multicolored spell.
this.addAbility(new ConditionalAnyColorManaAbility(1, new PillarOfTheParunsManaBuilder())); this.addAbility(new ConditionalAnyColorManaAbility(1, new ConditionalSpellManaBuilder(filter)));
} }
public PillarOfTheParuns(final PillarOfTheParuns card) { public PillarOfTheParuns(final PillarOfTheParuns card) {
@ -65,44 +65,3 @@ public class PillarOfTheParuns extends CardImpl {
return new PillarOfTheParuns(this); return new PillarOfTheParuns(this);
} }
} }
class PillarOfTheParunsManaBuilder extends ConditionalManaBuilder {
@Override
public ConditionalMana build(Object... options) {
return new PillarOfTheParunsConditionalMana(this.mana);
}
@Override
public String getRule() {
return "Spend this mana only to cast a multicolored spell";
}
}
class PillarOfTheParunsConditionalMana extends ConditionalMana {
public PillarOfTheParunsConditionalMana(Mana mana) {
super(mana);
staticText = "Spend this mana only to cast a multicolored spell";
addCondition(new MultiColoredSpellCastManaCondition());
}
}
class MultiColoredSpellCastManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
MageObject object = game.getObject(source.getSourceId());
if (object != null && object.getColor(game).getColorCount() > 1) {
return true;
}
}
return false;
}
@Override
public boolean apply(Game game, Ability source, UUID originalId) {
return apply(game, source);
}
}

View file

@ -41,12 +41,13 @@ import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.mana.ColorlessManaAbility; import mage.abilities.mana.ColorlessManaAbility;
import mage.abilities.mana.ConditionalAnyColorManaAbility; import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.abilities.mana.builder.SubtypeCastManaBuilder; import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
import mage.abilities.mana.conditional.CreatureCastManaCondition; import mage.abilities.mana.conditional.CreatureCastManaCondition;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game; import mage.game.Game;
@ -59,9 +60,14 @@ import mage.game.permanent.token.Token;
public class SliverHive extends CardImpl { public class SliverHive extends CardImpl {
private static final FilterControlledPermanent filter = new FilterControlledPermanent("Sliver"); private static final FilterControlledPermanent filter = new FilterControlledPermanent("Sliver");
private static final FilterSpell filterSpell = new FilterSpell("a Sliver spell");
static {
}
static { static {
filter.add(new SubtypePredicate("Sliver")); filter.add(new SubtypePredicate("Sliver"));
filterSpell.add(new SubtypePredicate("Sliver"));
} }
public SliverHive(UUID ownerId) { public SliverHive(UUID ownerId) {
@ -72,7 +78,7 @@ public class SliverHive extends CardImpl {
this.addAbility(new ColorlessManaAbility()); this.addAbility(new ColorlessManaAbility());
// {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a Sliver spell. // {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a Sliver spell.
this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new SubtypeCastManaBuilder("Sliver"), true)); this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new ConditionalSpellManaBuilder(filterSpell), true));
// {5}, {T}: Put a 1/1 colorless Sliver creature token onto the battlefield. Activate this ability only if you control a Sliver. // {5}, {T}: Put a 1/1 colorless Sliver creature token onto the battlefield. Activate this ability only if you control a Sliver.
Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new SliverToken()), new TapSourceCost(), Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new SliverToken()), new TapSourceCost(),

View file

@ -28,14 +28,13 @@
package mage.sets.vintagemasters; package mage.sets.vintagemasters;
import java.util.UUID; import java.util.UUID;
import mage.ConditionalMana;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.mana.ConditionalColorlessManaAbility; import mage.abilities.mana.ConditionalColorlessManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
import mage.abilities.mana.conditional.ArtifactCastConditionalMana;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.filter.common.FilterArtifactSpell;
/** /**
* *
@ -48,7 +47,8 @@ public class MishrasWorkshop extends CardImpl {
this.expansionSetCode = "VMA"; this.expansionSetCode = "VMA";
// {tap}: Add {3} to your mana pool. Spend this mana only to cast artifact spells. // {tap}: Add {3} to your mana pool. Spend this mana only to cast artifact spells.
this.addAbility(new ConditionalColorlessManaAbility(new TapSourceCost(), 3, new MishrasWorkshopManaBuilder())); this.addAbility(new ConditionalColorlessManaAbility(new TapSourceCost(), 3,
new ConditionalSpellManaBuilder(new FilterArtifactSpell("artifact spells"))));
} }
@ -61,15 +61,3 @@ public class MishrasWorkshop extends CardImpl {
return new MishrasWorkshop(this); return new MishrasWorkshop(this);
} }
} }
class MishrasWorkshopManaBuilder extends ConditionalManaBuilder {
@Override
public ConditionalMana build(Object... options) {
return new ArtifactCastConditionalMana(this.mana);
}
@Override
public String getRule() {
return "Spend this mana only to cast artifact spells";
}
}

View file

@ -3,7 +3,6 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package mage.abilities.effects.common; package mage.abilities.effects.common;
import mage.Mana; import mage.Mana;
@ -16,7 +15,6 @@ import mage.players.Player;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class AddConditionalColorlessManaEffect extends ManaEffect { public class AddConditionalColorlessManaEffect extends ManaEffect {
private final int amount; private final int amount;
@ -54,4 +52,8 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
public Mana getMana(Game game, Ability source) { public Mana getMana(Game game, Ability source) {
return manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build(); return manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build();
} }
public Mana getMana() {
return new Mana(0, 0, 0, 0, 0, amount, 0);
}
} }

View file

@ -25,23 +25,16 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.mana; package mage.abilities.mana;
import java.util.UUID; import java.util.UUID;
import mage.Mana;
import mage.constants.Zone;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.effects.common.AddConditionalColorlessManaEffect;
import mage.abilities.effects.common.BasicManaEffect; import mage.abilities.effects.common.BasicManaEffect;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
/**
*
* @author LevelX2
*/
public class ActivateIfConditionManaAbility extends ManaAbility { public class ActivateIfConditionManaAbility extends ManaAbility {
private final Condition condition; private final Condition condition;
@ -52,6 +45,12 @@ public class ActivateIfConditionManaAbility extends ManaAbility {
this.condition = condition; this.condition = condition;
} }
public ActivateIfConditionManaAbility(Zone zone, AddConditionalColorlessManaEffect effect, Cost cost, Condition condition) {
super(zone, effect, cost);
this.netMana.add(effect.getMana());
this.condition = condition;
}
public ActivateIfConditionManaAbility(ActivateIfConditionManaAbility ability) { public ActivateIfConditionManaAbility(ActivateIfConditionManaAbility ability) {
super(ability); super(ability);
this.condition = ability.condition; this.condition = ability.condition;

View file

@ -1,67 +0,0 @@
/*
* 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.builder;
import java.util.UUID;
import mage.ConditionalMana;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.mana.conditional.CreatureCastManaCondition;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public class SubtypeCastManaBuilder extends ConditionalManaBuilder {
private final String subtype;
public SubtypeCastManaBuilder(String subtype) {
this.subtype = subtype;
}
@Override
public ConditionalMana build(Object... options) {
this.mana.setFlag(true); // indicates that the mana is from second ability
return new SubtypeCastConditionalMana(this.mana, subtype);
}
@Override
public String getRule() {
return "Spend this mana only to cast a " + subtype + " spell.";
}
}
class SubtypeCastConditionalMana extends ConditionalMana {
SubtypeCastConditionalMana(Mana mana, String subtype) {
super(mana);
staticText = "Spend this mana only to cast a " + subtype + " spell.";
addCondition(new SubtypeCastManaCondition(subtype));
}
}
class SubtypeCastManaCondition extends CreatureCastManaCondition {
private final String subtype;
public SubtypeCastManaCondition(String subtype) {
this.subtype = subtype;
}
@Override
public boolean apply(Game game, Ability source, UUID manaProducer) {
if (super.apply(game, source)) {
MageObject object = game.getObject(source.getSourceId());
if (object.hasSubtype(subtype)) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,77 @@
/*
* 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.conditional;
import java.util.UUID;
import mage.ConditionalMana;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.condition.Condition;
import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.filter.FilterSpell;
import mage.game.Game;
import mage.game.stack.StackObject;
/**
*
* @author LevelX2
*/
public class ConditionalSpellManaBuilder extends ConditionalManaBuilder {
private final FilterSpell filter;
public ConditionalSpellManaBuilder(FilterSpell filter) {
this.filter = filter;
}
@Override
public ConditionalMana build(Object... options) {
this.mana.setFlag(true); // indicates that the mana is from second ability
return new SpellCastConditionalMana(this.mana, filter);
}
@Override
public String getRule() {
return "Spend this mana only to cast " + filter.getMessage() + ".";
}
}
class SpellCastConditionalMana extends ConditionalMana {
SpellCastConditionalMana(Mana mana, FilterSpell filter) {
super(mana);
staticText = "Spend this mana only to cast " + filter.getMessage() + ".";
addCondition(new SpellCastManaCondition(filter));
}
}
class SpellCastManaCondition extends ManaCondition implements Condition {
private final FilterSpell filter;
public SpellCastManaCondition(FilterSpell filter) {
this.filter = filter;
}
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
MageObject object = game.getObject(source.getSourceId());
if (object != null && (object instanceof StackObject)) {
return filter.match((StackObject) object, source.getSourceId(), source.getControllerId(), game);
}
}
return false;
}
@Override
public boolean apply(Game game, Ability source, UUID originalId) {
return apply(game, source);
}
}