mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00: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());
|
||||||
|
@ -77,20 +73,22 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TurnaboutEffect() {
|
public TurnaboutEffect() {
|
||||||
super(Outcome.Benefit);
|
super(Outcome.Benefit);
|
||||||
staticText = "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";
|
staticText = "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";
|
||||||
|
@ -107,52 +105,56 @@ 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();
|
||||||
|
|
||||||
if(choosenType.equals(CardType.ARTIFACT.toString())){
|
if (choosenType.equals(CardType.ARTIFACT.toString())) {
|
||||||
type = CardType.ARTIFACT;
|
type = CardType.ARTIFACT;
|
||||||
}else if(choosenType.equals(CardType.LAND.toString())){
|
} else if (choosenType.equals(CardType.LAND.toString())) {
|
||||||
type = CardType.LAND;
|
type = CardType.LAND;
|
||||||
}else{
|
} else {
|
||||||
type = CardType.CREATURE;
|
type = CardType.CREATURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
if(permanent.getControllerId().equals(target)){
|
if (permanent.getControllerId().equals(target)) {
|
||||||
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)) {
|
||||||
permanent.tap(game);
|
permanent.tap(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue