forked from External/mage
[OGW] Fixed Surge to work with triggered abilities of permanents.
This commit is contained in:
parent
d4692d6371
commit
af5ff0f407
5 changed files with 60 additions and 11 deletions
|
|
@ -53,18 +53,17 @@ public class TyrantOfValakut extends CardImpl {
|
|||
this.power = new MageInt(5);
|
||||
this.toughness = new MageInt(4);
|
||||
|
||||
// Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn)
|
||||
addAbility(new SurgeAbility(this, "{3}{R}{R}"));
|
||||
|
||||
// Flying
|
||||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
|
||||
// When Tyrant of Valakut enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player.
|
||||
EntersBattlefieldTriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new DamageTargetEffect(3), false);
|
||||
ability.addTarget(new TargetCreatureOrPlayer());
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, SurgedCondition.getInstance(),
|
||||
"When {this} enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player."));
|
||||
|
||||
// Has to be placed last here, because added spellAbility objects (e.g. effects) have to be copied from this
|
||||
// Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn)
|
||||
addAbility(new SurgeAbility(this, "{3}{R}{R}"));
|
||||
}
|
||||
|
||||
public TyrantOfValakut(final TyrantOfValakut card) {
|
||||
|
|
|
|||
|
|
@ -88,4 +88,26 @@ public class SurgeTest extends CardTestPlayerBase {
|
|||
assertLife(playerB, 17);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTyrantOfValakut() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
|
||||
// Surge {3}{R}{R} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn)
|
||||
// Flying
|
||||
// When Tyrant of Valakut enters the battlefield, if its surge cost was paid, it deals 3 damage to target creature or player.
|
||||
addCard(Zone.HAND, playerA, "Tyrant of Valakut"); // {5}{R}{R}
|
||||
addCard(Zone.HAND, playerA, "Lightning Bolt");
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tyrant of Valakut");
|
||||
addTarget(playerA, playerB);
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertGraveyardCount(playerA, "Lightning Bolt", 1);
|
||||
assertPermanentCount(playerA, "Tyrant of Valakut", 1);
|
||||
|
||||
assertLife(playerB, 14);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase {
|
|||
/**
|
||||
* Geist of Saint Traft - Legendary Spirit Cleric 2/2, {1}{W}{U}
|
||||
*
|
||||
* Hexproof
|
||||
* Whenever Geist of Saint Traft attacks, put a 4/4 white Angel creature token with flying onto the battlefield tapped and attacking. Exile that token at end of combat.
|
||||
* Hexproof Whenever Geist of Saint Traft attacks, put a 4/4 white Angel
|
||||
* creature token with flying onto the battlefield tapped and attacking.
|
||||
* Exile that token at end of combat.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
|
|
@ -51,7 +52,7 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase {
|
|||
|
||||
attack(2, playerB, "Geist of Saint Traft");
|
||||
|
||||
setStopAt(2, PhaseStep.END_COMBAT);
|
||||
setStopAt(2, PhaseStep.COMBAT_DAMAGE);
|
||||
execute();
|
||||
|
||||
assertPermanentCount(playerB, "Geist of Saint Traft", 1);
|
||||
|
|
@ -63,7 +64,6 @@ public class GeistOfSaintTraftTest extends CardTestPlayerBase {
|
|||
assertLife(playerB, 20);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTokenwillBeExiled() {
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@
|
|||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.keyword.SurgeAbility;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
|
|
@ -52,7 +54,15 @@ public class SurgedCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
// if surge is used for permanents we have to chnage implementation
|
||||
return source instanceof SurgeAbility;
|
||||
if (source.getAbilityType().equals(AbilityType.TRIGGERED)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<Integer> surgeActivations = (ArrayList) game.getState().getValue(SurgeAbility.SURGE_ACTIVATION_VALUE_KEY + source.getSourceId());
|
||||
if (surgeActivations != null) {
|
||||
return surgeActivations.contains(game.getState().getZoneChangeCounter(source.getSourceId()) - 1);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return source instanceof SurgeAbility;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
|
|
@ -43,6 +44,8 @@ import mage.watchers.common.CastSpellLastTurnWatcher;
|
|||
*/
|
||||
public class SurgeAbility extends SpellAbility {
|
||||
|
||||
public static final String SURGE_ACTIVATION_VALUE_KEY = "surgeActivation";
|
||||
|
||||
private String rule;
|
||||
|
||||
public SurgeAbility(Card card, String surgeCosts) {
|
||||
|
|
@ -81,6 +84,21 @@ public class SurgeAbility extends SpellAbility {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean activate(Game game, boolean noMana) {
|
||||
if (super.activate(game, noMana)) {
|
||||
ArrayList<Integer> surgeActivations = (ArrayList) game.getState().getValue(SURGE_ACTIVATION_VALUE_KEY + getSourceId());
|
||||
if (surgeActivations == null) {
|
||||
surgeActivations = new ArrayList<>(); // zoneChangeCounter
|
||||
game.getState().setValue(SURGE_ACTIVATION_VALUE_KEY + getSourceId(), surgeActivations);
|
||||
}
|
||||
surgeActivations.add(game.getState().getZoneChangeCounter(getSourceId()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SurgeAbility copy() {
|
||||
return new SurgeAbility(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue