mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
[NPH] Fix Hex Parasite wrong behaviour when X=0. Closes #9446.
This commit is contained in:
parent
9b0e63ef30
commit
bfa5b6ab5f
2 changed files with 74 additions and 27 deletions
|
@ -66,34 +66,37 @@ class HexParasiteEffect extends OneShotEffect {
|
|||
TargetPermanent target = (TargetPermanent) source.getTargets().get(0);
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (permanent != null
|
||||
&& controller != null) {
|
||||
int toRemove = source.getManaCostsToPay().getX();
|
||||
int removed = 0;
|
||||
String[] counterNames = permanent.getCounters(game).keySet().toArray(new String[0]);
|
||||
for (String counterName : counterNames) {
|
||||
if (controller.chooseUse(Outcome.Neutral, "Remove " + counterName + " counters?", source, game)) {
|
||||
if (permanent.getCounters(game).get(counterName).getCount() == 1 || (toRemove - removed == 1)) {
|
||||
permanent.removeCounters(counterName, 1, source, game);
|
||||
removed++;
|
||||
} else {
|
||||
int amount = controller.getAmount(1, Math.min(permanent.getCounters(game).get(counterName).getCount(), toRemove - removed), "How many?", game);
|
||||
if (amount > 0) {
|
||||
removed += amount;
|
||||
permanent.removeCounters(counterName, amount, source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removed >= toRemove) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (removed > 0) {
|
||||
game.addEffect(new BoostSourceEffect(removed, 0, Duration.EndOfTurn), source);
|
||||
}
|
||||
if (permanent == null || controller == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int toRemove = source.getManaCostsToPay().getX();
|
||||
if (toRemove == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int removed = 0;
|
||||
String[] counterNames = permanent.getCounters(game).keySet().toArray(new String[0]);
|
||||
for (String counterName : counterNames) {
|
||||
if (controller.chooseUse(Outcome.Neutral, "Remove " + counterName + " counters?", source, game)) {
|
||||
if (permanent.getCounters(game).get(counterName).getCount() == 1 || (toRemove - removed == 1)) {
|
||||
permanent.removeCounters(counterName, 1, source, game);
|
||||
removed++;
|
||||
} else {
|
||||
int amount = controller.getAmount(1, Math.min(permanent.getCounters(game).get(counterName).getCount(), toRemove - removed), "How many?", game);
|
||||
if (amount > 0) {
|
||||
removed += amount;
|
||||
permanent.removeCounters(counterName, amount, source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removed >= toRemove) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (removed > 0) {
|
||||
game.addEffect(new BoostSourceEffect(removed, 0, Duration.EndOfTurn), source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.mage.test.cards.single.nph;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* {@link mage.cards.h.HexParasite Hex Parasite}
|
||||
*
|
||||
* {X}{B/P}: Remove up to X counters from target permanent.
|
||||
* For each counter removed this way, Hex Parasite gets +1/+0 until end of turn.
|
||||
*
|
||||
* @author Alex-Vasile
|
||||
*/
|
||||
public class HexParasiteTest extends CardTestPlayerBase {
|
||||
|
||||
private static final String hexParasite = "Hex Parasite";
|
||||
|
||||
/**
|
||||
* Reported bug: https://github.com/magefree/mage/issues/9446
|
||||
* Removing 0 counters results in "Server's error: (minimum = value = maximum) is false"
|
||||
*/
|
||||
@Test
|
||||
public void remove0Counters() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, hexParasite);
|
||||
addCard(Zone.HAND, playerA, "Urza's Saga");
|
||||
|
||||
setStrictChooseMode(true);
|
||||
|
||||
playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Urza's Saga");
|
||||
|
||||
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "{X}");
|
||||
setChoice(playerA, "X=0");
|
||||
setChoice(playerA, "Yes"); // Pay 2 life
|
||||
addTarget(playerA, "Urza's Saga");
|
||||
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertCounterCount(playerA, "Urza's Saga", CounterType.LORE, 1);
|
||||
assertLife(playerA, 20 - 2);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue