use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.
the class OutOfTimeReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> creatures = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
int numCreatures = creatures.size();
if (numCreatures > 0) {
Set<UUID> creatureIds = new HashSet<>(numCreatures);
for (Permanent creature : creatures) {
creature.untap(game);
creatureIds.add(creature.getId());
}
// https://magic.wizards.com/en/articles/archive/feature/modern-horizons-2-release-notes-2021-06-04
// If Out of Time leaves the battlefield before its enter the battlefield trigger resolves, creatures will untap, but they won't phase out.
Permanent outOfTime = game.getPermanent(source.getSourceId());
if (outOfTime != null) {
new PhaseOutAllEffect(new ArrayList<>(creatureIds)).apply(game, source);
new AddCountersSourceEffect(CounterType.TIME.createInstance(numCreatures)).apply(game, source);
game.getState().setValue("phasedOutCreatures" + source.getId().toString(), creatureIds);
game.getState().setValue("phasedOutBySourceId" + source.getSourceId(), source.getId());
game.addDelayedTriggeredAbility(new OutOfTimeDelayedTriggeredAbility(), source);
game.addEffect(new OutOfTimeReplacementEffect(), source);
}
}
return true;
}
use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.
the class PoultrygeistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int result = controller.rollDice(outcome, source, game, 6);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (result == 1) {
return permanent.sacrifice(source, game);
} else {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
}
}
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.
the class SpectralAdversaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Integer timesPaid = (Integer) getValue("timesPaid");
if (timesPaid == null || timesPaid <= 0) {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(timesPaid)), false, staticText);
ability.addEffect(new PhaseOutTargetEffect());
ability.addTarget(new TargetPermanent(0, timesPaid, filter));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.
the class FlowstoneSculptureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose ability to add");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
String chosen = choice.getChoice();
if (chosen.equals("+1/+1 counter")) {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
} else {
Ability gainedAbility;
switch(chosen) {
case "Flying":
gainedAbility = FlyingAbility.getInstance();
break;
case "First strike":
gainedAbility = FirstStrikeAbility.getInstance();
break;
default:
gainedAbility = TrampleAbility.getInstance();
break;
}
game.addEffect(new GainAbilitySourceEffect(gainedAbility, Duration.WhileOnBattlefield), source);
return true;
}
}
return false;
}
use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.
the class GallopingLizrogEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
RemoveVariableCountersTargetCost variableCost = new RemoveVariableCountersTargetCost(StaticFilters.FILTER_CONTROLLED_CREATURE, CounterType.P1P1);
int toPay = variableCost.announceXValue(source, game);
Cost cost = variableCost.getFixedCostsFromAnnouncedValue(toPay);
if (!cost.pay(source, game, source, source.getControllerId(), true)) {
return false;
}
return new AddCountersSourceEffect(CounterType.P1P1.createInstance(2 * toPay)).apply(game, source);
}
Aggregations