fixes ticket 47

This commit is contained in:
North 2012-03-27 09:43:46 +03:00
parent deb6533bd8
commit 86c93b2a06
2 changed files with 59 additions and 48 deletions

View file

@ -30,10 +30,8 @@ package mage.sets.innistrad;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Layer;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.Constants.SubLayer;
import mage.Constants.Zone;
import mage.MageInt;
import mage.MageObject;
@ -41,12 +39,9 @@ import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.CountersCount;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continious.SetPowerToughnessSourceEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.game.Game;
@ -71,7 +66,6 @@ public class GutterGrime extends CardImpl<GutterGrime> {
// Whenever a nontoken creature you control dies, put a slime counter on Gutter Grime, then put a green Ooze creature token onto the battlefield with "This creature's power and toughness are each equal to the number of slime counters on Gutter Grime."
this.addAbility(new GutterGrimeTriggeredAbility());
}
public GutterGrime(final GutterGrime card) {
@ -105,7 +99,7 @@ class GutterGrimeTriggeredAbility extends TriggeredAbilityImpl<GutterGrimeTrigge
if (event.getType() == EventType.ZONE_CHANGE) {
UUID targetId = event.getTargetId();
MageObject card = game.getLastKnownInformation(targetId, Zone.BATTLEFIELD);
if (card != null && card instanceof Permanent && !(card instanceof PermanentToken)) {
if (card instanceof Permanent && !(card instanceof PermanentToken)) {
Permanent permanent = (Permanent) card;
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD
@ -158,46 +152,12 @@ class GutterGrimeToken extends Token {
cardType.add(CardType.CREATURE);
subtype.add("Ooze");
color.setGreen(true);
power = MageInt.EmptyMageInt;
toughness = MageInt.EmptyMageInt;
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GutterGrimeTokenEffect(sourceId)));
power = new MageInt(0);
toughness = new MageInt(0);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetPowerToughnessSourceEffect(new GutterGrimeCounters(sourceId), Duration.WhileOnBattlefield)));
}
}
class GutterGrimeTokenEffect extends ContinuousEffectImpl<GutterGrimeTokenEffect> {
private GutterGrimeCounters counters;
public GutterGrimeTokenEffect(UUID sourceId) {
super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.SetPT_7b, Outcome.BoostCreature);
counters = new GutterGrimeCounters(sourceId);
staticText = "This creature's power and toughness are each equal to the number of slime counters on Gutter Grime";
}
public GutterGrimeTokenEffect(final GutterGrimeTokenEffect effect) {
super(effect);
counters = effect.counters.clone();
}
@Override
public GutterGrimeTokenEffect copy() {
return new GutterGrimeTokenEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent token = game.getPermanent(source.getSourceId());
if (token != null) {
int count = counters.calculate(game, source);
token.getPower().setValue(count);
token.getToughness().setValue(count);
return true;
}
return false;
}
}
class GutterGrimeCounters implements DynamicValue {
private UUID sourceId;
@ -222,11 +182,11 @@ class GutterGrimeCounters implements DynamicValue {
@Override
public String getMessage() {
return "the number of slime counters on Gutter Grime";
return "slime counters on Gutter Grime";
}
@Override
public String toString() {
return "+X";
return "1";
}
}

View file

@ -0,0 +1,51 @@
package org.mage.test.cards;
import mage.Constants.PhaseStep;
import mage.Constants.Zone;
import mage.filter.Filter;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author North
*/
public class TestGutterGrime extends CardTestPlayerBase {
/**
* If Gutter Grime leaves the battlefield, the power and toughness of each Ooze token it created will become 0.
* Unless another effect is raising its toughness above 0, each of these Ooze tokens will be put into its owner's
* graveyard the next time state-based actions are checked.
*/
@Test
public void testScenario1() {
addCard(Zone.BATTLEFIELD, playerA, "Gutter Grime");
addCard(Zone.BATTLEFIELD, playerA, "Runeclaw Bear", 2);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
addCard(Zone.HAND, playerA, "Lightning Bolt", 1);
addCard(Zone.HAND, playerA, "Naturalize", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Runeclaw Bear");
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Naturalize", "Gutter Grime");
setStopAt(3, PhaseStep.END_TURN);
execute();
assertPermanentCount(playerA, "Ooze", 0);
}
@Test
public void testScenario2() {
addCard(Zone.BATTLEFIELD, playerA, "Intangible Virtue");
addCard(Zone.BATTLEFIELD, playerA, "Gutter Grime");
addCard(Zone.BATTLEFIELD, playerA, "Runeclaw Bear", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.HAND, playerA, "Lightning Bolt", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", "Runeclaw Bear");
setStopAt(3, PhaseStep.END_TURN);
execute();
assertPowerToughness(playerA, "Ooze", 2, 2, Filter.ComparisonScope.Any);
}
}