Search in sources :

Example 21 with MageObject

use of mage.MageObject 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 22 with MageObject

use of mage.MageObject in project mage by magefree.

the class MedomaisProphecyLookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourcePermanentOrLKI(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).forEachOrdered(player -> controller.lookAtCards(sourceObject.getIdName() + " " + player.getName(), player.getLibrary().getFromTop(game), game));
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject)

Example 23 with MageObject

use of mage.MageObject in project mage by magefree.

the class MutinyFirstTarget method canChoose.

@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
    if (super.canChoose(sourceId, sourceControllerId, game)) {
        UUID controllingPlayerId = game.getControllerId(sourceId);
        for (UUID playerId : game.getOpponents(controllingPlayerId)) {
            int possibleTargets = 0;
            MageObject sourceObject = game.getObject(sourceId);
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
                if (permanent.canBeTargetedBy(sourceObject, controllingPlayerId, game)) {
                    possibleTargets++;
                }
            }
            if (possibleTargets > 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 24 with MageObject

use of mage.MageObject in project mage by magefree.

the class MutinyFirstTarget method canTarget.

@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
    if (super.canTarget(controllerId, id, source, game)) {
        // can only target, if the controller has at least two targetable creatures
        UUID controllingPlayerId = game.getControllerId(id);
        int possibleTargets = 0;
        MageObject sourceObject = game.getObject(source.getId());
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllingPlayerId, game)) {
            if (permanent.canBeTargetedBy(sourceObject, controllerId, game)) {
                possibleTargets++;
            }
        }
        return possibleTargets > 1;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 25 with MageObject

use of mage.MageObject in project mage by magefree.

the class MurmursFromBeyondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
        if (!cards.isEmpty()) {
            controller.revealCards(staticText, cards, game);
            Card cardToGraveyard;
            if (cards.size() == 1) {
                cardToGraveyard = cards.getRandom(game);
            } else {
                Player opponent;
                Set<UUID> opponents = game.getOpponents(controller.getId());
                if (opponents.size() == 1) {
                    opponent = game.getPlayer(opponents.iterator().next());
                } else {
                    Target target = new TargetOpponent(true);
                    controller.chooseTarget(Outcome.Detriment, target, source, game);
                    opponent = game.getPlayer(target.getFirstTarget());
                }
                TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
                opponent.chooseTarget(outcome, cards, target, source, game);
                cardToGraveyard = game.getCard(target.getFirstTarget());
            }
            if (cardToGraveyard != null) {
                controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
                cards.remove(cardToGraveyard);
            }
            controller.moveCards(cards, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41