Search in sources :

Example 56 with Game

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

the class AngelicGuardianGainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    if (you != null) {
        game.getCombat().getAttackers().stream().map(game::getPermanent).filter(Objects::nonNull).filter(permanent -> permanent.isControlledBy(you.getId())).filter(permanent1 -> permanent1.isCreature(game)).forEach(permanent -> {
            ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        });
        return true;
    }
    return false;
}
Also used : IndestructibleAbility(mage.abilities.keyword.IndestructibleAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) AttacksWithCreaturesTriggeredAbility(mage.abilities.common.AttacksWithCreaturesTriggeredAbility) Duration(mage.constants.Duration) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 57 with Game

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

the class AnowonTheRuinThiefWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
        damageMap.clear();
        return;
    }
    if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return;
    }
    Permanent creature = game.getPermanent(event.getSourceId());
    if (creature == null || !creature.hasSubtype(SubType.ROGUE, game)) {
        return;
    }
    damageMap.computeIfAbsent(event.getTargetId(), x -> new HashMap<>()).compute(creature.getControllerId(), (uuid, i) -> i == null ? event.getAmount() : event.getAmount() + i);
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) StaticFilters(mage.filter.StaticFilters) java.util(java.util) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) 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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) mage.constants(mage.constants) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 58 with Game

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

the class BloodForBonesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getGraveyard().getCards(game).stream().noneMatch(card -> card.isCreature(game))) {
        return false;
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
    if (player.choose(outcome, player.getGraveyard(), target, game)) {
        player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
    }
    if (player.getGraveyard().getCards(game).stream().noneMatch(card -> card.isCreature(game))) {
        return true;
    }
    target = new TargetCardInYourGraveyard(filter2);
    if (player.choose(outcome, player.getGraveyard(), target, game)) {
        player.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game);
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) FILTER_CONTROLLED_CREATURE_SHORT_TEXT(mage.filter.StaticFilters.FILTER_CONTROLLED_CREATURE_SHORT_TEXT) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) CardSetInfo(mage.cards.CardSetInfo) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) CardsImpl(mage.cards.CardsImpl)

Example 59 with Game

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

the class EcologicalAppreciationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {

        @Override
        public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
            if (!super.canTarget(playerId, id, source, game)) {
                return false;
            }
            Card card = game.getCard(id);
            Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
            return isValidTarget(card, disallowedCards);
        }
    };
    targetCardsInLibrary.setNotTarget(true);
    targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
    player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
    Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
    boolean status = !cards.isEmpty();
    if (status) {
        int remainingCards = 4 - cards.size();
        if (remainingCards > 0) {
            TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {

                @Override
                public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
                    if (!super.canTarget(playerId, id, source, game)) {
                        return false;
                    }
                    Card card = game.getCard(id);
                    Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
                    Set<Card> checkList = new HashSet<>();
                    checkList.addAll(disallowedCards);
                    checkList.addAll(cards.getCards(game));
                    return isValidTarget(card, checkList);
                }
            };
            targetCardsInGY.setNotTarget(true);
            targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
            player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
            cards.addAll(targetCardsInGY.getTargets());
        }
        TargetOpponent targetOpponent = new TargetOpponent();
        targetOpponent.setNotTarget(true);
        player.choose(outcome, targetOpponent, source.getSourceId(), game);
        Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
        if (opponent == null) {
            status = false;
        }
        if (status) {
            TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
            chosenCards.setNotTarget(true);
            opponent.choose(outcome, cards, chosenCards, game);
            Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
            player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
            cards.removeAll(toShuffle);
            player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        }
    }
    player.shuffleLibrary(source, game);
    return status;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Game(mage.game.Game) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 60 with Game

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

the class EchoingReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (player == null || card == null) {
        return false;
    }
    Cards cards = new CardsImpl(card);
    player.getGraveyard().getCards(game).stream().filter(c -> CardUtil.haveSameNames(c.getName(), card.getName())).forEach(cards::add);
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : StaticFilters(mage.filter.StaticFilters) Game(mage.game.Game) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) mage.cards(mage.cards) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) Ability(mage.abilities.Ability) Player(mage.players.Player) mage.cards(mage.cards)

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