Search in sources :

Example 11 with ActivatedAbility

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

the class QuickSilverElementalBlueManaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent creature = game.getPermanent(source.getTargets().getFirstTarget());
    if (permanent != null && creature != null) {
        for (ActivatedAbility ability : creature.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
            Ability newAbility = ability.copy();
            newAbility.newOriginalId();
            game.addEffect(new GainAbilitySourceEffect(newAbility, Duration.EndOfTurn), source);
        }
        return true;
    }
    return false;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ActivatedAbility(mage.abilities.ActivatedAbility)

Example 12 with ActivatedAbility

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

the class MairsilThePretenderGainAbilitiesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent perm = game.getPermanent(source.getSourceId());
    if (perm == null) {
        return false;
    }
    for (Card card : game.getExile().getAllCards(game)) {
        if (filter.match(card, game) && Objects.equals(card.getOwnerId(), perm.getControllerId())) {
            for (Ability ability : card.getAbilities(game)) {
                if (ability instanceof ActivatedAbility) {
                    ActivatedAbility copyAbility = (ActivatedAbility) ability.copy();
                    copyAbility.setMaxActivationsPerTurn(1);
                    perm.addAbility(copyAbility, source.getSourceId(), game);
                }
            }
        }
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) ActivatedAbility(mage.abilities.ActivatedAbility) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 13 with ActivatedAbility

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

the class DrainPowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        List<Permanent> ignorePermanents = new ArrayList<>();
        Map<Permanent, List<ActivatedManaAbilityImpl>> manaAbilitiesMap = new HashMap<>();
        TargetPermanent target = null;
        while (true) {
            targetPlayer.setPayManaMode(true);
            manaAbilitiesMap.clear();
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, targetPlayer.getId(), game)) {
                if (!ignorePermanents.contains(permanent)) {
                    List<ActivatedManaAbilityImpl> manaAbilities = new ArrayList<>();
                    abilitySearch: for (Ability ability : permanent.getAbilities()) {
                        if (ability instanceof ActivatedAbility && ability.getAbilityType() == AbilityType.MANA) {
                            ActivatedManaAbilityImpl manaAbility = (ActivatedManaAbilityImpl) ability;
                            if (manaAbility.canActivate(targetPlayer.getId(), game).canActivate()) {
                                // so it's necessary to filter them out manually - might be buggy in some fringe cases
                                for (ManaCost manaCost : manaAbility.getManaCosts()) {
                                    if (!targetPlayer.getManaPool().getMana().includesMana(manaCost.getMana())) {
                                        continue abilitySearch;
                                    }
                                }
                                manaAbilities.add(manaAbility);
                            }
                        }
                    }
                    if (!manaAbilities.isEmpty()) {
                        manaAbilitiesMap.put(permanent, manaAbilities);
                    }
                }
            }
            if (manaAbilitiesMap.isEmpty()) {
                break;
            }
            List<Permanent> permList = new ArrayList<>(manaAbilitiesMap.keySet());
            Permanent permanent;
            if (permList.size() > 1 || target != null) {
                FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
                filter2.add(new PermanentInListPredicate(permList));
                target = new TargetPermanent(1, 1, filter2, true);
                while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
                    targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);
                }
                permanent = game.getPermanent(target.getFirstTarget());
            } else {
                permanent = permList.get(0);
            }
            if (permanent != null) {
                int i = 0;
                for (ActivatedManaAbilityImpl manaAbility : manaAbilitiesMap.get(permanent)) {
                    i++;
                    if (manaAbilitiesMap.get(permanent).size() <= i || targetPlayer.chooseUse(Outcome.Neutral, "Activate mana ability \"" + manaAbility.getRule() + "\" of " + permanent.getLogName() + "? (Choose \"no\" to activate next mana ability)", source, game)) {
                        boolean originalCanUndo = manaAbility.isUndoPossible();
                        // prevents being able to undo Drain Power
                        manaAbility.setUndoPossible(false);
                        if (targetPlayer.activateAbility(manaAbility, game)) {
                            ignorePermanents.add(permanent);
                        }
                        // resets undoPossible to its original state
                        manaAbility.setUndoPossible(originalCanUndo);
                        break;
                    }
                }
            }
        }
        targetPlayer.setPayManaMode(false);
        // 106.12. One card (Drain Power) causes one player to lose unspent mana and another to add “the mana lost this way.” (Note that these may be the same player.)
        // This empties the former player's mana pool and causes the mana emptied this way to be put into the latter player's mana pool. Which permanents, spells, and/or
        // abilities produced that mana are unchanged, as are any restrictions or additional effects associated with any of that mana.
        List<ManaPoolItem> manaItems = targetPlayer.getManaPool().getManaItems();
        targetPlayer.getManaPool().emptyPool(game);
        for (ManaPoolItem manaPoolItem : manaItems) {
            controller.getManaPool().addMana(manaPoolItem.isConditional() ? manaPoolItem.getConditionalMana() : manaPoolItem.getMana(), game, source, Duration.EndOfTurn.equals(manaPoolItem.getDuration()));
        }
        return true;
    }
    return false;
}
Also used : ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) ActivatedAbility(mage.abilities.ActivatedAbility) FilterLandPermanent(mage.filter.common.FilterLandPermanent) ManaPoolItem(mage.players.ManaPoolItem) ManaCost(mage.abilities.costs.mana.ManaCost) ArrayList(java.util.ArrayList) List(java.util.List) TargetPermanent(mage.target.TargetPermanent)

