mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Created a more generic ConditionalSpellManaBuilder. Replaced some custom mana builders (more to do).
This commit is contained in:
parent
74161c665d
commit
afe352168c
8 changed files with 123 additions and 151 deletions
|
@ -36,12 +36,14 @@ import mage.abilities.costs.mana.GenericManaCost;
|
|||
import mage.abilities.effects.common.ReturnToHandTargetEffect;
|
||||
import mage.abilities.mana.ColorlessManaAbility;
|
||||
import mage.abilities.mana.ConditionalAnyColorManaAbility;
|
||||
import mage.abilities.mana.builder.SubtypeCastManaBuilder;
|
||||
import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.ColorlessPredicate;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/**
|
||||
|
@ -50,6 +52,12 @@ import mage.target.common.TargetControlledCreaturePermanent;
|
|||
*/
|
||||
public class AllyEncampment extends CardImpl {
|
||||
|
||||
private static final FilterSpell filter = new FilterSpell("an Ally spell");
|
||||
|
||||
static {
|
||||
filter.add(new ColorlessPredicate());
|
||||
}
|
||||
|
||||
public AllyEncampment(UUID ownerId) {
|
||||
super(ownerId, 228, "Ally Encampment", Rarity.RARE, new CardType[]{CardType.LAND}, "");
|
||||
this.expansionSetCode = "BFZ";
|
||||
|
@ -58,7 +66,7 @@ public class AllyEncampment extends CardImpl {
|
|||
this.addAbility(new ColorlessManaAbility());
|
||||
|
||||
// {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.
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandTargetEffect(), new GenericManaCost(1));
|
||||
|
|
|
@ -28,19 +28,13 @@
|
|||
package mage.sets.dissension;
|
||||
|
||||
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.builder.ConditionalManaBuilder;
|
||||
import mage.abilities.mana.conditional.ManaCondition;
|
||||
import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
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 {
|
||||
|
||||
private static final FilterSpell filter = new FilterSpell("a multicolored spell");
|
||||
|
||||
static {
|
||||
filter.add(new MulticoloredPredicate());
|
||||
}
|
||||
|
||||
public PillarOfTheParuns(UUID ownerId) {
|
||||
super(ownerId, 176, "Pillar of the Paruns", Rarity.RARE, new CardType[]{CardType.LAND}, "");
|
||||
this.expansionSetCode = "DIS";
|
||||
|
||||
// {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) {
|
||||
|
@ -65,44 +65,3 @@ public class PillarOfTheParuns extends CardImpl {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,12 +41,13 @@ import mage.abilities.effects.common.CreateTokenEffect;
|
|||
import mage.abilities.mana.ColorlessManaAbility;
|
||||
import mage.abilities.mana.ConditionalAnyColorManaAbility;
|
||||
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.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.mageobject.SubtypePredicate;
|
||||
import mage.game.Game;
|
||||
|
@ -59,9 +60,14 @@ import mage.game.permanent.token.Token;
|
|||
public class SliverHive extends CardImpl {
|
||||
|
||||
private static final FilterControlledPermanent filter = new FilterControlledPermanent("Sliver");
|
||||
private static final FilterSpell filterSpell = new FilterSpell("a Sliver spell");
|
||||
|
||||
static {
|
||||
}
|
||||
|
||||
static {
|
||||
filter.add(new SubtypePredicate("Sliver"));
|
||||
filterSpell.add(new SubtypePredicate("Sliver"));
|
||||
}
|
||||
|
||||
public SliverHive(UUID ownerId) {
|
||||
|
@ -72,7 +78,7 @@ public class SliverHive extends CardImpl {
|
|||
this.addAbility(new ColorlessManaAbility());
|
||||
|
||||
// {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.
|
||||
Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new CreateTokenEffect(new SliverToken()), new TapSourceCost(),
|
||||
|
|
|
@ -28,14 +28,13 @@
|
|||
package mage.sets.vintagemasters;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.ConditionalMana;
|
||||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.mana.ConditionalColorlessManaAbility;
|
||||
import mage.abilities.mana.builder.ConditionalManaBuilder;
|
||||
import mage.abilities.mana.conditional.ArtifactCastConditionalMana;
|
||||
import mage.abilities.mana.conditional.ConditionalSpellManaBuilder;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.filter.common.FilterArtifactSpell;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -48,7 +47,8 @@ public class MishrasWorkshop extends CardImpl {
|
|||
this.expansionSetCode = "VMA";
|
||||
|
||||
// {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);
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.Mana;
|
||||
|
@ -16,7 +15,6 @@ import mage.players.Player;
|
|||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class AddConditionalColorlessManaEffect extends ManaEffect {
|
||||
|
||||
private final int amount;
|
||||
|
@ -26,7 +24,7 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
|
|||
super();
|
||||
this.amount = amount;
|
||||
this.manaBuilder = manaBuilder;
|
||||
staticText = "Add {" + amount + "} to your mana pool. " + manaBuilder.getRule();
|
||||
staticText = "Add {" + amount + "} to your mana pool. " + manaBuilder.getRule();
|
||||
}
|
||||
|
||||
public AddConditionalColorlessManaEffect(final AddConditionalColorlessManaEffect effect) {
|
||||
|
@ -54,4 +52,8 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
|
|||
public Mana getMana(Game game, Ability source) {
|
||||
return manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build();
|
||||
}
|
||||
|
||||
public Mana getMana() {
|
||||
return new Mana(0, 0, 0, 0, 0, amount, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,23 +25,16 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.mana;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.effects.common.AddConditionalColorlessManaEffect;
|
||||
import mage.abilities.effects.common.BasicManaEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
|
||||
public class ActivateIfConditionManaAbility extends ManaAbility {
|
||||
|
||||
private final Condition condition;
|
||||
|
@ -52,6 +45,12 @@ public class ActivateIfConditionManaAbility extends ManaAbility {
|
|||
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) {
|
||||
super(ability);
|
||||
this.condition = ability.condition;
|
||||
|
@ -75,7 +74,7 @@ public class ActivateIfConditionManaAbility extends ManaAbility {
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return new StringBuilder(super.getRule()).append(" Activate this ability only if ").append(condition.toString()).append(".").toString() ;
|
||||
return new StringBuilder(super.getRule()).append(" Activate this ability only if ").append(condition.toString()).append(".").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue