Search in sources :

Example 31 with Token

use of mage.game.permanent.token.Token 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)

Example 32 with Token

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

the class ThroneOfEmpiresEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean scepter = false;
    boolean crown = false;
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
        if (permanent.getName().equals("Scepter of Empires")) {
            scepter = true;
        } else if (permanent.getName().equals("Crown of Empires")) {
            crown = true;
        }
        if (scepter && crown)
            break;
    }
    Token soldier = new SoldierToken();
    int count = scepter && crown ? 5 : 1;
    soldier.putOntoBattlefield(count, game, source, source.getControllerId());
    return false;
}
Also used : SoldierToken(mage.game.permanent.token.SoldierToken) Permanent(mage.game.permanent.Permanent) SoldierToken(mage.game.permanent.token.SoldierToken) Token(mage.game.permanent.token.Token)

Example 33 with Token

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

the class TidalWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Token token = new TidalWaveWallToken();
    if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
        for (UUID tokenId : token.getLastAddedTokenIds()) {
            Permanent tokenPermanent = game.getPermanent(tokenId);
            if (tokenPermanent != null) {
                SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect();
                sacrificeEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) TidalWaveWallToken(mage.game.permanent.token.TidalWaveWallToken) Permanent(mage.game.permanent.Permanent) TidalWaveWallToken(mage.game.permanent.token.TidalWaveWallToken) Token(mage.game.permanent.token.Token) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) UUID(java.util.UUID)

Example 34 with Token

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

the class ZaxaraTheExemplaryHydraTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
        Object needObject = game.getState().getValue(source.getSourceId() + ZaxaraTheExemplary.needPrefix);
        // create token
        if (needObject instanceof Spell) {
            Spell spell = (Spell) needObject;
            int xValue = spell.getSpellAbility().getManaCostsToPay().getX();
            Token hydraToken = new ZaxaraTheExemplaryHydraToken();
            hydraToken.putOntoBattlefield(1, game, source, source.getControllerId());
            for (UUID tokenId : hydraToken.getLastAddedTokenIds()) {
                Permanent permanent = game.getPermanent(tokenId);
                if (permanent != null)
                    permanent.addCounters(CounterType.P1P1.createInstance(xValue), source.getControllerId(), source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ZaxaraTheExemplaryHydraToken(mage.game.permanent.token.ZaxaraTheExemplaryHydraToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID) Spell(mage.game.stack.Spell) ZaxaraTheExemplaryHydraToken(mage.game.permanent.token.ZaxaraTheExemplaryHydraToken)

Example 35 with Token

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

the class MomirEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int value = source.getManaCostsToPay().getX();
    if (game.isSimulation()) {
        // Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
        Token token = new CreatureToken(value, value + 1);
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    // should this be random across card names
    CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
    List<CardInfo> options = CardRepository.instance.findCards(criteria);
    if (options == null || options.isEmpty()) {
        game.informPlayers("No random creature card with mana value of " + value + " was found.");
        return false;
    }
    // search for a random non custom set creature
    EmptyToken token = null;
    while (!options.isEmpty()) {
        int index = RandomUtil.nextInt(options.size());
        ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
        if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
            options.remove(index);
        } else {
            Card card = options.get(index).getCard();
            if (card != null) {
                token = new EmptyToken();
                CardUtil.copyTo(token).from(card, game);
                break;
            } else {
                options.remove(index);
            }
        }
    }
    if (token != null) {
        token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
        return true;
    }
    return false;
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) EmptyToken(mage.game.permanent.token.EmptyToken) CreatureToken(mage.game.permanent.token.custom.CreatureToken) Token(mage.game.permanent.token.Token) ExpansionSet(mage.cards.ExpansionSet) CreatureToken(mage.game.permanent.token.custom.CreatureToken) EmptyToken(mage.game.permanent.token.EmptyToken) Card(mage.cards.Card)

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