Search in sources :

Example 41 with Token

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

the class VolrathsLaboratoryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
    SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
    Token token = new VolrathsLaboratoryToken(color, subType);
    return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : SubType(mage.constants.SubType) ObjectColor(mage.ObjectColor) VolrathsLaboratoryToken(mage.game.permanent.token.VolrathsLaboratoryToken) Token(mage.game.permanent.token.Token) VolrathsLaboratoryToken(mage.game.permanent.token.VolrathsLaboratoryToken)

Example 42 with Token

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

the class GarbageElementalCEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Integer> results = controller.rollDice(outcome, source, game, 6, 2, 0);
        int thisRoll = results.get(0);
        int thatRoll = results.get(1);
        Token token = new GoblinToken();
        return token.putOntoBattlefield(Math.abs(thatRoll - thisRoll), game, source, source.getControllerId());
    }
    return false;
}
Also used : Player(mage.players.Player) GoblinToken(mage.game.permanent.token.GoblinToken) Token(mage.game.permanent.token.Token) GoblinToken(mage.game.permanent.token.GoblinToken)

Example 43 with Token

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

the class KamahlsSummonsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Map<UUID, Integer> revealedCards = new HashMap<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.getHand().count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
                    TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURE);
                    if (player.choose(outcome, target, source.getSourceId(), game)) {
                        Cards cards = new CardsImpl(target.getTargets());
                        controller.revealCards(sourceObject.getIdName(), cards, game);
                        revealedCards.put(playerId, target.getTargets().size());
                    }
                }
            }
        }
        Token token = new BearToken();
        for (Map.Entry<UUID, Integer> revealedCardsByPlayer : revealedCards.entrySet()) {
            int value = revealedCardsByPlayer.getValue();
            if (value > 0) {
                token.putOntoBattlefield(value, game, source, revealedCardsByPlayer.getKey());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) HashMap(java.util.HashMap) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) BearToken(mage.game.permanent.token.BearToken) Token(mage.game.permanent.token.Token) BearToken(mage.game.permanent.token.BearToken) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 44 with Token

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

Example 45 with Token

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

the class SmokeSpiritsAidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Token token = new SmokeBlessingToken();
    for (UUID targetId : getTargetPointer().getTargets(game, source)) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent == null) {
            continue;
        }
        token.putOntoBattlefield(1, game, source);
        for (UUID tokenId : token.getLastAddedTokenIds()) {
            Permanent aura = game.getPermanent(tokenId);
            if (aura == null) {
                continue;
            }
            aura.getAbilities().get(0).getTargets().get(0).add(source.getFirstTarget(), game);
            aura.getAbilities().get(0).getEffects().get(0).apply(game, aura.getAbilities().get(0));
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) SmokeBlessingToken(mage.game.permanent.token.SmokeBlessingToken) SmokeBlessingToken(mage.game.permanent.token.SmokeBlessingToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

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