Search in sources :

Example 1 with DwarfBerserkerToken

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

the class RecklessCrewEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int equipCount = game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game);
    int vehicleCount = game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game);
    if (equipCount + vehicleCount < 1) {
        return false;
    }
    Token token = new DwarfBerserkerToken();
    token.putOntoBattlefield(equipCount + vehicleCount, game, source, source.getControllerId());
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (equipCount < 1) {
        return true;
    }
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        Permanent permanent = game.getPermanent(tokenId);
        if (permanent == null) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(0, 1, filter1, true);
        target.withChooseHint("(to attach to " + permanent.getIdName() + ")");
        player.choose(outcome, target, source.getSourceId(), game);
        permanent.addAttachment(target.getFirstTarget(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) DwarfBerserkerToken(mage.game.permanent.token.DwarfBerserkerToken) Token(mage.game.permanent.token.Token) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) DwarfBerserkerToken(mage.game.permanent.token.DwarfBerserkerToken)

Aggregations

UUID (java.util.UUID)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 Permanent (mage.game.permanent.Permanent)1 DwarfBerserkerToken (mage.game.permanent.token.DwarfBerserkerToken)1 Token (mage.game.permanent.token.Token)1 Player (mage.players.Player)1 TargetPermanent (mage.target.TargetPermanent)1