Search in sources :

Example 26 with Game

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

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) 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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 27 with Game

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

the class CavalierOfThornsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    if (cards.isEmpty()) {
        return true;
    }
    controller.revealCards(source, cards, game);
    TargetCard target = new TargetCard(1, 1, Zone.LIBRARY, filter);
    if (cards.getCards(game).stream().anyMatch(card1 -> card1.isLand(game)) && controller.choose(Outcome.PutCardInPlay, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
            cards.remove(card);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
    }
    controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) PutOnLibraryTargetEffect(mage.abilities.effects.common.PutOnLibraryTargetEffect) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ExileSourceFromGraveCost(mage.abilities.costs.common.ExileSourceFromGraveCost) UUID(java.util.UUID) MageInt(mage.MageInt) ReachAbility(mage.abilities.keyword.ReachAbility) SubType(mage.constants.SubType) Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) Game(mage.game.Game) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard)

Example 28 with Game

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

the class CelebrateTheHarvestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
    TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
    player.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 29 with Game

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

the class CoercedConfessionMillEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    int creaturesMilled = player.millCards(4, source, game).getCards(game).stream().filter(Objects::nonNull).filter(card -> game.getState().getZone(card.getId()) == Zone.GRAVEYARD).filter(card1 -> card1.isCreature(game)).mapToInt(x -> 1).sum();
    if (creaturesMilled < 1) {
        return true;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return true;
    }
    controller.drawCards(creaturesMilled, source, game);
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) Zone(mage.constants.Zone) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) Player(mage.players.Player) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Objects(java.util.Objects)

Example 30 with Game

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

the class HeavenlyBlademasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (sourcePermanent == null || player == null) {
        return false;
    }
    Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    target.getTargets().stream().map(attachmentId -> game.getPermanent(attachmentId)).filter(attachment -> attachment != null).forEachOrdered((attachment) -> {
        if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
            if (attachment.getAttachedTo() != sourcePermanent.getId()) {
                if (attachment.getAttachedTo() != null) {
                    Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
                    if (fromPermanent != null) {
                        fromPermanent.removeAttachment(attachment.getId(), source, game);
                    }
                }
            }
            sourcePermanent.addAttachment(attachment.getId(), source, game);
            game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
        }
    });
    return true;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AuraAttachedCount(mage.abilities.dynamicvalue.common.AuraAttachedCount) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) DynamicValue(mage.abilities.dynamicvalue.DynamicValue) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) StaticFilters(mage.filter.StaticFilters) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) DoubleStrikeAbility(mage.abilities.keyword.DoubleStrikeAbility) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) AdditiveDynamicValue(mage.abilities.dynamicvalue.AdditiveDynamicValue) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) EquipmentAttachedCount(mage.abilities.dynamicvalue.common.EquipmentAttachedCount) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

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