Search in sources :

Example 96 with Game

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

the class LegionsEndEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    Player player = game.getPlayer(permanent.getControllerId());
    if (player == null) {
        return false;
    }
    String name = permanent.getName();
    if (name == null || name.equals("")) {
        player.revealCards(source, player.getHand(), game);
        return player.moveCards(permanent, Zone.EXILED, source, game);
    }
    Cards cards = new CardsImpl();
    game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, player.getId(), game).stream().filter(perm -> name.equals(perm.getName())).forEach(cards::add);
    player.revealCards(source, player.getHand(), game);
    player.getHand().getCards(game).stream().filter(card -> name.equals(card.getName())).forEach(cards::add);
    player.getGraveyard().getCards(game).stream().filter(card -> name.equals(card.getName())).forEach(cards::add);
    return player.moveCards(cards, Zone.EXILED, source, game);
}
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) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 97 with Game

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

the class NimbleTrapfinderWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        return;
    }
    Permanent permanent = game.getPermanent(event.getTargetId());
    if (!filter.match(permanent, game)) {
        return;
    }
    playerMap.computeIfAbsent(event.getPlayerId(), u -> new HashSet<>()).add(new MageObjectReference(permanent, game));
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) java.util(java.util) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) MageObjectReference(mage.MageObjectReference) Predicates(mage.filter.predicate.Predicates) Hint(mage.abilities.hint.Hint) PartyCountHint(mage.abilities.hint.common.PartyCountHint) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) mage.constants(mage.constants) FullPartyCondition(mage.abilities.condition.common.FullPartyCondition) StaticFilters(mage.filter.StaticFilters) ConditionalRestrictionEffect(mage.abilities.decorator.ConditionalRestrictionEffect) Condition(mage.abilities.condition.Condition) CantBeBlockedSourceEffect(mage.abilities.effects.common.combat.CantBeBlockedSourceEffect) MageInt(mage.MageInt) ConditionHint(mage.abilities.hint.ConditionHint) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) MageObjectReference(mage.MageObjectReference)

Example 98 with Game

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

the class PortalOfSanctuaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent == null || player == null) {
        return false;
    }
    Cards cards = new CardsImpl(permanent);
    permanent.getAttachments().stream().map(uuid -> game.getPermanent(uuid)).filter(perm -> perm != null && perm.hasSubtype(SubType.AURA, game)).forEach(perm -> cards.add(perm));
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : MyTurnHint(mage.abilities.hint.common.MyTurnHint) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) ActivateIfConditionActivatedAbility(mage.abilities.common.ActivateIfConditionActivatedAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) SubType(mage.constants.SubType) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) MyTurnCondition(mage.abilities.condition.common.MyTurnCondition) CardType(mage.constants.CardType) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 99 with Game

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

the class WillScholarOfFrostEffect 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(targetPointer.getTargets(game, source));
    Map<UUID, Integer> playerMap = cards.getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).map(game::getControllerId).filter(Objects::nonNull).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
    player.moveCards(cards, Zone.EXILED, source, game);
    for (Map.Entry<UUID, Integer> entry : playerMap.entrySet()) {
        new Elemental44Token().putOntoBattlefield(entry.getValue(), game, source, entry.getKey());
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) Hint(mage.abilities.hint.Hint) Function(java.util.function.Function) MageItem(mage.MageItem) Player(mage.players.Player) RowanScholarOfSparksEmblem(mage.game.command.emblems.RowanScholarOfSparksEmblem) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Map(java.util.Map) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) mage.constants(mage.constants) CardsAmountDrawnThisTurnWatcher(mage.watchers.common.CardsAmountDrawnThisTurnWatcher) FilterCard(mage.filter.FilterCard) StaticFilters(mage.filter.StaticFilters) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) Condition(mage.abilities.condition.Condition) Cards(mage.cards.Cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Elemental44Token(mage.game.permanent.token.Elemental44Token) Collectors(java.util.stream.Collectors) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) GetEmblemEffect(mage.abilities.effects.common.GetEmblemEffect) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) Objects(java.util.Objects) UUID(java.util.UUID) Map(java.util.Map) Elemental44Token(mage.game.permanent.token.Elemental44Token) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 100 with Game

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

the class SphinxsTutelageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        int possibleIterations = targetPlayer.getLibrary().size() / 2;
        int iteration = 0;
        boolean colorShared;
        do {
            iteration++;
            if (iteration > possibleIterations + 20) {
                // 801.16. If the game somehow enters a "loop" of mandatory actions, repeating a sequence of events
                // with no way to stop, the game is a draw for each player who controls an object that's involved in
                // that loop, as well as for each player within the range of influence of any of those players. They
                // leave the game. All remaining players continue to play the game.
                game.setDraw(source.getControllerId());
                return true;
            }
            colorShared = false;
            List<Card> cards = targetPlayer.millCards(2, source, game).getCards(game).stream().filter(card -> !card.isLand(game)).collect(Collectors.toList());
            if (cards.size() < 2) {
                break;
            }
            for (int i = 0; i < cards.size(); i++) {
                if (colorShared) {
                    break;
                }
                ObjectColor color1 = cards.get(i).getColor(game);
                if (color1.isColorless()) {
                    continue;
                }
                for (int j = 0; j < cards.size(); j++) {
                    if (i >= j) {
                        continue;
                    }
                    ObjectColor color2 = cards.get(j).getColor(game);
                    if (color1.shares(color2)) {
                        colorShared = true;
                        break;
                    }
                }
            }
        } while (colorShared);
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) DrawDiscardControllerEffect(mage.abilities.effects.common.DrawDiscardControllerEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) List(java.util.List) DrawCardControllerTriggeredAbility(mage.abilities.common.DrawCardControllerTriggeredAbility) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ObjectColor(mage.ObjectColor) Card(mage.cards.Card) Ability(mage.abilities.Ability) Player(mage.players.Player) ObjectColor(mage.ObjectColor) Card(mage.cards.Card)

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