mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
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() {
|
||||
addCard(Zone.HAND, playerA, "Plains", 7);
|
||||
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.
|
||||
// Sasaya's Essence: Legendary Enchantment
|
||||
|
|
|
|||
|
|
@ -1723,8 +1723,6 @@ public abstract class GameImpl implements Game {
|
|||
// tests - try to fail fast
|
||||
throw new MageException(UNIT_TESTS_ERROR_TEXT);
|
||||
}
|
||||
} finally {
|
||||
//setCheckPlayableState(false); // TODO: delete
|
||||
}
|
||||
state.getPlayerList().getNext();
|
||||
}
|
||||
|
|
@ -1743,7 +1741,6 @@ public abstract class GameImpl implements Game {
|
|||
} finally {
|
||||
resetLKI();
|
||||
clearAllBookmarks();
|
||||
//setCheckPlayableState(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4078,176 +4078,172 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
Game game = originalGame.createSimulationForPlayableCalc();
|
||||
try {
|
||||
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);
|
||||
if (hidden && (fromAll || fromZone == Zone.HAND)) {
|
||||
for (Card card : hand.getCards(game)) {
|
||||
for (Ability ability : card.getAbilities(game)) { // gets this activated ability from hand? (Morph?)
|
||||
if (ability.getZone().match(Zone.HAND)) {
|
||||
boolean isPlaySpell = (ability instanceof SpellAbility);
|
||||
boolean isPlayLand = (ability instanceof PlayLandAbility);
|
||||
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);
|
||||
if (hidden && (fromAll || fromZone == Zone.HAND)) {
|
||||
for (Card card : hand.getCards(game)) {
|
||||
for (Ability ability : card.getAbilities(game)) { // gets this activated ability from hand? (Morph?)
|
||||
if (ability.getZone().match(Zone.HAND)) {
|
||||
boolean isPlaySpell = (ability instanceof SpellAbility);
|
||||
boolean isPlayLand = (ability instanceof PlayLandAbility);
|
||||
|
||||
// play land restrictions
|
||||
if (isPlayLand && game.getContinuousEffects().preventedByRuleModification(
|
||||
GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(),
|
||||
ability, this.getId()), ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
// cast spell restrictions 1
|
||||
GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL,
|
||||
ability.getId(), ability, this.getId());
|
||||
castEvent.setZone(fromZone);
|
||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||
castEvent, ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
// cast spell restrictions 2
|
||||
GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE,
|
||||
ability.getId(), ability, this.getId());
|
||||
castLateEvent.setZone(fromZone);
|
||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||
castLateEvent, ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
// play land restrictions
|
||||
if (isPlayLand && game.getContinuousEffects().preventedByRuleModification(
|
||||
GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(),
|
||||
ability, this.getId()), ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
// cast spell restrictions 1
|
||||
GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL,
|
||||
ability.getId(), ability, this.getId());
|
||||
castEvent.setZone(fromZone);
|
||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||
castEvent, ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
// cast spell restrictions 2
|
||||
GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE,
|
||||
ability.getId(), ability, this.getId());
|
||||
castLateEvent.setZone(fromZone);
|
||||
if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
|
||||
castLateEvent, ability, game, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ActivatedAbility playAbility = findActivatedAbilityFromPlayable(card, availableMana, ability, game);
|
||||
if (playAbility != null && !playable.contains(playAbility)) {
|
||||
playable.add(playAbility);
|
||||
}
|
||||
ActivatedAbility playAbility = findActivatedAbilityFromPlayable(card, availableMana, ability, game);
|
||||
if (playAbility != null && !playable.contains(playAbility)) {
|
||||
playable.add(playAbility);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fromAll || fromZone == Zone.GRAVEYARD) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
getPlayableFromObjectAll(game, Zone.GRAVEYARD, card, availableMana, playable);
|
||||
}
|
||||
if (fromAll || fromZone == Zone.GRAVEYARD) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
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) {
|
||||
for (ExileZone exile : game.getExile().getExileZones()) {
|
||||
for (Card card : exile.getCards(game)) {
|
||||
getPlayableFromObjectAll(game, Zone.EXILED, 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) {
|
||||
getPlayableFromObjectAll(game, Zone.LIBRARY, 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
// check the hand zone (Sen Triplets)
|
||||
// TODO: remove direct hand check (reveal fix in Sen Triplets)?
|
||||
// human games: cards from opponent's hand must be revealed before play
|
||||
// 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.LIBRARY, card, availableMana, playable);
|
||||
getPlayableFromObjectAll(game, Zone.HAND, card, availableMana, playable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check the hand zone (Sen Triplets)
|
||||
// TODO: remove direct hand check (reveal fix in Sen Triplets)?
|
||||
// human games: cards from opponent's hand must be revealed before play
|
||||
// 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)
|
||||
Map<String, ActivatedAbility> activatedUnique = new HashMap<>();
|
||||
List<ActivatedAbility> activatedAll = new ArrayList<>();
|
||||
|
||||
// eliminate duplicate activated abilities (uses for AI plays)
|
||||
Map<String, ActivatedAbility> activatedUnique = new HashMap<>();
|
||||
List<ActivatedAbility> activatedAll = new ArrayList<>();
|
||||
|
||||
// activated abilities from battlefield objects
|
||||
if (fromAll || fromZone == Zone.BATTLEFIELD) {
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
||||
boolean canUseActivated = permanent.canUseActivatedAbilities(game);
|
||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||
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);
|
||||
// activated abilities from battlefield objects
|
||||
if (fromAll || fromZone == Zone.BATTLEFIELD) {
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
||||
boolean canUseActivated = permanent.canUseActivatedAbilities(game);
|
||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||
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 objects in the command zone (emblems or commanders)
|
||||
if (fromAll || fromZone == Zone.COMMAND) {
|
||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||
List<ActivatedAbility> currentPlayable = new ArrayList<>();
|
||||
getPlayableFromObjectAll(game, Zone.COMMAND, commandObject, availableMana, currentPlayable);
|
||||
for (ActivatedAbility ability : currentPlayable) {
|
||||
activatedUnique.put(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hideDuplicatedAbilities) {
|
||||
playable.addAll(activatedUnique.values());
|
||||
} else {
|
||||
playable.addAll(activatedAll);
|
||||
// activated abilities from objects in the command zone (emblems or commanders)
|
||||
if (fromAll || fromZone == Zone.COMMAND) {
|
||||
for (CommandObject commandObject : game.getState().getCommand()) {
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue