[NEO] Implemented Myojin of Cryptic Dreams and Myojin of Grim Betrayal (#8680)

* - Implemented Myojin of Cryptic Dreams and Myojin of Grim Betrayal.
- Updated CardsPutIntoGraveyardWatcher to keep track of all cards that entered the graveyard.
- Added documentation to CardsPutIntoGraveyardWatcher.

* Fixed add indestructible counter ability
This commit is contained in:
Alex Vasile 2022-02-10 09:23:13 -05:00 committed by GitHub
parent 8010ce50e4
commit 3709b5c098
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 297 additions and 28 deletions

View file

@ -0,0 +1,20 @@
package mage.filter.predicate.card;
import mage.cards.Card;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.watchers.common.CardsPutIntoGraveyardWatcher;
/**
* @author Alex-Vasile
*/
public enum PutIntoGraveFromAnywhereThisTurnPredicate implements Predicate<Card> {
instance;
@Override
public boolean apply(Card input, Game game) {
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
return watcher != null && watcher.checkCardFromAnywhere(input, game);
}
}

View file

@ -13,16 +13,20 @@ import java.util.*;
import java.util.stream.Collectors;
/**
* Counts amount of cards put into graveyards of players during the current
* turn. Also the UUIDs of cards that went to graveyard from Battlefield this
* turn.
* Counts how many cards are put into each player's graveyard this turn.
* Keeps track of the UUIDs of the cards that went to graveyard this turn.
* from the battlefield, from anywhere other both from anywhere and from only the battlefield.
*
* @author LevelX2
*/
public class CardsPutIntoGraveyardWatcher extends Watcher {
// Number of cards that have entered each players graveyards
private final Map<UUID, Integer> amountOfCardsThisTurn = new HashMap<>();
private final Set<MageObjectReference> cardsPutToGraveyardFromBattlefield = new HashSet<>();
// UUID of cards that entered the graveyard from the battlefield
private final Set<MageObjectReference> cardsPutIntoGraveyardFromBattlefield = new HashSet<>();
// UUID of cards that entered the graveyard from everywhere other than the battlefield
private final Set<MageObjectReference> cardsPutIntoGraveyardFromEverywhereElse = new HashSet<>();
public CardsPutIntoGraveyardWatcher() {
super(WatcherScope.GAME);
@ -34,33 +38,102 @@ public class CardsPutIntoGraveyardWatcher extends Watcher {
|| ((ZoneChangeEvent) event).getToZone() != Zone.GRAVEYARD) {
return;
}
UUID playerId = event.getPlayerId();
if (playerId == null || game.getCard(event.getTargetId()) == null) {
return;
}
amountOfCardsThisTurn.compute(playerId, (k, amount) -> amount == null ? 1 : Integer.sum(amount, 1));
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
cardsPutToGraveyardFromBattlefield.add(new MageObjectReference(((ZoneChangeEvent) event).getTarget(), game, 1));
cardsPutIntoGraveyardFromBattlefield.add(new MageObjectReference(((ZoneChangeEvent) event).getTarget(), game, 1));
} else {
cardsPutIntoGraveyardFromEverywhereElse.add(new MageObjectReference(((ZoneChangeEvent) event).getTarget(), game, 1));
}
}
/**
* The number of cards that were put into a specific player's graveyard this turn.
*
* @param playerId The player's UUID.
* @return The number of cards.
*/
public int getAmountCardsPutToGraveyard(UUID playerId) {
return amountOfCardsThisTurn.getOrDefault(playerId, 0);
}
public Set<Card> getCardsPutToGraveyardFromBattlefield(Game game) {
return cardsPutToGraveyardFromBattlefield.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).collect(Collectors.toSet());
/**
* The cards put into any graveyard from the battelfield this turn.
*
* @param game The game to check for.
* @return A set containing the card objects.
*/
public Set<Card> getCardsPutIntoGraveyardFromBattlefield(Game game) {
return cardsPutIntoGraveyardFromBattlefield.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).collect(Collectors.toSet());
}
/**
* The cards put into any graveyard from anywhere other than the battelfield this turn.
*
* @param game The game to check for.
* @return A set containing the card objects.
*/
public Set<Card> getCardsPutIntoGraveyardNotFromBattlefield(Game game) {
return cardsPutIntoGraveyardFromEverywhereElse.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).collect(Collectors.toSet());
}
/**
* The cards put into any graveyard from anywhere this turn.
*
* @param game The game to check for.
* @return A set containing the card objects.
*/
public Set<Card> getCardsPutIntoGraveyardFromAnywhere(Game game) {
Set<Card> cardsPutIntoGraveyardFromAnywhere = getCardsPutIntoGraveyardFromBattlefield(game);
cardsPutIntoGraveyardFromAnywhere.addAll(getCardsPutIntoGraveyardNotFromBattlefield(game));
return cardsPutIntoGraveyardFromAnywhere;
}
/**
* Check if the passed card was put into the graveyard from the battlefield this turn.
*
* @param card The card to check.
* @param game The game to check for.
* @return Boolean indicating if the card was put into the graveyard from the battlefield this turn.
*/
public boolean checkCardFromBattlefield(Card card, Game game) {
return cardsPutToGraveyardFromBattlefield.stream().anyMatch(mor -> mor.refersTo(card, game));
return cardsPutIntoGraveyardFromBattlefield.stream().anyMatch(mor -> mor.refersTo(card, game));
}
/**
* Check if the passed card was put into the graveyard from anywhere other than the battlefield this turn.
*
* @param card The card to check.
* @param game The game to check for.
* @return Boolean indicating if the card was put into the graveyard from anywhere other than the battlefield this turn.
*/
public boolean checkCardNotFromBattlefield(Card card, Game game) {
return cardsPutIntoGraveyardFromEverywhereElse.stream().anyMatch(mor -> mor.refersTo(card, game));
}
/**
* Check if the passed card was put into the graveyard from anywhere this turn.
*
* @param card The card to check.
* @param game The game to check for.
* @return Boolean indicating if the card was put into the graveyard from anywhere this turn.
*/
public boolean checkCardFromAnywhere(Card card, Game game) {
return checkCardFromBattlefield(card, game) || checkCardNotFromBattlefield(card, game);
}
@Override
public void reset() {
super.reset();
amountOfCardsThisTurn.clear();
cardsPutToGraveyardFromBattlefield.clear();
cardsPutIntoGraveyardFromBattlefield.clear();
cardsPutIntoGraveyardFromEverywhereElse.clear();
}
}