Search in sources :

Example 16 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class CemeteryIlluminatorWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    // Once per turn clause checked by Watcher same as Lurrus of the Dream Den
    if (affectedControllerId.equals(source.getControllerId())) {
        Player controller = game.getPlayer(source.getControllerId());
        CemeteryIlluminatorWatcher watcher = game.getState().getWatcher(CemeteryIlluminatorWatcher.class);
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (controller != null && watcher != null && sourceObject != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game))) {
            Card card = game.getCard(objectId);
            Card topCard = controller.getLibrary().getFromTop(game);
            if (card != null && topCard != null && topCard.getId().equals(card.getMainCard().getId()) && !card.isLand(game) && !card.getManaCost().isEmpty()) {
                // Check if it shares a card type with exiled cards
                UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
                ExileZone exileZone = game.getExile().getExileZone(exileId);
                if (exileZone != null) {
                    HashSet<CardType> cardTypes = new HashSet<>(card.getCardType(game));
                    for (UUID exileCardId : exileZone) {
                        Card exileCard = game.getCard(exileCardId);
                        if (exileCard != null) {
                            for (CardType exileType : exileCard.getCardType(game)) {
                                if (cardTypes.contains(exileType)) {
                                    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) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 17 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class ColfenorTheLastYewTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
    filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
    filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference)

Example 18 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class FalseOrdersUnblockEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
    if (controller == null || permanent == null) {
        return false;
    }
    // Remove target creature from combat
    Effect effect = new RemoveFromCombatTargetEffect();
    effect.apply(game, source);
    // Make blocked creatures unblocked
    BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
    if (watcher != null) {
        Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
        if (combatGroups != null) {
            for (CombatGroup combatGroup : combatGroups) {
                if (combatGroup != null) {
                    combatGroup.setBlocked(false, game);
                }
            }
        }
    }
    if (!permanent.isCreature(game) || !controller.chooseUse(Outcome.Benefit, "Have " + permanent.getLogName() + " block an attacking creature?", source, game)) {
        return false;
    }
    // Choose new creature to block
    // according to the following mail response from MTG Rules Management about False Orders:
    // "if Player A attacks Players B and C, Player B's creatures cannot block creatures attacking Player C"
    // therefore we need to single out creatures attacking the target blocker's controller (disappointing, I know)
    List<Permanent> list = new ArrayList<>();
    for (CombatGroup combatGroup : game.getCombat().getGroups()) {
        if (combatGroup.getDefendingPlayerId().equals(permanent.getControllerId())) {
            for (UUID attackingCreatureId : combatGroup.getAttackers()) {
                Permanent targetsControllerAttacker = game.getPermanent(attackingCreatureId);
                list.add(targetsControllerAttacker);
            }
        }
    }
    Player targetsController = game.getPlayer(permanent.getControllerId());
    if (targetsController == null) {
        return false;
    }
    FilterAttackingCreature filter = new FilterAttackingCreature("creature attacking " + targetsController.getLogName());
    filter.add(new PermanentInListPredicate(list));
    TargetAttackingCreature target = new TargetAttackingCreature(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
        while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
            controller.chooseTarget(outcome, target, source, game);
        }
    } else {
        return true;
    }
    Permanent chosenPermanent = game.getPermanent(target.getFirstTarget());
    if (chosenPermanent == null || !chosenPermanent.isCreature(game)) {
        return false;
    }
    CombatGroup chosenGroup = game.getCombat().findGroup(chosenPermanent.getId());
    if (chosenGroup != null) {
        // Relevant ruling for Balduvian Warlord:
        // 7/15/2006 	If an attacking creature has an ability that triggers “When this creature becomes blocked,”
        // it triggers when a creature blocks it due to the Warlord's ability only if it was unblocked at that point.
        boolean notYetBlocked = chosenGroup.getBlockers().isEmpty();
        chosenGroup.addBlockerToGroup(permanent.getId(), controller.getId(), game);
        // 702.21h
        game.getCombat().addBlockingGroup(permanent.getId(), chosenPermanent.getId(), controller.getId(), game);
        if (notYetBlocked) {
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, chosenPermanent.getId(), source, null));
            Set<MageObjectReference> morSet = new HashSet<>();
            morSet.add(new MageObjectReference(chosenPermanent, game));
            for (UUID bandedId : chosenPermanent.getBandedCards()) {
                CombatGroup bandedGroup = game.getCombat().findGroup(bandedId);
                if (bandedGroup != null && chosenGroup.getBlockers().size() == 1) {
                    morSet.add(new MageObjectReference(bandedId, game));
                    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_BLOCKED, bandedId, source, null));
                }
            }
            String key = UUID.randomUUID().toString();
            game.getState().setValue("becameBlocked_" + key, morSet);
            game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BATCH_BLOCK_NONCOMBAT, source.getSourceId(), source, source.getControllerId(), key, 0));
        }
        game.fireEvent(new BlockerDeclaredEvent(chosenPermanent.getId(), permanent.getId(), permanent.getControllerId()));
    }
    // a new blockingGroup is formed, so it's necessary to find it again
    CombatGroup blockGroup = findBlockingGroup(permanent, game);
    if (blockGroup != null) {
        blockGroup.pickAttackerOrder(permanent.getControllerId(), game);
    }
    return true;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterAttackingCreature(mage.filter.common.FilterAttackingCreature) RemoveFromCombatTargetEffect(mage.abilities.effects.common.RemoveFromCombatTargetEffect) TargetAttackingCreature(mage.target.common.TargetAttackingCreature) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) RemoveFromCombatTargetEffect(mage.abilities.effects.common.RemoveFromCombatTargetEffect) BlockedByOnlyOneCreatureThisCombatWatcher(mage.watchers.common.BlockedByOnlyOneCreatureThisCombatWatcher) BlockerDeclaredEvent(mage.game.events.BlockerDeclaredEvent) CombatGroup(mage.game.combat.CombatGroup) MageObjectReference(mage.MageObjectReference)

Example 19 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GisaAndGeralfWatcher method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (source.isControlledBy(affectedControllerId) && Zone.GRAVEYARD.equals(game.getState().getZone(objectId))) {
        Card objectCard = game.getCard(objectId);
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (sourceObject != null && objectCard != null && objectCard.isOwnedBy(source.getControllerId()) && objectCard.isCreature(game) && objectCard.hasSubtype(SubType.ZOMBIE, game) && objectCard.getSpellAbility() != null && objectCard.getSpellAbility().spellCanBeActivatedRegularlyNow(affectedControllerId, game)) {
            GisaAndGeralfWatcher watcher = game.getState().getWatcher(GisaAndGeralfWatcher.class);
            return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 20 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class GreatOakGuardianUntapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
        Permanent permanent = it.next().getPermanent(game);
        if (permanent != null) {
            permanent.addPower(2);
            permanent.addToughness(2);
        } else {
            it.remove();
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) 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