[WOC] Implement Court of Garenbrig (#10970)

* add DoubleCounterOnEachPermanentEffect

* Clean text generation of ConditionalOneShotEffect to prevent "if if"

* [WOC] Implement Court of Garenbrig

* better rule generation

* fix target, add tests
This commit is contained in:
Susucre 2023-09-09 21:31:49 +02:00 committed by GitHub
parent a8887e743a
commit 8b79053deb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 275 additions and 37 deletions

View file

@ -0,0 +1,51 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.List;
/**
* @author Susucr
*/
public class DoubleCounterOnEachPermanentEffect extends OneShotEffect {
private final CounterType counterType;
private final FilterPermanent filter;
public DoubleCounterOnEachPermanentEffect(CounterType counterType, FilterPermanent filter) {
super(Outcome.BoostCreature);
this.counterType = counterType;
this.filter = filter.copy();
this.staticText = "double the number of " + counterType.getName() + " counters on each " + filter.getMessage();
}
private DoubleCounterOnEachPermanentEffect(final DoubleCounterOnEachPermanentEffect effect) {
super(effect);
this.counterType = effect.counterType;
this.filter = effect.filter.copy();
}
@Override
public DoubleCounterOnEachPermanentEffect copy() {
return new DoubleCounterOnEachPermanentEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game);
for (Permanent permanent : permanents) {
int existingCounters = permanent.getCounters(game).getCount(counterType);
if (existingCounters > 0) {
permanent.addCounters(counterType.createInstance(existingCounters), source.getControllerId(), source, game);
}
}
return true;
}
}