forked from External/mage
code clean
This commit is contained in:
parent
e8e2f23284
commit
88eb35ebc7
3 changed files with 136 additions and 144 deletions
|
|
@ -52,7 +52,6 @@ public class SasayaOrochiAscendantTest extends CardTestPlayerBase {
|
||||||
public void testSasayasEssence() {
|
public void testSasayasEssence() {
|
||||||
addCard(Zone.HAND, playerA, "Plains", 7);
|
addCard(Zone.HAND, playerA, "Plains", 7);
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
|
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
|
||||||
addCard(Zone.BATTLEFIELD, playerB, "Fountain of Renewal", 5);
|
|
||||||
|
|
||||||
// Reveal your hand: If you have seven or more land cards in your hand, flip Sasaya, Orochi Ascendant.
|
// Reveal your hand: If you have seven or more land cards in your hand, flip Sasaya, Orochi Ascendant.
|
||||||
// Sasaya's Essence: Legendary Enchantment
|
// Sasaya's Essence: Legendary Enchantment
|
||||||
|
|
|
||||||
|
|
@ -1723,8 +1723,6 @@ public abstract class GameImpl implements Game {
|
||||||
// tests - try to fail fast
|
// tests - try to fail fast
|
||||||
throw new MageException(UNIT_TESTS_ERROR_TEXT);
|
throw new MageException(UNIT_TESTS_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
//setCheckPlayableState(false); // TODO: delete
|
|
||||||
}
|
}
|
||||||
state.getPlayerList().getNext();
|
state.getPlayerList().getNext();
|
||||||
}
|
}
|
||||||
|
|
@ -1743,7 +1741,6 @@ public abstract class GameImpl implements Game {
|
||||||
} finally {
|
} finally {
|
||||||
resetLKI();
|
resetLKI();
|
||||||
clearAllBookmarks();
|
clearAllBookmarks();
|
||||||
//setCheckPlayableState(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4078,176 +4078,172 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
Game game = originalGame.createSimulationForPlayableCalc();
|
Game game = originalGame.createSimulationForPlayableCalc();
|
||||||
try {
|
ManaOptions availableMana = getManaAvailable(game); // get available mana options (mana pool and conditional mana added (but conditional still lose condition))
|
||||||
ManaOptions availableMana = getManaAvailable(game); // get available mana options (mana pool and conditional mana added (but conditional still lose condition))
|
boolean fromAll = fromZone.equals(Zone.ALL);
|
||||||
boolean fromAll = fromZone.equals(Zone.ALL);
|
if (hidden && (fromAll || fromZone == Zone.HAND)) {
|
||||||
if (hidden && (fromAll || fromZone == Zone.HAND)) {
|
for (Card card : hand.getCards(game)) {
|
||||||
for (Card card : hand.getCards(game)) {
|
for (Ability ability : card.getAbilities(game)) { // gets this activated ability from hand? (Morph?)
|
||||||
for (Ability ability : card.getAbilities(game)) { // gets this activated ability from hand? (Morph?)
|
if (ability.getZone().match(Zone.HAND)) {
|
||||||
if (ability.getZone().match(Zone.HAND)) {
|
boolean isPlaySpell = (ability instanceof SpellAbility);
|
||||||
boolean isPlaySpell = (ability instanceof SpellAbility);
|
boolean isPlayLand = (ability instanceof PlayLandAbility);
|
||||||
boolean isPlayLand = (ability instanceof PlayLandAbility);
|
|
||||||
|
|
||||||
// play land restrictions
|
// play land restrictions
|
||||||
if (isPlayLand && game.getContinuousEffects().preventedByRuleModification(
|
if (isPlayLand && game.getContinuousEffects().preventedByRuleModification(
|
||||||
GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(),
|
GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(),
|
||||||
ability, this.getId()), ability, game, true)) {
|
ability, this.getId()), ability, game, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// cast spell restrictions 1
|
// cast spell restrictions 1
|
||||||
GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL,
|
GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL,
|
||||||
ability.getId(), ability, this.getId());
|
ability.getId(), ability, this.getId());
|
||||||
castEvent.setZone(fromZone);
|
castEvent.setZone(fromZone);
|
||||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||||
castEvent, ability, game, true)) {
|
castEvent, ability, game, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// cast spell restrictions 2
|
// cast spell restrictions 2
|
||||||
GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE,
|
GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE,
|
||||||
ability.getId(), ability, this.getId());
|
ability.getId(), ability, this.getId());
|
||||||
castLateEvent.setZone(fromZone);
|
castLateEvent.setZone(fromZone);
|
||||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||||
castLateEvent, ability, game, true)) {
|
castLateEvent, ability, game, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivatedAbility playAbility = findActivatedAbilityFromPlayable(card, availableMana, ability, game);
|
ActivatedAbility playAbility = findActivatedAbilityFromPlayable(card, availableMana, ability, game);
|
||||||
if (playAbility != null && !playable.contains(playAbility)) {
|
if (playAbility != null && !playable.contains(playAbility)) {
|
||||||
playable.add(playAbility);
|
playable.add(playAbility);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fromAll || fromZone == Zone.GRAVEYARD) {
|
if (fromAll || fromZone == Zone.GRAVEYARD) {
|
||||||
for (UUID playerId : game.getState().getPlayersInRange(getId(), game)) {
|
for (UUID playerId : game.getState().getPlayersInRange(getId(), game)) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (Card card : player.getGraveyard().getCards(game)) {
|
for (Card card : player.getGraveyard().getCards(game)) {
|
||||||
getPlayableFromObjectAll(game, Zone.GRAVEYARD, card, availableMana, playable);
|
getPlayableFromObjectAll(game, Zone.GRAVEYARD, card, availableMana, playable);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromAll || fromZone == Zone.EXILED) {
|
||||||
|
for (ExileZone exile : game.getExile().getExileZones()) {
|
||||||
|
for (Card card : exile.getCards(game)) {
|
||||||
|
getPlayableFromObjectAll(game, Zone.EXILED, card, availableMana, playable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check to play revealed cards
|
||||||
|
if (fromAll) {
|
||||||
|
for (Cards revealedCards : game.getState().getRevealed().values()) {
|
||||||
|
for (Card card : revealedCards.getCards(game)) {
|
||||||
|
// revealed cards can be from any zones
|
||||||
|
getPlayableFromObjectAll(game, game.getState().getZone(card.getId()), card, availableMana, playable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// outside cards
|
||||||
|
if (fromAll || fromZone == Zone.OUTSIDE) {
|
||||||
|
// companion cards
|
||||||
|
for (Cards companionCards : game.getState().getCompanion().values()) {
|
||||||
|
for (Card card : companionCards.getCards(game)) {
|
||||||
|
getPlayableFromObjectAll(game, Zone.OUTSIDE, card, availableMana, playable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromAll || fromZone == Zone.EXILED) {
|
// sideboard cards (example: Wish)
|
||||||
for (ExileZone exile : game.getExile().getExileZones()) {
|
for (UUID sideboardCardId : this.getSideboard()) {
|
||||||
for (Card card : exile.getCards(game)) {
|
Card sideboardCard = game.getCard(sideboardCardId);
|
||||||
getPlayableFromObjectAll(game, Zone.EXILED, card, availableMana, playable);
|
if (sideboardCard != null) {
|
||||||
|
getPlayableFromObjectAll(game, Zone.OUTSIDE, sideboardCard, availableMana, playable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if it's possible to play the top card of a library
|
||||||
|
if (fromAll || fromZone == Zone.LIBRARY) {
|
||||||
|
for (UUID playerInRangeId : game.getState().getPlayersInRange(getId(), game)) {
|
||||||
|
Player player = game.getPlayer(playerInRangeId);
|
||||||
|
if (player != null && player.getLibrary().hasCards()) {
|
||||||
|
Card card = player.getLibrary().getFromTop(game);
|
||||||
|
if (card != null) {
|
||||||
|
getPlayableFromObjectAll(game, Zone.LIBRARY, card, availableMana, playable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check to play revealed cards
|
// check the hand zone (Sen Triplets)
|
||||||
if (fromAll) {
|
// TODO: remove direct hand check (reveal fix in Sen Triplets)?
|
||||||
for (Cards revealedCards : game.getState().getRevealed().values()) {
|
// human games: cards from opponent's hand must be revealed before play
|
||||||
for (Card card : revealedCards.getCards(game)) {
|
// AI games: computer can see and play cards from opponent's hand without reveal
|
||||||
// revealed cards can be from any zones
|
if (fromAll || fromZone == Zone.HAND) {
|
||||||
getPlayableFromObjectAll(game, game.getState().getZone(card.getId()), card, availableMana, playable);
|
for (UUID playerInRangeId : game.getState().getPlayersInRange(getId(), game)) {
|
||||||
}
|
Player player = game.getPlayer(playerInRangeId);
|
||||||
}
|
if (player != null && !player.getHand().isEmpty()) {
|
||||||
}
|
for (Card card : player.getHand().getCards(game)) {
|
||||||
|
|
||||||
// outside cards
|
|
||||||
if (fromAll || fromZone == Zone.OUTSIDE) {
|
|
||||||
// companion cards
|
|
||||||
for (Cards companionCards : game.getState().getCompanion().values()) {
|
|
||||||
for (Card card : companionCards.getCards(game)) {
|
|
||||||
getPlayableFromObjectAll(game, Zone.OUTSIDE, card, availableMana, playable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// sideboard cards (example: Wish)
|
|
||||||
for (UUID sideboardCardId : this.getSideboard()) {
|
|
||||||
Card sideboardCard = game.getCard(sideboardCardId);
|
|
||||||
if (sideboardCard != null) {
|
|
||||||
getPlayableFromObjectAll(game, Zone.OUTSIDE, sideboardCard, availableMana, playable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if it's possible to play the top card of a library
|
|
||||||
if (fromAll || fromZone == Zone.LIBRARY) {
|
|
||||||
for (UUID playerInRangeId : game.getState().getPlayersInRange(getId(), game)) {
|
|
||||||
Player player = game.getPlayer(playerInRangeId);
|
|
||||||
if (player != null && player.getLibrary().hasCards()) {
|
|
||||||
Card card = player.getLibrary().getFromTop(game);
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
getPlayableFromObjectAll(game, Zone.LIBRARY, card, availableMana, playable);
|
getPlayableFromObjectAll(game, Zone.HAND, card, availableMana, playable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check the hand zone (Sen Triplets)
|
// eliminate duplicate activated abilities (uses for AI plays)
|
||||||
// TODO: remove direct hand check (reveal fix in Sen Triplets)?
|
Map<String, ActivatedAbility> activatedUnique = new HashMap<>();
|
||||||
// human games: cards from opponent's hand must be revealed before play
|
List<ActivatedAbility> activatedAll = new ArrayList<>();
|
||||||
// AI games: computer can see and play cards from opponent's hand without reveal
|
|
||||||
if (fromAll || fromZone == Zone.HAND) {
|
|
||||||
for (UUID playerInRangeId : game.getState().getPlayersInRange(getId(), game)) {
|
|
||||||
Player player = game.getPlayer(playerInRangeId);
|
|
||||||
if (player != null && !player.getHand().isEmpty()) {
|
|
||||||
for (Card card : player.getHand().getCards(game)) {
|
|
||||||
if (card != null) {
|
|
||||||
getPlayableFromObjectAll(game, Zone.HAND, card, availableMana, playable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// eliminate duplicate activated abilities (uses for AI plays)
|
// activated abilities from battlefield objects
|
||||||
Map<String, ActivatedAbility> activatedUnique = new HashMap<>();
|
if (fromAll || fromZone == Zone.BATTLEFIELD) {
|
||||||
List<ActivatedAbility> activatedAll = new ArrayList<>();
|
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
||||||
|
boolean canUseActivated = permanent.canUseActivatedAbilities(game);
|
||||||
// activated abilities from battlefield objects
|
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||||
if (fromAll || fromZone == Zone.BATTLEFIELD) {
|
getPlayableFromObjectAll(game, Zone.BATTLEFIELD, permanent, availableMana, currentPlayable);
|
||||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
for (ActivatedAbility ability : currentPlayable) {
|
||||||
boolean canUseActivated = permanent.canUseActivatedAbilities(game);
|
if (ability instanceof SpecialAction || canUseActivated) {
|
||||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
activatedUnique.putIfAbsent(ability.toString(), ability);
|
||||||
getPlayableFromObjectAll(game, Zone.BATTLEFIELD, permanent, availableMana, currentPlayable);
|
|
||||||
for (ActivatedAbility ability : currentPlayable) {
|
|
||||||
if (ability instanceof SpecialAction || canUseActivated) {
|
|
||||||
activatedUnique.putIfAbsent(ability.toString(), ability);
|
|
||||||
activatedAll.add(ability);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// activated abilities from stack objects
|
|
||||||
if (fromAll || fromZone == Zone.STACK) {
|
|
||||||
for (StackObject stackObject : game.getState().getStack()) {
|
|
||||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
|
||||||
getPlayableFromObjectAll(game, Zone.STACK, stackObject, availableMana, currentPlayable);
|
|
||||||
for (ActivatedAbility ability : currentPlayable) {
|
|
||||||
activatedUnique.put(ability.toString(), ability);
|
|
||||||
activatedAll.add(ability);
|
activatedAll.add(ability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// activated abilities from objects in the command zone (emblems or commanders)
|
// activated abilities from stack objects
|
||||||
if (fromAll || fromZone == Zone.COMMAND) {
|
if (fromAll || fromZone == Zone.STACK) {
|
||||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
for (StackObject stackObject : game.getState().getStack()) {
|
||||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||||
getPlayableFromObjectAll(game, Zone.COMMAND, commandObject, availableMana, currentPlayable);
|
getPlayableFromObjectAll(game, Zone.STACK, stackObject, availableMana, currentPlayable);
|
||||||
for (ActivatedAbility ability : currentPlayable) {
|
for (ActivatedAbility ability : currentPlayable) {
|
||||||
activatedUnique.put(ability.toString(), ability);
|
activatedUnique.put(ability.toString(), ability);
|
||||||
activatedAll.add(ability);
|
activatedAll.add(ability);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (hideDuplicatedAbilities) {
|
// activated abilities from objects in the command zone (emblems or commanders)
|
||||||
playable.addAll(activatedUnique.values());
|
if (fromAll || fromZone == Zone.COMMAND) {
|
||||||
} else {
|
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||||
playable.addAll(activatedAll);
|
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||||
|
getPlayableFromObjectAll(game, Zone.COMMAND, commandObject, availableMana, currentPlayable);
|
||||||
|
for (ActivatedAbility ability : currentPlayable) {
|
||||||
|
activatedUnique.put(ability.toString(), ability);
|
||||||
|
activatedAll.add(ability);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
//game.setCheckPlayableState(previousState); // TODO: delete
|
|
||||||
|
if (hideDuplicatedAbilities) {
|
||||||
|
playable.addAll(activatedUnique.values());
|
||||||
|
} else {
|
||||||
|
playable.addAll(activatedAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure it independent of sim game
|
// make sure it independent of sim game
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue