use of mage.filter.Filter in project mage by magefree.
the class MoveTargetAuraEffect method apply.
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
Permanent potentialAttachment = input.getObject();
for (TargetAddress addr : TargetAddress.walk(aura)) {
Target target = addr.getTarget(aura);
Filter filter = target.getFilter();
return filter.match(potentialAttachment, game);
}
return false;
}
use of mage.filter.Filter in project mage by magefree.
the class CardTestPlayerAPIImpl method assertAbilityCount.
public void assertAbilityCount(Player player, String cardName, Class<? extends Ability> searchedAbility, int amount) {
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
found = permanent;
break;
}
}
Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
Assert.assertEquals(amount, found.getAbilities(currentGame).stream().filter(a -> searchedAbility.isAssignableFrom(a.getClass())).collect(Collectors.toList()).size());
}
use of mage.filter.Filter in project mage by magefree.
the class SteamVinesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent steamVines = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (steamVines != null) {
Permanent enchantedLand = game.getPermanentOrLKIBattlefield(steamVines.getAttachedTo());
Player controller = game.getPlayer(source.getControllerId());
if (enchantedLand != null && controller != null) {
Player landsController = game.getPlayer(enchantedLand.getControllerId());
if (game.getState().getZone(enchantedLand.getId()) == Zone.BATTLEFIELD) {
// if 2 or more Steam Vines were on a land
enchantedLand.destroy(source, game, false);
if (landsController != null) {
landsController.damage(1, source.getSourceId(), source, game);
}
}
if (!game.getBattlefield().getAllActivePermanents(CardType.LAND, game).isEmpty()) {
// lands are available on the battlefield
Target target = new TargetLandPermanent();
// not a target, it is chosen
target.setNotTarget(true);
Card steamVinesCard = game.getCard(source.getSourceId());
if (steamVinesCard != null && landsController != null) {
if (landsController.choose(Outcome.DestroyPermanent, target, source.getId(), game)) {
if (target.getFirstTarget() != null) {
Permanent landChosen = game.getPermanent(target.getFirstTarget());
if (landChosen != null) {
for (Target targetTest : steamVinesCard.getSpellAbility().getTargets()) {
Filter filterTest = targetTest.getFilter();
if (filterTest.match(landChosen, game)) {
if (game.getBattlefield().containsPermanent(landChosen.getId())) {
// verify that it is still on the battlefield
game.informPlayers(landsController.getLogName() + " attaches " + steamVines.getLogName() + " to " + landChosen.getLogName());
Effect effect = new AttachEffect(Outcome.Neutral);
effect.setTargetPointer(new FixedTarget(landChosen, game));
return effect.apply(game, source);
}
}
}
}
}
}
}
}
}
}
return false;
}
use of mage.filter.Filter in project mage by magefree.
the class YasharnImplacableEarthEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
boolean canTargetLand = true;
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || event.getType() == GameEvent.EventType.CAST_SPELL) {
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
if (permanent == null) {
return false;
}
}
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
for (Cost cost : ability.get().getCosts()) {
if (cost instanceof PayLifeCost || cost instanceof PayVariableLifeCost) {
// can't pay with life
return true;
}
if (cost instanceof SacrificeSourceCost && !permanent.isLand()) {
return true;
}
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
Filter filter = sacrificeCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAllCost) {
SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAttachedCost) {
SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeAttachmentCost) {
SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost;
Filter filter = sacrificeAllCost.getTargets().get(0).getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
if (cost instanceof SacrificeXTargetCost) {
SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost;
Filter filter = sacrificeCost.getFilter();
for (Object predicate : filter.getPredicates()) {
if (predicate instanceof CardType.CardTypePredicate) {
if (!predicate.toString().equals("CardType(Land)")) {
canTargetLand = false;
}
}
}
// must be nonland target
return !canTargetLand;
}
}
}
return false;
}
use of mage.filter.Filter in project mage by magefree.
the class AuraPermanentCanAttachToPermanentId method apply.
@Override
public boolean apply(Permanent input, Game game) {
final Permanent permanent = game.getPermanent(toBeCheckedPermanentId);
Filter filter;
if (input.getSpellAbility() != null && input.getSpellAbility().getTargets() != null) {
for (Target target : input.getSpellAbility().getTargets()) {
filter = target.getFilter();
if (filter.match(permanent, game)) {
return true;
}
}
}
return false;
}
Aggregations