foul-magics/Mage/src/main/java/mage/abilities/effects/common/RemoveAllCountersSourceEffect.java
2018-06-02 17:59:49 +02:00

45 lines
1.3 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LoneFox
*/
public class RemoveAllCountersSourceEffect extends OneShotEffect {
private final CounterType counterType;
public RemoveAllCountersSourceEffect(CounterType counterType) {
super(Outcome.Neutral);
this.counterType = counterType;
staticText = "remove all " + counterType.getName() + " counters from it.";
}
public RemoveAllCountersSourceEffect(final RemoveAllCountersSourceEffect effect) {
super(effect);
this.counterType = effect.counterType;
}
@Override
public RemoveAllCountersSourceEffect copy() {
return new RemoveAllCountersSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int count = sourcePermanent.getCounters(game).getCount(counterType);
sourcePermanent.removeCounters(counterType.getName(), count, game);
return true;
}
return false;
}
}