mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Condensed "targets a permanent you control" conditions into a single class
This commit is contained in:
parent
993c11f279
commit
8463d693d4
4 changed files with 86 additions and 106 deletions
|
|
@ -0,0 +1,45 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class SourceTargetsPermanentCondition implements Condition {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
|
||||
public SourceTargetsPermanentCondition(FilterPermanent filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
|
||||
if (sourceSpell == null) {
|
||||
return false;
|
||||
}
|
||||
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
|
||||
while (targets.hasNext()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
|
||||
if (permanent != null && filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "it targets " + filter.getMessage();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue