mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
* Turnabout - Fixed possible endless loops for player choices.
This commit is contained in:
parent
422b92e4ad
commit
d204af0b55
1 changed files with 38 additions and 36 deletions
|
@ -29,15 +29,14 @@ package mage.sets.urzassaga;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mage.constants.CardType;
|
|
||||||
import mage.constants.Rarity;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.choices.ChoiceImpl;
|
import mage.choices.ChoiceImpl;
|
||||||
|
import mage.constants.CardType;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
|
import mage.constants.Rarity;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||||
|
@ -53,13 +52,10 @@ import mage.target.TargetPlayer;
|
||||||
*/
|
*/
|
||||||
public class Turnabout extends CardImpl {
|
public class Turnabout extends CardImpl {
|
||||||
|
|
||||||
|
|
||||||
public Turnabout(UUID ownerId) {
|
public Turnabout(UUID ownerId) {
|
||||||
super(ownerId, 105, "Turnabout", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{U}{U}");
|
super(ownerId, 105, "Turnabout", Rarity.UNCOMMON, new CardType[]{CardType.INSTANT}, "{2}{U}{U}");
|
||||||
this.expansionSetCode = "USG";
|
this.expansionSetCode = "USG";
|
||||||
|
|
||||||
this.color.setBlue(true);
|
|
||||||
|
|
||||||
// Choose artifact, creature, or land. Tap all untapped permanents of the chosen type target player controls, or untap all tapped permanents of that type that player controls.
|
// Choose artifact, creature, or land. Tap all untapped permanents of the chosen type target player controls, or untap all tapped permanents of that type that player controls.
|
||||||
this.getSpellAbility().addTarget(new TargetPlayer());
|
this.getSpellAbility().addTarget(new TargetPlayer());
|
||||||
this.getSpellAbility().addEffect(new TurnaboutEffect());
|
this.getSpellAbility().addEffect(new TurnaboutEffect());
|
||||||
|
@ -78,14 +74,16 @@ public class Turnabout extends CardImpl {
|
||||||
|
|
||||||
class TurnaboutEffect extends OneShotEffect {
|
class TurnaboutEffect extends OneShotEffect {
|
||||||
|
|
||||||
private static final HashSet<String> choice = new HashSet<String>();
|
private static final HashSet<String> choice = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
choice.add(CardType.ARTIFACT.toString());
|
choice.add(CardType.ARTIFACT.toString());
|
||||||
choice.add(CardType.CREATURE.toString());
|
choice.add(CardType.CREATURE.toString());
|
||||||
choice.add(CardType.LAND.toString());
|
choice.add(CardType.LAND.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashSet<String> choice2 = new HashSet<String>();
|
private static final HashSet<String> choice2 = new HashSet<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
choice2.add("Untap");
|
choice2.add("Untap");
|
||||||
choice2.add("Tap");
|
choice2.add("Tap");
|
||||||
|
@ -107,12 +105,16 @@ class TurnaboutEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
UUID target = source.getFirstTarget();
|
UUID target = source.getFirstTarget();
|
||||||
if(player != null && target != null){
|
if (controller != null && target != null) {
|
||||||
Choice choiceImpl = new ChoiceImpl();
|
Choice choiceImpl = new ChoiceImpl();
|
||||||
choiceImpl.setChoices(choice);
|
choiceImpl.setChoices(choice);
|
||||||
while(!player.choose(outcome.Neutral, choiceImpl, game));
|
while (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
|
||||||
|
if (!controller.isInGame()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
CardType type;
|
CardType type;
|
||||||
String choosenType = choiceImpl.getChoice();
|
String choosenType = choiceImpl.getChoice();
|
||||||
|
|
||||||
|
@ -126,12 +128,15 @@ class TurnaboutEffect extends OneShotEffect {
|
||||||
|
|
||||||
choiceImpl = new ChoiceImpl();
|
choiceImpl = new ChoiceImpl();
|
||||||
choiceImpl.setChoices(choice2);
|
choiceImpl.setChoices(choice2);
|
||||||
while(!player.choose(outcome.Neutral, choiceImpl, game));
|
while (!controller.choose(Outcome.Neutral, choiceImpl, game)) {
|
||||||
|
if (!controller.isInGame()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FilterPermanent filter = new FilterPermanent();
|
FilterPermanent filter = new FilterPermanent();
|
||||||
filter.add(new CardTypePredicate(type));
|
filter.add(new CardTypePredicate(type));
|
||||||
|
|
||||||
|
|
||||||
if (choiceImpl.getChoice().equals("Untap")) {
|
if (choiceImpl.getChoice().equals("Untap")) {
|
||||||
filter.add(new TappedPredicate());
|
filter.add(new TappedPredicate());
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
|
||||||
|
@ -139,8 +144,7 @@ class TurnaboutEffect extends OneShotEffect {
|
||||||
permanent.untap(game);
|
permanent.untap(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
filter.add(Predicates.not(new TappedPredicate()));
|
filter.add(Predicates.not(new TappedPredicate()));
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
|
||||||
if (permanent.getControllerId().equals(target)) {
|
if (permanent.getControllerId().equals(target)) {
|
||||||
|
@ -149,10 +153,8 @@ class TurnaboutEffect extends OneShotEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue