allow Cards in exile zone to be targeted + add card owner to filters

This commit is contained in:
BetaSteward 2011-10-04 22:21:15 -04:00
parent 8526c678fc
commit 2f3108c57c
6 changed files with 91 additions and 24 deletions

View file

@ -49,6 +49,7 @@ public interface Cards extends Set<UUID>, Serializable {
public Collection<Card> getUniqueCards(Game game);
public Card getRandom(Game game);
public int count(FilterCard filter, Game game);
public int count(FilterCard filter, UUID playerId, Game game);
public void checkTriggers(GameEvent event, Game game);

View file

@ -123,6 +123,16 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
return result;
}
@Override
public int count(FilterCard filter, UUID playerId, Game game) {
int result = 0;
for (UUID card: this) {
if (filter.match(game.getCard(card), playerId, game))
result++;
}
return result;
}
@Override
public void checkTriggers(GameEvent event, Game game) {
for (UUID card: this) {

View file

@ -33,7 +33,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.Constants.TargetController;
import mage.cards.Card;
import mage.game.Game;
/**
*
@ -47,6 +49,7 @@ public class FilterCard<T extends FilterCard<T>> extends FilterObject<Card, Filt
protected boolean notOwner;
protected List<String> expansionSetCode = new ArrayList<String>();
protected boolean notExpansionSetCode;
protected TargetController owner = TargetController.ANY;
/**
* Text that appears on card.
@ -72,6 +75,7 @@ public class FilterCard<T extends FilterCard<T>> extends FilterObject<Card, Filt
this.expansionSetCode.add(code);
}
this.notExpansionSetCode = filter.notExpansionSetCode;
this.owner = filter.owner;
}
@Override
@ -115,6 +119,30 @@ public class FilterCard<T extends FilterCard<T>> extends FilterObject<Card, Filt
return !notFilter;
}
public boolean match(Card card, UUID playerId, Game game) {
if (!this.match(card))
return notFilter;
if (owner != TargetController.ANY && playerId != null) {
switch(owner) {
case YOU:
if (!card.getOwnerId().equals(playerId))
return notFilter;
break;
case OPPONENT:
if (!game.getOpponents(playerId).contains(card.getOwnerId()))
return notFilter;
break;
case NOT_YOU:
if (card.getOwnerId().equals(playerId))
return notFilter;
break;
}
}
return !notFilter;
}
public List<UUID> getOwnerId() {
return ownerId;
@ -136,6 +164,10 @@ public class FilterCard<T extends FilterCard<T>> extends FilterObject<Card, Filt
this.text = text;
}
public void setTargetOwner(TargetController owner) {
this.owner = owner;
}
public boolean matchOwner(UUID testOwnerId) {
if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner)
return false;

View file

@ -30,6 +30,7 @@ package mage.filter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Constants.CardType;
import mage.MageObject;
import mage.ObjectColor;
@ -180,8 +181,18 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
return notFilter;
}
if (abilities.size() > 0 && object.getAbilities().containsAll(abilities) == notAbilities) {
return notFilter;
if (abilities.size() > 0) {
List<Ability> test = new ArrayList<Ability>(abilities);
for (Ability ability: object.getAbilities()) {
for (Ability abilityTest: test) {
if (ability == abilityTest || ability.getClass().equals(abilityTest.getClass())) {
test.remove(abilityTest);
break;
}
}
}
if (test.isEmpty() == notAbilities)
return notFilter;
}
if (convertedManaCostComparison != null) {

View file

@ -53,6 +53,7 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
protected boolean usePhased;
protected boolean phasedIn;
protected TargetController controller = TargetController.ANY;
protected TargetController owner = TargetController.ANY;
public FilterPermanent() {
super("permanent");
@ -77,6 +78,7 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
this.usePhased = filter.usePhased;
this.phasedIn = filter.phasedIn;
this.controller = filter.controller;
this.owner = filter.owner;
}
public FilterPermanent(String name) {
@ -130,7 +132,24 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
}
}
if (another) {
if (owner != TargetController.ANY && playerId != null) {
switch(owner) {
case YOU:
if (!permanent.getOwnerId().equals(playerId))
return notFilter;
break;
case OPPONENT:
if (!game.getOpponents(playerId).contains(permanent.getOwnerId()))
return notFilter;
break;
case NOT_YOU:
if (permanent.getOwnerId().equals(playerId))
return notFilter;
break;
}
}
if (another) {
// filter out itself
if (permanent.getId().equals(sourceId)) {
return notFilter;
@ -184,25 +203,9 @@ public class FilterPermanent<T extends FilterPermanent<T>> extends FilterObject<
this.controller = controller;
}
// public void setController(UUID playerId, Game game) {
// controllerId.clear();
// switch (controller) {
// case ANY:
// break;
// case YOU:
// controllerId.add(playerId);
// notController = false;
// break;
// case NOT_YOU:
// controllerId.add(playerId);
// notController = true;
// break;
// case OPPONENT:
// controllerId.addAll(game.getOpponents(playerId));
// notController = false;
// break;
// }
// }
public void setTargetOwner(TargetController owner) {
this.owner = owner;
}
public boolean matchOwner(UUID testOwnerId) {
if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner)

View file

@ -104,17 +104,21 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
if (player != null) {
switch (zone) {
case HAND:
if (player.getHand().count(filter, game) >= this.minNumberOfTargets)
if (player.getHand().count(filter, player.getId(), game) >= this.minNumberOfTargets)
return true;
break;
case GRAVEYARD:
if (player.getGraveyard().count(filter, game) >= this.minNumberOfTargets)
if (player.getGraveyard().count(filter, player.getId(), game) >= this.minNumberOfTargets)
return true;
break;
case LIBRARY:
if (player.getLibrary().count(filter, game) >= this.minNumberOfTargets)
return true;
break;
case EXILED:
if (game.getExile().getPermanentExile().count(filter, player.getId(), game) >= this.minNumberOfTargets)
return true;
break;
}
}
}
@ -149,6 +153,12 @@ public class TargetCard<T extends TargetCard<T>> extends TargetObject<TargetCard
possibleTargets.add(card.getId());
}
break;
case EXILED:
for (Card card: game.getExile().getPermanentExile().getUniqueCards(game)) {
if (filter.match(card, player.getId(), game))
possibleTargets.add(card.getId());
}
break;
}
}
return possibleTargets;