Search in sources :

Example 31 with Game

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

the class JourneyForTheElixirGraveyardTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Cards alreadyTargeted = new CardsImpl(this.getTargets());
    alreadyTargeted.addAll(cards);
    boolean hasBasic = alreadyTargeted.getCards(game).stream().filter(Objects::nonNull).filter(card1 -> card1.isLand(game)).anyMatch(MageObject::isBasic);
    possibleTargets.removeIf(uuid -> {
        Card card = game.getCard(uuid);
        return card != null && hasBasic && card.isLand(game) && card.isBasic();
    });
    boolean hasYanggu = alreadyTargeted.getCards(game).stream().filter(Objects::nonNull).map(MageObject::getName).anyMatch(name::equals);
    possibleTargets.removeIf(uuid -> {
        Card card = game.getCard(uuid);
        return card != null && hasYanggu && name.equals(card.getName());
    });
    return possibleTargets;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) mage.cards(mage.cards) Outcome(mage.constants.Outcome) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) Player(mage.players.Player) Objects(java.util.Objects) Game(mage.game.Game) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) MageObject(mage.MageObject) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) Objects(java.util.Objects) MageObject(mage.MageObject) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 32 with Game

use of mage.game.Game 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)

Example 33 with Game

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

the class PrimalEmpathyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int highestPower = game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(0);
    boolean flag = game.getBattlefield().getAllActivePermanents(source.getControllerId()).stream().filter(permanent1 -> permanent1.isCreature(game)).map(Permanent::getPower).mapToInt(MageInt::getValue).anyMatch(i -> i >= highestPower);
    if (flag) {
        return player.drawCards(1, source, game) > 0;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
Also used : Target(mage.target.Target) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageInt(mage.MageInt) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 34 with Game

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

the class SchemingSymmetryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    source.getTargets().get(0).getTargets().stream().map(playerId -> game.getPlayer(playerId)).filter(player -> player != null).forEach(player -> {
        TargetCardInLibrary targetCard = new TargetCardInLibrary();
        if (player.searchLibrary(targetCard, source, game)) {
            Cards cards = new CardsImpl();
            cards.add(targetCard.getFirstTarget());
            player.shuffleLibrary(source, game);
            player.putCardsOnTopOfLibrary(cards, game, source, false);
        }
    });
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Ability(mage.abilities.Ability) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 35 with Game

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

the class ShowOfConfidenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = (Spell) getValue("spellCast");
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (spell == null || watcher == null) {
        return false;
    }
    int copies = watcher.getSpellsCastThisTurn(source.getControllerId()).stream().filter(Objects::nonNull).filter(spell1 -> spell1.isInstantOrSorcery(game)).filter(s -> !s.getSourceId().equals(source.getSourceId()) || s.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()).mapToInt(x -> 1).sum();
    if (copies > 0) {
        spell.createCopyOnStack(game, source, source.getControllerId(), true, copies);
    }
    return true;
}
Also used : AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CastSourceTriggeredAbility(mage.abilities.effects.common.CastSourceTriggeredAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) CardImpl(mage.cards.CardImpl) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) Objects(java.util.Objects) Spell(mage.game.stack.Spell)

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