Search in sources :

Example 21 with Token

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

the class XornReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event instanceof CreateTokenEvent) {
        CreateTokenEvent tokenEvent = (CreateTokenEvent) event;
        TreasureToken treasureToken = null;
        Map<Token, Integer> tokens = tokenEvent.getTokens();
        for (Token token : tokens.keySet()) {
            if (token instanceof TreasureToken) {
                treasureToken = (TreasureToken) token;
                break;
            }
        }
        if (treasureToken == null) {
            treasureToken = new TreasureToken();
        }
        tokens.put(treasureToken, tokens.getOrDefault(treasureToken, 0) + 1);
    }
    return false;
}
Also used : TreasureToken(mage.game.permanent.token.TreasureToken) Token(mage.game.permanent.token.Token) TreasureToken(mage.game.permanent.token.TreasureToken) CreateTokenEvent(mage.game.events.CreateTokenEvent)

Example 22 with Token

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

the class FlickerformReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Exile enchanted creature and all Auras attached to it.
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (enchantment == null) {
        enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (enchantment != null && enchantment.getAttachedTo() != null) {
        Permanent enchantedCreature = game.getPermanent(enchantment.getAttachedTo());
        if (enchantedCreature != null) {
            UUID exileZoneId = UUID.randomUUID();
            enchantedCreature.moveToExile(exileZoneId, enchantment.getName(), source, game);
            for (UUID attachementId : enchantedCreature.getAttachments()) {
                Permanent attachment = game.getPermanent(attachementId);
                if (attachment != null && filter.match(attachment, game)) {
                    attachment.moveToExile(exileZoneId, enchantment.getName(), source, game);
                }
            }
            if (!(enchantedCreature instanceof Token)) {
                // At the beginning of the next end step, return that card to the battlefield under its owner's control.
                // If you do, return the other cards exiled this way to the battlefield under their owners' control attached to that creature
                AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new FlickerformReturnEffect(enchantedCreature.getId(), exileZoneId));
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
            return true;
        }
    }
    return false;
}
Also used : AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

Example 23 with Token

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

the class NahiriTheLithomancerSecondAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Token token = new KorSoldierToken();
        if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
            for (UUID tokenId : token.getLastAddedTokenIds()) {
                Permanent tokenPermanent = game.getPermanent(tokenId);
                if (tokenPermanent != null) {
                    // TODO: Make sure the Equipment can legally enchant the token, preferably on targetting.
                    Target target = new TargetControlledPermanent(0, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Attach an Equipment you control to the created " + tokenPermanent.getIdName() + '?', source, game)) {
                        if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                            Permanent equipmentPermanent = game.getPermanent(target.getFirstTarget());
                            if (equipmentPermanent != null) {
                                Permanent attachedTo = game.getPermanent(equipmentPermanent.getAttachedTo());
                                if (attachedTo != null) {
                                    attachedTo.removeAttachment(equipmentPermanent.getId(), source, game);
                                }
                                tokenPermanent.addAttachment(equipmentPermanent.getId(), source, game);
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) NahiriTheLithomancerEquipmentToken(mage.game.permanent.token.NahiriTheLithomancerEquipmentToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

Example 24 with Token

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

the class RiptideReplicatorEffect 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);
    if (subType == null) {
        return false;
    }
    int x = (new CountersSourceCount(CounterType.CHARGE)).calculate(game, source, this);
    Token token = new RiptideReplicatorToken(color, subType, x);
    return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : CountersSourceCount(mage.abilities.dynamicvalue.common.CountersSourceCount) RiptideReplicatorToken(mage.game.permanent.token.RiptideReplicatorToken) SubType(mage.constants.SubType) ObjectColor(mage.ObjectColor) RiptideReplicatorToken(mage.game.permanent.token.RiptideReplicatorToken) Token(mage.game.permanent.token.Token)

Example 25 with Token

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

the class SmashingSuccessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null && permanent.isPhasedIn() && !permanent.isPhasedOutIndirectly()) {
        if (permanent.isArtifact(game)) {
            if (permanent.destroy(source, game, false)) {
                Token token = new TreasureToken();
                token.putOntoBattlefield(1, game, source, source.getControllerId());
                return true;
            }
        } else {
            return permanent.destroy(source, game, false);
        }
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TreasureToken(mage.game.permanent.token.TreasureToken) Token(mage.game.permanent.token.Token) TreasureToken(mage.game.permanent.token.TreasureToken)

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