mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Change zone - only the choose card left inside if condition
This commit is contained in:
@@ -8,7 +8,6 @@ import com.google.common.base.Predicates;
|
|||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.ai.ComputerUtilCard;
|
|
||||||
import forge.ai.ability.ChangeZoneAi;
|
import forge.ai.ability.ChangeZoneAi;
|
||||||
import forge.card.CardCharacteristicName;
|
import forge.card.CardCharacteristicName;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
@@ -711,29 +710,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
source.clearImprinted();
|
source.clearImprinted();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> movedCards;
|
|
||||||
if (decider.getLobbyPlayer().isHuman()) {
|
|
||||||
movedCards = changeHiddenOriginResolveHuman(decider, sa, player, changeNum, origin, destination, fetchList, libraryPos);
|
|
||||||
} else {
|
|
||||||
movedCards = hiddenOriginResolveAI(decider, sa, player, changeNum, origin, destination, fetchList, libraryPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((!ZoneType.Battlefield.equals(destination) && changeType != null && !defined)
|
|
||||||
|| (sa.hasParam("Reveal") && !movedCards.isEmpty())) && !sa.hasParam("NoReveal")) {
|
|
||||||
game.getAction().reveal(movedCards, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined && shuffleMandatory)
|
|
||||||
|| (sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle")))) {
|
|
||||||
player.shuffle(sa);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Card> changeHiddenOriginResolveHuman(final Player decider, final SpellAbility sa, Player player, int changeNum, List<ZoneType> origin, ZoneType destination, List<Card> fetchList, int libraryPos) {
|
|
||||||
final List<Card> movedCards = new ArrayList<Card>();
|
|
||||||
|
|
||||||
final Card source = sa.getSourceCard();
|
|
||||||
final Game game = player.getGame();
|
|
||||||
|
|
||||||
final boolean remember = sa.hasParam("RememberChanged");
|
final boolean remember = sa.hasParam("RememberChanged");
|
||||||
final boolean champion = sa.hasParam("Champion");
|
final boolean champion = sa.hasParam("Champion");
|
||||||
@@ -744,10 +721,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
int totcmc = AbilityUtils.calculateAmount(source, totalcmc, sa);
|
int totcmc = AbilityUtils.calculateAmount(source, totalcmc, sa);
|
||||||
|
|
||||||
|
|
||||||
|
List<Card> chosenCards = new ArrayList<Card>();
|
||||||
for (int i = 0; i < changeNum && destination != null; i++) {
|
for (int i = 0; i < changeNum && destination != null; i++) {
|
||||||
if (sa.hasParam("DifferentNames")) {
|
if (sa.hasParam("DifferentNames")) {
|
||||||
for (Card c : movedCards) {
|
for (Card c : chosenCards) {
|
||||||
fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName())));
|
fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -763,7 +740,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
} else if (sa.hasParam("Defined")) {
|
} else if (sa.hasParam("Defined")) {
|
||||||
c = Iterables.getFirst(fetchList, null);
|
c = Iterables.getFirst(fetchList, null);
|
||||||
} else {
|
} else {
|
||||||
c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !sa.hasParam("Mandatory"));
|
if (decider.getController().getLobbyPlayer().isHuman())
|
||||||
|
c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !sa.hasParam("Mandatory"), decider);
|
||||||
|
else
|
||||||
|
c = ChangeZoneAi.chooseCardToHiddenOriginChangeZone(destination, origin, sa, fetchList, player, decider);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
@@ -778,12 +758,20 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchList.remove(c);
|
fetchList.remove(c);
|
||||||
Card movedCard = null;
|
chosenCards.add(c);
|
||||||
|
|
||||||
|
if (totalcmc != null) {
|
||||||
|
totcmc -= c.getCMC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Card> movedCards = new ArrayList<Card>();
|
||||||
|
for(Card c : chosenCards) {
|
||||||
|
Card movedCard = null;
|
||||||
if (destination.equals(ZoneType.Library)) {
|
if (destination.equals(ZoneType.Library)) {
|
||||||
// do not shuffle the library once we have placed a fetched
|
// do not shuffle the library once we have placed a fetched
|
||||||
// card on top.
|
// card on top.
|
||||||
if (origin.contains(ZoneType.Library) && (i < 1) && !"False".equals(sa.getParam("Shuffle"))) {
|
if (origin.contains(ZoneType.Library) && !"False".equals(sa.getParam("Shuffle"))) {
|
||||||
player.shuffle(sa);
|
player.shuffle(sa);
|
||||||
}
|
}
|
||||||
movedCard = game.getAction().moveToLibrary(c, libraryPos);
|
movedCard = game.getAction().moveToLibrary(c, libraryPos);
|
||||||
@@ -891,6 +879,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
} else {
|
} else {
|
||||||
movedCard = game.getAction().moveTo(destination, c);
|
movedCard = game.getAction().moveTo(destination, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
movedCards.add(movedCard);
|
movedCards.add(movedCard);
|
||||||
|
|
||||||
if (champion) {
|
if (champion) {
|
||||||
@@ -910,163 +899,18 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
if (imprint) {
|
if (imprint) {
|
||||||
source.addImprinted(movedCard);
|
source.addImprinted(movedCard);
|
||||||
}
|
}
|
||||||
if (totalcmc != null) {
|
|
||||||
totcmc -= movedCard.getCMC();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return movedCards;
|
if (((!ZoneType.Battlefield.equals(destination) && changeType != null && !defined)
|
||||||
|
|| (sa.hasParam("Reveal") && !movedCards.isEmpty())) && !sa.hasParam("NoReveal")) {
|
||||||
|
game.getAction().reveal(movedCards, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined && shuffleMandatory)
|
||||||
private List<Card> hiddenOriginResolveAI(final Player decider, final SpellAbility sa, Player player, int changeNum, List<ZoneType> origin, ZoneType destination, List<Card> fetchList, int libraryPos) {
|
|| (sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle")))) {
|
||||||
final List<Card> movedCards = new ArrayList<Card>();
|
player.shuffle(sa);
|
||||||
|
|
||||||
final Card source = sa.getSourceCard();
|
|
||||||
final Game game = decider.getGame();
|
|
||||||
|
|
||||||
|
|
||||||
final boolean remember = sa.hasParam("RememberChanged");
|
|
||||||
final boolean forget = sa.hasParam("ForgetChanged");
|
|
||||||
final boolean champion = sa.hasParam("Champion");
|
|
||||||
final boolean imprint = sa.hasParam("Imprint");
|
|
||||||
final String totalcmc = sa.getParam("WithTotalCMC");
|
|
||||||
int totcmc = AbilityUtils.calculateAmount(source, totalcmc, sa);
|
|
||||||
|
|
||||||
for (int i = 0; i < changeNum; i++) {
|
|
||||||
if (sa.hasParam("DifferentNames")) {
|
|
||||||
for (Card c : movedCards) {
|
|
||||||
fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (totalcmc != null) {
|
|
||||||
if (totcmc >= 0) {
|
|
||||||
fetchList = CardLists.getValidCards(fetchList, "Card.cmcLE" + Integer.toString(totcmc), decider, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fetchList.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Improve the AI for fetching.
|
|
||||||
Card c = null;
|
|
||||||
if (sa.hasParam("AtRandom")) {
|
|
||||||
c = Aggregates.random(fetchList);
|
|
||||||
} else if (sa.hasParam("Defined")) {
|
|
||||||
c = fetchList.get(0);
|
|
||||||
} else {
|
|
||||||
c = ChangeZoneAi.chooseCardToHiddenOriginChangeZone(destination, origin, sa, fetchList, player, decider);
|
|
||||||
}
|
|
||||||
|
|
||||||
movedCards.add(c);
|
|
||||||
fetchList.remove(c);
|
|
||||||
if (totalcmc != null) {
|
|
||||||
totcmc -= c.getCMC();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Card c : movedCards) {
|
|
||||||
Card movedCard = null;
|
|
||||||
if (ZoneType.Library.equals(destination)) {
|
|
||||||
movedCard = game.getAction().moveToLibrary(c, libraryPos);
|
|
||||||
} else if (ZoneType.Battlefield.equals(destination)) {
|
|
||||||
if (sa.hasParam("Tapped")) {
|
|
||||||
c.setTapped(true);
|
|
||||||
}
|
|
||||||
if (sa.hasParam("GainControl")) {
|
|
||||||
Player newController = sa.getActivatingPlayer();
|
|
||||||
if (sa.hasParam("NewController")) {
|
|
||||||
newController = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("NewController"), sa).get(0);
|
|
||||||
}
|
|
||||||
c.setController(newController, game.getNextTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sa.hasParam("AttachedTo")) {
|
|
||||||
List<Card> list = AbilityUtils.getDefinedCards(sa.getSourceCard(),
|
|
||||||
sa.getParam("AttachedTo"), sa);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
list = game.getCardsIn(ZoneType.Battlefield);
|
|
||||||
list = CardLists.getValidCards(list, sa.getParam("AttachedTo"), c.getController(), c);
|
|
||||||
}
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
final Card attachedTo = ComputerUtilCard.getBestAI(list);
|
|
||||||
if (c.isEnchanting()) {
|
|
||||||
// If this Card is already Enchanting something, need
|
|
||||||
// to unenchant it, then clear out the commands
|
|
||||||
final GameEntity oldEnchanted = c.getEnchanting();
|
|
||||||
c.removeEnchanting(oldEnchanted);
|
|
||||||
}
|
|
||||||
c.enchantEntity(attachedTo);
|
|
||||||
} else { // When it should enter the battlefield attached to an illegal permanent it fails
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sa.hasParam("Attacking")) {
|
|
||||||
final Combat combat = game.getCombat();
|
|
||||||
if ( null != combat ) {
|
|
||||||
final List<GameEntity> e = combat.getDefenders();
|
|
||||||
final GameEntity defender = player.getController().chooseSingleEntityForEffect(e, sa, "Declare " + c);
|
|
||||||
combat.addAttacker(c, defender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sa.hasParam("Blocking")) {
|
|
||||||
final Combat combat = game.getCombat();
|
|
||||||
if ( null != combat ) {
|
|
||||||
List<Card> attackers = AbilityUtils.getDefinedCards(source, sa.getParam("Blocking"), sa);
|
|
||||||
if (!attackers.isEmpty()) {
|
|
||||||
Card attacker = attackers.get(0);
|
|
||||||
if (combat.isAttacking(attacker)) {
|
|
||||||
combat.addBlocker(attacker, c);
|
|
||||||
combat.orderAttackersForDamageAssignment(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Auras without Candidates stay in their current location
|
|
||||||
if (c.isAura()) {
|
|
||||||
final SpellAbility saAura = AttachEffect.getAttachSpellAbility(c);
|
|
||||||
if (!saAura.getTargetRestrictions().hasCandidates(saAura, false)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
movedCard = game.getAction().moveTo(c.getController().getZone(destination), c);
|
|
||||||
if (sa.hasParam("Tapped")) {
|
|
||||||
movedCard.setTapped(true);
|
|
||||||
}
|
|
||||||
} else if (destination.equals(ZoneType.Exile)) {
|
|
||||||
movedCard = game.getAction().exile(c);
|
|
||||||
if (sa.hasParam("ExileFaceDown")) {
|
|
||||||
movedCard.setState(CardCharacteristicName.FaceDown);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
movedCard = game.getAction().moveTo(destination, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (champion) {
|
|
||||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
|
||||||
runParams.put("Card", source);
|
|
||||||
runParams.put("Championed", c);
|
|
||||||
game.getTriggerHandler().runTrigger(TriggerType.Championed, runParams, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remember) {
|
|
||||||
source.addRemembered(movedCard);
|
|
||||||
}
|
|
||||||
if (forget) {
|
|
||||||
source.removeRemembered(movedCard);
|
|
||||||
}
|
|
||||||
// for imprinted since this doesn't use Target
|
|
||||||
if (imprint) {
|
|
||||||
source.addImprinted(movedCard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return movedCards;
|
|
||||||
} // end changeHiddenOriginResolveAI
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
Reference in New Issue
Block a user