* Jareth, Leonine Titan - Fixed that the protection giving ability did not work correctly.

This commit is contained in:
LevelX2 2015-05-23 18:02:37 +02:00
parent 7003dc7e3f
commit f4718deae4
6 changed files with 116 additions and 288 deletions

View file

@ -29,23 +29,13 @@ package mage.sets.championsofkamigawa;
import java.util.UUID;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.effects.common.continuous.GainProtectionFromColorSourceEffect;
import mage.cards.CardImpl;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.filter.FilterCard;
import mage.filter.common.FilterSpiritOrArcaneCard;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -77,62 +67,3 @@ public class KamiOfThePaintedRoad extends CardImpl {
return new KamiOfThePaintedRoad(this);
}
}
class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect {
FilterCard protectionFilter;
public GainProtectionFromColorSourceEffect(Duration duration) {
super(new ProtectionAbility(new FilterCard()), duration);
protectionFilter = (FilterCard)((ProtectionAbility)ability).getFilter();
}
public GainProtectionFromColorSourceEffect(final GainProtectionFromColorSourceEffect effect) {
super(effect);
this.protectionFilter = effect.protectionFilter.copy();
}
@Override
public GainProtectionFromColorSourceEffect copy() {
return new GainProtectionFromColorSourceEffect(this);
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor colorChoice = new ChoiceColor(true);
colorChoice.setMessage("Choose color for protection ability");
while (!colorChoice.isChosen()) {
controller.choose(outcome, colorChoice, game);
if (!controller.isInGame()) {
discard();
return;
}
}
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
protectionFilter.setMessage(colorChoice.getChoice());
((ProtectionAbility)ability).setFilter(protectionFilter);
return;
}
discard();
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && new MageObjectReference(permanent, game).refersTo(source.getSourceObject(game), game)) {
permanent.addAbility(ability, source.getSourceId(), game);
} else {
// the source permanent is no longer on the battlefield, effect can be discarded
discard();
}
return true;
}
@Override
public String getText(Mode mode) {
return "{this} gains protection from the color of your choice " + duration.toString();
}
}

View file

@ -29,27 +29,18 @@ package mage.sets.dragonsoftarkir;
import java.util.UUID;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.effects.common.UntapSourceEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.effects.common.continuous.GainProtectionFromColorSourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.ProtectionAbility;
import mage.cards.CardImpl;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.filter.FilterCard;
import mage.filter.FilterSpell;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -88,62 +79,3 @@ public class PristineSkywise extends CardImpl {
return new PristineSkywise(this);
}
}
class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect {
FilterCard protectionFilter;
public GainProtectionFromColorSourceEffect(Duration duration) {
super(new ProtectionAbility(new FilterCard()), duration);
protectionFilter = (FilterCard)((ProtectionAbility)ability).getFilter();
}
public GainProtectionFromColorSourceEffect(final GainProtectionFromColorSourceEffect effect) {
super(effect);
this.protectionFilter = effect.protectionFilter.copy();
}
@Override
public GainProtectionFromColorSourceEffect copy() {
return new GainProtectionFromColorSourceEffect(this);
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor colorChoice = new ChoiceColor(true);
colorChoice.setMessage("Choose color for protection ability");
while (!colorChoice.isChosen()) {
controller.choose(outcome, colorChoice, game);
if (!controller.isInGame()) {
discard();
return;
}
}
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
protectionFilter.setMessage(colorChoice.getChoice());
((ProtectionAbility)ability).setFilter(protectionFilter);
return;
}
discard();
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && new MageObjectReference(permanent, game).refersTo(source.getSourceObject(game), game)) {
permanent.addAbility(ability, source.getSourceId(), game);
} else {
// the source permanent is no longer on the battlefield, effect can be discarded
discard();
}
return true;
}
@Override
public String getText(Mode mode) {
return "{this} gains protection from the color of your choice " + duration.toString();
}
}

View file

