[WOE] Implement Johann, Apprentice Sorcerer (#10877)

This commit is contained in:
Susucre 2023-08-18 21:17:59 +02:00 committed by GitHub
parent 54ec026369
commit ea513386fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 168 additions and 1 deletions

View file

@ -0,0 +1,165 @@
package mage.cards.j;
import mage.MageIdentifier;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.common.continuous.LookAtTopCardOfLibraryAnyTimeEffect;
import mage.abilities.hint.Hint;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.*;
/**
* @author Susucr
*/
public final class JohannApprenticeSorcerer extends CardImpl {
public JohannApprenticeSorcerer(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}{R}");
this.supertype.add(SuperType.LEGENDARY);
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.WIZARD);
this.power = new MageInt(2);
this.toughness = new MageInt(5);
// You may look at the top card of your library any time.
this.addAbility(new SimpleStaticAbility(new LookAtTopCardOfLibraryAnyTimeEffect()));
// Once each turn, you may cast an instant or sorcery spell from the top of your library.
this.addAbility(
new SimpleStaticAbility(new JohannApprenticeSorcererPlayTopEffect())
.setIdentifier(MageIdentifier.JohannApprenticeSorcererWatcher)
.addHint(JohannApprenticeSorcererHint.instance),
new JohannApprenticeSorcererWatcher()
);
}
private JohannApprenticeSorcerer(final JohannApprenticeSorcerer card) {
super(card);
}
@Override
public JohannApprenticeSorcerer copy() {
return new JohannApprenticeSorcerer(this);
}
}
enum JohannApprenticeSorcererHint implements Hint {
instance;
@Override
public String getText(Game game, Ability ability) {
JohannApprenticeSorcererWatcher watcher = game.getState().getWatcher(JohannApprenticeSorcererWatcher.class);
if (watcher != null) {
boolean used = watcher.isAbilityUsed(ability.getControllerId(), new MageObjectReference(ability.getSourceId(), game));
if (used) {
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
return "A spell has been cast by " + player.getLogName() + " with {this} this turn.";
}
}
}
return "";
}
@Override
public JohannApprenticeSorcererHint copy() {
return this;
}
}
class JohannApprenticeSorcererPlayTopEffect extends AsThoughEffectImpl {
public JohannApprenticeSorcererPlayTopEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.WhileOnBattlefield, Outcome.Benefit, true);
staticText = "Once each turn, you may cast an instant or sorcery spell from the top of your library";
}
private JohannApprenticeSorcererPlayTopEffect(final JohannApprenticeSorcererPlayTopEffect effect) {
super(effect);
}
@Override
public JohannApprenticeSorcererPlayTopEffect copy() {
return new JohannApprenticeSorcererPlayTopEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
// Only applies for the controller of the ability.
if (!affectedControllerId.equals(source.getControllerId())) {
return false;
}
Player controller = game.getPlayer(source.getControllerId());
JohannApprenticeSorcererWatcher watcher = game.getState().getWatcher(JohannApprenticeSorcererWatcher.class);
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (controller == null || watcher == null || sourceObject == null) {
return false;
}
// Has the ability already been used this turn by the player?
if (watcher.isAbilityUsed(controller.getId(), new MageObjectReference(sourceObject, game))) {
return false;
}
Card card = game.getCard(objectId);
Card topCard = controller.getLibrary().getFromTop(game);
// Is the card attempted to be played the top card of the library?
if (card == null || topCard == null || !topCard.getId().equals(card.getMainCard().getId())) {
return false;
}
// Only works for instant & sorcery.
return card.isInstantOrSorcery(game);
}
}
class JohannApprenticeSorcererWatcher extends Watcher {
// player -> set of all permanent's mor that already used their once per turn Approval.
private final Map<UUID, Set<MageObjectReference>> usedFrom = new HashMap<>();
public JohannApprenticeSorcererWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
UUID playerId = event.getPlayerId();
if (event.getType() == GameEvent.EventType.SPELL_CAST
&& event.hasApprovingIdentifier(MageIdentifier.JohannApprenticeSorcererWatcher)
&& playerId != null) {
usedFrom.computeIfAbsent(playerId, k -> new HashSet<>())
.add(event.getAdditionalReference().getApprovingMageObjectReference());
}
}
@Override
public void reset() {
super.reset();
usedFrom.clear();
}
public boolean isAbilityUsed(UUID playerId, MageObjectReference mor) {
return usedFrom.getOrDefault(playerId, new HashSet<>()).contains(mor);
}
}

View file

@ -52,6 +52,7 @@ public final class WildsOfEldraine extends ExpansionSet {
cards.add(new SetCardInfo("Hopeless Nightmare", 95, Rarity.COMMON, mage.cards.h.HopelessNightmare.class));
cards.add(new SetCardInfo("Howling Galefang", 175, Rarity.UNCOMMON, mage.cards.h.HowlingGalefang.class));
cards.add(new SetCardInfo("Island", 263, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Johann, Apprentice Sorcerer", 207, Rarity.UNCOMMON, mage.cards.j.JohannApprenticeSorcerer.class));
cards.add(new SetCardInfo("Kellan, the Fae-Blooded", 230, Rarity.MYTHIC, mage.cards.k.KellanTheFaeBlooded.class));
cards.add(new SetCardInfo("Knight of Doves", 19, Rarity.UNCOMMON, mage.cards.k.KnightOfDoves.class));
cards.add(new SetCardInfo("Lich-Knights' Conquest", 96, Rarity.RARE, mage.cards.l.LichKnightsConquest.class));

View file

@ -19,5 +19,6 @@ public enum MageIdentifier {
WishWatcher,
GlimpseTheCosmosWatcher,
SerraParagonWatcher,
OneWithTheMultiverseWatcher
OneWithTheMultiverseWatcher,
JohannApprenticeSorcererWatcher
}