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;
}
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;
}
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;
}
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));
}
Aggregations