Replaced some custom classes by ChooseCreatureTypeEffect.

This commit is contained in:
LevelX2 2015-10-15 21:56:03 +02:00 committed by AlumiuN
parent a0e8241347
commit 7274f9a8ac
6 changed files with 50 additions and 255 deletions

View file

@ -38,15 +38,12 @@ import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.abilities.mana.ColorlessManaAbility;
import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.abilities.mana.conditional.CreatureCastManaCondition;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
@ -55,10 +52,8 @@ import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import mage.watchers.Watcher;
/**
@ -67,14 +62,12 @@ import mage.watchers.Watcher;
*/
public class CavernOfSouls extends CardImpl {
private static final String ruleText = "choose a creature type";
public CavernOfSouls(UUID ownerId) {
super(ownerId, 226, "Cavern of Souls", Rarity.RARE, new CardType[]{CardType.LAND}, "");
this.expansionSetCode = "AVR";
// As Cavern of Souls enters the battlefield, choose a creature type.
this.addAbility(new AsEntersBattlefieldAbility(new CavernOfSoulsEffect(), ruleText));
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature)));
// {T}: Add {1} to your mana pool.
this.addAbility(new ColorlessManaAbility());
@ -82,7 +75,7 @@ public class CavernOfSouls extends CardImpl {
// {T}: Add one mana of any color to your mana pool. Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered.
Ability ability = new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new CavernOfSoulsManaBuilder(), true);
this.addAbility(ability, new CavernOfSoulsWatcher(ability.getOriginalId()));
this.addAbility(new SimpleStaticAbility(Zone.ALL, new CavernOfSoulsCantCounterEffect()));
this.addAbility(new SimpleStaticAbility(Zone.ALL, new CavernOfSoulsCantCounterEffect()));
}
public CavernOfSouls(final CavernOfSouls card) {
@ -95,60 +88,23 @@ public class CavernOfSouls extends CardImpl {
}
}
class CavernOfSoulsEffect extends OneShotEffect {
public CavernOfSoulsEffect() {
super(Outcome.Benefit);
staticText = "As {this} enters the battlefield, choose a creature type";
}
public CavernOfSoulsEffect(final CavernOfSoulsEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose creature type");
typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
while (!player.choose(Outcome.Benefit, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}
return false;
}
@Override
public CavernOfSoulsEffect copy() {
return new CavernOfSoulsEffect(this);
}
}
class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
String creatureType;
@Override
public ConditionalManaBuilder setMana(Mana mana, Ability source, Game game) {
Object value = game.getState().getValue(source.getSourceId() + "_type");
if (value != null && value instanceof String) {
creatureType = (String) value;
}
}
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
game.informPlayers(controller.getLogName() + " produces " + mana.toString() + " with " + sourceObject.getLogName() +
" (can only be spend to cast for creatures of type " + creatureType + " and that spell can't be countered)");
}
return super.setMana(mana, source, game);
game.informPlayers(controller.getLogName() + " produces " + mana.toString() + " with " + sourceObject.getLogName()
+ " (can only be spend to cast for creatures of type " + creatureType + " and that spell can't be countered)");
}
return super.setMana(mana, source, game);
}
@Override
@ -174,11 +130,11 @@ class CavernOfSoulsConditionalMana extends ConditionalMana {
class CavernOfSoulsManaCondition extends CreatureCastManaCondition {
String creatureType;
CavernOfSoulsManaCondition(String creatureType) {
this.creatureType = creatureType;
}
@Override
public boolean apply(Game game, Ability source, UUID manaProducer) {
// check: ... to cast a creature spell
@ -197,7 +153,7 @@ class CavernOfSoulsWatcher extends Watcher {
private List<UUID> spells = new ArrayList<>();
private final String originalId;
public CavernOfSoulsWatcher(UUID originalId) {
super("ManaPaidFromCavernOfSoulsWatcher", WatcherScope.CARD);
this.originalId = originalId.toString();
@ -222,7 +178,7 @@ class CavernOfSoulsWatcher extends Watcher {
}
}
}
public boolean spellCantBeCountered(UUID spellId) {
return spells.contains(spellId);
}

View file

@ -27,27 +27,28 @@
*/
package mage.sets.avacynrestored;
import mage.constants.*;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.keyword.VigilanceAbility;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.UUID;
/**
* @author noxx
@ -66,7 +67,7 @@ public class RidersOfGavony extends CardImpl {
this.addAbility(VigilanceAbility.getInstance());
// As Riders of Gavony enters the battlefield, choose a creature type.
this.addAbility(new AsEntersBattlefieldAbility(new RidersOfGavonyEffect()));
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.Protect)));
// Human creatures you control have protection from creatures of the chosen type.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new RidersOfGavonyGainAbilityControlledEffect()));
@ -82,46 +83,6 @@ public class RidersOfGavony extends CardImpl {
}
}
class RidersOfGavonyEffect extends OneShotEffect {
public RidersOfGavonyEffect() {
super(Outcome.BoostCreature);
staticText = "choose a creature type";
}
public RidersOfGavonyEffect(final RidersOfGavonyEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose creature type");
typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
if (typeChoice.getChoice() != null) {
game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", "<i>Chosen type: " + typeChoice.getChoice() + "</i>", game);
}
}
return false;
}
@Override
public RidersOfGavonyEffect copy() {
return new RidersOfGavonyEffect(this);
}
}
class RidersOfGavonyGainAbilityControlledEffect extends ContinuousEffectImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("Human creatures you control");
@ -154,13 +115,13 @@ class RidersOfGavonyGainAbilityControlledEffect extends ContinuousEffectImpl {
if (permanent != null) {
String subtype = (String) game.getState().getValue(permanent.getId() + "_type");
if (subtype != null) {
protectionFilter = new FilterPermanent(subtype+"s");
protectionFilter = new FilterPermanent(subtype + "s");
protectionFilter.add(new SubtypePredicate(subtype));
}
}
}
if (protectionFilter != null) {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
perm.addAbility(new ProtectionAbility(protectionFilter), source.getSourceId(), game);
}
return true;

View file

@ -33,12 +33,9 @@ import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
@ -57,7 +54,6 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player;
/**
*
@ -70,7 +66,8 @@ public class DoorOfDestinies extends CardImpl {
this.expansionSetCode = "M14";
// As Door of Destinies enters the battlefield, choose a creature type.
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect()));
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature)));
// Whenever you cast a spell of the chosen type, put a charge counter on Door of Destinies.
this.addAbility(new AddCounterAbility());
// Creatures you control of the chosen type get +1/+1 for each charge counter on Door of Destinies.
@ -87,44 +84,6 @@ public class DoorOfDestinies extends CardImpl {
}
}
class ChooseCreatureTypeEffect extends OneShotEffect {
public ChooseCreatureTypeEffect() {
super(Outcome.BoostCreature);
staticText = "choose a creature type";
}
public ChooseCreatureTypeEffect(final ChooseCreatureTypeEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose creature type");
typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", "<i>Chosen type: " + typeChoice.getChoice().toString() + "</i>", game);
}
return false;
}
@Override
public ChooseCreatureTypeEffect copy() {
return new ChooseCreatureTypeEffect(this);
}
}
class AddCounterAbility extends TriggeredAbilityImpl {
public AddCounterAbility() {

View file

@ -32,12 +32,9 @@ import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.abilities.keyword.ConvokeAbility;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
@ -48,8 +45,6 @@ import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
*
@ -63,10 +58,10 @@ public class ObeliskOfUrd extends CardImpl {
// Convoke
this.addAbility(new ConvokeAbility());
// As Obelisk of Urd enters the battlefield, choose a creature type.
this.addAbility(new AsEntersBattlefieldAbility(new ObeliskOfUrdEnterBattlefieldEffect()));
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.BoostCreature)));
// Creatures you control of the chosen type get +2/+2.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ObeliskOfUrdBoostEffect()));
}
@ -81,43 +76,6 @@ public class ObeliskOfUrd extends CardImpl {
}
}
class ObeliskOfUrdEnterBattlefieldEffect extends OneShotEffect {
ObeliskOfUrdEnterBattlefieldEffect() {
super(Outcome.BoostCreature);
staticText = "choose a creature type";
}
ObeliskOfUrdEnterBattlefieldEffect(final ObeliskOfUrdEnterBattlefieldEffect effect) {
super(effect);
}
@Override
public ObeliskOfUrdEnterBattlefieldEffect copy() {
return new ObeliskOfUrdEnterBattlefieldEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose a creature type:");
typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}
return false;
}
}
class ObeliskOfUrdBoostEffect extends ContinuousEffectImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
@ -142,7 +100,7 @@ class ObeliskOfUrdBoostEffect extends ContinuousEffectImpl {
if (permanent != null) {
String subtype = (String) game.getState().getValue(permanent.getId() + "_type");
if (subtype != null) {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
if (perm.hasSubtype(subtype)) {
perm.addPower(2);
perm.addToughness(2);

View file

@ -29,6 +29,12 @@ package mage.sets.newphyrexia;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
@ -36,19 +42,9 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -60,9 +56,8 @@ public class Xenograft extends CardImpl {
super(ownerId, 51, "Xenograft", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{U}");
this.expansionSetCode = "NPH";
// As Xenograft enters the battlefield, choose a creature type.
this.addAbility(new AsEntersBattlefieldAbility(new XenograftEffect()));
this.addAbility(new AsEntersBattlefieldAbility(new ChooseCreatureTypeEffect(Outcome.Detriment)));
// Each creature you control is the chosen type in addition to its other types.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new XenograftAddSubtypeEffect()));
}
@ -77,43 +72,6 @@ public class Xenograft extends CardImpl {
}
}
class XenograftEffect extends OneShotEffect {
public XenograftEffect() {
super(Outcome.DrawCard);
staticText = "choose a creature type";
}
public XenograftEffect(final XenograftEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose creature type");
typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(source.getSourceId() + "_XenograftType", typeChoice.getChoice());
permanent.addInfo("chosen type", "<i>Chosen type: " + typeChoice.getChoice().toString() + "</i>", game);
}
return false;
}
@Override
public XenograftEffect copy() {
return new XenograftEffect(this);
}
}
class XenograftAddSubtypeEffect extends ContinuousEffectImpl {
public XenograftAddSubtypeEffect() {
@ -127,7 +85,7 @@ class XenograftAddSubtypeEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
String subtype = (String) game.getState().getValue(source.getSourceId() + "_XenograftType");
String subtype = (String) game.getState().getValue(source.getSourceId() + "_type");
if (subtype != null) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), game);
for (Permanent permanent : permanents) {

View file

@ -35,6 +35,7 @@ import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseColorEffect;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
@ -57,10 +58,12 @@ public class VolrathsLaboratory extends CardImpl {
this.expansionSetCode = "TPR";
// As Volrath's Laboratory enters the battlefield, choose a color and a creature type.
Ability ability = new EntersBattlefieldAbility(new ChooseColorEffect(Outcome.Neutral), null, true, "As Volrath's Laboratory enters the battlefield, choose a color and a creature type.", "");
Ability ability = new EntersBattlefieldAbility(new ChooseColorEffect(Outcome.Neutral));
Effect effect = new ChooseColorEffect(Outcome.Neutral);
effect.setText("and a creature type");
ability.addEffect(new ChooseCreatureTypeEffect(Outcome.Neutral));
this.addAbility(ability);
// {5}, {T}: Put a 2/2 creature token of the chosen color and type onto the battlefield.
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new VolrathsLaboratoryEffect(), new GenericManaCost(5));
ability.addCost(new TapSourceCost());
@ -78,21 +81,21 @@ public class VolrathsLaboratory extends CardImpl {
}
class VolrathsLaboratoryEffect extends OneShotEffect {
VolrathsLaboratoryEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "Put a 2/2 creature token of the chosen color and type onto the battlefield";
}
VolrathsLaboratoryEffect(final VolrathsLaboratoryEffect effect) {
super(effect);
}
@Override
public VolrathsLaboratoryEffect copy() {
return new VolrathsLaboratoryEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");