Fixed filter for "Target ANOTHER permanent" not working. Now sourceId is passed to match method. Updated sever plugins (game freezes otherwise).

This commit is contained in:
magenoxx 2011-08-10 12:28:57 +04:00
parent cbf8f02df3
commit a60fe86fbb
20 changed files with 72 additions and 40 deletions

View file

@ -89,7 +89,7 @@ public class CantTargetControlledEffect extends ReplacementEffectImpl<CantTarget
if (event.getType() == EventType.TARGET) {
filterTarget.setTargetController(TargetController.YOU);
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && filterTarget.match(permanent, source.getControllerId(), game)) {
if (permanent != null && filterTarget.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
if (filterSource == null)
return true;
else {

View file

@ -82,12 +82,12 @@ public class PreventAllDamageToEffect extends PreventionEffectImpl<PreventAllDam
if (super.applies(event, source, game)) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null) {
if (filter.match(permanent, source.getControllerId(), game))
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game))
return true;
}
else {
Player player = game.getPlayer(event.getTargetId());
if (player != null && filter.match(player, source.getControllerId(), game))
if (player != null && filter.match(player, source.getSourceId(), source.getControllerId(), game))
return true;
}
}

View file

@ -66,7 +66,7 @@ public class AddCountersAllEffect extends OneShotEffect<AddCountersAllEffect> {
UUID controllerId = source.getControllerId();
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents();
for (Permanent permanent : permanents) {
if (filter.match(permanent, controllerId, game)) {
if (filter.match(permanent, source.getSourceId(), controllerId, game)) {
permanent.addCounters(counter.copy());
applied = true;
}

View file

@ -29,6 +29,8 @@
package mage.filter;
import java.util.UUID;
import mage.abilities.Ability;
import mage.game.Game;
/**
@ -37,7 +39,7 @@ import mage.game.Game;
*/
public interface FilterInPlay<E> extends Filter<E> {
public boolean match(E o, UUID playerId, Game game);
public boolean match(E o, UUID sourceId, UUID playerId, Game game);
@Override
public FilterInPlay<E> copy();

View file

@ -73,6 +73,11 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
protected UUID id;
protected boolean notId;
/**
* Indicates that filter shouldn't match the source.
*/
protected boolean another;
@Override
public FilterObject<E, T> copy() {
return new FilterObject<E, T>(this);
@ -125,6 +130,7 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
this.toughnessComparison = filter.toughnessComparison;
this.id = filter.id;
this.notId = filter.notId;
this.another = filter.another;
}
@Override
@ -323,4 +329,11 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
this.notId = notId;
}
public boolean isAnother() {
return another;
}
public void setAnother(boolean another) {
this.another = another;
}
}

View file

@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants.TargetController;
import mage.abilities.Ability;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -109,7 +110,7 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
return !notFilter;
}
public boolean match(Permanent permanent, UUID playerId, Game game) {
public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) {
if (!this.match(permanent))
return notFilter;
@ -130,6 +131,13 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
}
}
if (another) {
// filter out itself
if (permanent.getId().equals(sourceId)) {
return notFilter;
}
}
return !notFilter;
}

View file

@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants.TargetController;
import mage.abilities.Ability;
import mage.game.Game;
import mage.players.Player;
@ -67,7 +68,7 @@ public class FilterPlayer extends FilterImpl<Player, FilterPlayer> implements Fi
return !notFilter;
}
public boolean match(Player player, UUID playerId, Game game) {
public boolean match(Player player, UUID sourceId, UUID playerId, Game game) {
if (!this.match(player))
return notFilter;

View file

@ -29,6 +29,8 @@
package mage.filter.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.filter.Filter;
import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
@ -82,12 +84,12 @@ public class FilterCreatureOrPlayer extends FilterImpl<Object, FilterCreatureOrP
}
@Override
public boolean match(Object o, UUID playerId, Game game) {
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
if (o instanceof Player) {
return playerFilter.match((Player)o, playerId, game);
return playerFilter.match((Player)o, sourceId, playerId, game);
}
else if (o instanceof Permanent) {
return creatureFilter.match((Permanent)o, playerId, game);
return creatureFilter.match((Permanent)o, sourceId, playerId, game);
}
return notFilter;
}

View file

@ -28,6 +28,7 @@
package mage.filter.common;
import mage.abilities.Ability;
import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
import mage.filter.FilterPermanent;
@ -81,11 +82,11 @@ public class FilterPermanentOrPlayer extends FilterImpl<Object, FilterPermanentO
}
@Override
public boolean match(Object o, UUID playerId, Game game) {
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
if (o instanceof Player) {
return playerFilter.match((Player) o, playerId, game);
return playerFilter.match((Player) o, sourceId, playerId, game);
} else if (o instanceof Permanent) {
return permanentFilter.match((Permanent) o, playerId, game);
return permanentFilter.match((Permanent) o, sourceId, playerId, game);
}
return notFilter;
}