@ -29,27 +29,18 @@ package mage.sets.gatecrash;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.effects.common.continuous.GainProtectionFromColorSourceEffect;
import mage.cards.CardImpl;
import mage.choices.ChoiceColor;
import mage.filter.FilterCard;
import mage.constants.Duration;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
/**
@ -65,6 +56,7 @@ public class CartelAristocrat extends CardImpl {
static {
filter.add(new AnotherPredicate());
}
public CartelAristocrat(UUID ownerId) {
super(ownerId, 150, "Cartel Aristocrat", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{W}{B}");
this.expansionSetCode = "GTC";
@ -75,9 +67,8 @@ public class CartelAristocrat extends CardImpl {
this.toughness = new MageInt(2);
// Sacrifice another creature: Cartel Aristocrat gains protection from the color of your choice until end of turn.
Ability ability = new SimpleActivatedAbility(
Zone.BATTLEFIELD, new CartelAristocratEffect(), new SacrificeTargetCost(new TargetControlledPermanent(filter)));
this.addAbility(ability);
this.addAbility(new SimpleActivatedAbility(
Zone.BATTLEFIELD, new GainProtectionFromColorSourceEffect(Duration.EndOfTurn), new SacrificeTargetCost(new TargetControlledPermanent(filter))));
}
public CartelAristocrat(final CartelAristocrat card) {
@ -89,35 +80,3 @@ public class CartelAristocrat extends CardImpl {
return new CartelAristocrat(this);
}
}
class CartelAristocratEffect extends OneShotEffect {
public CartelAristocratEffect() {
super(Outcome.Protect);
this.staticText = "{this} gains protection from the color of your choice until end of turn";
}
public CartelAristocratEffect(final CartelAristocratEffect effect) {
super(effect);
}
@Override
public CartelAristocratEffect copy() {
return new CartelAristocratEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
ChoiceColor choice = new ChoiceColor();
choice.setMessage("Choose color to get protection from");
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && controller.choose(outcome, choice, game)) {
FilterCard protectionFilter = new FilterCard();
protectionFilter.add(new ColorPredicate(choice.getColor()));
protectionFilter.setMessage(choice.getChoice().toLowerCase());
ContinuousEffect effect = new GainAbilitySourceEffect(new ProtectionAbility(protectionFilter), Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
return false;
}
}

View file

@ -30,23 +30,15 @@ package mage.sets.odyssey;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.continuous.GainProtectionFromColorSourceEffect;
import mage.abilities.keyword.FirstStrikeAbility;
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.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
@ -66,7 +58,7 @@ public class ResilientWanderer extends CardImpl {
// First strike
this.addAbility(FirstStrikeAbility.getInstance());
// Discard a card: Resilient Wanderer gains protection from the color of your choice until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainProtectionFromColorSourceEffect(), new DiscardCardCost());
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainProtectionFromColorSourceEffect(Duration.EndOfTurn), new DiscardCardCost());
this.addAbility(ability);
}
@ -80,40 +72,3 @@ public class ResilientWanderer extends CardImpl {
}
}
class GainProtectionFromColorSourceEffect extends ContinuousEffectImpl {
protected FilterCard protectionFilter;
public GainProtectionFromColorSourceEffect() {
super(Duration.EndOfTurn, Outcome.AddAbility);
}
public GainProtectionFromColorSourceEffect(final GainProtectionFromColorSourceEffect effect) {
super(effect);
}
@Override
public GainProtectionFromColorSourceEffect copy() {
return new GainProtectionFromColorSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getSourceId());
if (creature != null) {
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
protectionFilter.add(new ColorPredicate(choice.getColor()));
protectionFilter.setMessage(choice.getChoice());
ProtectionAbility ability = new ProtectionAbility(protectionFilter);
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;
}
@Override
public String getText(Mode mode) {
return "{this} gains protection from the color of your choice " + duration.toString();
}
}

View file

@ -30,25 +30,16 @@ package mage.sets.onslaught;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.BlocksTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.effects.common.continuous.GainProtectionFromColorSourceEffect;
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.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -69,7 +60,7 @@ public class JarethLeonineTitan extends CardImpl {
// Whenever Jareth, Leonine Titan blocks, it gets +7/+7 until end of turn.
this.addAbility(new BlocksTriggeredAbility(new BoostSourceEffect(7,7,Duration.EndOfTurn), false));
// {W}: Jareth gains protection from the color of your choice until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new JarethsGainProtectionFromColorSourceEffect(), new ManaCostsImpl("{W}"));
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainProtectionFromColorSourceEffect(Duration.EndOfTurn), new ManaCostsImpl("{W}"));
this.addAbility(ability);
}
@ -83,48 +74,3 @@ public class JarethLeonineTitan extends CardImpl {
return new JarethLeonineTitan(this);
}
}
class JarethsGainProtectionFromColorSourceEffect extends ContinuousEffectImpl {
protected FilterCard protectionFilter;
public JarethsGainProtectionFromColorSourceEffect() {
super(Duration.EndOfTurn, Outcome.AddAbility);
}
public JarethsGainProtectionFromColorSourceEffect(final JarethsGainProtectionFromColorSourceEffect effect) {
super(effect);
}
@Override
public JarethsGainProtectionFromColorSourceEffect copy() {
return new JarethsGainProtectionFromColorSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent creature = game.getPermanent(source.getSourceId());
if (controller != null && creature != null) {
ChoiceColor choice = new ChoiceColor();
while (!choice.isChosen()) {
controller.choose(Outcome.Protect, choice, game);
if (!controller.isInGame()) {
return false;
}
}
protectionFilter.add(new ColorPredicate(choice.getColor()));
protectionFilter.setMessage(choice.getChoice());
ProtectionAbility ability = new ProtectionAbility(protectionFilter);
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
return false;
}
@Override
public String getText(Mode mode) {
return "{this} gains protection from the color of your choice " + duration.toString();
}
}

View file

@ -0,0 +1,105 @@
/*
* 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.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.keyword.ProtectionAbility;
import mage.choices.ChoiceColor;
import mage.constants.Duration;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class GainProtectionFromColorSourceEffect extends GainAbilitySourceEffect {
FilterCard protectionFilter;
public GainProtectionFromColorSourceEffect(Duration duration) {
super(new ProtectionAbility(new FilterCard()), duration);
protectionFilter = (FilterCard)((ProtectionAbility)ability).getFilter();
}
public GainProtectionFromColorSourceEffect(final GainProtectionFromColorSourceEffect effect) {
super(effect);
this.protectionFilter = effect.protectionFilter.copy();
}
@Override
public GainProtectionFromColorSourceEffect copy() {
return new GainProtectionFromColorSourceEffect(this);
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor colorChoice = new ChoiceColor(true);
colorChoice.setMessage("Choose color for protection ability");
while (!colorChoice.isChosen()) {
controller.choose(outcome, colorChoice, game);
if (!controller.isInGame()) {
discard();
return;
}
}
game.informPlayers("Choosen color: " + colorChoice.getColor());
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
protectionFilter.setMessage(colorChoice.getChoice());
((ProtectionAbility)ability).setFilter(protectionFilter);
return;
}
discard();
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && new MageObjectReference(permanent, game).refersTo(source.getSourceObject(game), game)) {
permanent.addAbility(ability, source.getSourceId(), game);
} else {
// the source permanent is no longer on the battlefield, effect can be discarded
discard();
}
return true;
}
@Override
public String getText(Mode mode) {
return "{this} gains protection from the color of your choice " + duration.toString();
}
}