Search in sources :

Example 26 with MageObject

use of mage.MageObject in project mage by magefree.

the class MycoidShepherdTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    MageObject lastKnown = game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
    if (lastKnown == null) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    if (super.getSourceId().equals(event.getTargetId()) || permanent.getPower().getValue() > 4 && permanent.isControlledBy(controllerId)) {
        Zone after = game.getState().getZone(event.getTargetId());
        return after != null && Zone.GRAVEYARD.match(after);
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Permanent(mage.game.permanent.Permanent) Zone(mage.constants.Zone) MageObject(mage.MageObject)

Example 27 with MageObject

use of mage.MageObject in project mage by magefree.

the class ManaCanBeSpentAsAnyColorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ObjectColor colorless = new ObjectColor();
        // permaments
        for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
            perm.getColor(game).setColor(colorless);
        }
        List<Card> affectedCards = new ArrayList<>();
        // spells
        for (MageObject object : game.getStack()) {
            if (object instanceof Spell) {
                game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
                Card card = ((Spell) object).getCard();
                affectedCards.add(card);
            }
        }
        // exile
        affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player == null) {
                continue;
            }
            // command
            affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
            // hand
            affectedCards.addAll(player.getHand().getCards(game));
            // library
            affectedCards.addAll(player.getLibrary().getCards(game));
            // graveyard
            affectedCards.addAll(player.getGraveyard().getCards(game));
        }
        // apply colors to all cards
        affectedCards.forEach(card -> {
            game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            // mdf cards
            if (card instanceof ModalDoubleFacesCard) {
                ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
                ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // split cards
            if (card instanceof SplitCard) {
                SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
                SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // double faces cards
            if (card.getSecondCardFace() != null) {
                game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            }
        });
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) UUID(java.util.UUID)

Example 28 with MageObject

use of mage.MageObject in project mage by magefree.

the class NissaNaturesArtisanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 2));
    if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getIdName(), cards, game);
        Set<Card> toBattlefield = new LinkedHashSet<>();
        for (Card card : cards.getCards(new FilterLandCard(), source.getSourceId(), source.getControllerId(), game)) {
            cards.remove(card);
            toBattlefield.add(card);
        }
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
        controller.moveCards(cards, Zone.HAND, source, game);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) MageObject(mage.MageObject) FilterLandCard(mage.filter.common.FilterLandCard)

Example 29 with MageObject

use of mage.MageObject in project mage by magefree.

the class NovaPentacleEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    // check source
    MageObject object = game.getObject(event.getSourceId());
    if (object == null) {
        game.informPlayers("Couldn't find source of damage");
        return false;
    }
    if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
        return false;
    }
    this.redirectTarget = source.getTargets().get(0);
    // check player
    Player player = game.getPlayer(event.getTargetId());
    if (player != null) {
        return player.getId().equals(source.getControllerId());
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

Example 30 with MageObject

use of mage.MageObject in project mage by magefree.

the class PeregrinationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target, source, game)) {
        if (!target.getTargets().isEmpty()) {
            Cards revealed = new CardsImpl();
            for (UUID cardId : target.getTargets()) {
                Card card = controller.getLibrary().getCard(cardId, game);
                revealed.add(card);
            }
            controller.revealCards(sourceObject.getIdName(), revealed, game);
            if (target.getTargets().size() == 2) {
                TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
                controller.choose(Outcome.Benefit, revealed, target2, game);
                Card card = revealed.get(target2.getFirstTarget(), game);
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                revealed.remove(card);
                Set<Card> cards = revealed.getCards(game);
                card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.HAND, source, game);
            } else if (target.getTargets().size() == 1) {
                Set<Card> cards = revealed.getCards(game);
                Card card = cards.isEmpty() ? null : cards.iterator().next();
                controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    controller.shuffleLibrary(source, game);
    return false;
}
Also used : Player(mage.players.Player) Set(java.util.Set) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) 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