Search in sources :

Example 86 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class EmptyTheLaboratoryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int toSacrifice = Math.min(source.getManaCostsToPay().getX(), game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game));
    if (toSacrifice < 1) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(toSacrifice, filter);
    target.setNotTarget(true);
    player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
    int sacrificed = 0;
    for (UUID permanentId : target.getTargets()) {
        Permanent permanent = game.getPermanent(permanentId);
        if (permanent != null && permanent.sacrifice(source, game)) {
            sacrificed++;
        }
    }
    Cards toReveal = new CardsImpl();
    int zombies = 0;
    for (Card card : player.getLibrary().getCards(game)) {
        toReveal.add(card);
        if (card.isCreature(game) && card.hasSubtype(SubType.ZOMBIE, game)) {
            zombies++;
        }
        if (zombies >= sacrificed) {
            break;
        }
    }
    player.revealCards(source, toReveal, game);
    player.moveCards(toReveal.getCards(filter2, game), Zone.BATTLEFIELD, source, game);
    toReveal.retainZone(Zone.LIBRARY, game);
    player.putCardsOnBottomOfLibrary(toReveal, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard)

Example 87 with TargetPermanent

use of mage.target.TargetPermanent 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 88 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class FeedThePackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Target target = new TargetPermanent(filter);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null && permanent.sacrifice(source, game)) {
            int toughness = permanent.getToughness().getValue();
            WolfToken token = new WolfToken();
            token.putOntoBattlefield(toughness, game, source, source.getControllerId());
            return true;
        }
    }
    return false;
}
Also used : WolfToken(mage.game.permanent.token.WolfToken) Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 89 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class GideonsSacrificeEffectReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetPermanent(filter);
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    game.addEffect(new GideonsSacrificeEffectReplacementEffect(new MageObjectReference(target.getFirstTarget(), game)), source);
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 90 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class GideonsSacrificeEffectReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent permanent = mor.getPermanent(game);
    if (permanent == null) {
        return false;
    }
    // Name of old target
    Permanent targetPermanent = game.getPermanent(event.getTargetId());
    StringBuilder message = new StringBuilder();
    message.append(permanent.getName()).append(": gets ");
    message.append(damageEvent.getAmount()).append(" damage redirected from ");
    if (targetPermanent != null) {
        message.append(targetPermanent.getName());
    } else {
        Player targetPlayer = game.getPlayer(event.getTargetId());
        if (targetPlayer != null) {
            message.append(targetPlayer.getLogName());
        } else {
            message.append("unknown");
        }
    }
    game.informPlayers(message.toString());
    // Redirect damage
    permanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Aggregations

TargetPermanent (mage.target.TargetPermanent)222 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)167 FilterPermanent (mage.filter.FilterPermanent)108 UUID (java.util.UUID)65 Target (mage.target.Target)58 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)47 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)36 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)32 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)24 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)19 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)19 FixedTarget (mage.target.targetpointer.FixedTarget)19 MageObject (mage.MageObject)18 Ability (mage.abilities.Ability)18 Card (mage.cards.Card)17 ArrayList (java.util.ArrayList)15 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)14 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13