Example 14 with ActivatedAbility

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

the class PlayableObjectRecord method load.

public void load(List<ActivatedAbility> activatedAbilities) {
    this.basicManaAbilities.clear();
    this.basicPlayAbilities.clear();
    this.basicCastAbilities.clear();
    this.other.clear();
    // split abilities to types (it allows to enable or disable playable icon)
    for (ActivatedAbility ability : activatedAbilities) {
        List<PlayableObjectRecord> dest;
        if (ability instanceof BasicManaAbility) {
            dest = this.basicManaAbilities;
        } else if (ability instanceof PlayLandAbility) {
            dest = this.basicPlayAbilities;
        } else if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.BASE)) {
            dest = this.basicCastAbilities;
        } else {
            dest = this.other;
        }
        // collect info about abilities for card icons popup, must be simple online text (html symbols are possible)
        // some long html tags can be miss (example: ability extra hint) -- that's ok
        String shortInfo = ability.toString();
        if (shortInfo.length() > 50) {
            shortInfo = shortInfo.substring(0, 50 - 1) + "...";
        }
        shortInfo = shortInfo.replace("<br>", " ");
        shortInfo = shortInfo.replace("\n", " ");
        dest.add(new PlayableObjectRecord(ability.getId(), shortInfo));
    }
}
Also used : PlayLandAbility(mage.abilities.PlayLandAbility) BasicManaAbility(mage.abilities.mana.BasicManaAbility) ActivatedAbility(mage.abilities.ActivatedAbility) SpellAbility(mage.abilities.SpellAbility)

Example 15 with ActivatedAbility

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

the class ComputerPlayerMCTS method priority.

@Override
public boolean priority(Game game) {
    if (game.getStep().getType() == PhaseStep.UPKEEP) {
        if (!lastPhase.equals(game.getTurn().getValue(game.getTurnNum()))) {
            logList(game.getTurn().getValue(game.getTurnNum()) + name + " hand: ", new ArrayList(hand.getCards(game)));
            lastPhase = game.getTurn().getValue(game.getTurnNum());
            if (MCTSNode.USE_ACTION_CACHE) {
                int count = MCTSNode.cleanupCache(game.getTurnNum());
                if (count > 0)
                    logger.info("Removed " + count + " cache entries");
            }
        }
    }
    game.getState().setPriorityPlayerId(playerId);
    game.firePriorityEvent(playerId);
    getNextAction(game, NextAction.PRIORITY);
    Ability ability = root.getAction();
    if (ability == null)
        logger.fatal("null ability");
    activateAbility((ActivatedAbility) ability, game);
    if (ability instanceof PassAbility)
        return false;
    logLife(game);
    logger.info("choose action:" + root.getAction() + " success ratio: " + root.getWinRatio());
    return true;
}
Also used : PassAbility(mage.abilities.common.PassAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) PassAbility(mage.abilities.common.PassAbility) ArrayList(java.util.ArrayList)

Aggregations

ActivatedAbility (mage.abilities.ActivatedAbility)21 Ability (mage.abilities.Ability)17 PassAbility (mage.abilities.common.PassAbility)11 Permanent (mage.game.permanent.Permanent)8 StackAbility (mage.game.stack.StackAbility)8 SpellAbility (mage.abilities.SpellAbility)7 Card (mage.cards.Card)7 Player (mage.players.Player)7 ArrayList (java.util.ArrayList)4 TriggeredAbility (mage.abilities.TriggeredAbility)4 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)4 Game (mage.game.Game)4 UUID (java.util.UUID)3 File (java.io.File)2 java.util (java.util)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MageObject (mage.MageObject)2 PlayLandAbility (mage.abilities.PlayLandAbility)2 StaticAbility (mage.abilities.StaticAbility)2