Search in sources :

Example 21 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class HeatStrokeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    BlockedThisTurnWatcher blockedWatcher = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    WasBlockedThisTurnWatcher wasBlockedThisTurnWatcher = game.getState().getWatcher(WasBlockedThisTurnWatcher.class);
    Set<Permanent> inROI = new HashSet<>(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
    boolean toRet = false;
    Set<MageObjectReference> toDestroy = new HashSet<>();
    if (blockedWatcher != null) {
        toDestroy.addAll(blockedWatcher.getBlockedThisTurnCreatures());
    }
    if (wasBlockedThisTurnWatcher != null) {
        toDestroy.addAll(wasBlockedThisTurnWatcher.getWasBlockedThisTurnCreatures());
    }
    for (MageObjectReference mor : toDestroy) {
        Permanent permanent = mor.getPermanent(game);
        if (permanent != null && permanent.isCreature(game) && inROI.contains(permanent)) {
            permanent.destroy(source, game, false);
            toRet = true;
        }
    }
    return toRet;
}
Also used : Permanent(mage.game.permanent.Permanent) WasBlockedThisTurnWatcher(mage.watchers.common.WasBlockedThisTurnWatcher) BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher) WasBlockedThisTurnWatcher(mage.watchers.common.WasBlockedThisTurnWatcher) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Example 22 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class KytheonHeroOfAkrosCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (sourceObject != null) {
        AttackedOrBlockedThisCombatWatcher watcher = game.getState().getWatcher(AttackedOrBlockedThisCombatWatcher.class);
        if (watcher != null) {
            boolean sourceFound = false;
            int number = 0;
            for (MageObjectReference mor : watcher.getAttackedThisTurnCreatures()) {
                if (mor.refersTo(sourceObject, game)) {
                    sourceFound = true;
                } else {
                    number++;
                }
            }
            return sourceFound && number >= 2;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedOrBlockedThisCombatWatcher(mage.watchers.common.AttackedOrBlockedThisCombatWatcher) MageObjectReference(mage.MageObjectReference)

Example 23 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class LurrusOfTheDreamDenWatcher 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)) && game.isActivePlayer(source.getControllerId())) {
        // only during your turn
        Card objectCard = game.getCard(objectId);
        Permanent sourceObject = game.getPermanent(source.getSourceId());
        if (sourceObject != null && objectCard != null && objectCard.isPermanent(game) && objectCard.isOwnedBy(source.getControllerId()) && objectCard.getManaValue() < 3 && objectCard.getSpellAbility() != null && objectCard.getSpellAbility().spellCanBeActivatedRegularlyNow(affectedControllerId, game)) {
            LurrusOfTheDreamDenWatcher watcher = game.getState().getWatcher(LurrusOfTheDreamDenWatcher.class);
            return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
        }
    }
    if (!objectId.equals(getTargetPointer().getFirst(game, source))) {
        return false;
    }
    if (!affectedControllerId.equals(source.getControllerId())) {
        return false;
    }
    LurrusOfTheDreamDenWatcher watcher = game.getState().getWatcher(LurrusOfTheDreamDenWatcher.class);
    return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(source.getSourceId(), game));
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 24 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class MetzaliTowerOfTriumphEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Watcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher instanceof AttackedThisTurnWatcher) {
        Set<MageObjectReference> attackedThisTurn = ((AttackedThisTurnWatcher) watcher).getAttackedThisTurnCreatures();
        List<Permanent> available = new ArrayList<>();
        for (MageObjectReference mor : attackedThisTurn) {
            Permanent permanent = mor.getPermanent(game);
            if (permanent != null && permanent.isCreature(game)) {
                available.add(permanent);
            }
        }
        if (!available.isEmpty()) {
            Permanent permanent = available.get(RandomUtil.nextInt(available.size()));
            if (permanent != null) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) ArrayList(java.util.ArrayList) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) Watcher(mage.watchers.Watcher) MageObjectReference(mage.MageObjectReference)

Example 25 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class PastInFlamesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.getGraveyard().stream().filter((cardId) -> (affectedObjectList.contains(new MageObjectReference(cardId, game)))).forEachOrdered((cardId) -> {
        Card card = game.getCard(cardId);
        if (card != null) {
            FlashbackAbility ability = new FlashbackAbility(card, card.getManaCost());
            ability.setSourceId(cardId);
            ability.setControllerId(card.getOwnerId());
            game.getState().addOtherAbility(card, ability);
        }
    });
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) FlashbackAbility(mage.abilities.keyword.FlashbackAbility) MageObjectReference(mage.MageObjectReference) UUID(java.util.UUID) Card(mage.cards.Card) mage.constants(mage.constants) Player(mage.players.Player) Ability(mage.abilities.Ability) FlashbackAbility(mage.abilities.keyword.FlashbackAbility) Player(mage.players.Player) MageObjectReference(mage.MageObjectReference) 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