Fix Soul Snare. Its targeting restriction could be implemented as a filter after all...

This commit is contained in:
LoneFox 2015-06-17 18:44:24 +03:00
parent f075e78967
commit 3695ffdc46

View file

@ -38,6 +38,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterAttackingCreature;
import mage.game.Game; import mage.game.Game;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -59,7 +60,7 @@ public class SoulSnare extends CardImpl {
effect.setText("Exile target creature that's attacking you or a planeswalker you control."); effect.setText("Exile target creature that's attacking you or a planeswalker you control.");
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{W}")); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{W}"));
ability.addCost(new SacrificeSourceCost()); ability.addCost(new SacrificeSourceCost());
ability.addTarget(new SoulSnareTarget()); ability.addTarget(new TargetCreaturePermanent(new SoulSnareFilter()));
this.addAbility(ability); this.addAbility(ability);
} }
@ -73,38 +74,39 @@ public class SoulSnare extends CardImpl {
} }
} }
class SoulSnareTarget extends TargetCreaturePermanent { class SoulSnareFilter extends FilterAttackingCreature {
public SoulSnareTarget() { public SoulSnareFilter() {
super(); super("creature that's attacking you or a planeswalker you control");
} }
public SoulSnareTarget(final SoulSnareTarget target) {
super(target); public SoulSnareFilter(final SoulSnareFilter filter) {
super(filter);
} }
@Override @Override
public SoulSnareTarget copy() { public SoulSnareFilter copy() {
return new SoulSnareTarget(this); return new SoulSnareFilter(this);
} }
@Override @Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) {
if(!super.canTarget(controllerId, id, source, game)) { if(!super.match(permanent, sourceId, playerId, game)) {
return false; return false;
} }
for(CombatGroup group : game.getCombat().getGroups()) { for(CombatGroup group : game.getCombat().getGroups()) {
for(UUID attacker : group.getAttackers()) { for(UUID attacker : group.getAttackers()) {
if(attacker.equals(id)) { if(attacker.equals(permanent.getId())) {
UUID defenderId = group.getDefenderId(); UUID defenderId = group.getDefenderId();
if(defenderId.equals(controllerId)) { if(defenderId.equals(playerId)) {
return true; return true;
} }
else { else {
Permanent permanent = game.getPermanent(defenderId); Permanent planeswalker = game.getPermanent(defenderId);
if(permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER) if(planeswalker != null && planeswalker.getCardType().contains(CardType.PLANESWALKER)
&& permanent.getControllerId().equals(controllerId)) { && planeswalker.getControllerId().equals(playerId)) {
return true; return true;
} }
} }