diff --git a/Mage.Sets/src/mage/cards/t/TheFourthDoctor.java b/Mage.Sets/src/mage/cards/t/TheFourthDoctor.java new file mode 100644 index 00000000000..1ed5a9e388d --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TheFourthDoctor.java @@ -0,0 +1,197 @@ +package mage.cards.t; + +import java.util.*; +import mage.MageIdentifier; +import mage.MageInt; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.Condition; +import mage.abilities.hint.Hint; +import mage.abilities.hint.common.ConditionPermanentHint; +import mage.abilities.effects.common.continuous.PlayFromTopOfLibraryEffect; +import mage.abilities.effects.common.continuous.LookAtTopCardOfLibraryAnyTimeEffect; +import mage.constants.*; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.filter.FilterCard; +import mage.filter.predicate.mageobject.HistoricPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.FoodToken; +import mage.players.Player; +import mage.watchers.Watcher; + + +/** + * @author padfoothelix + */ +public final class TheFourthDoctor extends CardImpl { + + public TheFourthDoctor(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{U}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.TIME_LORD); + this.subtype.add(SubType.DOCTOR); + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // You may look at the top card of your library any time. + this.addAbility(new SimpleStaticAbility(new LookAtTopCardOfLibraryAnyTimeEffect())); + + // Would You Like A...? -- Once each turn, you may play a historic land or cast a historic spell from the top of your library. When you do, create a Food token. + this.addAbility( + new SimpleStaticAbility( + new TheFourthDoctorPlayFromTopEffect()) + .setIdentifier(MageIdentifier.TheFourthDoctorWatcher) + .addHint(new ConditionPermanentHint( + TheFourthDoctorCondition.instance, + "You may play a historic land or cast a historic spell from the top of your library.", + null, + "You have already played a historic land or cast a historic spell from the top of your library this turn", + null, + true + )) + .withFlavorWord("Would You Like A…?"), + new TheFourthDoctorWatcher() + ); + this.addAbility(new TheFourthDoctorTriggeredAbility()); + } + + private TheFourthDoctor(final TheFourthDoctor card) { + super(card); + } + + @Override + public TheFourthDoctor copy() { + return new TheFourthDoctor(this); + } +} + +class TheFourthDoctorPlayFromTopEffect extends PlayFromTopOfLibraryEffect { + + private static final FilterCard filter = new FilterCard(""); + + static { + filter.add(HistoricPredicate.instance); + } + + TheFourthDoctorPlayFromTopEffect() { + super(filter); + staticText = "Once each turn, you may play a historic land or cast a historic spell from the top of your library. " + + "When you do, create a Food token."; + } + + private TheFourthDoctorPlayFromTopEffect(final TheFourthDoctorPlayFromTopEffect effect) { + super(effect); + } + + @Override + public TheFourthDoctorPlayFromTopEffect copy() { + return new TheFourthDoctorPlayFromTopEffect(this); + } + + @Override + public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { + + if (!super.applies(objectId, affectedAbility, source, game, playerId)) { + return false; + } + + Player controller = game.getPlayer(source.getControllerId()); + TheFourthDoctorWatcher watcher = game.getState().getWatcher(TheFourthDoctorWatcher.class); + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + + return controller != null + && watcher != null + && !watcher.isAbilityUsed( + controller.getId(), + new MageObjectReference(sourcePermanent, game) + ); + } +} + +class TheFourthDoctorTriggeredAbility extends TriggeredAbilityImpl { + + TheFourthDoctorTriggeredAbility() { + super(Zone.BATTLEFIELD, new CreateTokenEffect(new FoodToken())); + this.setRuleVisible(false); + } + + private TheFourthDoctorTriggeredAbility(final TheFourthDoctorTriggeredAbility ability) { + super(ability); + } + + @Override + public TheFourthDoctorTriggeredAbility copy() { + return new TheFourthDoctorTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.SPELL_CAST + || event.getType() == GameEvent.EventType.LAND_PLAYED; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + // returns true if a card was played via this card's ability + // (i.e. same identifier and same approving object) + if (event.hasApprovingIdentifier(MageIdentifier.TheFourthDoctorWatcher)) { + return event + .getApprovingObject() + .getApprovingAbility() + .getSourceId() + .equals(this.getSourceId()); + } + return false; + } +} + +// adapted from OnceEachTurnCastWatcher +class TheFourthDoctorWatcher extends Watcher { + + // we store a map of playerIds linked to a set of used approving objects. + private final Map> usedFrom = new HashMap<>(); + + TheFourthDoctorWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if ((event.getType() == GameEvent.EventType.SPELL_CAST + ||event.getType() == GameEvent.EventType.LAND_PLAYED) + && event.getPlayerId()!= null + && event.hasApprovingIdentifier(MageIdentifier.TheFourthDoctorWatcher)) { + usedFrom.computeIfAbsent(event.getPlayerId(), k -> new HashSet<>()) + .add(event.getApprovingObject().getApprovingMageObjectReference()); + + } + } + + @Override + public void reset() { + super.reset(); + usedFrom.clear(); + } + + boolean isAbilityUsed(UUID playerId, MageObjectReference mor) { + return usedFrom.getOrDefault(playerId, Collections.emptySet()).contains(mor); + } +} + +enum TheFourthDoctorCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + TheFourthDoctorWatcher watcher = game.getState().getWatcher(TheFourthDoctorWatcher.class); + return watcher != null + && !watcher.isAbilityUsed(source.getControllerId(), new MageObjectReference(source.getSourceId(), game)); + } +} diff --git a/Mage.Sets/src/mage/sets/DoctorWho.java b/Mage.Sets/src/mage/sets/DoctorWho.java index e90aca9d94d..9a907dce2a1 100644 --- a/Mage.Sets/src/mage/sets/DoctorWho.java +++ b/Mage.Sets/src/mage/sets/DoctorWho.java @@ -942,14 +942,14 @@ public final class DoctorWho extends ExpansionSet { //cards.add(new SetCardInfo("The Foretold Soldier", 395, Rarity.RARE, mage.cards.t.TheForetoldSoldier.class, NON_FULL_USE_VARIOUS)); //cards.add(new SetCardInfo("The Foretold Soldier", 707, Rarity.RARE, mage.cards.t.TheForetoldSoldier.class, NON_FULL_USE_VARIOUS)); //cards.add(new SetCardInfo("The Foretold Soldier", 986, Rarity.RARE, mage.cards.t.TheForetoldSoldier.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", "555z", Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 1006, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 1146, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 193, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 2, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 415, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 555, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); - //cards.add(new SetCardInfo("The Fourth Doctor", 607, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", "555z", Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 1006, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 1146, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 193, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 2, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 415, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 555, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("The Fourth Doctor", 607, Rarity.MYTHIC, mage.cards.t.TheFourthDoctor.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("The Fugitive Doctor", 1008, Rarity.RARE, mage.cards.t.TheFugitiveDoctor.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("The Fugitive Doctor", 1132, Rarity.RARE, mage.cards.t.TheFugitiveDoctor.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("The Fugitive Doctor", 130, Rarity.RARE, mage.cards.t.TheFugitiveDoctor.class, NON_FULL_USE_VARIOUS)); diff --git a/Mage/src/main/java/mage/MageIdentifier.java b/Mage/src/main/java/mage/MageIdentifier.java index db65ff23de3..08224c3a446 100644 --- a/Mage/src/main/java/mage/MageIdentifier.java +++ b/Mage/src/main/java/mage/MageIdentifier.java @@ -38,6 +38,7 @@ public enum MageIdentifier { CoramTheUndertakerWatcher, ThundermanDragonWatcher, LockeTreasureHunterWatcher, + TheFourthDoctorWatcher, // ----------------------------// // alternate casts //