Search in sources :

Example 36 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class CreamOfTheCropEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && permanent != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, permanent.getPower().getValue()));
        if (!cards.isEmpty()) {
            TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
            target.setNotTarget(true);
            controller.chooseTarget(Outcome.Benefit, cards, target, source, game);
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true);
            }
            controller.putCardsOnBottomOfLibrary(cards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 37 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class DefiantVanguardEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent blocker = game.getPermanent(event.getSourceId());
    Permanent blocked = game.getPermanent(event.getTargetId());
    if (blocker != null && blocked != null) {
        // in case the attacker changes zone
        game.getState().setValue(blocked.toString(), blocked.getZoneChangeCounter(game));
        // in case the blocker changes zone
        game.getState().setValue(blocker.toString(), blocker.getZoneChangeCounter(game));
        getAllEffects().setTargetPointer(new FixedTarget(blocked.getId()));
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent)

Example 38 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class DefilerOfSoulsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("monocolored creature");
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    filter.add(MonocoloredPredicate.instance);
    int amount;
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    amount = Math.min(1, realCount);
    Target target = new TargetControlledPermanent(amount, amount, filter, false);
    target.setNotTarget(true);
    // had, if thats the case this ability should fizzle.
    if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
        boolean abilityApplied = false;
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        }
        for (int idx = 0; idx < target.getTargets().size(); idx++) {
            Permanent permanent = game.getPermanent(target.getTargets().get(idx));
            if (permanent != null) {
                abilityApplied |= permanent.sacrifice(source, game);
            }
        }
        return abilityApplied;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 39 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class DeflectingPalmEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    this.used = true;
    // only one use
    this.discard();
    if (preventionData.getPreventedDamage() > 0) {
        MageObject damageDealingObject = game.getObject(target.getFirstTarget());
        UUID objectControllerId = null;
        if (damageDealingObject instanceof Permanent) {
            objectControllerId = ((Permanent) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Ability) {
            objectControllerId = ((Ability) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Spell) {
            objectControllerId = ((Spell) damageDealingObject).getControllerId();
        }
        if (objectControllerId != null) {
            Player objectController = game.getPlayer(objectControllerId);
            if (objectController != null) {
                objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 40 with Permanent

use of mage.game.permanent.Permanent in project mage by magefree.

the class DelifsConePreventEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (player != null || permanent != null) {
        player.gainLife(permanent.getPower().getValue(), game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

Permanent (mage.game.permanent.Permanent)3269 Player (mage.players.Player)1706 UUID (java.util.UUID)665 TargetPermanent (mage.target.TargetPermanent)571 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)541 FixedTarget (mage.target.targetpointer.FixedTarget)496 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)467 FilterPermanent (mage.filter.FilterPermanent)466 Card (mage.cards.Card)425 MageObject (mage.MageObject)246 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)226 Target (mage.target.Target)225 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)217 ContinuousEffect (mage.abilities.effects.ContinuousEffect)207 Effect (mage.abilities.effects.Effect)183 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)179 Test (org.junit.Test)179 OneShotEffect (mage.abilities.effects.OneShotEffect)175 FilterCard (mage.filter.FilterCard)158 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)153