* 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.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
@ -29,17 +25,17 @@ import java.util.List;
import java.util.UUID;
/**
*
* @author Blinke
*/
public final class ForgottenAncient extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature");
static {
filter.add(AnotherPredicate.instance);
}
public ForgottenAncient(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{G}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{G}");
this.subtype.add(SubType.ELEMENTAL);
this.power = new MageInt(0);
this.toughness = new MageInt(3);
@ -88,31 +84,40 @@ public final class ForgottenAncient extends CardImpl {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if(controller == null || sourcePermanent == null) {
if (controller == null || sourcePermanent == null) {
return false;
}
int numCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
if (numCounters == 0) {
return false;
}
List<CounterMovement> counterMovements = new ArrayList<>();
do {
Target target = new TargetCreaturePermanent(1, 1, filter, true);
if(numCounters == 0 || !target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) {
continue;
if (!target.canChoose(source.getSourceId(), controller.getId(), game)) {
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);
if(amountToMove > 0)
{
if (amountToMove == 0) {
break;
}
boolean previouslyChosen = false;
for (CounterMovement cm : counterMovements) {
if(cm.target.equals(target.getFirstTarget()))
{
if (cm.target.equals(target.getFirstTarget())) {
cm.counters += amountToMove;
previouslyChosen = true;
}
}
if(!previouslyChosen) {
if (!previouslyChosen) {
CounterMovement cm = new CounterMovement();
cm.target = target.getFirstTarget();
cm.counters = amountToMove;
@ -120,11 +125,11 @@ public final class ForgottenAncient extends CardImpl {
}
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
for(CounterMovement cm: counterMovements) {
for (CounterMovement cm : counterMovements) {
sourcePermanent.removeCounters(CounterType.P1P1.createInstance(cm.counters), game);
game.getPermanent(cm.target).addCounters(CounterType.P1P1.createInstance(cm.counters), source, game);
}