[filters] Replaced EvilTwin filter with predicate

This commit also touches the targeting system. Changes were made for consistency.
This commit is contained in:
North 2012-07-21 23:18:17 +03:00
parent c8617c0a55
commit d773ed3d13
4 changed files with 21 additions and 19 deletions

View file

@ -242,8 +242,8 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
public boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game) {
updateGameStatePriority("chooseTarget", game);
while (!abort) {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getId(), playerId, game);
boolean required = possibleTargets.size() == 0 ? false : target.isRequired();
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
boolean required = possibleTargets.isEmpty() ? false : target.isRequired();
game.fireSelectTargetEvent(playerId, target.getMessage(), possibleTargets, required, getOptions(target));
waitForResponse();
if (response.getUUID() != null) {

View file

@ -43,6 +43,8 @@ import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.continious.GainAbilitySourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
@ -53,6 +55,12 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class EvilTwin extends CardImpl<EvilTwin> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with the same name as this creature");
static {
filter.add(new EvilTwinPredicate());
}
public EvilTwin(UUID ownerId) {
super(ownerId, 212, "Evil Twin", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{2}{U}{B}");
this.expansionSetCode = "ISD";
@ -67,7 +75,7 @@ public class EvilTwin extends CardImpl<EvilTwin> {
Ability ability1 = new SimpleStaticAbility(Zone.BATTLEFIELD, new EntersBattlefieldEffect(new CopyPermanentEffect(), "You may have {this} enter the battlefield as a copy of any creature on the battlefield except it gains {U}{B}, {T}: Destroy target creature with the same name as this creature"));
Ability ability2 = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{U}{B}"));
ability2.addCost(new TapSourceCost());
ability2.addTarget(new TargetCreaturePermanent(new EvilTwinFilter()));
ability2.addTarget(new TargetCreaturePermanent(filter));
ability1.addEffect(new GainAbilitySourceEffect(ability2));
this.addAbility(ability1);
}
@ -82,24 +90,18 @@ public class EvilTwin extends CardImpl<EvilTwin> {
}
}
class EvilTwinFilter extends FilterCreaturePermanent {
class EvilTwinPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {
public EvilTwinFilter() {
super("creature with the same name as this creature");
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
Permanent permanent = input.getObject();
Permanent twin = game.getPermanent(input.getSourceId());
return permanent != null && twin != null && permanent.getName().equals(twin.getName());
}
@Override
public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) {
if (!super.match(permanent, game))
return notFilter;
Permanent twin = game.getPermanent(sourceId);
if (twin != null) {
if (!permanent.getName().equals(twin.getName()))
return false;
public String toString() {
return "SameNameAsSource";
}
return !notFilter;
}
}

View file

@ -87,7 +87,7 @@ public class Targets extends ArrayList<Target> {
public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, Game game) {
if (this.size() > 0) {
if (!canChoose(source.getId(), playerId, game))
if (!canChoose(source.getSourceId(), playerId, game))
return false;
while (!isChosen()) {
Target target = this.getUnchosen().get(0);