* Hydromorph Guardian - Used custom predicate instead of custom target.

This commit is contained in:
LevelX2 2015-08-14 15:34:16 +02:00
parent 9f635b304f
commit f71a0c05e6
14 changed files with 158 additions and 245 deletions

View file

@ -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);

View file

@ -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()));
}

View file

@ -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);
}
}

View file

@ -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<ObjectSourcePlayer<MageObject>> {
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<UUID> 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<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<UUID>();
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<MageObject> 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";
}
}

View file

@ -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);
}
}
}

View file

@ -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;
}
}