Merge pull request #5209 from tamaroth/master

Fix Tuvasa the Sunlit triggered ability.
This commit is contained in:
LevelX2 2018-08-15 08:52:34 +02:00 committed by GitHub
commit 1322bd3c23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 10 deletions

View file

@ -6,8 +6,8 @@ import java.util.UUID;
import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
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;
@ -81,34 +81,57 @@ public final class TuvasaTheSunlit extends CardImpl {
}
}
class TuvasaTheSunlitTriggeredAbility extends SpellCastControllerTriggeredAbility {
class TuvasaTheSunlitTriggeredAbility extends TriggeredAbilityImpl {
private static final FilterSpell filter
= new FilterSpell("an enchantment spell");
private static FilterSpell filter = new FilterSpell("an enchantment spell");
protected String rule;
static {
filter.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
public TuvasaTheSunlitTriggeredAbility() {
super(new DrawCardSourceControllerEffect(1), filter, false);
super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1));
this.rule = "Whenever you cast your first enchantment spell each turn, draw a card.";
}
public TuvasaTheSunlitTriggeredAbility(final TuvasaTheSunlitTriggeredAbility ability) {
super(ability);
this.rule = ability.rule;
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.SPELL_CAST;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!super.checkTrigger(event, game)) {
return false;
if (event.getPlayerId().equals(this.getControllerId())) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) {
TuvasaTheSunlitWatcher watcher = (TuvasaTheSunlitWatcher) game.getState().getWatchers().get(
TuvasaTheSunlitWatcher.class.getSimpleName()
);
MageObjectReference mor = watcher.getFirstEnchantmentThisTurn(this.getControllerId());
return mor.getSourceId().equals(event.getTargetId());
}
}
TuvasaTheSunlitWatcher watcher = (TuvasaTheSunlitWatcher) game.getState().getWatchers().get(TuvasaTheSunlitWatcher.class.getSimpleName());
MageObjectReference mor = watcher.getFirstEnchantmentThisTurn(this.getControllerId());
return mor == null || mor.refersTo(event.getTargetId(), game);
return false;
}
@Override
public String getRule() {
if (rule != null && !rule.isEmpty()) {
return rule;
}
return "Whenever you cast " + filter.getMessage() + ", " + super.getRule();
}
@Override
public TuvasaTheSunlitTriggeredAbility copy() {
return new TuvasaTheSunlitTriggeredAbility(this);
}
}
class TuvasaTheSunlitWatcher extends Watcher {

View file

@ -0,0 +1,40 @@
package org.mage.test.cards.triggers;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author tamaroth
*/
public class TuvasaTheSunlitTest extends CardTestPlayerBase {
/**
* Playing more than one enchantment spell in a single turn does not draw more than 1 additional card.
*/
@Test
public void testWithStriveSpell() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
// Whenever you play your first enchantment spell of the turn, draw a card.
addCard(Zone.BATTLEFIELD, playerA, "Tuvasa the Sunlit", 1);
// Two enchantments to play
addCard(Zone.HAND, playerA, "Burgeoning", 1);
addCard(Zone.HAND, playerA, "Ajani's Welcome", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Burgeoning");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ajani's Welcome");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertHandCount(playerA, 1);
}
}