View file

@ -28,6 +28,7 @@
package mage.filter.common;
import mage.abilities.Ability;
import mage.filter.FilterImpl;
import mage.filter.FilterInPlay;
import mage.filter.FilterPermanent;
@ -36,6 +37,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import javax.xml.transform.Source;
import java.util.UUID;
/**
@ -85,11 +87,11 @@ public class FilterPermanentOrPlayerWithCounter extends FilterPermanentOrPlayer
}
@Override
public boolean match(Object o, UUID playerId, Game game) {
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
if (o instanceof Player) {
return playerFilter.match((Player) o, playerId, game);
return playerFilter.match((Player) o, sourceId, playerId, game);
} else if (o instanceof Permanent) {
return permanentFilter.match((Permanent) o, playerId, game);
return permanentFilter.match((Permanent) o, sourceId, playerId, game);
}
return notFilter;
}

View file

@ -122,7 +122,7 @@ public class Battlefield implements Serializable {
int count = 0;
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
for (Permanent permanent: field.values()) {
if (filter.match(permanent, sourcePlayerId, game)) {
if (filter.match(permanent, null, sourcePlayerId, game)) {
count++;
}
}
@ -130,7 +130,7 @@ public class Battlefield implements Serializable {
else {
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
for (Permanent permanent: field.values()) {
if (range.contains(permanent.getControllerId()) && filter.match(permanent, sourcePlayerId, game)) {
if (range.contains(permanent.getControllerId()) && filter.match(permanent, null, sourcePlayerId, game)) {
count++;
}
}
@ -193,7 +193,7 @@ public class Battlefield implements Serializable {
int count = 0;
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
for (Permanent permanent: field.values()) {
if (filter.match(permanent, sourcePlayerId, game)) {
if (filter.match(permanent, null, sourcePlayerId, game)) {
count++;
if (num == count)
return true;
@ -203,7 +203,7 @@ public class Battlefield implements Serializable {
else {
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
for (Permanent permanent: field.values()) {
if (range.contains(permanent.getControllerId()) && filter.match(permanent, sourcePlayerId, game)) {
if (range.contains(permanent.getControllerId()) && filter.match(permanent, null, sourcePlayerId, game)) {
count++;
if (num == count)
return true;
@ -352,14 +352,14 @@ public class Battlefield implements Serializable {
List<Permanent> active = new ArrayList<Permanent>();
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
for (Permanent perm: field.values()) {
if (perm.isPhasedIn() && filter.match(perm, sourcePlayerId, game))
if (perm.isPhasedIn() && filter.match(perm, null, sourcePlayerId, game))
active.add(perm);
}
}
else {
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
for (Permanent perm: field.values()) {
if (perm.isPhasedIn() && range.contains(perm.getControllerId()) && filter.match(perm, sourcePlayerId, game))
if (perm.isPhasedIn() && range.contains(perm.getControllerId()) && filter.match(perm, null, sourcePlayerId, game))
active.add(perm);
}
}

View file

@ -102,6 +102,9 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
}
return sb.toString();
}
if (targetName.startsWith("another")) {
return "Select " + targetName;
}
return "Select a " + targetName;
}

View file

@ -82,9 +82,9 @@ public class TargetPermanent<T extends TargetPermanent<T>> extends TargetObject<
if (permanent != null) {
if (source != null)
//TODO: check for replacement effects
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, controllerId, game);
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, source.getSourceId(), controllerId, game);
else
return filter.match(permanent, controllerId, game);
return filter.match(permanent, null, controllerId, game);
}
return false;
}

View file

@ -99,9 +99,9 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
if (permanent != null) {
if (source != null)
//TODO: check for replacement effects
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, controllerId, game);
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, source.getSourceId(), controllerId, game);
else
return filter.match(permanent, controllerId, game);
return filter.match(permanent, source.getSourceId(), controllerId, game);
}
Player player = game.getPlayer(id);
if (player != null)
@ -134,7 +134,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -163,7 +163,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -183,7 +183,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
@ -200,7 +200,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}

View file

@ -85,7 +85,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
MageObject targetSource = game.getObject(source.getSourceId());
if (permanent != null) {
if (source != null)
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getControllerId(), game);
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
else
return filter.match(permanent);
}
@ -111,7 +111,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -132,7 +132,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -152,7 +152,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
@ -169,7 +169,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}

View file

@ -109,7 +109,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
MageObject targetSource = game.getObject(source.getSourceId());
if (permanent != null) {
if (source != null)
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getControllerId(), game);
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
else
return filter.match(permanent);
}
@ -144,7 +144,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -173,7 +173,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(filterPermanent, sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets)
return true;
@ -193,7 +193,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}
@ -210,7 +210,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
if (filter.match(permanent, sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
}