Search in sources :

Example 11 with Token

use of mage.game.permanent.token.Token in project mage by magefree.

the class NecromentiaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    Player controller = game.getPlayer(source.getControllerId());
    if (cardName != null && controller != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        // cards in Graveyard
        int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        }
        // cards in Hand
        int numberOfCardsExiledFromHand = 0;
        cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
            TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
            if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
                numberOfCardsExiledFromHand = target.getTargets().size();
                controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
        }
        // cards in Library
        Cards cardsInLibrary = new CardsImpl();
        cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
        cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
        if (cardsCount > 0) {
            filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
            TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
            if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
                controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
            }
        } else {
            targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
        }
        targetPlayer.shuffleLibrary(source, game);
        if (numberOfCardsExiledFromHand > 0) {
            game.getState().applyEffects(game);
            Token zombieToken = new ZombieToken();
            zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) ZombieToken(mage.game.permanent.token.ZombieToken) TargetCard(mage.target.TargetCard) Token(mage.game.permanent.token.Token) ZombieToken(mage.game.permanent.token.ZombieToken) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) HashSet(java.util.HashSet)

Example 12 with Token

use of mage.game.permanent.token.Token in project mage by magefree.

the class OozeFluxCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int xValue = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof RemoveVariableCountersTargetCost) {
            xValue = ((RemoveVariableCountersTargetCost) cost).getAmount();
            break;
        }
    }
    Token tokenCopy = token.copy();
    tokenCopy.getAbilities().newId();
    tokenCopy.getPower().modifyBaseValue(xValue);
    tokenCopy.getToughness().modifyBaseValue(xValue);
    tokenCopy.putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost) Token(mage.game.permanent.token.Token) OozeToken(mage.game.permanent.token.OozeToken) Cost(mage.abilities.costs.Cost) RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost)

Example 13 with Token

use of mage.game.permanent.token.Token in project mage by magefree.

the class OozeToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    int value = 0;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            value = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
        }
    }
    Token token = new OozeToken(value);
    // neccessary if token has ability like DevourAbility()
    token.getAbilities().newId();
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Token(mage.game.permanent.token.Token) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 14 with Token

use of mage.game.permanent.token.Token in project mage by magefree.

