From 25e2fb59e14ad13bb3309733230c3db94f0923ed Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 26 Jul 2014 15:01:17 +0200 Subject: [PATCH] Support of play_land event for get playable cards. --- .../src/mage/player/ai/SimulatedPlayer2.java | 2 +- .../java/mage/player/ai/ComputerPlayer.java | 18 ++++++++++++++---- Mage/src/mage/abilities/PlayLandAbility.java | 6 ++---- Mage/src/mage/players/PlayerImpl.java | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java index b197de6e07..f355f0a395 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java @@ -125,7 +125,7 @@ public class SimulatedPlayer2 extends ComputerPlayer { playables = filterAbilities(game, playables, suggested); for (Ability ability: playables) { List options = game.getPlayer(playerId).getPlayableOptions(ability, game); - options = filterOptions(game, options, ability, suggested); + options = filterOptions(game, options, ability, suggested); options = optimizeOptions(game, options, ability); if (options.isEmpty()) { allActions.add(ability); diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index e543e8ec74..5c0fdfb386 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -82,6 +82,7 @@ import java.util.*; import java.util.HashSet; import java.util.Map.Entry; import mage.abilities.costs.VariableCost; +import mage.abilities.keyword.FlashAbility; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; @@ -812,8 +813,15 @@ public class ComputerPlayer extends PlayerImpl implements Player { protected void playLand(Game game) { log.debug("playLand"); - Set lands = hand.getCards(new FilterLandCard(), game); - while (lands.size() > 0 && this.landsPlayed < this.landsPerTurn) { + Set lands = new LinkedHashSet<>(); + for (Card landCard: hand.getCards(new FilterLandCard(), game)) { + // remove lands that can not be played + if (game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, landCard.getId(), landCard.getId(), playerId), game, true)) { + break; + } + lands.add(landCard); + } + while (lands.size() > 0 && this.canPlayLand()) { if (lands.size() == 1) { this.playLand(lands.iterator().next(), game); } @@ -875,8 +883,10 @@ public class ComputerPlayer extends PlayerImpl implements Player { for (Mana avail: available) { if (mana.enough(avail)) { SpellAbility ability = card.getSpellAbility(); - if (ability != null && ability.canActivate(playerId, game)) { - if (card.getCardType().contains(CardType.INSTANT)) { + if (ability != null && ability.canActivate(playerId, game) && game.getContinuousEffects(). + preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), ability.getSourceId(), playerId), game, true)) { + if (card.getCardType().contains(CardType.INSTANT) + || card.hasAbility(FlashAbility.getInstance().getId(), game)) { playableInstant.add(card); } else { diff --git a/Mage/src/mage/abilities/PlayLandAbility.java b/Mage/src/mage/abilities/PlayLandAbility.java index fdcd5d74da..f25fc785ad 100644 --- a/Mage/src/mage/abilities/PlayLandAbility.java +++ b/Mage/src/mage/abilities/PlayLandAbility.java @@ -32,6 +32,7 @@ import java.util.UUID; import mage.constants.AbilityType; import mage.constants.Zone; import mage.game.Game; +import mage.game.events.GameEvent; /** * @@ -55,10 +56,7 @@ public class PlayLandAbility extends ActivatedAbilityImpl { return false; } //20091005 - 114.2a - if (game.canPlaySorcery(playerId)) { - return game.getPlayer(playerId).canPlayLand(); - } - return false; + return game.canPlaySorcery(playerId) && game.getPlayer(playerId).canPlayLand(); } @Override diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index ed8a3b1011..c743400d48 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -774,12 +774,12 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean playLand(Card card, Game game) { //20091005 - 305.1 - if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, card.getId(), playerId))) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, card.getId(), card.getId(), playerId))) { // int bookmark = game.bookmarkState(); Zone zone = game.getState().getZone(card.getId()); if (card.putOntoBattlefield(game, zone, null, playerId)) { landsPlayed++; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LAND_PLAYED, card.getId(), playerId)); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LAND_PLAYED, card.getId(), card.getId(), playerId)); game.fireInformEvent(name + " plays " + card.getName()); // game.removeBookmark(bookmark); resetStoredBookmark(game); @@ -1900,6 +1900,11 @@ public abstract class PlayerImpl implements Player, Serializable { if (hidden) { for (Card card : hand.getUniqueCards(game)) { for (ActivatedAbility ability : card.getAbilities().getActivatedAbilities(Zone.HAND)) { + if (ability instanceof PlayLandAbility) { + if (game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), playerId), game, true)) { + break; + } + } if (canPlay(ability, available, game)) { playable.add(ability); } @@ -1990,6 +1995,11 @@ public abstract class PlayerImpl implements Player, Serializable { for (Card card : hand.getCards(game)) { for (ActivatedAbility ability : card.getAbilities().getPlayableAbilities(Zone.HAND)) { + if (ability instanceof PlayLandAbility) { + if (game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), playerId), game, true)) { + break; + } + } if (canPlay(ability, available, game)) { playable.add(card.getId()); break;