Implemented Tuvasa the Sunlit

This commit is contained in:
Evan Kranzler 2018-07-25 16:45:57 -04:00
parent 2a6181b67a
commit ea2842cd23
2 changed files with 154 additions and 0 deletions

View file

@ -0,0 +1,153 @@
package mage.cards.t;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.TargetController;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.FilterSpell;
import mage.filter.common.FilterEnchantmentPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
/**
*
* @author TheElk801
*/
public final class TuvasaTheSunlit extends CardImpl {
private static final FilterEnchantmentPermanent filter
= new FilterEnchantmentPermanent("enchantment you control");
static {
filter.add(new ControllerPredicate(TargetController.YOU));
}
public TuvasaTheSunlit(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}{W}{U}");
this.addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.MERFOLK);
this.subtype.add(SubType.SHAMAN);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// Tuvasa the Sunlit gets +1/+1 for each enchantment you control.
DynamicValue value
= new PermanentsOnBattlefieldCount(new FilterPermanent(filter));
Ability ability = new SimpleStaticAbility(
Zone.BATTLEFIELD,
new BoostSourceEffect(
value, value, Duration.WhileOnBattlefield
).setText("{this} gets +1/+1 for each enchantment you control")
);
this.addAbility(ability);
// Whenever you cast your first enchantment spell each turn, draw a card.
this.addAbility(
new TuvasaTheSunlitTriggeredAbility(),
new TuvasaTheSunlitWatcher()
);
}
public TuvasaTheSunlit(final TuvasaTheSunlit card) {
super(card);
}
@Override
public TuvasaTheSunlit copy() {
return new TuvasaTheSunlit(this);
}
}
class TuvasaTheSunlitTriggeredAbility extends SpellCastControllerTriggeredAbility {
private static final FilterSpell filter
= new FilterSpell("an enchantment spell");
static {
filter.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
public TuvasaTheSunlitTriggeredAbility() {
super(new DrawCardSourceControllerEffect(1), filter, false);
this.rule = "Whenever you cast your first enchantment spell each turn, draw a card.";
}
public TuvasaTheSunlitTriggeredAbility(final TuvasaTheSunlitTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!super.checkTrigger(event, game)) {
return false;
}
TuvasaTheSunlitWatcher watcher = (TuvasaTheSunlitWatcher) game.getState().getWatchers().get(TuvasaTheSunlitWatcher.class.getSimpleName());
MageObjectReference mor = watcher.getFirstEnchantmentThisTurn(this.getControllerId());
return mor == null || mor.refersTo(event.getTargetId(), game);
}
}
class TuvasaTheSunlitWatcher extends Watcher {
private final Map<UUID, MageObjectReference> firstEnchantmentThisTurn = new HashMap();
public TuvasaTheSunlitWatcher() {
super(TuvasaTheSunlitWatcher.class.getSimpleName(), WatcherScope.GAME);
}
public TuvasaTheSunlitWatcher(final TuvasaTheSunlitWatcher watcher) {
super(watcher);
this.firstEnchantmentThisTurn.putAll(watcher.firstEnchantmentThisTurn);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.isEnchantment()) {
firstEnchantmentThisTurn.putIfAbsent(
event.getPlayerId(),
new MageObjectReference(spell, game)
);
}
}
}
@Override
public void reset() {
firstEnchantmentThisTurn.clear();
}
public MageObjectReference getFirstEnchantmentThisTurn(UUID playerId) {
return firstEnchantmentThisTurn.get(playerId);
}
@Override
public Watcher copy() {
return new TuvasaTheSunlitWatcher(this);
}
}

View file

@ -59,6 +59,7 @@ public final class Commander2018 extends ExpansionSet {
cards.add(new SetCardInfo("Tawnos, Urza's Apprentice", 45, Rarity.MYTHIC, mage.cards.t.TawnosUrzasApprentice.class));
cards.add(new SetCardInfo("Thantis the Warweaver", 46, Rarity.MYTHIC, mage.cards.t.ThantisTheWarweaver.class));
cards.add(new SetCardInfo("Thopter Spy Network", 107, Rarity.RARE, mage.cards.t.ThopterSpyNetwork.class));
cards.add(new SetCardInfo("Tuvasa the Sunlit", 47, Rarity.MYTHIC, mage.cards.t.TuvasaTheSunlit.class));
cards.add(new SetCardInfo("Varchild, Betrayer of Kjeldor", 28, Rarity.RARE, mage.cards.v.VarchildBetrayerOfKjeldor.class));
cards.add(new SetCardInfo("Whiptongue Hydra", 36, Rarity.RARE, mage.cards.w.WhiptongueHydra.class));
}