mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Support of play_land event for get playable cards.
This commit is contained in:
parent
db76a7a8c0
commit
25e2fb59e1
4 changed files with 29 additions and 11 deletions
|
@ -82,6 +82,7 @@ import java.util.*;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import mage.abilities.costs.VariableCost;
|
import mage.abilities.costs.VariableCost;
|
||||||
|
import mage.abilities.keyword.FlashAbility;
|
||||||
import mage.cards.repository.ExpansionInfo;
|
import mage.cards.repository.ExpansionInfo;
|
||||||
import mage.cards.repository.ExpansionRepository;
|
import mage.cards.repository.ExpansionRepository;
|
||||||
|
|
||||||
|
@ -812,8 +813,15 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
|
|
||||||
protected void playLand(Game game) {
|
protected void playLand(Game game) {
|
||||||
log.debug("playLand");
|
log.debug("playLand");
|
||||||
Set<Card> lands = hand.getCards(new FilterLandCard(), game);
|
Set<Card> lands = new LinkedHashSet<>();
|
||||||
while (lands.size() > 0 && this.landsPlayed < this.landsPerTurn) {
|
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) {
|
if (lands.size() == 1) {
|
||||||
this.playLand(lands.iterator().next(), game);
|
this.playLand(lands.iterator().next(), game);
|
||||||
}
|
}
|
||||||
|
@ -875,8 +883,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
for (Mana avail: available) {
|
for (Mana avail: available) {
|
||||||
if (mana.enough(avail)) {
|
if (mana.enough(avail)) {
|
||||||
SpellAbility ability = card.getSpellAbility();
|
SpellAbility ability = card.getSpellAbility();
|
||||||
if (ability != null && ability.canActivate(playerId, game)) {
|
if (ability != null && ability.canActivate(playerId, game) && game.getContinuousEffects().
|
||||||
if (card.getCardType().contains(CardType.INSTANT)) {
|
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);
|
playableInstant.add(card);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.UUID;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -55,10 +56,7 @@ public class PlayLandAbility extends ActivatedAbilityImpl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//20091005 - 114.2a
|
//20091005 - 114.2a
|
||||||
if (game.canPlaySorcery(playerId)) {
|
return game.canPlaySorcery(playerId) && game.getPlayer(playerId).canPlayLand();
|
||||||
return game.getPlayer(playerId).canPlayLand();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -774,12 +774,12 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public boolean playLand(Card card, Game game) {
|
public boolean playLand(Card card, Game game) {
|
||||||
//20091005 - 305.1
|
//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();
|
// int bookmark = game.bookmarkState();
|
||||||
Zone zone = game.getState().getZone(card.getId());
|
Zone zone = game.getState().getZone(card.getId());
|
||||||
if (card.putOntoBattlefield(game, zone, null, playerId)) {
|
if (card.putOntoBattlefield(game, zone, null, playerId)) {
|
||||||
landsPlayed++;
|
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.fireInformEvent(name + " plays " + card.getName());
|
||||||
// game.removeBookmark(bookmark);
|
// game.removeBookmark(bookmark);
|
||||||
resetStoredBookmark(game);
|
resetStoredBookmark(game);
|
||||||
|
@ -1900,6 +1900,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
for (Card card : hand.getUniqueCards(game)) {
|
for (Card card : hand.getUniqueCards(game)) {
|
||||||
for (ActivatedAbility ability : card.getAbilities().getActivatedAbilities(Zone.HAND)) {
|
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)) {
|
if (canPlay(ability, available, game)) {
|
||||||
playable.add(ability);
|
playable.add(ability);
|
||||||
}
|
}
|
||||||
|
@ -1990,6 +1995,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
|
|
||||||
for (Card card : hand.getCards(game)) {
|
for (Card card : hand.getCards(game)) {
|
||||||
for (ActivatedAbility ability : card.getAbilities().getPlayableAbilities(Zone.HAND)) {
|
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)) {
|
if (canPlay(ability, available, game)) {
|
||||||
playable.add(card.getId());
|
playable.add(card.getId());
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue