Search in sources :

Example 71 with Game

use of mage.game.Game in project mage by magefree.

the class UginTheIneffableLookAtFaceDownEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
    if (zEvent.getToZone() == Zone.BATTLEFIELD || tokenRefs.stream().noneMatch(tokenRef -> tokenRef.refersTo(zEvent.getTarget(), game))) {
        return false;
    }
    this.getEffects().clear();
    Effect effect = new ReturnToHandTargetEffect();
    effect.setTargetPointer(new FixedTarget(cardRef));
    this.addEffect(effect);
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) UginTheIneffableToken(mage.game.permanent.token.UginTheIneffableToken) MageObjectReference(mage.MageObjectReference) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) HashSet(java.util.HashSet) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) Card(mage.cards.Card) mage.constants(mage.constants) FilterCard(mage.filter.FilterCard) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) Effect(mage.abilities.effects.Effect) GameEvent(mage.game.events.GameEvent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) InfoEffect(mage.abilities.effects.common.InfoEffect) CardImpl(mage.cards.CardImpl) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ColorlessPredicate(mage.filter.predicate.mageobject.ColorlessPredicate) Benefit(mage.constants.Outcome.Benefit) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) InfoEffect(mage.abilities.effects.common.InfoEffect) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Example 72 with Game

use of mage.game.Game in project mage by magefree.

the class TymaretChosenFromDeathEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).collect(Collectors.toSet()));
    player.moveCards(cards, Zone.EXILED, source, game);
    int lifeGain = cards.getCards(game).stream().filter(card -> card.isCreature(game)).map(Card::getId).map(game.getState()::getZone).filter(Zone.EXILED::equals).mapToInt(x -> 1).sum();
    player.gainLife(lifeGain, game, source);
    return true;
}
Also used : Target(mage.target.Target) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) StaticFilters(mage.filter.StaticFilters) mage.cards(mage.cards) Collection(java.util.Collection) SetToughnessSourceEffect(mage.abilities.effects.common.continuous.SetToughnessSourceEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) DevotionCount(mage.abilities.dynamicvalue.common.DevotionCount) mage.constants(mage.constants) Ability(mage.abilities.Ability) Player(mage.players.Player) Collection(java.util.Collection)

Example 73 with Game

use of mage.game.Game in project mage by magefree.

the class FloodOfTearsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> nonlands = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), source.getSourceId(), game);
    Cards cards = new CardsImpl();
    if (!nonlands.isEmpty()) {
        nonlands.forEach(cards::add);
        boolean putIntoPlay = nonlands.stream().filter(permanent -> permanent.isControlledBy(player.getId())).filter(permanent -> !(permanent instanceof PermanentToken)).count() > 3;
        player.moveCards(cards, Zone.HAND, source, game);
        if (putIntoPlay) {
            new PutCardFromHandOntoBattlefieldEffect().apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) PutCardFromHandOntoBattlefieldEffect(mage.abilities.effects.common.PutCardFromHandOntoBattlefieldEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 74 with Game

use of mage.game.Game in project mage by magefree.

the class GideonChampionOfJusticeToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    MageObjectReference mor = new MageObjectReference(source.getSourceObject(game), game);
    Cards cards = new CardsImpl();
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, source.getControllerId(), game).stream().filter(Objects::nonNull).filter(permanent -> !mor.refersTo(permanent, game)).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : IndestructibleAbility(mage.abilities.keyword.IndestructibleAbility) TargetOpponent(mage.target.common.TargetOpponent) TokenImpl(mage.game.permanent.token.TokenImpl) MageObjectReference(mage.MageObjectReference) BecomesCreatureSourceEffect(mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect) Player(mage.players.Player) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) mage.constants(mage.constants) StaticFilters(mage.filter.StaticFilters) LockedInDynamicValue(mage.abilities.dynamicvalue.LockedInDynamicValue) Cards(mage.cards.Cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) PreventAllDamageToSourceEffect(mage.abilities.effects.common.PreventAllDamageToSourceEffect) Game(mage.game.Game) PermanentsTargetOpponentControlsCount(mage.abilities.dynamicvalue.common.PermanentsTargetOpponentControlsCount) CardImpl(mage.cards.CardImpl) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Objects(java.util.Objects) MageObjectReference(mage.MageObjectReference) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 75 with Game

use of mage.game.Game in project mage by magefree.

the class IdolOfEnduranceWatcher method addPlayable.

static void addPlayable(Ability source, Game game) {
    MageObjectReference mor = new MageObjectReference(source);
    game.getState().getWatcher(IdolOfEnduranceWatcher.class).morMap.computeIfAbsent(mor, m -> new HashMap<>()).compute(source.getControllerId(), CardUtil::setOrIncrementValue);
}
Also used : MageObjectReference(mage.MageObjectReference) HashMap(java.util.HashMap) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Map(java.util.Map) mage.constants(mage.constants) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) ExileZone(mage.game.ExileZone) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) HashMap(java.util.HashMap) MageObjectReference(mage.MageObjectReference) CardUtil(mage.util.CardUtil)

Aggregations

Game (mage.game.Game)212 Ability (mage.abilities.Ability)139 Player (mage.players.Player)126 UUID (java.util.UUID)117 OneShotEffect (mage.abilities.effects.OneShotEffect)104 CardSetInfo (mage.cards.CardSetInfo)102 CardImpl (mage.cards.CardImpl)100 CardType (mage.constants.CardType)82 Outcome (mage.constants.Outcome)78 Permanent (mage.game.permanent.Permanent)66 MageInt (mage.MageInt)60 mage.constants (mage.constants)47 Zone (mage.constants.Zone)46 GameEvent (mage.game.events.GameEvent)44 Objects (java.util.Objects)41 StaticFilters (mage.filter.StaticFilters)40 Collectors (java.util.stream.Collectors)35 SubType (mage.constants.SubType)34 Card (mage.cards.Card)32 MageObjectReference (mage.MageObjectReference)30