Search in sources :

Example 91 with Permanent

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

the class JuxtaposeEffect method init.

@Override
public void init(Ability source, Game game) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (you != null && targetPlayer != null) {
        Permanent permanent1 = chooseOnePermanentsWithTheHighestCMC(game, you, filter);
        Permanent permanent2 = chooseOnePermanentsWithTheHighestCMC(game, targetPlayer, filter);
        if (permanent1 != null && permanent2 != null) {
            // exchange works only for two different controllers
            if (permanent1.isControlledBy(permanent2.getControllerId())) {
                // discard effect if controller of both permanents is the same
                discard();
                return;
            }
            this.lockedControllers.put(permanent1.getId(), permanent2.getControllerId());
            this.zoneChangeCounter.put(permanent1.getId(), permanent1.getZoneChangeCounter(game));
            this.lockedControllers.put(permanent2.getId(), permanent1.getControllerId());
            this.zoneChangeCounter.put(permanent2.getId(), permanent2.getZoneChangeCounter(game));
            permanent1.changeControllerId(targetPlayer.getId(), game, source);
            permanent2.changeControllerId(you.getId(), game, source);
            MageObject sourceObject = game.getCard(source.getSourceId());
            game.informPlayers((sourceObject != null ? sourceObject.getLogName() : "") + ": " + you.getLogName() + " and " + targetPlayer.getLogName() + " exchange control of " + permanent1.getLogName() + " and " + permanent2.getName());
        } else {
            // discard if there are less than 2 permanents
            discard();
        }
    }
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) MageObject(mage.MageObject)

Example 92 with Permanent

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

the class JuxtaposeEffect method getPermanentsWithTheHighestCMC.

private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
    List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
    int highestCMC = -1;
    for (Permanent permanent : permanents) {
        if (highestCMC < permanent.getManaValue()) {
            highestCMC = permanent.getManaValue();
        }
    }
    List<Permanent> result = new ArrayList<>();
    for (Permanent permanent : permanents) {
        if (permanent.getManaValue() == highestCMC) {
            result.add(permanent);
        }
    }
    return result;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent)

Example 93 with Permanent

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

the class KalainReclusivePainterEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    if (creature == null) {
        return false;
    }
    int manaPaid = ManaPaidSourceWatcher.getTreasurePaid(creature.getId(), game);
    if (manaPaid < 1) {
        return false;
    }
    creature.addCounters(CounterType.P1P1.createInstance(manaPaid), source.getControllerId(), source, game, event.getAppliedEffects());
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Example 94 with Permanent

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

the class KaerveksPurgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Destroy target creature with converted mana cost X.
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null && targetCreature.destroy(source, game, false)) {
        game.getState().processAction(game);
        if (targetCreature.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(targetCreature.getId()) && game.getState().getZone(targetCreature.getId()) != Zone.GRAVEYARD) {
            // A replacement effect has moved the card to another zone as graveyard
            return true;
        }
        // If that creature dies this way, Kaervek's Purge deals damage equal to the creature's power to the creature's controller
        Player creatureController = game.getPlayer(targetCreature.getControllerId());
        int power = targetCreature.getPower().getValue();
        if (creatureController != null) {
            creatureController.damage(power, source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 95 with Permanent

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

the class KaaliaOfTheVastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, "Put an Angel, Demon, or Dragon creature card from your hand onto the battlefield tapped and attacking?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(filter);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(outcome, controller.getId(), source.getSourceId(), game)) {
        if (!target.getTargets().isEmpty()) {
            UUID cardId = target.getFirstTarget();
            Card card = game.getCard(cardId);
            if (card != null && game.getCombat() != null) {
                UUID defenderId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
                if (defenderId != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                    Permanent creature = game.getPermanent(cardId);
                    if (creature != null) {
                        game.getCombat().addAttackerToCombat(card.getId(), defenderId, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

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