Search in sources :

Example 71 with Permanent

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

the class GlintHawkEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Return an artifact you control to its owner's hand?", source, game)) {
        controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            controller.moveCards(permanent, Zone.HAND, source, game);
            return true;
        }
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    return permanent != null && permanent.sacrifice(source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 72 with Permanent

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

the class GlissaSunseekerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller == null || permanent == null) {
        return false;
    }
    ManaPool pool = controller.getManaPool();
    int blackMana = pool.getBlack();
    int whiteMana = pool.getWhite();
    int blueMana = pool.getBlue();
    int greenMana = pool.getGreen();
    int redMana = pool.getRed();
    int colorlessMana = pool.getColorless();
    int manaPoolTotal = blackMana + whiteMana + blueMana + greenMana + redMana + colorlessMana;
    if (permanent.getManaValue() == manaPoolTotal) {
        return permanent.destroy(source, game, false);
    }
    return false;
}
Also used : Player(mage.players.Player) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) ManaPool(mage.players.ManaPool)

Example 73 with Permanent

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

the class GoblinBombEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller != null && permanent != null) {
        if (controller.flipCoin(source, game, true)) {
            game.informPlayers("Goblin Bomb: Won flip. Put a fuse counter on Goblin Bomb.");
            new AddCountersSourceEffect(CounterType.FUSE.createInstance(1)).apply(game, source);
            return true;
        } else {
            game.informPlayers("Goblin Bomb: Lost flip. Remove a fuse counter from Goblin Bomb.");
            new RemoveCounterSourceEffect(CounterType.FUSE.createInstance(1)).apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 74 with Permanent

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

the class GloomlanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        Player targetController = game.getPlayer(targetCreature.getControllerId());
        targetCreature.destroy(source, game, false);
        Permanent destroyedCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (destroyedCreature.getColor(game).isGreen() || destroyedCreature.getColor(game).isWhite()) {
            if (targetController != null) {
                targetController.discard(1, false, false, source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 75 with Permanent

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

the class HatefulEidolonTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    int auraCount = 0;
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (!zEvent.isDiesEvent()) {
        return false;
    }
    Permanent deadCreature = game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (deadCreature.getAttachments().isEmpty()) {
        return false;
    }
    for (UUID auraId : deadCreature.getAttachments()) {
        Permanent attachment = game.getPermanentOrLKIBattlefield(auraId);
        if (attachment.getControllerId().equals(controllerId) && attachment.isEnchantment(game)) {
            // Shadowspear or any other equipment does not count
            auraCount += 1;
        }
    }
    if (auraCount == 0) {
        // just equipment not aura's
        return false;
    }
    Player controller = game.getPlayer(controllerId);
    if (controller != null && controller.canRespond()) {
        this.getEffects().clear();
        DrawCardTargetEffect drawCard = new DrawCardTargetEffect(auraCount);
        drawCard.setTargetPointer(new FixedTarget(controllerId));
        this.addEffect(drawCard);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) UUID(java.util.UUID)

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