Search in sources :

Example 71 with Ability

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

the class CardTestPlayerAPIImpl method assertAbilityCount.

public void assertAbilityCount(Player player, String cardName, Class<? extends Ability> searchedAbility, int amount) {
    Permanent found = null;
    for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
        if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
            found = permanent;
            break;
        }
    }
    Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
    Assert.assertEquals(amount, found.getAbilities(currentGame).stream().filter(a -> searchedAbility.isAssignableFrom(a.getClass())).collect(Collectors.toList()).size());
}
Also used : java.util(java.util) CardScanner(mage.cards.repository.CardScanner) mage.game(mage.game) ComputerPlayer7(mage.player.ai.ComputerPlayer7) PlayerAction(org.mage.test.player.PlayerAction) Player(mage.players.Player) CardTestAPI(org.mage.test.serverside.base.CardTestAPI) Matcher(java.util.regex.Matcher) MatchOptions(mage.game.match.MatchOptions) ManaPool(mage.players.ManaPool) MageObject(mage.MageObject) SystemUtil(mage.server.util.SystemUtil) ObjectColor(mage.ObjectColor) Card(mage.cards.Card) DeckCardLists(mage.cards.decks.DeckCardLists) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ComputerPlayerMCTS(mage.player.ai.ComputerPlayerMCTS) Before(org.junit.Before) FilterCard(mage.filter.FilterCard) TestPlayer(org.mage.test.player.TestPlayer) CardTestCodePayload(org.mage.test.serverside.base.CardTestCodePayload) DeckImporter(mage.cards.decks.importer.DeckImporter) GameSessionPlayer(mage.server.game.GameSessionPlayer) Deck(mage.cards.decks.Deck) Assert.assertTrue(org.junit.Assert.assertTrue) CardUtil(mage.util.CardUtil) CardRepository(mage.cards.repository.CardRepository) GameView(mage.view.GameView) Collectors(java.util.stream.Collectors) Filter(mage.filter.Filter) CommandObject(mage.game.command.CommandObject) FileNotFoundException(java.io.FileNotFoundException) CardInfo(mage.cards.repository.CardInfo) Permanent(mage.game.permanent.Permanent) PermanentCard(mage.game.permanent.PermanentCard) MageTestPlayerBase(org.mage.test.serverside.base.MageTestPlayerBase) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) Mana(mage.Mana) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 72 with Ability

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

the class CardTestPlayerAPIImpl method assertAbilities.

/**
 * {@inheritDoc}
 */
@Override
public void assertAbilities(Player player, String cardName, List<Ability> abilities) throws AssertionError {
    // Assert.assertNotEquals("", cardName);
    int count = 0;
    Permanent found = null;
    for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
        if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
            found = permanent;
            count++;
        }
    }
    Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
    assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, count == 1);
    for (Ability ability : abilities) {
        assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + ", cardName" + cardName, found.getAbilities().contains(ability));
    }
}
Also used : Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 73 with Ability

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

the class CardTestAPIImpl method assertAbilities.

/**
 * {@inheritDoc}
 */
@Override
public void assertAbilities(Player player, String cardName, List<Ability> abilities) throws AssertionError {
    int count = 0;
    Permanent found = null;
    for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
        if (permanent.getName().equals(cardName)) {
            found = permanent;
        }
    }
    Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
    Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, count == 1);
    for (Ability ability : abilities) {
        Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + ", cardName=" + cardName, found.getAbilities().contains(ability));
    }
}
Also used : Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent)

Example 74 with Ability

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

the class ManifestTargetPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
        for (Card card : cards) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
        for (Card card : cards) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.setManifested(true);
            }
        }
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 75 with Ability

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

the class TargetsHaveToTargetPermanentIfAbleEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetingPlayer = game.getPlayer(event.getPlayerId());
    if (controller != null && // TODO: This target handling does only work for non AI players so AI logic
    targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(), game)) {
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject.isCopy()) {
            return false;
        }
        Ability stackAbility = stackObject.getStackAbility();
        // Ensure that this ability is activated or a cast spell, because Flag Bearer effects don't require triggered abilities to choose a Standard Bearer
        if (!(stackAbility instanceof ActivatedAbility) && !(stackAbility instanceof SpellAbility)) {
            return false;
        }
        // Also check that targeting player controls the ability
        if (!stackAbility.isControlledBy(targetingPlayer.getId())) {
            return false;
        }
        Ability ability = (Ability) getValue("targetAbility");
        if (ability != null) {
            // Get all the allowed permanents on the battlefield in range of the abilities controller
            List<Permanent> allowedPermanents = game.getBattlefield().getActivePermanents(filter, event.getPlayerId(), event.getSourceId(), game);
            if (!allowedPermanents.isEmpty()) {
                boolean canTargetAllowedPermanent = false;
                for (UUID modeId : ability.getModes().getSelectedModes()) {
                    ability.getModes().setActiveMode(modeId);
                    for (Target target : ability.getTargets()) {
                        // Check if already targeted
                        for (Permanent allowedPermanent : allowedPermanents) {
                            if (target.getTargets().contains(allowedPermanent.getId())) {
                                return false;
                            }
                            if (target.canTarget(stackObject.getControllerId(), allowedPermanent.getId(), source, game)) {
                                canTargetAllowedPermanent = true;
                            }
                        }
                    }
                }
                return canTargetAllowedPermanent;
            }
        }
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) ActivatedAbility(mage.abilities.ActivatedAbility) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID)

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