[MOM] fixed Artistic Refusal (wrong modes), added additional checks for modes

This commit is contained in:
Oleg Agafonov 2023-04-05 12:13:36 +04:00
parent dddb7363b2
commit 64434fbcbc
3 changed files with 18 additions and 2 deletions

View file

@ -24,7 +24,7 @@ public final class ArtisticRefusal extends CardImpl {
// Choose one or both -- // Choose one or both --
this.getSpellAbility().getModes().setMinModes(1); this.getSpellAbility().getModes().setMinModes(1);
this.getSpellAbility().getModes().setMinModes(2); this.getSpellAbility().getModes().setMaxModes(2);
// * Counter target spell. // * Counter target spell.
this.getSpellAbility().addEffect(new CounterTargetEffect()); this.getSpellAbility().addEffect(new CounterTargetEffect());

View file

@ -937,6 +937,21 @@ public abstract class AbilityImpl implements Ability {
@Override @Override
public void addMode(Mode mode) { public void addMode(Mode mode) {
getModes().addMode(mode); getModes().addMode(mode);
// runtime check: modes must have good settings
int currentMin = getModes().getMinModes();
int currentMax = getModes().getMaxModes(null, null);
boolean isFine = true;
if (currentMin < 0 || currentMax < 0) {
isFine = false;
}
if (currentMin > 0 && currentMin > currentMax) {
isFine = false;
}
if (!isFine) {
throw new IllegalArgumentException(String.format("Wrong code usage: you must setup correct min and max modes (%d, %d) for %s",
currentMin, currentMax, this));
}
} }
@Override @Override

View file

@ -490,7 +490,8 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
} else if (this.getMinModes() == this.getMaxModes(null, null)) { } else if (this.getMinModes() == this.getMaxModes(null, null)) {
sb.append(CardUtil.numberToText(this.getMinModes())); sb.append(CardUtil.numberToText(this.getMinModes()));
} else { } else {
throw new UnsupportedOperationException("no text available for this selection of min and max modes"); throw new UnsupportedOperationException(String.format("no text available for this selection of min and max modes (%d and %d)",
this.getMinModes(), this.getMaxModes(null, null)));
} }
} else { } else {
sb.append(chooseText); sb.append(chooseText);