use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class GreaterWerewolfEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
Effect effect = new AddCountersTargetEffect(CounterType.M0M2.createInstance(), Outcome.UnboostCreature);
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class EssenceFluxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToBattlefield = new CardsImpl();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
UUID mainCardId = CardUtil.getMainCardId(game, targetId);
if (game.getExile().containsId(mainCardId, game)) {
cardsToBattlefield.add(mainCardId);
} else {
Card card = game.getCard(targetId);
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();
if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
cardsToBattlefield.add(topCard);
}
if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
cardsToBattlefield.add(bottomCard);
}
}
}
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
for (UUID cardId : cardsToBattlefield) {
Permanent permanent = game.getPermanent(cardId);
if (permanent != null && permanent.hasSubtype(SubType.SPIRIT, game)) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance());
effect.setTargetPointer(new FixedTarget(permanent, game));
return effect.apply(game, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class FierceInvocationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
new ManifestEffect(1).apply(game, source);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(2));
effect.setTargetPointer(new FixedTarget(permanent, game));
return effect.apply(game, source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class RakdosRiteknifeEffect method makeAbility.
private static Ability makeAbility(Permanent permanent, Game game) {
Ability ability = new SimpleActivatedAbility(new AddCountersTargetEffect(CounterType.BLOOD.createInstance()).setText("put a blood counter on " + permanent.getName()).setTargetPointer(new FixedTarget(permanent, game)), new TapSourceCost());
ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT)));
return ability;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class BolsterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (amount.calculate(game, source, this) <= 0) {
return true;
}
int leastToughness = Integer.MAX_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (leastToughness > permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = permanent;
} else if (leastToughness == permanent.getToughness().getValue()) {
leastToughness = permanent.getToughness().getValue();
selectedCreature = null;
}
}
if (leastToughness != Integer.MAX_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
effect.setTargetPointer(new FixedTarget(selectedCreature, game));
return effect.apply(game, source);
}
}
return true;
}
return false;
}
Aggregations