Search in sources :

Example 61 with Token

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

the class SarpadianEmpiresCreateSelectedTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    String tokenType = game.getState().getValue(source.getSourceId().toString() + "_SarpadianEmpiresVolVii").toString();
    Token token;
    switch(tokenType) {
        case "White Citizen":
            token = new CitizenToken();
            break;
        case "Blue Camarid":
            token = new CamaridToken();
            break;
        case "Black Thrull":
            token = new ThrullToken();
            break;
        case "Red Goblin":
            token = new GoblinToken();
            break;
        default:
            token = new SaprolingToken();
            break;
    }
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    return true;
}
Also used : SaprolingToken(mage.game.permanent.token.SaprolingToken) ThrullToken(mage.game.permanent.token.ThrullToken) CitizenToken(mage.game.permanent.token.CitizenToken) GoblinToken(mage.game.permanent.token.GoblinToken) CamaridToken(mage.game.permanent.token.CamaridToken) CitizenToken(mage.game.permanent.token.CitizenToken) ThrullToken(mage.game.permanent.token.ThrullToken) SaprolingToken(mage.game.permanent.token.SaprolingToken) Token(mage.game.permanent.token.Token) CamaridToken(mage.game.permanent.token.CamaridToken) GoblinToken(mage.game.permanent.token.GoblinToken)

Example 62 with Token

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

the class SaprolingBurstDestroyEffect method apply.

@Override
@SuppressWarnings("unchecked")
public boolean apply(Game game, Ability source) {
    Token token = new SaprolingBurstToken(new MageObjectReference(source.getSourceObject(game), game));
    token.putOntoBattlefield(1, game, source, source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game));
        Set<UUID> tokensCreated;
        if (object != null) {
            tokensCreated = (Set<UUID>) object;
        } else {
            tokensCreated = new HashSet<>();
        }
        for (UUID tokenId : token.getLastAddedTokenIds()) {
            tokensCreated.add(tokenId);
        }
        game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) SaprolingBurstToken(mage.game.permanent.token.SaprolingBurstToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID) SaprolingBurstToken(mage.game.permanent.token.SaprolingBurstToken) MageObjectReference(mage.MageObjectReference)

Example 63 with Token

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

the class SarkhanTheMadDragonDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
    if (permanent != null) {
        permanent.sacrifice(source, game);
        Player player = game.getPlayer(permanent.getControllerId());
        if (player != null) {
            Token dragonToken = new DragonToken2();
            dragonToken.putOntoBattlefield(1, game, source, player.getId());
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DragonToken2(mage.game.permanent.token.DragonToken2) Token(mage.game.permanent.token.Token)

Example 64 with Token

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

the class TheBookOfVileDarknessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<MageObjectReference> morSet = (Set<MageObjectReference>) getValue("BookEyeHand");
    if (morSet == null) {
        return false;
    }
    Token token = new VecnaToken();
    for (MageObjectReference mor : morSet) {
        // the card object in the mor doesn't work, so the permanent object is used
        Permanent card = mor.getPermanentOrLKIBattlefield(game);
        if (card == null) {
            continue;
        }
        for (Ability ability : card.getAbilities(game)) {
            if (ability instanceof TriggeredAbility) {
                Ability copyAbility = ability.copy();
                copyAbility.newId();
                copyAbility.setControllerId(source.getControllerId());
                token.addAbility(copyAbility);
            }
        }
    }
    return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Also used : BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TriggeredAbility(mage.abilities.TriggeredAbility) Ability(mage.abilities.Ability) HashSet(java.util.HashSet) Set(java.util.Set) FilterPermanent(mage.filter.FilterPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) VecnaToken(mage.game.permanent.token.VecnaToken) Token(mage.game.permanent.token.Token) ZombieToken(mage.game.permanent.token.ZombieToken) VecnaToken(mage.game.permanent.token.VecnaToken) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) TriggeredAbility(mage.abilities.TriggeredAbility) MageObjectReference(mage.MageObjectReference)

Example 65 with Token

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

the class MageBook method loadTokens.

public List<Object> loadTokens() {
    List<Object> res = new ArrayList<>();
    // tokens
    List<CardDownloadData> allTokens = getTokenCardUrls();
    for (CardDownloadData token : allTokens) {
        if (token.getSet().equals(currentSet)) {
            try {
                String className = token.getName();
                className = className.replaceAll("[^a-zA-Z0-9]", "");
                className = "mage.game.permanent.token." + className + "Token";
                if (token.getTokenClassName() != null && token.getTokenClassName().length() > 0) {
                    if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*token.*")) {
                        className = token.getTokenClassName();
                        className = "mage.game.permanent.token." + className;
                    } else if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
                        continue;
                    }
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newToken = cons.newInstance();
                if (newToken instanceof Token) {
                    ((Token) newToken).setOriginalExpansionSetCode(currentSet);
                    ((Token) newToken).setExpansionSetCodeForImage(currentSet);
                    ((Token) newToken).setTokenType(token.getType());
                    res.add(newToken);
                }
            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            // Swallow exception
            }
        }
    }
    // emblems
    List<CardDownloadData> allEmblems = getTokenCardUrls();
    for (CardDownloadData emblem : allEmblems) {
        if (emblem.getSet().equals(currentSet)) {
            try {
                String className = emblem.getName();
                if (emblem.getTokenClassName() != null && emblem.getTokenClassName().length() > 0) {
                    if (emblem.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
                        className = emblem.getTokenClassName();
                        className = "mage.game.command.emblems." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newEmblem = cons.newInstance();
                if (newEmblem instanceof Emblem) {
                    ((Emblem) newEmblem).setExpansionSetCodeForImage(currentSet);
                    res.add(newEmblem);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    // planes
    List<CardDownloadData> allPlanes = getTokenCardUrls();
    for (CardDownloadData plane : allPlanes) {
        if (plane.getSet().equals(currentSet)) {
            try {
                String className = plane.getName();
                if (plane.getTokenClassName() != null && plane.getTokenClassName().length() > 0) {
                    if (plane.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*plane.*")) {
                        className = plane.getTokenClassName();
                        className = "mage.game.command.planes." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newPlane = cons.newInstance();
                if (newPlane instanceof Plane) {
                    ((Plane) newPlane).setExpansionSetCodeForImage(currentSet);
                    res.add(newPlane);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    // dungeons
    List<CardDownloadData> allDungeons = getTokenCardUrls();
    for (CardDownloadData dungeon : allDungeons) {
        if (dungeon.getSet().equals(currentSet)) {
            try {
                String className = dungeon.getName();
                if (dungeon.getTokenClassName() != null && dungeon.getTokenClassName().length() > 0) {
                    if (dungeon.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*dungeon.*")) {
                        className = dungeon.getTokenClassName();
                        className = "mage.game.command.dungeons." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newDungeon = cons.newInstance();
                if (newDungeon instanceof Dungeon) {
                    ((Dungeon) newDungeon).setExpansionSetCodeForImage(currentSet);
                    res.add(newDungeon);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    return res;
}
Also used : CardDownloadData(org.mage.plugins.card.images.CardDownloadData) Plane(mage.game.command.Plane) ArrayList(java.util.ArrayList) PermanentToken(mage.game.permanent.PermanentToken) Token(mage.game.permanent.token.Token) InvocationTargetException(java.lang.reflect.InvocationTargetException) Emblem(mage.game.command.Emblem) Dungeon(mage.game.command.Dungeon)

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