consolidate effects which add counters to players

This commit is contained in:
theelk801 2023-01-26 08:35:39 -05:00
parent de3efda5ce
commit f942c36651
12 changed files with 74 additions and 152 deletions

View file

@ -1,50 +0,0 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.Counter;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.UUID;
/**
* @author nantuko
*/
public class AddCountersControllerEffect extends OneShotEffect {
private Counter counter;
/**
* @param counter Counter to add. Includes type and amount.
*/
public AddCountersControllerEffect(Counter counter) {
super(Outcome.Benefit);
this.counter = counter.copy();
staticText = "you get" + counter.getDescription();
}
public AddCountersControllerEffect(final AddCountersControllerEffect effect) {
super(effect);
if (effect.counter != null) {
this.counter = effect.counter.copy();
}
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.addCounters(counter, source.getControllerId(), source, game);
return true;
}
return false;
}
@Override
public AddCountersControllerEffect copy() {
return new AddCountersControllerEffect(this);
}
}

View file

@ -1,46 +1,40 @@
package mage.abilities.effects.common.counter;
import mage.abilities.Ability;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.counters.CounterType;
import mage.counters.Counter;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.*;
/**
* @author TheElk801
*/
public class AddPoisonCounterAllEffect extends OneShotEffect {
public class AddCountersPlayersEffect extends OneShotEffect {
private final int amount;
private final Counter counter;
private final TargetController targetController;
public AddPoisonCounterAllEffect(TargetController targetController) {
this(1, targetController);
}
public AddPoisonCounterAllEffect(int amount, TargetController targetController) {
public AddCountersPlayersEffect(Counter counter, TargetController targetController) {
super(Outcome.Benefit);
this.amount = amount;
this.counter = counter;
this.targetController = targetController;
staticText = makeText();
}
private AddPoisonCounterAllEffect(final AddPoisonCounterAllEffect effect) {
private AddCountersPlayersEffect(final AddCountersPlayersEffect effect) {
super(effect);
this.amount = effect.amount;
this.counter = effect.counter;
this.targetController = effect.targetController;
}
@Override
public AddPoisonCounterAllEffect copy() {
return new AddPoisonCounterAllEffect(this);
public AddCountersPlayersEffect copy() {
return new AddCountersPlayersEffect(this);
}
private Collection<UUID> getPlayers(Game game, Ability source) {
@ -71,7 +65,7 @@ public class AddPoisonCounterAllEffect extends OneShotEffect {
for (UUID playerId : getPlayers(game, source)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.addCounters(CounterType.POISON.createInstance(amount), source.getControllerId(), source, game);
player.addCounters(counter, source.getControllerId(), source, game);
}
}
return true;
@ -96,10 +90,8 @@ public class AddPoisonCounterAllEffect extends OneShotEffect {
default:
throw new UnsupportedOperationException(targetController + " not supported");
}
sb.append(' ' + CardUtil.numberToText(amount, "a") + " poison counter");
if (amount > 1) {
sb.append('s');
}
sb.append(' ');
sb.append(counter.getDescription());
return sb.toString();
}
}