From fcbc9ce3a5dc0ea8b93981a215eddea34b7d30b5 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 18 Sep 2015 15:31:49 +0200 Subject: [PATCH] Fixed a bug of TargetSpellOrPermanent. --- .../target/common/TargetSpellOrPermanent.java | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/Mage/src/mage/target/common/TargetSpellOrPermanent.java b/Mage/src/mage/target/common/TargetSpellOrPermanent.java index 0e338680926..fea5811abbf 100644 --- a/Mage/src/mage/target/common/TargetSpellOrPermanent.java +++ b/Mage/src/mage/target/common/TargetSpellOrPermanent.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,7 +25,7 @@ * 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.common; @@ -51,7 +51,6 @@ import mage.target.TargetImpl; public class TargetSpellOrPermanent extends TargetImpl { protected FilterSpellOrPermanent filter; - protected FilterPermanent filterPermanent; public TargetSpellOrPermanent() { this(1, 1); @@ -62,28 +61,28 @@ public class TargetSpellOrPermanent extends TargetImpl { } public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets) { - this.minNumberOfTargets = minNumTargets; - this.maxNumberOfTargets = maxNumTargets; - this.zone = Zone.ALL; - this.filter = new FilterSpellOrPermanent(); - this.targetName = filter.getMessage(); - this.filterPermanent = new FilterPermanent(); + this(minNumTargets, maxNumTargets, false); } public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets, boolean notTarget) { - this(minNumTargets, maxNumTargets); + this(minNumTargets, maxNumTargets, new FilterSpellOrPermanent(), notTarget); this.notTarget = notTarget; } - public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets, FilterSpellOrPermanent filter,boolean notTarget) { - this(minNumTargets, maxNumTargets); + public TargetSpellOrPermanent(int minNumTargets, int maxNumTargets, FilterSpellOrPermanent filter, boolean notTarget) { + super(notTarget); + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.ALL; + this.targetName = filter.getMessage(); this.notTarget = notTarget; this.filter = filter; + this.targetName = filter.getMessage(); } + public TargetSpellOrPermanent(final TargetSpellOrPermanent target) { super(target); this.filter = target.filter.copy(); - this.filterPermanent = target.filterPermanent.copy(); } @Override @@ -92,7 +91,7 @@ public class TargetSpellOrPermanent extends TargetImpl { } public FilterPermanent getPermanentFilter() { - return this.filterPermanent; + return this.filter.getPermanentFilter(); } public void setFilter(FilterSpellOrPermanent filter) { @@ -136,19 +135,21 @@ public class TargetSpellOrPermanent extends TargetImpl { } /** - * Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} that can be chosen. Should only be used - * for Ability targets since this checks for protection, shroud etc. + * Checks if there are enough {@link mage.game.permanent.Permanent} or + * {@link mage.game.stack.Spell} that can be chosen. Should only be used for + * Ability targets since this checks for protection, shroud etc. * * @param sourceId - the target event source * @param sourceControllerId - controller of the target event source * @param game - * @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} exist + * @return - true if enough valid {@link mage.game.permanent.Permanent} or + * {@link mage.game.stack.Spell} exist */ @Override public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { int count = 0; MageObject targetSource = game.getObject(sourceId); - for (StackObject stackObject: game.getStack()) { + for (StackObject stackObject : game.getStack()) { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, sourceId, sourceControllerId, game)) { count++; @@ -157,7 +158,7 @@ public class TargetSpellOrPermanent extends TargetImpl { } } } - for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) { @@ -169,17 +170,19 @@ public class TargetSpellOrPermanent extends TargetImpl { } /** - * Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} that can be selected. Should not be used + * Checks if there are enough {@link mage.game.permanent.Permanent} or + * {@link mage.game.stack.Spell} that can be selected. Should not be used * for Ability targets since this does not check for protection, shroud etc. * * @param sourceControllerId - controller of the select event * @param game - * @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.game.stack.Spell} exist + * @return - true if enough valid {@link mage.game.permanent.Permanent} or + * {@link mage.game.stack.Spell} exist */ @Override public boolean canChoose(UUID sourceControllerId, Game game) { int count = 0; - for (StackObject stackObject: game.getStack()) { + for (StackObject stackObject : game.getStack()) { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, null, sourceControllerId, game) && filter.match(spell, game)) { count++; @@ -188,7 +191,7 @@ public class TargetSpellOrPermanent extends TargetImpl { } } } - for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game) && filter.match(permanent, game)) { count++; if (count >= this.minNumberOfTargets) { @@ -203,13 +206,13 @@ public class TargetSpellOrPermanent extends TargetImpl { public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); - for (StackObject stackObject: game.getStack()) { + for (StackObject stackObject : game.getStack()) { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, null, sourceControllerId, game) && filter.match(spell, game)) { possibleTargets.add(spell.getId()); } } - for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } @@ -220,13 +223,13 @@ public class TargetSpellOrPermanent extends TargetImpl { @Override public Set possibleTargets(UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); - for (StackObject stackObject: game.getStack()) { + for (StackObject stackObject : game.getStack()) { Spell spell = game.getStack().getSpell(stackObject.getId()); if (spell != null && filter.match(spell, null, sourceControllerId, game) && filter.match(spell, game)) { possibleTargets.add(spell.getId()); } } - for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } @@ -237,12 +240,11 @@ public class TargetSpellOrPermanent extends TargetImpl { @Override public String getTargetedName(Game game) { StringBuilder sb = new StringBuilder(); - for (UUID targetId: getTargets()) { + for (UUID targetId : getTargets()) { Permanent permanent = game.getPermanent(targetId); if (permanent != null) { sb.append(permanent.getLogName()).append(" "); - } - else { + } else { Spell spell = game.getStack().getSpell(targetId); sb.append(spell.getLogName()).append(" "); }