* Forgotten Ancient - fixed AI game freeze, improved dialog logic (#5023);

This commit is contained in:
Oleg Agafonov 2019-04-04 10:20:45 +04:00
parent 238aa7abdc
commit 7ab73dec60

View file

@ -10,11 +10,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.*;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate; import mage.filter.predicate.permanent.AnotherPredicate;
@ -29,11 +25,11 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
*
* @author Blinke * @author Blinke
*/ */
public final class ForgottenAncient extends CardImpl { public final class ForgottenAncient extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature"); private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature");
static { static {
filter.add(AnotherPredicate.instance); filter.add(AnotherPredicate.instance);
} }
@ -93,21 +89,30 @@ public final class ForgottenAncient extends CardImpl {
} }
int numCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1); int numCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
if (numCounters == 0) {
return false;
}
List<CounterMovement> counterMovements = new ArrayList<>(); List<CounterMovement> counterMovements = new ArrayList<>();
do { do {
Target target = new TargetCreaturePermanent(1, 1, filter, true); Target target = new TargetCreaturePermanent(1, 1, filter, true);
if(numCounters == 0 || !target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) { if (!target.canChoose(source.getSourceId(), controller.getId(), game)) {
continue; break;
}
if (!target.choose(Outcome.BoostCreature, source.getControllerId(), source.getSourceId(), game)) {
break;
} }
int amountToMove = controller.getAmount(0, numCounters, "How many counters do you want to move? " + '(' + numCounters + ')' + " counters remaining.", game); int amountToMove = controller.getAmount(0, numCounters, "How many counters do you want to move? " + '(' + numCounters + ')' + " counters remaining.", game);
if(amountToMove > 0) if (amountToMove == 0) {
{ break;
}
boolean previouslyChosen = false; boolean previouslyChosen = false;
for (CounterMovement cm : counterMovements) { for (CounterMovement cm : counterMovements) {
if(cm.target.equals(target.getFirstTarget())) if (cm.target.equals(target.getFirstTarget())) {
{
cm.counters += amountToMove; cm.counters += amountToMove;
previouslyChosen = true; previouslyChosen = true;
} }
@ -120,8 +125,8 @@ public final class ForgottenAncient extends CardImpl {
} }
numCounters -= amountToMove; numCounters -= amountToMove;
}
} while(numCounters > 0 && controller.chooseUse(Outcome.Benefit, "Move additonal counters?", source, game)); } while (numCounters > 0 && controller.chooseUse(Outcome.Benefit, "Move additional counters?", source, game));
//Move all the counters for each chosen creature //Move all the counters for each chosen creature
for (CounterMovement cm : counterMovements) { for (CounterMovement cm : counterMovements) {