Search in sources :

Example 1 with GoblinRogueToken

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

the class WarrenWeirdingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player == null) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new ControllerIdPredicate(player.getId()));
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    // had, if thats the case this ability should fizzle.
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            permanent.sacrifice(source, game);
            if (filterGoblin.match(permanent, game)) {
                for (int i = 0; i < 2; i++) {
                    Token token = new GoblinRogueToken();
                    Effect effect = new CreateTokenTargetEffect(token);
                    effect.setTargetPointer(new FixedTarget(player.getId()));
                    if (effect.apply(game, source)) {
                        Permanent tokenPermanent = game.getPermanent(token.getLastAddedToken());
                        if (tokenPermanent != null) {
                            ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                            hasteEffect.setTargetPointer(new FixedTarget(tokenPermanent.getId()));
                            game.addEffect(hasteEffect, source);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) GoblinRogueToken(mage.game.permanent.token.GoblinRogueToken) Token(mage.game.permanent.token.Token) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) GoblinRogueToken(mage.game.permanent.token.GoblinRogueToken) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 CreateTokenTargetEffect (mage.abilities.effects.common.CreateTokenTargetEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 GoblinRogueToken (mage.game.permanent.token.GoblinRogueToken)1 Token (mage.game.permanent.token.Token)1 Player (mage.players.Player)1 TargetPlayer (mage.target.TargetPlayer)1 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)1 FixedTarget (mage.target.targetpointer.FixedTarget)1