SetStateAi: use more generic way to check if a Card should be transformed or not. Also does check if Legendary Rule does still apply for that.

This commit is contained in:
Hanmac
2016-05-08 09:43:20 +00:00
parent b0a6f9ffdb
commit 37f0b07a28
2 changed files with 11 additions and 8 deletions

View File

@@ -1158,7 +1158,7 @@ public class AiController {
// check on legendary // check on legendary
if (card.getType().isLegendary() && !game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) { if (card.getType().isLegendary() && !game.getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
if (Iterables.any(player.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals(card.getName()))) { if (player.isCardInPlay(card.getName())) {
return AiPlayDecision.WouldDestroyLegend; return AiPlayDecision.WouldDestroyLegend;
} }
} }

View File

@@ -2,8 +2,9 @@ package forge.ai.ability;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.GlobalRuleChange;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardCollection; import forge.game.card.CardState;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
@@ -12,12 +13,14 @@ public class SetStateAi extends SpellAbilityAi {
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) { protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
// Prevent transform into legendary creature if copy already exists // Prevent transform into legendary creature if copy already exists
final Card source = sa.getHostCard(); final Card source = sa.getHostCard();
if ("Westvale Abbey".equals(source.getName())) {
CardCollection list = aiPlayer.getCreaturesInPlay(); // Check first if Legend Rule does still apply
for (Card c : list) { if (!aiPlayer.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.noLegendRule)) {
if (c.getName().equals("Ormendahl, Profane Prince")) {
return false; // check if the other side is legendary and if such Card already is in Play
} final CardState other = source.getAlternateState();
if (other.getType().isLegendary() && aiPlayer.isCardInPlay(other.getName())) {
return false;
} }
} }