Search in sources :

Example 26 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class RadiantScrollwielderWatcher method checkSpell.

static boolean checkSpell(Card card, Ability source, Game game) {
    if (card == null) {
        return false;
    }
    RadiantScrollwielderWatcher watcher = game.getState().getWatcher(RadiantScrollwielderWatcher.class);
    if (watcher == null) {
        return false;
    }
    MageObjectReference mor = watcher.morMap.getOrDefault(new MageObjectReference(card, game), null);
    return mor != null && mor.refersTo(source.getSourceObject(game), game);
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 27 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SoulflayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        // one time abilities collect
        if (objectReference == null || !objectReference.refersTo(permanent, game)) {
            abilitiesToAdd = new HashSet<>();
            this.objectReference = new MageObjectReference(permanent, game);
            String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
            Cards delvedCards = (Cards) game.getState().getValue(keyString);
            if (delvedCards != null) {
                for (Card card : delvedCards.getCards(game)) {
                    if (!card.isCreature(game)) {
                        continue;
                    }
                    for (Ability cardAbility : card.getAbilities(game)) {
                        if (cardAbility instanceof FlyingAbility) {
                            abilitiesToAdd.add(FlyingAbility.getInstance());
                        }
                        if (cardAbility instanceof FirstStrikeAbility) {
                            abilitiesToAdd.add(FirstStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DoubleStrikeAbility) {
                            abilitiesToAdd.add(DoubleStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DeathtouchAbility) {
                            abilitiesToAdd.add(DeathtouchAbility.getInstance());
                        }
                        if (cardAbility instanceof HasteAbility) {
                            abilitiesToAdd.add(HasteAbility.getInstance());
                        }
                        if (cardAbility instanceof HexproofBaseAbility) {
                            abilitiesToAdd.add(HexproofAbility.getInstance());
                        }
                        if (cardAbility instanceof IndestructibleAbility) {
                            abilitiesToAdd.add(IndestructibleAbility.getInstance());
                        }
                        if (cardAbility instanceof LifelinkAbility) {
                            abilitiesToAdd.add(LifelinkAbility.getInstance());
                        }
                        if (cardAbility instanceof ReachAbility) {
                            abilitiesToAdd.add(ReachAbility.getInstance());
                        }
                        if (cardAbility instanceof TrampleAbility) {
                            abilitiesToAdd.add(TrampleAbility.getInstance());
                        }
                        if (cardAbility instanceof VigilanceAbility) {
                            abilitiesToAdd.add(VigilanceAbility.getInstance());
                        }
                    }
                }
            }
        }
        // all time abilities apply
        for (Ability ability : abilitiesToAdd) {
            permanent.addAbility(ability, source.getSourceId(), game);
        }
        return true;
    } else if (abilitiesToAdd != null) {
        abilitiesToAdd = null;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) Card(mage.cards.Card) MageObjectReference(mage.MageObjectReference) Cards(mage.cards.Cards)

Example 28 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SparkOfCreativityPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            controller.moveCards(card, Zone.EXILED, source, game);
            // You may have Spark of Creativity deal damage to that creature equal to the converted mana cost of the exiled card.
            Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (targetCreature != null) {
                int cmc = card.getManaCost().manaValue();
                if (controller.chooseUse(outcome, "Let " + sourceObject.getLogName() + " deal " + cmc + " damage to " + targetCreature.getLogName() + '?', source, game)) {
                    targetCreature.damage(cmc, source.getSourceId(), source, game, false, true);
                    return true;
                }
            }
            // If you don't, you may play that card until end of turn
            game.addEffect(new SparkOfCreativityPlayEffect(new MageObjectReference(card, game)), source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObject(mage.MageObject) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 29 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class TakenoSamuraiGeneralEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (this.affectedObjectsSet) {
        for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
            // filter may not be used again, because object can have changed filter relevant attributes but still geets boost
            Permanent permanent = it.next().getPermanent(game);
            if (permanent != null) {
                for (Ability ability : permanent.getAbilities()) {
                    if (ability instanceof BushidoAbility) {
                        int value = ((BushidoAbility) ability).getValue(source, game, this);
                        permanent.addPower(value);
                        permanent.addToughness(value);
                    }
                }
            } else {
                // no longer on the battlefield, remove reference to object
                it.remove();
            }
        }
    } else {
        for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
            if (!perm.getId().equals(source.getSourceId())) {
                for (Ability ability : perm.getAbilities()) {
                    if (ability instanceof BushidoAbility) {
                        int value = ((BushidoAbility) ability).getValue(source, game, this);
                        perm.addPower(value);
                        perm.addToughness(value);
                    }
                }
            }
        }
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BushidoAbility(mage.abilities.keyword.BushidoAbility) Ability(mage.abilities.Ability) BushidoAbility(mage.abilities.keyword.BushidoAbility) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 30 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ThousandYearStormWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.SPELL_CAST) {
        MageObject object = game.getObject(event.getTargetId());
        if (object != null && object.isInstantOrSorcery(game)) {
            UUID playerId = event.getPlayerId();
            List<MageObjectReference> spellsCast = spellsThisTurn.getOrDefault(playerId, new ArrayList<MageObjectReference>());
            spellsCast.add(new MageObjectReference(object, game));
            spellsThisTurn.put(playerId, spellsCast);
        }
    }
}
Also used : MageObject(mage.MageObject) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReference (mage.MageObjectReference)250 Permanent (mage.game.permanent.Permanent)147 Player (mage.players.Player)76 UUID (java.util.UUID)47 Card (mage.cards.Card)45 Ability (mage.abilities.Ability)34 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)33 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)26 OneShotEffect (mage.abilities.effects.OneShotEffect)24 FilterPermanent (mage.filter.FilterPermanent)23 Game (mage.game.Game)22 Spell (mage.game.stack.Spell)21 TargetPermanent (mage.target.TargetPermanent)20 CardImpl (mage.cards.CardImpl)18 CardSetInfo (mage.cards.CardSetInfo)18 MageObject (mage.MageObject)17 Effect (mage.abilities.effects.Effect)16 HashSet (java.util.HashSet)15 mage.constants (mage.constants)14 GameEvent (mage.game.events.GameEvent)13