From 28ed7f1b63fd8eecf155f645e9bd860f56edff9b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 9 Dec 2014 16:11:10 +0100 Subject: [PATCH] * Brave the Elements - Fixed not working choose color effect. --- .../mage/sets/onslaught/AkromasBlessing.java | 47 +++++----- .../mage/sets/zendikar/BraveTheElements.java | 58 ++++++------ .../src/mage/sets/zendikar/KabiraEvangel.java | 89 ++++++++----------- Mage/src/mage/abilities/CompoundAbility.java | 5 +- 4 files changed, 95 insertions(+), 104 deletions(-) diff --git a/Mage.Sets/src/mage/sets/onslaught/AkromasBlessing.java b/Mage.Sets/src/mage/sets/onslaught/AkromasBlessing.java index c37ae10d0b..5e1b449710 100644 --- a/Mage.Sets/src/mage/sets/onslaught/AkromasBlessing.java +++ b/Mage.Sets/src/mage/sets/onslaught/AkromasBlessing.java @@ -28,9 +28,12 @@ package mage.sets.onslaught; import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.continious.GainAbilityControlledEffect; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continious.GainAbilityAllEffect; import mage.abilities.keyword.CyclingAbility; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; @@ -40,6 +43,7 @@ import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.filter.FilterCard; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; import mage.players.Player; @@ -57,7 +61,7 @@ public class AkromasBlessing extends CardImpl { this.color.setWhite(true); // Choose a color. Creatures you control gain protection from the chosen color until end of turn. - this.getSpellAbility().addEffect(new AcromasBlessingEffect()); + this.getSpellAbility().addEffect(new AkromasBlessingChooseColorEffect()); // Cycling {W} this.addAbility(new CyclingAbility(new ManaCostsImpl("{W}"))); } @@ -72,44 +76,45 @@ public class AkromasBlessing extends CardImpl { } } +class AkromasBlessingChooseColorEffect extends OneShotEffect { -class AcromasBlessingEffect extends GainAbilityControlledEffect { - - private final FilterCard filter2; - - public AcromasBlessingEffect() { - super(new ProtectionAbility(new FilterCard()), Duration.EndOfTurn); - filter2 = (FilterCard)((ProtectionAbility)getFirstAbility()).getFilter(); - staticText = "Choose a color. Creatures you control gain protection from the chosen color until end of turn"; + public AkromasBlessingChooseColorEffect() { + super(Outcome.Benefit); + this.staticText = "Choose a color. Creatures you control gain protection from the chosen color until end of turn"; } - public AcromasBlessingEffect(final AcromasBlessingEffect effect) { + public AkromasBlessingChooseColorEffect(final AkromasBlessingChooseColorEffect effect) { super(effect); - this.filter2 = effect.filter2.copy(); } @Override - public AcromasBlessingEffect copy() { - return new AcromasBlessingEffect(this); + public AkromasBlessingChooseColorEffect copy() { + return new AkromasBlessingChooseColorEffect(this); } @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { + MageObject sourceObject = game.getObject(source.getSourceId()); + if (sourceObject != null && controller != null) { ChoiceColor choice = new ChoiceColor(); while (!choice.isChosen()) { - controller.choose(Outcome.Protect, choice, game); + controller.choose(outcome, choice, game); if (!controller.isInGame()) { return false; } } - filter2.add(new ColorPredicate(choice.getColor())); - filter2.setMessage(choice.getChoice()); - setAbility(new ProtectionAbility(new FilterCard(filter2))); - return super.apply(game, source); + if (choice.getColor() == null) { + return false; + } + game.informPlayers(sourceObject.getName() + ": " + controller.getName() + " has chosen " + choice.getChoice()); + FilterCard filterColor = new FilterCard(); + filterColor.add(new ColorPredicate(choice.getColor())); + filterColor.setMessage(choice.getChoice()); + ContinuousEffect effect = new GainAbilityAllEffect(new ProtectionAbility(new FilterCard(filterColor)), Duration.EndOfTurn, new FilterControlledCreaturePermanent()); + game.addEffect(effect, source); + return true; } return false; } - } diff --git a/Mage.Sets/src/mage/sets/zendikar/BraveTheElements.java b/Mage.Sets/src/mage/sets/zendikar/BraveTheElements.java index adde9b0793..7ef99c4186 100644 --- a/Mage.Sets/src/mage/sets/zendikar/BraveTheElements.java +++ b/Mage.Sets/src/mage/sets/zendikar/BraveTheElements.java @@ -28,21 +28,25 @@ package mage.sets.zendikar; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Rarity; +import java.util.UUID; +import mage.MageObject; import mage.ObjectColor; import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continious.GainAbilityAllEffect; import mage.abilities.effects.common.continious.GainAbilityControlledEffect; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.choices.ChoiceColor; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; import mage.filter.FilterCard; -import mage.filter.common.FilterCreaturePermanent; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.mageobject.ColorPredicate; import mage.game.Game; - -import java.util.UUID; import mage.players.Player; /** @@ -57,7 +61,7 @@ public class BraveTheElements extends CardImpl { this.color.setWhite(true); // Choose a color. White creatures you control gain protection from the chosen color until end of turn. - this.getSpellAbility().addEffect(new BraveTheElementsEffect()); + this.getSpellAbility().addEffect(new BraveTheElementsChooseColorEffect()); } public BraveTheElements(final BraveTheElements card) { @@ -71,36 +75,34 @@ public class BraveTheElements extends CardImpl { } -class BraveTheElementsEffect extends GainAbilityControlledEffect { - private static final FilterCreaturePermanent filter1 = new FilterCreaturePermanent(); +class BraveTheElementsChooseColorEffect extends OneShotEffect { + + private static final FilterControlledCreaturePermanent filter1 = new FilterControlledCreaturePermanent(); static { filter1.add(new ColorPredicate(ObjectColor.WHITE)); } - private final FilterCard filter2; - - public BraveTheElementsEffect() { - super(new ProtectionAbility(new FilterCard()), Duration.EndOfTurn, filter1); - filter2 = (FilterCard)((ProtectionAbility)getFirstAbility()).getFilter(); - staticText = "Choose a color. White creatures you control gain protection from the chosen color until end of turn"; + public BraveTheElementsChooseColorEffect() { + super(Outcome.Benefit); + this.staticText = "Choose a color. White creatures you control gain protection from the chosen color until end of turn"; } - public BraveTheElementsEffect(final BraveTheElementsEffect effect) { + public BraveTheElementsChooseColorEffect(final BraveTheElementsChooseColorEffect effect) { super(effect); - this.filter2 = effect.filter2.copy(); } @Override - public BraveTheElementsEffect copy() { - return new BraveTheElementsEffect(this); + public BraveTheElementsChooseColorEffect copy() { + return new BraveTheElementsChooseColorEffect(this); } @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getFirstTarget()); - if (controller != null) { + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = game.getObject(source.getSourceId()); + if (sourceObject != null && controller != null) { ChoiceColor choice = new ChoiceColor(); while (!choice.isChosen()) { controller.choose(outcome, choice, game); @@ -111,12 +113,14 @@ class BraveTheElementsEffect extends GainAbilityControlledEffect { if (choice.getColor() == null) { return false; } - filter2.add(new ColorPredicate(choice.getColor())); - filter2.setMessage(choice.getChoice()); - setAbility(new ProtectionAbility(new FilterCard(filter2))); - return super.apply(game, source); + game.informPlayers(sourceObject.getName() + ": " + controller.getName() + " has chosen " + choice.getChoice()); + FilterCard filterColor = new FilterCard(); + filterColor.add(new ColorPredicate(choice.getColor())); + filterColor.setMessage(choice.getChoice()); + ContinuousEffect effect = new GainAbilityAllEffect(new ProtectionAbility(new FilterCard(filterColor)), Duration.EndOfTurn, filter1); + game.addEffect(effect, source); + return true; } return false; } - -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/zendikar/KabiraEvangel.java b/Mage.Sets/src/mage/sets/zendikar/KabiraEvangel.java index 5e164a47e3..4b984655ca 100644 --- a/Mage.Sets/src/mage/sets/zendikar/KabiraEvangel.java +++ b/Mage.Sets/src/mage/sets/zendikar/KabiraEvangel.java @@ -29,11 +29,11 @@ package mage.sets.zendikar; import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility; +import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.common.continious.GainAbilityControlledEffect; +import mage.abilities.effects.common.continious.GainAbilityAllEffect; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.choices.ChoiceColor; @@ -72,13 +72,13 @@ public class KabiraEvangel extends CardImpl { this.power = new MageInt(2); this.toughness = new MageInt(3); - FilterPermanent filter = new FilterPermanent("Kabira Evangel or another Ally"); + FilterPermanent filter = new FilterPermanent(getName() + " or another Ally"); filter.add(Predicates.or( new CardIdPredicate(this.getId()), new SubtypePredicate("Ally"))); // Whenever Kabira Evangel or another Ally enters the battlefield under your control, you may choose a color. If you do, Allies you control gain protection from the chosen color until end of turn. - this.addAbility(new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, new ChooseColorEffect(), filter, true)); + this.addAbility(new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, new KabiraEvangelChooseColorEffect(), filter, true)); } public KabiraEvangel(final KabiraEvangel card) { @@ -91,39 +91,9 @@ public class KabiraEvangel extends CardImpl { } } -class ChooseColorEffect extends OneShotEffect { - public ChooseColorEffect() { - super(Outcome.Benefit); - staticText = "choose a color. All Allies you control gain protection from the chosen color until end of turn"; - } - public ChooseColorEffect(final ChooseColorEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - Permanent perm = game.getPermanent(source.getSourceId()); - if (player != null && perm != null) { - ChoiceColor colorChoice = new ChoiceColor(); - if (player.choose(Outcome.Benefit, colorChoice, game)) { - game.informPlayers(perm.getName() + ": " + player.getName() + " has chosen " + colorChoice.getChoice()); - game.addEffect(new GainProtectionFromChosenColorEffect(colorChoice.getColor()), source); - } - return true; - } - return false; - } - - @Override - public ChooseColorEffect copy() { - return new ChooseColorEffect(this); - } -} - -class GainProtectionFromChosenColorEffect extends GainAbilityControlledEffect { +class KabiraEvangelChooseColorEffect extends OneShotEffect { private static final FilterCreaturePermanent filter1 = new FilterCreaturePermanent(); @@ -131,31 +101,44 @@ class GainProtectionFromChosenColorEffect extends GainAbilityControlledEffect { filter1.add(new ControllerPredicate(TargetController.YOU)); filter1.add(new SubtypePredicate("Ally")); } - private final FilterCard filter2; - private final ObjectColor chosenColor; - public GainProtectionFromChosenColorEffect(ObjectColor chosenColor) { - super(new ProtectionAbility(new FilterCard()), Duration.EndOfTurn, filter1); - filter2 = (FilterCard) ((ProtectionAbility) getFirstAbility()).getFilter(); - this.chosenColor = chosenColor; + public KabiraEvangelChooseColorEffect() { + super(Outcome.Benefit); + staticText = "choose a color. All Allies you control gain protection from the chosen color until end of turn"; } - public GainProtectionFromChosenColorEffect(final GainProtectionFromChosenColorEffect effect) { + public KabiraEvangelChooseColorEffect(final KabiraEvangelChooseColorEffect effect) { super(effect); - this.filter2 = effect.filter2.copy(); - this.chosenColor = effect.chosenColor; - } - - @Override - public GainProtectionFromChosenColorEffect copy() { - return new GainProtectionFromChosenColorEffect(this); } @Override public boolean apply(Game game, Ability source) { - filter2.add(new ColorPredicate(chosenColor)); - filter2.setMessage(chosenColor.getDescription()); - setAbility(new ProtectionAbility(new FilterCard(filter2))); - return super.apply(game, source); + Player controller = game.getPlayer(source.getControllerId()); + Permanent sourceObject = game.getPermanent(source.getSourceId()); + if (sourceObject != null && controller != null) { + ChoiceColor choice = new ChoiceColor(); + while (!choice.isChosen()) { + controller.choose(outcome, choice, game); + if (!controller.isInGame()) { + return false; + } + } + if (choice.getColor() == null) { + return false; + } + game.informPlayers(sourceObject.getName() + ": " + controller.getName() + " has chosen " + choice.getChoice()); + FilterCard filterColor = new FilterCard(); + filterColor.add(new ColorPredicate(choice.getColor())); + filterColor.setMessage(choice.getChoice()); + ContinuousEffect effect = new GainAbilityAllEffect(new ProtectionAbility(new FilterCard(filterColor)), Duration.EndOfTurn, filter1); + game.addEffect(effect, source); + return true; + } + return false; + } + + @Override + public KabiraEvangelChooseColorEffect copy() { + return new KabiraEvangelChooseColorEffect(this); } } diff --git a/Mage/src/mage/abilities/CompoundAbility.java b/Mage/src/mage/abilities/CompoundAbility.java index b27a8438f1..d122735f84 100644 --- a/Mage/src/mage/abilities/CompoundAbility.java +++ b/Mage/src/mage/abilities/CompoundAbility.java @@ -1,5 +1,6 @@ package mage.abilities; +import java.util.Arrays; import java.util.List; /** @@ -14,9 +15,7 @@ public class CompoundAbility extends AbilitiesImpl { } public CompoundAbility(String ruleText, Ability... abilities) { - for (Ability ability : abilities) { - add(ability); - } + addAll(Arrays.asList(abilities)); } public CompoundAbility(final CompoundAbility compoundAbility) {