* 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);
@ -48,7 +44,7 @@ public final class ForgottenAncient extends CardImpl {
Effect effect = new AddCountersSourceEffect(CounterType.P1P1.createInstance());
Ability ability = new SpellCastAllTriggeredAbility(effect, true);
this.addAbility(ability);
// At the beginning of your upkeep, you may move any number of +1/+1 counters from Forgotten Ancient onto other creatures.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new ForgottenAncientEffect(), TargetController.YOU, true));
}
@ -61,70 +57,79 @@ public final class ForgottenAncient extends CardImpl {
public ForgottenAncient copy() {
return new ForgottenAncient(this);
}
class CounterMovement {
public UUID target;
public int counters;
}
class ForgottenAncientEffect extends OneShotEffect {
public ForgottenAncientEffect() {
super(Outcome.Benefit);
this.staticText = "you may move any number of +1/+1 counters from {this} onto other creatures.";
}
public ForgottenAncientEffect(final ForgottenAncientEffect effect) {
super(effect);
}
@Override
public ForgottenAncientEffect copy() {
return new ForgottenAncientEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
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)
{
boolean previouslyChosen = false;
for (CounterMovement cm : counterMovements) {
if(cm.target.equals(target.getFirstTarget()))
{
cm.counters += amountToMove;
previouslyChosen = true;
}
}
if(!previouslyChosen) {
CounterMovement cm = new CounterMovement();
cm.target = target.getFirstTarget();
cm.counters = amountToMove;
counterMovements.add(cm);
}
numCounters -= amountToMove;
if (amountToMove == 0) {
break;
}
} while(numCounters > 0 && controller.chooseUse(Outcome.Benefit, "Move additonal counters?", source, game));
boolean previouslyChosen = false;
for (CounterMovement cm : counterMovements) {
if (cm.target.equals(target.getFirstTarget())) {
cm.counters += amountToMove;
previouslyChosen = true;
}
}
if (!previouslyChosen) {
CounterMovement cm = new CounterMovement();
cm.target = target.getFirstTarget();
cm.counters = amountToMove;
counterMovements.add(cm);
}
numCounters -= amountToMove;
} 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);
}