mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
implement [PIP] Tato Farmer
This commit is contained in:
parent
a60f01a99f
commit
ebe232cadb
5 changed files with 157 additions and 67 deletions
|
|
@ -0,0 +1,23 @@
|
|||
package mage.filter.predicate.card;
|
||||
|
||||
import mage.MageObjectReference;
|
||||
import mage.cards.Card;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.CardsMilledWatcher;
|
||||
|
||||
/**
|
||||
* Needs CardsMilledWatcher to work.
|
||||
*
|
||||
* @author Susucr
|
||||
*/
|
||||
public enum MilledThisTurnPredicate implements Predicate<Card> {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Card input, Game game) {
|
||||
return CardsMilledWatcher.wasMilledThisTurn(
|
||||
new MageObjectReference(input.getMainCard(), game), game
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.MageObjectReference;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Track MOR of mainCard milled this turn.
|
||||
*
|
||||
* @author Susucr
|
||||
*/
|
||||
public class CardsMilledWatcher extends Watcher {
|
||||
|
||||
// set of Cards (the main card's mor) milled this turn.
|
||||
private final Set<MageObjectReference> milledThisTurn = new HashSet<>();
|
||||
|
||||
public CardsMilledWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() != GameEvent.EventType.MILLED_CARD) {
|
||||
return;
|
||||
}
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
if (card == null) {
|
||||
return;
|
||||
}
|
||||
Card mainCard = card.getMainCard();
|
||||
if (game.getState().getZone(mainCard.getId()) != Zone.GRAVEYARD) {
|
||||
// Ensure that the current zone is indeed the graveyard
|
||||
return;
|
||||
}
|
||||
milledThisTurn.add(new MageObjectReference(mainCard, game));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
milledThisTurn.clear();
|
||||
}
|
||||
|
||||
public static boolean wasMilledThisTurn(MageObjectReference morMainCard, Game game) {
|
||||
CardsMilledWatcher watcher = game.getState().getWatcher(CardsMilledWatcher.class);
|
||||
return watcher != null && watcher
|
||||
.milledThisTurn
|
||||
.contains(morMainCard);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue