Search in sources :

Example 61 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class KethisTheHiddenHandGraveyardEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    if (!this.affectedObjectsSet) {
        return;
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return;
    }
    player.getGraveyard().stream().map(game::getCard).filter(Objects::nonNull).filter(Card::isLegendary).forEach(card -> affectedObjectList.add(new MageObjectReference(card, game)));
}
Also used : Player(mage.players.Player) Objects(java.util.Objects) MageObjectReference(mage.MageObjectReference)

Example 62 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class MarshCasualtiesEffect 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(power);
            permanent.addToughness(toughness);
        } else {
            it.remove();
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 63 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class MindlinkMechApplier method watch.

@Override
public void watch(GameEvent event, Game game) {
    Permanent vehicle;
    Permanent crewer;
    switch(event.getType()) {
        case VEHICLE_CREWED:
            vehicle = game.getPermanent(event.getTargetId());
            crewer = null;
            break;
        case CREWED_VEHICLE:
            vehicle = game.getPermanent(event.getSourceId());
            crewer = game.getPermanent(event.getTargetId());
            break;
        default:
            return;
    }
    if (vehicle == null) {
        return;
    }
    if (crewer == null) {
        crewCount.compute(new MageObjectReference(vehicle, game), (m, i) -> i == null ? 1 : Integer.sum(i, 1));
        return;
    }
    crewMap.computeIfAbsent(new MageObjectReference(vehicle, game), x -> new HashSet<>()).add(new MageObjectReference(crewer, game));
}
Also used : java.util(java.util) CopyApplier(mage.util.functions.CopyApplier) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) CrewAbility(mage.abilities.keyword.CrewAbility) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 64 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class OtherworldlyJourneyEntersBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        if (permanent.moveToExile(source.getSourceId(), "Otherworldly Journey", source, game)) {
            ExileZone exile = game.getExile().getExileZone(source.getSourceId());
            // only if permanent is in exile (tokens would be stop to exist)
            if (exile != null && !exile.isEmpty()) {
                Card card = game.getCard(permanent.getId());
                if (card != null) {
                    // create delayed triggered ability
                    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new OtherworldlyJourneyReturnFromExileEffect(new MageObjectReference(card, game)));
                    game.addDelayedTriggeredAbility(delayedAbility, source);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ExileZone(mage.game.ExileZone) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Example 65 with MageObjectReference

use of mage.MageObjectReference in project mage by magefree.

the class SerpentsSoulJarWatcher method addPlayable.

static void addPlayable(Ability source, Game game) {
    MageObjectReference mor = new MageObjectReference(source);
    game.getState().getWatcher(SerpentsSoulJarWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Also used : DiesCreatureTriggeredAbility(mage.abilities.common.DiesCreatureTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) PayLifeCost(mage.abilities.costs.common.PayLifeCost) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) HashMap(java.util.HashMap) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) ExileZone(mage.game.ExileZone) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) Map(java.util.Map) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) HashMap(java.util.HashMap) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil)

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