mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
[TSP] fixed implementation of Weatherseed Totem
This commit is contained in:
parent
60a7ea797f
commit
f6306630b3
3 changed files with 87 additions and 52 deletions
|
@ -1,15 +1,12 @@
|
|||
|
||||
package mage.cards.w;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.PutIntoGraveFromBattlefieldSourceTriggeredAbility;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.common.ReturnToHandSourceEffect;
|
||||
import mage.abilities.effects.common.ReturnSourceFromGraveyardToHandEffect;
|
||||
import mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect;
|
||||
import mage.abilities.keyword.TrampleAbility;
|
||||
import mage.abilities.mana.GreenManaAbility;
|
||||
|
@ -18,13 +15,13 @@ import mage.cards.CardSetInfo;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.token.TokenImpl;
|
||||
import mage.game.permanent.token.custom.CreatureToken;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class WeatherseedTotem extends CardImpl {
|
||||
|
@ -36,13 +33,19 @@ public final class WeatherseedTotem extends CardImpl {
|
|||
this.addAbility(new GreenManaAbility());
|
||||
|
||||
// {2}{G}{G}{G}: Weatherseed Totem becomes a 5/3 green Treefolk artifact creature with trample until end of turn.
|
||||
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesCreatureSourceEffect(new WeatherseedTotemToken(), "", Duration.EndOfTurn), new ManaCostsImpl<>("{2}{G}{G}{G}")));
|
||||
this.addAbility(new SimpleActivatedAbility(new BecomesCreatureSourceEffect(
|
||||
new CreatureToken(5, 3, "5/3 green Treefolk artifact creature with trample")
|
||||
.withColor("G")
|
||||
.withSubType(SubType.TREEFOLK)
|
||||
.withType(CardType.ARTIFACT)
|
||||
.withAbility(TrampleAbility.getInstance()),
|
||||
"", Duration.EndOfTurn
|
||||
), new ManaCostsImpl<>("{2}{G}{G}{G}")));
|
||||
|
||||
// When Weatherseed Totem is put into a graveyard from the battlefield, if it was a creature, return this card to its owner's hand.
|
||||
this.addAbility(new ConditionalInterveningIfTriggeredAbility(
|
||||
new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new ReturnToHandSourceEffect()),
|
||||
new WeatherseedTotemCondition(),
|
||||
"When {this} is put into a graveyard from the battlefield, "
|
||||
new PutIntoGraveFromBattlefieldSourceTriggeredAbility(new ReturnSourceFromGraveyardToHandEffect()),
|
||||
WeatherseedTotemCondition.instance, "When {this} is put into a graveyard from the battlefield, "
|
||||
+ "if it was a creature, return this card to its owner's hand"
|
||||
));
|
||||
}
|
||||
|
@ -57,38 +60,16 @@ public final class WeatherseedTotem extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class WeatherseedTotemCondition implements Condition {
|
||||
|
||||
public WeatherseedTotemCondition() {
|
||||
}
|
||||
enum WeatherseedTotemCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
return permanent.isCreature(game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class WeatherseedTotemToken extends TokenImpl {
|
||||
|
||||
public WeatherseedTotemToken() {
|
||||
super("", "5/3 green Treefolk artifact creature with trample");
|
||||
cardType.add(CardType.CREATURE);
|
||||
cardType.add(CardType.ARTIFACT);
|
||||
subtype.add(SubType.TREEFOLK);
|
||||
color.setGreen(true);
|
||||
power = new MageInt(5);
|
||||
toughness = new MageInt(3);
|
||||
this.addAbility(TrampleAbility.getInstance());
|
||||
}
|
||||
public WeatherseedTotemToken(final WeatherseedTotemToken token) {
|
||||
super(token);
|
||||
}
|
||||
|
||||
public WeatherseedTotemToken copy() {
|
||||
return new WeatherseedTotemToken(this);
|
||||
return source
|
||||
.getEffects()
|
||||
.stream()
|
||||
.map(effect -> effect.getValue("permanentWasCreature"))
|
||||
.filter(Objects::nonNull)
|
||||
.anyMatch(Boolean.class::cast);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.mage.test.cards.single.tsp;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class WeatherseedTotemTest extends CardTestPlayerBase {
|
||||
private static final String totem = "Weatherseed Totem";
|
||||
private static final String naturalize = "Naturalize";
|
||||
|
||||
@Test
|
||||
public void testNonCreature() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, totem);
|
||||
addCard(Zone.HAND, playerA, naturalize);
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, naturalize, totem);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertHandCount(playerA, totem, 0);
|
||||
assertGraveyardCount(playerA, totem, 1);
|
||||
assertGraveyardCount(playerA, naturalize, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreature() {
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Forest", 7);
|
||||
addCard(Zone.BATTLEFIELD, playerA, totem);
|
||||
addCard(Zone.HAND, playerA, naturalize);
|
||||
|
||||
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{2}{G}{G}{G}");
|
||||
|
||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, naturalize, totem);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertHandCount(playerA, totem, 1);
|
||||
assertGraveyardCount(playerA, totem, 0);
|
||||
assertGraveyardCount(playerA, naturalize, 1);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import mage.game.permanent.Permanent;
|
|||
*/
|
||||
public class PutIntoGraveFromBattlefieldSourceTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private boolean onlyToControllerGraveyard;
|
||||
private final boolean onlyToControllerGraveyard;
|
||||
|
||||
public PutIntoGraveFromBattlefieldSourceTriggeredAbility(Effect effect) {
|
||||
this(effect, false, false);
|
||||
|
@ -42,19 +42,21 @@ public class PutIntoGraveFromBattlefieldSourceTriggeredAbility extends Triggered
|
|||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getTargetId().equals(getSourceId())) {
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
Permanent permanent = zEvent.getTarget();
|
||||
if (permanent != null
|
||||
&& zEvent.isDiesEvent()) {
|
||||
return !onlyToControllerGraveyard || this.isControlledBy(game.getOwnerId(zEvent.getTargetId()));
|
||||
}
|
||||
if (!event.getTargetId().equals(getSourceId())) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
Permanent permanent = zEvent.getTarget();
|
||||
if (permanent == null || !zEvent.isDiesEvent()
|
||||
|| (onlyToControllerGraveyard && !this.isControlledBy(game.getOwnerId(zEvent.getTargetId())))) {
|
||||
return false;
|
||||
}
|
||||
this.getEffects().setValue("permanentWasCreature", permanent.isCreature(game));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTriggerPhrase() {
|
||||
return "When {this} is put into " + (onlyToControllerGraveyard ? "your" : "a") + " graveyard from the battlefield, " ;
|
||||
return "When {this} is put into " + (onlyToControllerGraveyard ? "your" : "a") + " graveyard from the battlefield, ";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue