* Armory Automaton - fixed infinite AI choose, added selects target cancel (#5023);

This commit is contained in:
Oleg Agafonov 2019-03-10 02:07:29 +04:00
parent 2b4a01410b
commit 3d70dadc22

View file

@ -1,7 +1,5 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility; import mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility;
@ -11,16 +9,22 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterArtifactPermanent; import mage.filter.common.FilterArtifactPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardIdPredicate;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.permanent.AttachedToPredicate;
import mage.filter.predicate.permanent.PermanentIdPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import java.util.UUID;
/** /**
*
* @author spjspj * @author spjspj
*/ */
public final class ArmoryAutomaton extends CardImpl { public final class ArmoryAutomaton extends CardImpl {
@ -73,9 +77,17 @@ class ArmoryAutomatonEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) { if (player != null && sourcePermanent != null) {
int countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game).size() - sourcePermanent.getAttachments().size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Attach a target Equipment?", source, game)) { // dynamic filter (can't selects own attaches and can't selects twice)
Target targetEquipment = new TargetPermanent(filter); FilterPermanent currentFilter = filter.copy();
FilterPermanent filterSourceId = new FilterPermanent();
filterSourceId.add(new CardIdPredicate(this.getId()));
currentFilter.add(Predicates.not(new AttachedToPredicate(filterSourceId)));
int countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Select and attach a target Equipment?", source, game)) {
Target targetEquipment = new TargetPermanent(currentFilter);
targetEquipment.setRequired(false);
if (player.choose(Outcome.Benefit, targetEquipment, source.getSourceId(), game)) { if (player.choose(Outcome.Benefit, targetEquipment, source.getSourceId(), game)) {
Permanent aura = game.getPermanent(targetEquipment.getFirstTarget()); Permanent aura = game.getPermanent(targetEquipment.getFirstTarget());
if (aura != null) { if (aura != null) {
@ -84,9 +96,12 @@ class ArmoryAutomatonEffect extends OneShotEffect {
attachedTo.removeAttachment(aura.getId(), game); attachedTo.removeAttachment(aura.getId(), game);
} }
sourcePermanent.addAttachment(aura.getId(), game); sourcePermanent.addAttachment(aura.getId(), game);
// exclude selected
currentFilter.add(Predicates.not(new PermanentIdPredicate(aura.getId())));
} }
} }
countBattlefield = game.getBattlefield().getAllActivePermanents(filter, game).size() - sourcePermanent.getAttachments().size(); countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
} }
return true; return true;
} }