use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class ShowOfDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int highestPower = Integer.MIN_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (highestPower < permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = permanent;
} else if (highestPower == permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = null;
}
}
if (highestPower != Integer.MIN_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
effect.setTargetPointer(target);
effect.apply(game, source);
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(target);
game.addEffect(continuousEffect, source);
return true;
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class SoulScarMageDamageReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent toGetCounters = game.getPermanent(event.getTargetId());
if (toGetCounters != null) {
AddCountersTargetEffect addCounters = new AddCountersTargetEffect(CounterType.M1M1.createInstance(), StaticValue.get(event.getAmount()));
addCounters.setTargetPointer(new FixedTarget(toGetCounters.getId(), game));
addCounters.apply(game, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class LesserWerewolfEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
// must be valid target
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (controller != null && sourcePermanent != null && targetPermanent != null) {
if (sourcePermanent.getPower().getValue() >= 1) {
game.addEffect(new BoostSourceEffect(-1, 0, Duration.EndOfTurn), source);
new AddCountersTargetEffect(new BoostCounter(0, -1), outcome).apply(game, source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class ServantOfTheScaleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (sourcePermanent != null && controller != null && (// Token
sourcePermanent.getZoneChangeCounter(game) == source.getSourceObjectZoneChangeCounter() || sourcePermanent.getZoneChangeCounter(game) + 1 == source.getSourceObjectZoneChangeCounter())) {
// PermanentCard
int amount = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
if (amount > 0) {
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount));
effect.setTargetPointer(targetPointer);
effect.apply(game, source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.
the class TormentOfVenomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
if (controllingPlayer != null) {
int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
Target target = new TargetPermanent(filter);
if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
}
}
if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
controllingPlayer.discardOne(false, false, source, game);
return true;
}
controllingPlayer.loseLife(3, game, source, false);
return true;
}
}
return false;
}
Aggregations