Search in sources :

Example 66 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SerpentsSoulJarWatcher method checkPermission.

static boolean checkPermission(UUID playerId, Ability source, Game game) {
    if (!playerId.equals(source.getControllerId())) {
        return false;
    }
    MageObjectReference mor = new MageObjectReference(source);
    SerpentsSoulJarWatcher watcher = game.getState().getWatcher(SerpentsSoulJarWatcher.class);
    return watcher.morMap.containsKey(mor) && watcher.morMap.get(mor).getOrDefault(playerId, 0) > 0;
}
Also used : MageObjectReference(mage.MageObjectReference)

Example 67 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class TitaniasSongEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    switch(layer) {
        case TypeChangingEffects_4:
            if (sublayer == SubLayer.NA) {
                affectedObjectList.clear();
                for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
                    if (permanent != null) {
                        affectedObjectList.add(new MageObjectReference(permanent, game));
                        permanent.addCardType(game, CardType.CREATURE);
                    }
                }
            }
            break;
        case AbilityAddingRemovingEffects_6:
            for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
                Permanent permanent = it.next().getPermanent(game);
                if (permanent != null) {
                    permanent.removeAllAbilities(source.getSourceId(), game);
                }
            }
            break;
        case PTChangingEffects_7:
            if (sublayer == SubLayer.SetPT_7b) {
                for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
                    Permanent permanent = it.next().getPermanent(game);
                    if (permanent != null) {
                        int manaCost = permanent.getManaValue();
                        permanent.getPower().setValue(manaCost);
                        permanent.getToughness().setValue(manaCost);
                    }
                }
            }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) MageObjectReference(mage.MageObjectReference)

Example 68 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class UginTheIneffableLookAtFaceDownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (player == null || sourceObject == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    // exile and look
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    if (player.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName() + " (" + player.getName() + ")")) {
        card.turnFaceDown(source, game, source.getControllerId());
        player.lookAtCards(player.getName() + " - " + card.getIdName() + " - " + CardUtil.sdf.format(System.currentTimeMillis()), card, game);
    }
    // create token
    Set<MageObjectReference> tokenObjs = new HashSet<>();
    CreateTokenEffect effect = new CreateTokenEffect(new UginTheIneffableToken());
    effect.apply(game, source);
    // with return ability
    for (UUID addedTokenId : effect.getLastAddedTokenIds()) {
        // display referenced exiled face-down card on token
        SimpleStaticAbility sa = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("Referenced object: " + card.getId().toString().substring(0, 3)));
        GainAbilityTargetEffect gainAbilityEffect = new GainAbilityTargetEffect(sa, Duration.WhileOnBattlefield);
        gainAbilityEffect.setTargetPointer(new FixedTarget(addedTokenId));
        game.addEffect(gainAbilityEffect, source);
        // look at face-down card in exile
        UginTheIneffableLookAtFaceDownEffect lookAtEffect = new UginTheIneffableLookAtFaceDownEffect();
        lookAtEffect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(lookAtEffect, source);
        tokenObjs.add(new MageObjectReference(addedTokenId, game));
        game.addDelayedTriggeredAbility(new UginTheIneffableDelayedTriggeredAbility(tokenObjs, new MageObjectReference(card, game)), source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) UginTheIneffableToken(mage.game.permanent.token.UginTheIneffableToken) MageObject(mage.MageObject) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) InfoEffect(mage.abilities.effects.common.InfoEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) HashSet(java.util.HashSet)

Example 69 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class WallOfDustRestrictionEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Permanent perm = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (perm != null) {
        targetPermanentReference = new MageObjectReference(perm, game);
        setStartingControllerAndTurnNum(game, perm.getControllerId(), game.getActivePlayerId());
    } else {
        discard();
    }
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 70 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class AttacksFirstTimeTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(this.getSourceId())) {
        return false;
    }
    AttackedThisTurnWatcher watcher = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    if (watcher == null) {
        return false;
    }
    Permanent sourcePerm = game.getPermanentOrLKIBattlefield(event.getSourceId());
    if (sourcePerm == null) {
        return false;
    }
    for (MageObjectReference mor : watcher.getAttackedThisTurnCreaturesCounts().keySet()) {
        if (mor.refersTo(sourcePerm, game) && watcher.getAttackedThisTurnCreaturesCounts().get(mor) > 1) {
            return false;
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) 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