Search in sources :

Example 36 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class RickSteadfastLeaderGainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Object choice = game.getState().getValue(source.getSourceId() + "_rick");
    if (!(choice instanceof String)) {
        return false;
    }
    Ability ability1 = null;
    Ability ability2 = null;
    switch(((String) choice)) {
        case "First strike and vigilance":
            ability1 = FirstStrikeAbility.getInstance();
            ability2 = VigilanceAbility.getInstance();
            break;
        case "First strike and lifelink":
            ability1 = FirstStrikeAbility.getInstance();
            ability2 = LifelinkAbility.getInstance();
            break;
        case "Vigilance and lifelink":
            ability1 = VigilanceAbility.getInstance();
            ability2 = LifelinkAbility.getInstance();
            break;
        default:
            return false;
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
        if (permanent == null) {
            continue;
        }
        permanent.addAbility(ability1, source.getSourceId(), game);
        permanent.addAbility(ability2, source.getSourceId(), game);
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) AsEntersBattlefieldAbility(mage.abilities.common.AsEntersBattlefieldAbility) Ability(mage.abilities.Ability) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent)

Example 37 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class RicochetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Targets targets = new Targets();
        Ability sourceAbility = spell.getSpellAbility();
        for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
            Mode mode = sourceAbility.getModes().get(modeId);
            targets.addAll(mode.getTargets());
        }
        if (targets.size() != 1 || targets.get(0).getTargets().size() != 1) {
            return false;
        }
        Map<Player, Integer> playerRolls = new HashMap<>();
        for (UUID playerId : game.getPlayerList().copy()) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                playerRolls.put(player, 7);
            }
        }
        do {
            for (Player player : playerRolls.keySet()) {
                // bad outcome - ai must choose lowest value
                playerRolls.put(player, player.rollDice(Outcome.Detriment, source, game, 6));
            }
            int minValueInMap = Collections.min(playerRolls.values());
            for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {
                if (mapEntry.getValue() > minValueInMap) {
                    playerRolls.remove(mapEntry.getKey());
                }
            }
        } while (playerRolls.size() > 1);
        if (playerRolls.size() == 1) {
            Player loser = (Player) playerRolls.keySet().toArray()[0];
            UUID loserId = loser.getId();
            Target target = targets.get(0);
            if (target.getFirstTarget().equals(loserId)) {
                return true;
            }
            String oldTargetName = null;
            if (target.canTarget(spell.getControllerId(), loserId, sourceAbility, game)) {
                Player oldPlayer = game.getPlayer(targets.getFirstTarget());
                if (oldPlayer != null) {
                    oldTargetName = oldPlayer.getLogName();
                }
                target.clearChosen();
                target.addTarget(loserId, sourceAbility, game);
            }
            MageObject sourceObject = game.getObject(source.getSourceId());
            if (oldTargetName != null && sourceObject != null) {
                game.informPlayers(sourceObject.getLogName() + ": Changed target of " + spell.getLogName() + " from " + oldTargetName + " to " + loser.getLogName());
            }
        }
        return true;
    }
    return false;
}
Also used : SpellCastAllTriggeredAbility(mage.abilities.common.SpellCastAllTriggeredAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) HashMap(java.util.HashMap) Mode(mage.abilities.Mode) MageObject(mage.MageObject) Targets(mage.target.Targets) Spell(mage.game.stack.Spell) FilterSpell(mage.filter.FilterSpell) Target(mage.target.Target) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 38 with Ability

use of mage.abilities.Ability 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 39 with Ability

use of mage.abilities.Ability 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)

Example 40 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class SoulflayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        // one time abilities collect
        if (objectReference == null || !objectReference.refersTo(permanent, game)) {
            abilitiesToAdd = new HashSet<>();
            this.objectReference = new MageObjectReference(permanent, game);
            String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
            Cards delvedCards = (Cards) game.getState().getValue(keyString);
            if (delvedCards != null) {
                for (Card card : delvedCards.getCards(game)) {
                    if (!card.isCreature(game)) {
                        continue;
                    }
                    for (Ability cardAbility : card.getAbilities(game)) {
                        if (cardAbility instanceof FlyingAbility) {
                            abilitiesToAdd.add(FlyingAbility.getInstance());
                        }
                        if (cardAbility instanceof FirstStrikeAbility) {
                            abilitiesToAdd.add(FirstStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DoubleStrikeAbility) {
                            abilitiesToAdd.add(DoubleStrikeAbility.getInstance());
                        }
                        if (cardAbility instanceof DeathtouchAbility) {
                            abilitiesToAdd.add(DeathtouchAbility.getInstance());
                        }
                        if (cardAbility instanceof HasteAbility) {
                            abilitiesToAdd.add(HasteAbility.getInstance());
                        }
                        if (cardAbility instanceof HexproofBaseAbility) {
                            abilitiesToAdd.add(HexproofAbility.getInstance());
                        }
                        if (cardAbility instanceof IndestructibleAbility) {
                            abilitiesToAdd.add(IndestructibleAbility.getInstance());
                        }
                        if (cardAbility instanceof LifelinkAbility) {
                            abilitiesToAdd.add(LifelinkAbility.getInstance());
                        }
                        if (cardAbility instanceof ReachAbility) {
                            abilitiesToAdd.add(ReachAbility.getInstance());
                        }
                        if (cardAbility instanceof TrampleAbility) {
                            abilitiesToAdd.add(TrampleAbility.getInstance());
                        }
                        if (cardAbility instanceof VigilanceAbility) {
                            abilitiesToAdd.add(VigilanceAbility.getInstance());
                        }
                    }
                }
            }
        }
        // all time abilities apply
        for (Ability ability : abilitiesToAdd) {
            permanent.addAbility(ability, source.getSourceId(), game);
        }
        return true;
    } else if (abilitiesToAdd != null) {
        abilitiesToAdd = null;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) Card(mage.cards.Card) MageObjectReference(mage.MageObjectReference) Cards(mage.cards.Cards)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35