the class RampageOfTheClansEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Map<UUID, Integer> playersWithPermanents = new HashMap<>();
    for (Permanent p : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT, source.getControllerId(), source.getSourceId(), game)) {
        UUID controllerId = p.getControllerId();
        if (p.destroy(source, game, false)) {
            playersWithPermanents.put(controllerId, playersWithPermanents.getOrDefault(controllerId, 0) + 1);
        }
    }
    Token token = new CentaurToken();
    for (Map.Entry<UUID, Integer> amountDestroyedByPlayer : playersWithPermanents.entrySet()) {
        token.putOntoBattlefield(amountDestroyedByPlayer.getValue(), game, source, amountDestroyedByPlayer.getKey());
    }
    return true;
}
Also used : CentaurToken(mage.game.permanent.token.CentaurToken) Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) CentaurToken(mage.game.permanent.token.CentaurToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with Token

use of mage.game.permanent.token.Token in project mage by magefree.

the class VerifyCardDataTest method test_checkMissingTokenData.

@Test
// TODO: enable test after massive token fixes
@Ignore
public void test_checkMissingTokenData() {
    Collection<String> errorsList = new ArrayList<>();
    Collection<String> warningsList = new ArrayList<>();
    // all tokens must be stores in card-pictures-tok.txt (if not then viewer and image downloader are missing token images)
    // https://github.com/ronmamo/reflections
    Reflections reflections = new Reflections("mage.");
    Set<Class<? extends TokenImpl>> tokenClassesList = reflections.getSubTypesOf(TokenImpl.class);
    // xmage tokens
    Set<Class<? extends TokenImpl>> privateTokens = new HashSet<>();
    Set<Class<? extends TokenImpl>> publicTokens = new HashSet<>();
    for (Class<? extends TokenImpl> tokenClass : tokenClassesList) {
        if (Modifier.isPublic(tokenClass.getModifiers())) {
            publicTokens.add(tokenClass);
        } else {
            privateTokens.add(tokenClass);
        }
    }
    // tok file's data
    List<CardDownloadData> tokFileTokens = DownloadPicturesService.getTokenCardUrls();
    LinkedHashMap<String, String> tokDataClassesIndex = new LinkedHashMap<>();
    LinkedHashMap<String, String> tokDataNamesIndex = new LinkedHashMap<>();
    for (CardDownloadData tokData : tokFileTokens) {
        String searchName;
        String setsList;
        // by class
        searchName = tokData.getTokenClassName();
        setsList = tokDataClassesIndex.getOrDefault(searchName, "");
        if (!setsList.isEmpty()) {
            setsList += ",";
        }
        setsList += tokData.getSet();
        tokDataClassesIndex.put(searchName, setsList);
        // by name
        searchName = tokData.getName();
        setsList = tokDataNamesIndex.getOrDefault(searchName, "");
        if (!setsList.isEmpty()) {
            setsList += ",";
        }
        setsList += tokData.getSet();
        tokDataNamesIndex.put(searchName, setsList);
    }
    // 1. check token name convention
    for (Class<? extends TokenImpl> tokenClass : tokenClassesList) {
        if (!tokenClass.getName().endsWith("Token")) {
            String className = extractShortClass(tokenClass);
            warningsList.add("warning, token class must ends with Token: " + className + " from " + tokenClass.getName());
        }
    }
    // 2. check store file for public
    for (Class<? extends TokenImpl> tokenClass : publicTokens) {
        String fullClass = tokenClass.getName();
        if (!fullClass.startsWith("mage.game.permanent.token.")) {
            String className = extractShortClass(tokenClass);
            errorsList.add("Error: public token must stores in mage.game.permanent.token package: " + className + " from " + tokenClass.getName());
        }
    }
    // 3. check private tokens (they aren't need at all)
    for (Class<? extends TokenImpl> tokenClass : privateTokens) {
        String className = extractShortClass(tokenClass);
        errorsList.add("Error: no needs in private tokens, replace it with CreatureToken: " + className + " from " + tokenClass.getName());
    }
    // 4. all public tokens must have tok-data (private tokens uses for innner abilities -- no need images for it)
    for (Class<? extends TokenImpl> tokenClass : publicTokens) {
        String className = extractShortClass(tokenClass);
        Token token = (Token) createNewObject(tokenClass);
        if (token == null) {
            errorsList.add("Error: token must have default constructor with zero params: " + tokenClass.getName());
        } else if (tokDataNamesIndex.getOrDefault(token.getName(), "").isEmpty()) {
            errorsList.add("Error: can't find data in card-pictures-tok.txt for token: " + tokenClass.getName() + " -> " + token.getName());
        }
    }
    // TODO: all sets must have full tokens data in tok file (token in every set)
    // 1. Download scryfall tokens list: https://api.scryfall.com/cards/search?q=t:token
    // 2. Proccess each token with all prints: read "prints_search_uri" field from token data and go to link like
    // https://api.scryfall.com/cards/search?order=set&q=%21%E2%80%9CAngel%E2%80%9D&unique=prints
    // 3. Collect all strings in "set@name"
    // 4. Proccess tokens data and find missing strings from "set@name" list
    printMessages(warningsList);
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found token errors: " + errorsList.size());
    }
// TODO: all token must have correct availableImageSetCodes (all sets with that token)
// Some sets have original card, but don't have token card at all. So you must use scryfall tokens list above to find
// all token's sets and compare with xmage
}
Also used : CardDownloadData(org.mage.plugins.card.images.CardDownloadData) TokenImpl(mage.game.permanent.token.TokenImpl) Token(mage.game.permanent.token.Token) Reflections(org.reflections.Reflections) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Token (mage.game.permanent.token.Token)68 Permanent (mage.game.permanent.Permanent)30 Player (mage.players.Player)29 UUID (java.util.UUID)28 FixedTargets (mage.target.targetpointer.FixedTargets)9 Map (java.util.Map)7 Effect (mage.abilities.effects.Effect)6 OneShotEffect (mage.abilities.effects.OneShotEffect)6 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)6 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)6 FixedTarget (mage.target.targetpointer.FixedTarget)6 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 TargetPermanent (mage.target.TargetPermanent)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 FilterPermanent (mage.filter.FilterPermanent)4 CreateTokenEvent (mage.game.events.CreateTokenEvent)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3