Search in sources :

Example 1 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class BoseijuWhoSheltersAllCantCounterEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    BoseijuWhoSheltersAllWatcher watcher = game.getState().getWatcher(BoseijuWhoSheltersAllWatcher.class, source.getSourceId());
    Spell spell = game.getStack().getSpell(event.getTargetId());
    return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game));
}
Also used : Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 2 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ChefsKissApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpell(source.getFirstTarget());
    if (spell == null) {
        return false;
    }
    spell.setControllerId(source.getControllerId());
    List<UUID> possibleTargets = new ArrayList<>(game.getState().getPlayersInRange(source.getControllerId(), game));
    possibleTargets.remove(source.getControllerId());
    game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(p -> !p.isControlledBy(source.getControllerId())).map(MageItem::getId).forEach(possibleTargets::add);
    possibleTargets.removeIf(uuid -> !spell.canTarget(game, uuid));
    StackObjectCopyApplier applier;
    MageObjectReferencePredicate predicate;
    if (possibleTargets.isEmpty()) {
        applier = null;
        predicate = null;
    } else {
        applier = new ChefsKissApplier(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game);
        predicate = new MageObjectReferencePredicate(new MageObjectReference(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game));
    }
    spell.createCopyOnStack(game, source, source.getControllerId(), false, 1, applier);
    if (predicate != null) {
        spell.chooseNewTargets(game, source.getControllerId(), true, true, predicate);
    }
    return true;
}
Also used : MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference)

Example 3 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GlyphOfReincarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && targetWall != null) {
        BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
        if (watcher != null) {
            Map<UUID, Player> destroyed = new HashMap<>();
            for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (!creature.getId().equals(targetWall.getId())) {
                    if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
                        if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
                            // If a commander is replaced to command zone, the creature does not die
                            Player permController = game.getPlayer(creature.getControllerId());
                            if (permController != null) {
                                destroyed.put(creature.getId(), permController);
                            }
                        }
                    }
                }
            }
            // onto the battlefield under its owner’s control
            for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
                Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
                Player player = entry.getValue();
                if (permanent != null && player != null) {
                    FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
                    filter.add(new OwnerIdPredicate(player.getId()));
                    Target targetCreature = new TargetCardInGraveyard(filter);
                    targetCreature.setNotTarget(true);
                    if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
                        Card card = game.getCard(targetCreature.getFirstTarget());
                        if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
                            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) BlockedAttackerWatcher(mage.watchers.common.BlockedAttackerWatcher) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) MageObjectReference(mage.MageObjectReference)

Example 4 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class HaukensInsightWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (affectedControllerId.equals(source.getControllerId()) && game.isActivePlayer(source.getControllerId())) {
        Player controller = game.getPlayer(source.getControllerId());
        HaukensInsightWatcher watcher = game.getState().getWatcher(HaukensInsightWatcher.class);
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (controller != null && watcher != null && sourceObject != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game))) {
            UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
            ExileZone exileZone = game.getExile().getExileZone(exileId);
            if (exileZone != null && exileZone.contains(CardUtil.getMainCardId(game, objectId))) {
                allowCardToPlayWithoutMana(objectId, source, affectedControllerId, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 5 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class LongRoadHomeEntersBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(objectToReturn.getSourceId());
    if (card != null && objectToReturn.refersTo(card, game)) {
        Player owner = game.getPlayer(card.getOwnerId());
        if (owner != null) {
            if (card instanceof MeldCard) {
                MeldCard meldCard = (MeldCard) card;
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(new MageObjectReference(meldCard.getTopHalfCard(), game)), source);
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(new MageObjectReference(meldCard.getBottomHalfCard(), game)), source);
            } else {
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(objectToReturn), source);
            }
            owner.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) MeldCard(mage.cards.MeldCard) MageObjectReference(mage.MageObjectReference) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card)

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