From f71a0c05e6e2051d50e7e797caa7270b8a95c11a Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 14 Aug 2015 15:34:16 +0200 Subject: [PATCH] * Hydromorph Guardian - Used custom predicate instead of custom target. --- .../mage/sets/magic2014/DoorOfDestinies.java | 5 +- .../sets/magicorigins/PyromancersGoggles.java | 2 +- .../mage/sets/timespiral/OpalineSliver.java | 2 +- .../mage/sets/torment/HydromorphGuardian.java | 130 ++++-------------- .../src/mage/sets/urzassaga/Oppression.java | 10 +- .../src/mage/sets/visions/Desertion.java | 7 +- .../common/SpellCastAllTriggeredAbility.java | 4 +- .../SpellCastControllerTriggeredAbility.java | 7 +- .../CantBeCounteredControlledEffect.java | 55 ++++---- .../common/CantBeTargetedAllEffect.java | 20 ++- Mage/src/mage/filter/FilterSpell.java | 59 ++++---- Mage/src/mage/filter/FilterStackObject.java | 16 +-- .../filter/common/FilterSpellOrPermanent.java | 9 +- Mage/src/mage/target/TargetSpell.java | 77 +++++------ 14 files changed, 158 insertions(+), 245 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2014/DoorOfDestinies.java b/Mage.Sets/src/mage/sets/magic2014/DoorOfDestinies.java index 5bc3c1c2891..95ef1ee6103 100644 --- a/Mage.Sets/src/mage/sets/magic2014/DoorOfDestinies.java +++ b/Mage.Sets/src/mage/sets/magic2014/DoorOfDestinies.java @@ -155,7 +155,7 @@ class AddCounterAbility extends TriggeredAbilityImpl { filter.add(new ControllerPredicate(TargetController.YOU)); filter.add(new SubtypePredicate(subtype)); Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, controllerId, game)) { + if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) { return true; } } @@ -169,7 +169,6 @@ class AddCounterAbility extends TriggeredAbilityImpl { } } - class BoostCreatureEffectEffect extends ContinuousEffectImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); @@ -194,7 +193,7 @@ class BoostCreatureEffectEffect 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)) { int boost = permanent.getCounters().getCount(CounterType.CHARGE); perm.addPower(boost); diff --git a/Mage.Sets/src/mage/sets/magicorigins/PyromancersGoggles.java b/Mage.Sets/src/mage/sets/magicorigins/PyromancersGoggles.java index f9729a180dd..02e4590a04b 100644 --- a/Mage.Sets/src/mage/sets/magicorigins/PyromancersGoggles.java +++ b/Mage.Sets/src/mage/sets/magicorigins/PyromancersGoggles.java @@ -112,7 +112,7 @@ class PyromancersGogglesTriggeredAbility extends TriggeredAbilityImpl { public boolean checkTrigger(GameEvent event, Game game) { if (event.getData().equals(abilityOriginalId)) { Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, getControllerId(), game)) { + if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) { for (Effect effect : getEffects()) { effect.setTargetPointer(new FixedTarget(event.getTargetId())); } diff --git a/Mage.Sets/src/mage/sets/timespiral/OpalineSliver.java b/Mage.Sets/src/mage/sets/timespiral/OpalineSliver.java index b891c5f5c31..f653af6f14a 100644 --- a/Mage.Sets/src/mage/sets/timespiral/OpalineSliver.java +++ b/Mage.Sets/src/mage/sets/timespiral/OpalineSliver.java @@ -112,7 +112,7 @@ class OpalineSliverTriggeredAbility extends TriggeredAbilityImpl { } else { return event.getTargetId().equals(this.getSourceId()) && game.getOpponents(this.controllerId).contains(event.getPlayerId()) - && spellCard.match(spell, event.getPlayerId(), game); + && spellCard.match(spell, getSourceId(), getControllerId(), game); } } diff --git a/Mage.Sets/src/mage/sets/torment/HydromorphGuardian.java b/Mage.Sets/src/mage/sets/torment/HydromorphGuardian.java index 56366bdd597..261fc1c2e34 100644 --- a/Mage.Sets/src/mage/sets/torment/HydromorphGuardian.java +++ b/Mage.Sets/src/mage/sets/torment/HydromorphGuardian.java @@ -27,11 +27,11 @@ */ package mage.sets.torment; -import java.util.HashSet; -import java.util.Set; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; +import mage.abilities.Mode; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.mana.ColoredManaCost; @@ -41,14 +41,14 @@ import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Rarity; import mage.constants.Zone; -import mage.filter.Filter; import mage.filter.FilterSpell; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.stack.Spell; -import mage.game.stack.StackObject; import mage.target.Target; -import mage.target.TargetObject; +import mage.target.TargetSpell; /** * @@ -56,7 +56,11 @@ import mage.target.TargetObject; */ public class HydromorphGuardian extends CardImpl { - private static FilterSpell filter = new FilterSpell("spell that targets one or more creatures you control"); + private final static FilterSpell filter = new FilterSpell("spell that targets one or more creatures you control"); + + static { + filter.add(new HydromorphGuardianPredicate()); + } public HydromorphGuardian(UUID ownerId) { super(ownerId, 39, "Hydromorph Guardian", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{2}{U}"); @@ -68,7 +72,7 @@ public class HydromorphGuardian extends CardImpl { // {U}, Sacrifice Hydromorph Guardian: Counter target spell that targets one or more creatures you control. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CounterTargetEffect(), new ColoredManaCost(ColoredManaSymbol.U)); ability.addCost(new SacrificeSourceCost()); - ability.addTarget(new CustomTargetSpell(filter)); + ability.addTarget(new TargetSpell(filter)); this.addAbility(ability); } @@ -80,108 +84,32 @@ public class HydromorphGuardian extends CardImpl { public HydromorphGuardian copy() { return new HydromorphGuardian(this); } - - private class CustomTargetSpell extends TargetObject { +} - protected FilterSpell filter; +class HydromorphGuardianPredicate implements ObjectSourcePlayerPredicate> { - public CustomTargetSpell() { - this(1, 1, new FilterSpell()); - } - - public CustomTargetSpell(FilterSpell filter) { - this(1, 1, filter); - } - - public CustomTargetSpell(int numTargets, FilterSpell filter) { - this(numTargets, numTargets, filter); - } - - public CustomTargetSpell(int minNumTargets, int maxNumTargets, FilterSpell filter) { - this.minNumberOfTargets = minNumTargets; - this.maxNumberOfTargets = maxNumTargets; - this.zone = Zone.STACK; - this.filter = filter; - this.targetName = filter.getMessage(); - } - - public CustomTargetSpell(final CustomTargetSpell target) { - super(target); - this.filter = target.filter.copy(); - } - - @Override - public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { - return canChoose(sourceControllerId, game); - } - - @Override - public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { - return possibleTargets(sourceControllerId, game); - } - - @Override - public boolean canTarget(UUID id, Ability source, Game game) { - if (super.canTarget(id, source, game)) { - if (targetsMyCreature(id, source.getControllerId(), game)) { - return true; - } - } - return false; - } - - @Override - public boolean canChoose(UUID sourceControllerId, Game game) { - int count = 0; - for (StackObject stackObject : game.getStack()) { - if (stackObject instanceof Spell && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match((Spell) stackObject, game)) { - if (targetsMyCreature(stackObject.getId(), sourceControllerId, game)) { - count++; - if (count >= this.minNumberOfTargets) - return true; - } - } - } - return false; - } - - @Override - public Set possibleTargets(UUID sourceControllerId, Game game) { - Set possibleTargets = new HashSet(); - for (StackObject stackObject : game.getStack()) { - if (stackObject instanceof Spell && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match((Spell) stackObject, game)) { - if (targetsMyCreature(stackObject.getId(), sourceControllerId, game)) { - possibleTargets.add(stackObject.getId()); - } - } - } - return possibleTargets; - } - - @Override - public Filter getFilter() { - return filter; - } - - private boolean targetsMyCreature(UUID id, UUID controllerId, Game game) { - StackObject spell = game.getStack().getStackObject(id); - if (spell != null) { - Ability ability = spell.getStackAbility(); - for (Target target : ability.getTargets()) { - for (UUID permanentId : target.getTargets()) { - Permanent permanent = game.getPermanent(permanentId); - if (permanent != null && permanent.getControllerId().equals(controllerId) && permanent.getCardType().contains(CardType.CREATURE)) { + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + Spell spell = game.getStack().getSpell(input.getObject().getId()); + if (spell != null) { + for (UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) { + Mode mode = spell.getSpellAbility().getModes().get(modeId); + for (Target target : mode.getTargets()) { + for (UUID targetId : target.getTargets()) { + Permanent permanent = game.getPermanent(targetId); + if (permanent.getCardType().contains(CardType.CREATURE) + && permanent.getControllerId().equals(input.getPlayerId())) { return true; } } } } - return false; } + return false; + } - @Override - public CustomTargetSpell copy() { - return new CustomTargetSpell(this); - } + @Override + public String toString() { + return "that targets one or more creatures you control"; } } diff --git a/Mage.Sets/src/mage/sets/urzassaga/Oppression.java b/Mage.Sets/src/mage/sets/urzassaga/Oppression.java index 5c626c2089e..dee4dea7f2b 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/Oppression.java +++ b/Mage.Sets/src/mage/sets/urzassaga/Oppression.java @@ -28,16 +28,11 @@ package mage.sets.urzassaga; import java.util.UUID; - -import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.SpellCastAllTriggeredAbility; import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.constants.Zone; -import mage.filter.FilterSpell; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.stack.Spell; @@ -53,7 +48,6 @@ public class Oppression extends CardImpl { super(ownerId, 143, "Oppression", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{1}{B}{B}"); this.expansionSetCode = "USG"; - // Whenever a player casts a spell, that player discards a card. this.addAbility(new OppressionTriggeredAbility()); } @@ -82,7 +76,7 @@ class OppressionTriggeredAbility extends SpellCastAllTriggeredAbility { public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST) { Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, getControllerId(), game)) { + if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) { this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getPlayerId())); return true; } @@ -94,4 +88,4 @@ class OppressionTriggeredAbility extends SpellCastAllTriggeredAbility { public OppressionTriggeredAbility copy() { return new OppressionTriggeredAbility(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/visions/Desertion.java b/Mage.Sets/src/mage/sets/visions/Desertion.java index 728c4856058..5c2f1b08387 100644 --- a/Mage.Sets/src/mage/sets/visions/Desertion.java +++ b/Mage.Sets/src/mage/sets/visions/Desertion.java @@ -56,7 +56,6 @@ public class Desertion extends CardImpl { super(ownerId, 30, "Desertion", Rarity.RARE, new CardType[]{CardType.INSTANT}, "{3}{U}{U}"); this.expansionSetCode = "VIS"; - // Counter target spell. If an artifact or creature spell is countered this way, put that card onto the battlefield under your control instead of into its owner's graveyard. this.getSpellAbility().addEffect(new DesertionEffect()); this.getSpellAbility().addTarget(new TargetSpell()); @@ -81,7 +80,7 @@ class DesertionEffect extends OneShotEffect { new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE))); } - + public DesertionEffect() { super(Outcome.Detriment); this.staticText = "Counter target spell. If an artifact or creature spell is countered this way, put that card onto the battlefield under your control instead of into its owner's graveyard."; @@ -106,7 +105,7 @@ class DesertionEffect extends OneShotEffect { if (stackObject instanceof Spell) { game.rememberLKI(objectId, Zone.STACK, (Spell) stackObject); game.getStack().remove(stackObject); - if (!((Spell) stackObject).isCopiedSpell() && filter.match(stackObject, source.getControllerId(), game)) { + if (!((Spell) stackObject).isCopiedSpell() && filter.match(stackObject, source.getSourceId(), source.getControllerId(), game)) { MageObject card = game.getObject(stackObject.getSourceId()); if (card instanceof Card) { ((Card) card).putOntoBattlefield(game, Zone.STACK, source.getSourceId(), source.getControllerId()); @@ -120,5 +119,5 @@ class DesertionEffect extends OneShotEffect { } return false; } - + } diff --git a/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java b/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java index 51882dc3bbd..4b552ae9ed0 100644 --- a/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/SpellCastAllTriggeredAbility.java @@ -86,10 +86,10 @@ public class SpellCastAllTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, getControllerId(), game)) { + if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) { if (!setTargetPointer.equals(SetTargetPointer.NONE)) { for (Effect effect : this.getEffects()) { - switch(setTargetPointer) { + switch (setTargetPointer) { case SPELL: effect.setTargetPointer(new FixedTarget(spell.getId())); break; diff --git a/Mage/src/mage/abilities/common/SpellCastControllerTriggeredAbility.java b/Mage/src/mage/abilities/common/SpellCastControllerTriggeredAbility.java index 471bda4c7ec..d576a13690a 100644 --- a/Mage/src/mage/abilities/common/SpellCastControllerTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/SpellCastControllerTriggeredAbility.java @@ -47,7 +47,8 @@ public class SpellCastControllerTriggeredAbility extends TriggeredAbilityImpl { protected String rule; /** - * If true, the source that triggered the ability will be set as target to effect. + * If true, the source that triggered the ability will be set as target to + * effect. */ protected boolean rememberSource = false; @@ -58,7 +59,7 @@ public class SpellCastControllerTriggeredAbility extends TriggeredAbilityImpl { public SpellCastControllerTriggeredAbility(Effect effect, FilterSpell filter, boolean optional) { this(effect, filter, optional, false); } - + public SpellCastControllerTriggeredAbility(Effect effect, FilterSpell filter, boolean optional, String rule) { this(effect, filter, optional, false); this.rule = rule; @@ -90,7 +91,7 @@ public class SpellCastControllerTriggeredAbility extends TriggeredAbilityImpl { public boolean checkTrigger(GameEvent event, Game game) { if (event.getPlayerId().equals(this.getControllerId())) { Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null && filter.match(spell, getControllerId(), game)) { + if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) { if (rememberSource) { this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getId())); } diff --git a/Mage/src/mage/abilities/effects/common/CantBeCounteredControlledEffect.java b/Mage/src/mage/abilities/effects/common/CantBeCounteredControlledEffect.java index 4776c73bf84..1d4de4da42d 100644 --- a/Mage/src/mage/abilities/effects/common/CantBeCounteredControlledEffect.java +++ b/Mage/src/mage/abilities/effects/common/CantBeCounteredControlledEffect.java @@ -1,31 +1,30 @@ /* -* 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. -*/ - + * 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; import mage.MageObject; @@ -89,7 +88,7 @@ public class CantBeCounteredControlledEffect extends ContinuousRuleModifyingEffe public boolean applies(GameEvent event, Ability source, Game game) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.getControllerId().equals(source.getControllerId()) - && filterTarget.match(spell, source.getControllerId(), game)) { + && filterTarget.match(spell, source.getSourceId(), source.getControllerId(), game)) { if (filterSource == null) { return true; } else { diff --git a/Mage/src/mage/abilities/effects/common/CantBeTargetedAllEffect.java b/Mage/src/mage/abilities/effects/common/CantBeTargetedAllEffect.java index 8fd76143d28..6e4322ca0cb 100644 --- a/Mage/src/mage/abilities/effects/common/CantBeTargetedAllEffect.java +++ b/Mage/src/mage/abilities/effects/common/CantBeTargetedAllEffect.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,12 +20,11 @@ * 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; import mage.abilities.Ability; @@ -60,7 +59,6 @@ public class CantBeTargetedAllEffect extends ContinuousRuleModifyingEffectImpl { setText(); } - public CantBeTargetedAllEffect(final CantBeTargetedAllEffect effect) { super(effect); if (effect.filterTarget != null) { @@ -92,10 +90,9 @@ public class CantBeTargetedAllEffect extends ContinuousRuleModifyingEffectImpl { if (permanent != null && filterTarget.match(permanent, source.getSourceId(), source.getControllerId(), game)) { if (filterSource == null) { return true; - } - else { + } else { StackObject sourceObject = game.getStack().getStackObject(event.getSourceId()); - if (sourceObject != null && filterSource.match(sourceObject, sourceObject.getSourceId(), game)) { + if (sourceObject != null && filterSource.match(sourceObject, source.getSourceId(), sourceObject.getControllerId(), game)) { return true; } } @@ -108,8 +105,7 @@ public class CantBeTargetedAllEffect extends ContinuousRuleModifyingEffectImpl { sb.append(filterTarget.getMessage()).append(" can't be the targets of "); if (filterSource != null) { sb.append(filterSource.getMessage()); - } - else { + } else { sb.append("spells"); } if (!duration.toString().isEmpty()) { diff --git a/Mage/src/mage/filter/FilterSpell.java b/Mage/src/mage/filter/FilterSpell.java index 258f2c9083d..9b6342aed7d 100644 --- a/Mage/src/mage/filter/FilterSpell.java +++ b/Mage/src/mage/filter/FilterSpell.java @@ -1,31 +1,30 @@ /* -* 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. -*/ - + * 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.filter; import java.util.UUID; @@ -50,13 +49,13 @@ public class FilterSpell extends FilterStackObject { public FilterSpell(final FilterSpell filter) { super(filter); } - + @Override - public boolean match(StackObject stackObject, UUID playerId, Game game) { + public boolean match(StackObject stackObject, UUID sourceId, UUID playerId, Game game) { if (!(stackObject instanceof Spell)) { return false; } - return super.match(stackObject, playerId, game); + return super.match(stackObject, sourceId, playerId, game); } @Override diff --git a/Mage/src/mage/filter/FilterStackObject.java b/Mage/src/mage/filter/FilterStackObject.java index 60a10aa913c..a7c478bd78a 100644 --- a/Mage/src/mage/filter/FilterStackObject.java +++ b/Mage/src/mage/filter/FilterStackObject.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,12 +20,11 @@ * 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.filter; import java.util.ArrayList; @@ -33,6 +32,7 @@ import java.util.List; import java.util.UUID; import mage.filter.predicate.ObjectPlayer; import mage.filter.predicate.ObjectPlayerPredicate; +import mage.filter.predicate.ObjectSourcePlayer; import mage.filter.predicate.Predicates; import mage.game.Game; import mage.game.permanent.Permanent; @@ -59,12 +59,12 @@ public class FilterStackObject extends FilterObject { this.extraPredicates = new ArrayList<>(filter.extraPredicates); } - public boolean match(StackObject stackObject, UUID playerId, Game game) { + public boolean match(StackObject stackObject, UUID sourceId, UUID playerId, Game game) { if (!this.match(stackObject, game)) { return false; } - return Predicates.and(extraPredicates).apply(new ObjectPlayer(stackObject, playerId), game); + return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(stackObject, sourceId, playerId), game); } public void add(ObjectPlayerPredicate predicate) { diff --git a/Mage/src/mage/filter/common/FilterSpellOrPermanent.java b/Mage/src/mage/filter/common/FilterSpellOrPermanent.java index 96631bbaaff..a4d3371cf63 100644 --- a/Mage/src/mage/filter/common/FilterSpellOrPermanent.java +++ b/Mage/src/mage/filter/common/FilterSpellOrPermanent.java @@ -1,5 +1,5 @@ /* - * + * * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are @@ -25,10 +25,11 @@ * 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.filter.common; +import java.util.UUID; import mage.filter.FilterImpl; import mage.filter.FilterInPlay; import mage.filter.FilterPermanent; @@ -37,8 +38,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.stack.Spell; -import java.util.UUID; - /** * * @author LevelX @@ -77,7 +76,7 @@ public class FilterSpellOrPermanent extends FilterImpl implements Filter @Override public boolean match(Object o, UUID sourceId, UUID playerId, Game game) { if (o instanceof Spell) { - return spellFilter.match((Spell) o, playerId, game); + return spellFilter.match((Spell) o, sourceId, playerId, game); } else if (o instanceof Permanent) { return permanentFilter.match((Permanent) o, sourceId, playerId, game); } diff --git a/Mage/src/mage/target/TargetSpell.java b/Mage/src/mage/target/TargetSpell.java index ec8dd9c6435..a070bbc3b7c 100644 --- a/Mage/src/mage/target/TargetSpell.java +++ b/Mage/src/mage/target/TargetSpell.java @@ -1,31 +1,30 @@ /* -* 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. -*/ - + * 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.target; import java.util.HashSet; @@ -84,7 +83,7 @@ public class TargetSpell extends TargetObject { } Spell spell = game.getStack().getSpell(id); if (spell != null) { - return filter.match(spell, source.getControllerId(), game); + return filter.match(spell, source.getSourceId(), source.getControllerId(), game); } return false; } @@ -92,12 +91,12 @@ public class TargetSpell extends TargetObject { @Override public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { int count = 0; - for (StackObject stackObject: game.getStack()) { + for (StackObject stackObject : game.getStack()) { // rule 114.4. A spell or ability on the stack is an illegal target for itself. if (sourceId != null && sourceId.equals(stackObject.getSourceId())) { continue; } - if (canBeChosen(stackObject, sourceControllerId, game)) { + if (canBeChosen(stackObject, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) { return true; @@ -114,28 +113,28 @@ public class TargetSpell extends TargetObject { @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { - return possibleTargets(sourceControllerId, game); - } - - @Override - public Set possibleTargets(UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); - for (StackObject stackObject: game.getStack()) { - if (canBeChosen(stackObject, sourceControllerId, game)) { + for (StackObject stackObject : game.getStack()) { + if (canBeChosen(stackObject, sourceId, sourceControllerId, game)) { possibleTargets.add(stackObject.getId()); } } return possibleTargets; } + @Override + public Set possibleTargets(UUID sourceControllerId, Game game) { + return this.possibleTargets(null, sourceControllerId, game); + } + @Override public TargetSpell copy() { return new TargetSpell(this); } - private boolean canBeChosen(StackObject stackObject, UUID sourceControllerId, Game game) { + private boolean canBeChosen(StackObject stackObject, UUID sourceID, UUID sourceControllerId, Game game) { return stackObject instanceof Spell && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) - && filter.match((Spell) stackObject, sourceControllerId, game); + && filter.match((Spell) stackObject, sourceID, sourceControllerId, game); } }