Support of play_land event for get playable cards.

This commit is contained in:
LevelX2 2014-07-26 15:01:17 +02:00
parent db76a7a8c0
commit 25e2fb59e1
4 changed files with 29 additions and 11 deletions

View file

@ -125,7 +125,7 @@ public class SimulatedPlayer2 extends ComputerPlayer {
playables = filterAbilities(game, playables, suggested);
for (Ability ability: playables) {
List<Ability> 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);

View file

@ -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<Card> lands = hand.getCards(new FilterLandCard(), game);
while (lands.size() > 0 && this.landsPlayed < this.landsPerTurn) {
Set<Card> 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 {

View file

@ -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

View file

@ -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;