[ONE] Implement Infectious Bite

This commit is contained in:
theelk801 2023-01-25 09:13:10 -05:00
parent efcda8cf2a
commit 602e622c7d
13 changed files with 177 additions and 105 deletions

View file

@ -16,19 +16,14 @@ import java.util.UUID;
public class AddCountersControllerEffect extends OneShotEffect {
private Counter counter;
private final boolean enchantedEquipped;
/**
* @param counter Counter to add. Includes type and amount.
* @param enchantedEquipped If true, not source controller will get the
* counter, but the permanent's controller that the source permanent
* enchants or equippes.
* @param counter Counter to add. Includes type and amount.
*/
public AddCountersControllerEffect(Counter counter, boolean enchantedEquipped) {
public AddCountersControllerEffect(Counter counter) {
super(Outcome.Benefit);
this.counter = counter.copy();
this.enchantedEquipped = enchantedEquipped;
staticText = (enchantedEquipped ? "its controller gets " : "you get ") + counter.getDescription();
staticText = "you get" + counter.getDescription();
}
public AddCountersControllerEffect(final AddCountersControllerEffect effect) {
@ -36,27 +31,11 @@ public class AddCountersControllerEffect extends OneShotEffect {
if (effect.counter != null) {
this.counter = effect.counter.copy();
}
this.enchantedEquipped = effect.enchantedEquipped;
}
@Override
public boolean apply(Game game, Ability source) {
UUID uuid = source.getControllerId();
if (this.enchantedEquipped) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
UUID eUuid = enchantment.getAttachedTo();
Permanent permanent = game.getPermanent(eUuid);
if (permanent != null) {
uuid = permanent.getControllerId();
} else {
return false;
}
} else {
return false;
}
}
Player player = game.getPlayer(uuid);
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.addCounters(counter, source.getControllerId(), source, game);
return true;

View file

@ -0,0 +1,105 @@
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.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 {
private final int amount;
private final TargetController targetController;
public AddPoisonCounterAllEffect(TargetController targetController) {
this(1, targetController);
}
public AddPoisonCounterAllEffect(int amount, TargetController targetController) {
super(Outcome.Benefit);
this.amount = amount;
this.targetController = targetController;
staticText = makeText();
}
private AddPoisonCounterAllEffect(final AddPoisonCounterAllEffect effect) {
super(effect);
this.amount = effect.amount;
this.targetController = effect.targetController;
}
@Override
public AddPoisonCounterAllEffect copy() {
return new AddPoisonCounterAllEffect(this);
}
private Collection<UUID> getPlayers(Game game, Ability source) {
switch (targetController) {
case OPPONENT:
return game.getOpponents(source.getControllerId());
case EACH_PLAYER:
case ANY:
return game.getState().getPlayersInRange(source.getControllerId(), game);
case YOU:
return Arrays.asList(source.getControllerId());
case CONTROLLER_ATTACHED_TO:
List<UUID> list = new ArrayList<>();
Optional.ofNullable(source.getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(Permanent::getAttachedTo)
.map(game::getControllerId)
.filter(Objects::nonNull)
.ifPresent(list::add);
return list;
default:
throw new UnsupportedOperationException(targetController + " not supported");
}
}
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : getPlayers(game, source)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.addCounters(CounterType.POISON.createInstance(amount), source.getControllerId(), source, game);
}
}
return true;
}
public String makeText() {
StringBuilder sb = new StringBuilder();
switch (targetController) {
case OPPONENT:
sb.append("each opponent gets");
break;
case ANY:
case EACH_PLAYER:
sb.append("each player gets");
break;
case YOU:
sb.append("you get");
break;
case CONTROLLER_ATTACHED_TO:
sb.append("its controller gets");
break;
default:
throw new UnsupportedOperationException(targetController + " not supported");
}
sb.append(' ' + CardUtil.numberToText(amount, "a") + " poison counter");
if (amount > 1) {
sb.append('s');
}
return sb.toString();
}
}