Search in sources :

Example 1 with KorWarriorToken

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

the class NahiriHeirOfTheAncientsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Token token = new KorWarriorToken();
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> tokens = token.getLastAddedTokenIds().stream().map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    int equipCount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
    if (tokens.isEmpty() || equipCount == 0 || !player.chooseUse(outcome, "Attach an equipment to the token?", source, game)) {
        return true;
    }
    Permanent tokenCreature = tokens.get(0);
    if (tokens.size() > 1) {
        FilterPermanent tokenFilter = new FilterPermanent("token");
        tokenFilter.add(Predicates.or(tokens.stream().map(MageObject::getId).map(PermanentIdPredicate::new).collect(Collectors.toSet())));
        TargetPermanent target = new TargetPermanent(tokenFilter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        tokenCreature = game.getPermanent(target.getFirstTarget());
    }
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    tokenCreature.addAttachment(target.getFirstTarget(), source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) KorWarriorToken(mage.game.permanent.token.KorWarriorToken) Token(mage.game.permanent.token.Token) TargetPermanent(mage.target.TargetPermanent) KorWarriorToken(mage.game.permanent.token.KorWarriorToken)

Aggregations

MageObject (mage.MageObject)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 Permanent (mage.game.permanent.Permanent)1 KorWarriorToken (mage.game.permanent.token.KorWarriorToken)1 Token (mage.game.permanent.token.Token)1 Player (mage.players.Player)1 TargetPermanent (mage.target.TargetPermanent)1