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;
}
Aggregations