Search in sources :

Example 1 with FilterArtifactOrEnchantmentPermanent

use of mage.filter.common.FilterArtifactOrEnchantmentPermanent in project mage by magefree.

the class FelineSovereignTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
        DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
        Permanent p = game.getPermanent(event.getSourceId());
        if (damageEvent.isCombatDamage() && p != null && p.isControlledBy(this.getControllerId()) && filter.match(p, getSourceId(), getControllerId(), game) && !damagedPlayerIds.contains(event.getPlayerId())) {
            damagedPlayerIds.add(event.getPlayerId());
            this.getTargets().clear();
            FilterArtifactOrEnchantmentPermanent filter = new FilterArtifactOrEnchantmentPermanent();
            filter.add(new ControllerIdPredicate(event.getPlayerId()));
            this.addTarget(new TargetPermanent(0, 1, filter, false));
            return true;
        }
    }
    if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_PRIORITY || (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(getSourceId()))) {
        damagedPlayerIds.clear();
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) TargetPermanent(mage.target.TargetPermanent) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent)

Example 2 with FilterArtifactOrEnchantmentPermanent

use of mage.filter.common.FilterArtifactOrEnchantmentPermanent in project mage by magefree.

the class DruidOfPurificationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterPermanent filter = new FilterArtifactOrEnchantmentPermanent("artifact or enchantment not controlled by " + controller.getName());
    filter.add(Predicates.not(new ControllerIdPredicate(controller.getId())));
    if (game.getBattlefield().count(filter, source.getControllerId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, filter);
    target.setNotTarget(true);
    Set<Permanent> permanents = new HashSet<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        target.clearChosen();
        player.choose(Outcome.DestroyPermanent, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null) {
            game.informPlayers(player.getLogName() + " has not chosen a permanent");
            continue;
        }
        game.informPlayers(player.getLogName() + " has chosen " + permanent.getLogName());
        permanents.add(permanent);
    }
    for (Permanent permanent : permanents) {
        permanent.destroy(source, game, false);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent) HashSet(java.util.HashSet)

Example 3 with FilterArtifactOrEnchantmentPermanent

use of mage.filter.common.FilterArtifactOrEnchantmentPermanent in project mage by magefree.

the class KappaTechWreckerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent filter = new FilterArtifactOrEnchantmentPermanent("artifact or enchantment that player controls");
    filter.add(new ControllerIdPredicate(getTargetPointer().getFirst(game, source)));
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new ExileTargetEffect(), false);
    ability.addTarget(new TargetPermanent(filter));
    return new DoWhenCostPaid(ability, new RemoveCountersSourceCost(CounterType.DEATHTOUCH.createInstance()), "Remove a deathtouch counter?").apply(game, source);
}
Also used : FilterPermanent(mage.filter.FilterPermanent) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost) DoWhenCostPaid(mage.abilities.effects.common.DoWhenCostPaid) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

FilterArtifactOrEnchantmentPermanent (mage.filter.common.FilterArtifactOrEnchantmentPermanent)3 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)3 TargetPermanent (mage.target.TargetPermanent)3 FilterPermanent (mage.filter.FilterPermanent)2 Permanent (mage.game.permanent.Permanent)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 RemoveCountersSourceCost (mage.abilities.costs.common.RemoveCountersSourceCost)1 DoWhenCostPaid (mage.abilities.effects.common.DoWhenCostPaid)1 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)1 Player (mage.players.Player)1