Search in sources :

Example 1 with ContinuousEffectImpl

use of mage.abilities.effects.ContinuousEffectImpl in project mage by magefree.

the class BorosBattleshaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature1 = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (creature1 != null) {
        if (game.getOpponents(creature1.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(AttacksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        }
    }
    Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (creature2 != null) {
        if (game.getOpponents(creature2.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new CantBlockTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new CantAttackTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) CantAttackTargetEffect(mage.abilities.effects.common.combat.CantAttackTargetEffect) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlocksIfAbleTargetEffect(mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) AttacksIfAbleTargetEffect(mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)

Example 2 with ContinuousEffectImpl

use of mage.abilities.effects.ContinuousEffectImpl in project mage by magefree.

the class NeoformReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sacrificedPermanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost) {
            SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
            if (!sacrificeCost.getPermanents().isEmpty()) {
                sacrificedPermanent = sacrificeCost.getPermanents().get(0);
            }
            break;
        }
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (sacrificedPermanent == null || controller == null) {
        return false;
    }
    int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
    FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
    filter.add(CardType.CREATURE.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            ContinuousEffectImpl effect = new NeoformReplacementEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
            if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                effect.discard();
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 3 with ContinuousEffectImpl

use of mage.abilities.effects.ContinuousEffectImpl in project mage by magefree.

the class ChainerDementiaMasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID cardId = this.getTargetPointer().getFirst(game, source);
        new ReturnFromGraveyardToBattlefieldTargetEffect().apply(game, source);
        Permanent permanent = game.getPermanent(cardId);
        if (permanent != null) {
            ContinuousEffectImpl effect = new BecomesColorTargetEffect(ObjectColor.BLACK, Duration.WhileOnBattlefield);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
            effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, SubType.NIGHTMARE, false);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) BecomesColorTargetEffect(mage.abilities.effects.common.continuous.BecomesColorTargetEffect) Player(mage.players.Player) BecomesCreatureTypeTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTypeTargetEffect) ReturnFromGraveyardToBattlefieldTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) UUID(java.util.UUID)

Example 4 with ContinuousEffectImpl

use of mage.abilities.effects.ContinuousEffectImpl in project mage by magefree.

the class GainAbilityDependenciesTest method test_GenerationByFilters.

@Test
public void test_GenerationByFilters() {
    // auto-dependency must find subtype predicate and add dependecy on it
    FilterPermanent filterEmpty = new FilterPermanent("empty");
    FilterPermanent filterSubtype = new FilterPermanent(SubType.HUMAN, "single");
    FilterPermanent filterOr = new FilterPermanent("or");
    filterOr.add(Predicates.or(SubType.HUMAN.getPredicate(), SubType.ORC.getPredicate()));
    FilterPermanent filterTree = new FilterPermanent("tree");
    filterTree.add(Predicates.and(new NamePredicate("test"), Predicates.or(SubType.HUMAN.getPredicate(), SubType.ORC.getPredicate())));
    FilterPermanent filterNotTree = new FilterPermanent("tree");
    filterNotTree.add(Predicates.not(Predicates.or(SubType.HUMAN.getPredicate(), SubType.ORC.getPredicate())));
    ContinuousEffectImpl effectEmpty = new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filterEmpty);
    ContinuousEffectImpl effectSubtype = new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filterSubtype);
    ContinuousEffectImpl effectOr = new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filterOr);
    ContinuousEffectImpl effectTree = new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filterTree);
    ContinuousEffectImpl effectNotTree = new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filterNotTree);
    Assert.assertFalse("must haven't depends with empty filter", effectEmpty.getDependedToTypes().contains(DependencyType.AddingCreatureType));
    Assert.assertTrue("must have depend from subtype predicate", effectSubtype.getDependedToTypes().contains(DependencyType.AddingCreatureType));
    Assert.assertTrue("must have depend from or predicate", effectOr.getDependedToTypes().contains(DependencyType.AddingCreatureType));
    Assert.assertTrue("must have depend from tree predicate", effectTree.getDependedToTypes().contains(DependencyType.AddingCreatureType));
    Assert.assertTrue("must have depend from not-tree predicate", effectNotTree.getDependedToTypes().contains(DependencyType.AddingCreatureType));
}
Also used : NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect) Test(org.junit.Test)

Aggregations

ContinuousEffectImpl (mage.abilities.effects.ContinuousEffectImpl)4 Permanent (mage.game.permanent.Permanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 FilterPermanent (mage.filter.FilterPermanent)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 Player (mage.players.Player)2 UUID (java.util.UUID)1 Cost (mage.abilities.costs.Cost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 ReturnFromGraveyardToBattlefieldTargetEffect (mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect)1 AttacksIfAbleTargetEffect (mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)1 BlocksIfAbleTargetEffect (mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect)1 CantAttackTargetEffect (mage.abilities.effects.common.combat.CantAttackTargetEffect)1 CantBlockTargetEffect (mage.abilities.effects.common.combat.CantBlockTargetEffect)1 BecomesColorTargetEffect (mage.abilities.effects.common.continuous.BecomesColorTargetEffect)1 BecomesCreatureTypeTargetEffect (mage.abilities.effects.common.continuous.BecomesCreatureTypeTargetEffect)1 GainAbilityAllEffect (mage.abilities.effects.common.continuous.GainAbilityAllEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 Card (mage.cards.Card)1 FilterCard (mage.filter.FilterCard)1