fixed Pelt Collector implementation, expanded test

This commit is contained in:
Evan Kranzler 2020-09-22 17:23:42 -04:00
parent 52047c046b
commit a022d79b65
2 changed files with 184 additions and 94 deletions

View file

@ -1,36 +1,36 @@
package mage.cards.p; package mage.cards.p;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.SourceHasCounterCondition; import mage.abilities.condition.common.SourceHasCounterCondition;
import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.constants.SubType;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/** /**
*
* @author TheElk801 * @author TheElk801
*/ */
public final class PeltCollector extends CardImpl { public final class PeltCollector extends CardImpl {
private static final Condition condition = new SourceHasCounterCondition(CounterType.P1P1, 3);
public PeltCollector(UUID ownerId, CardSetInfo setInfo) { public PeltCollector(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}");
@ -40,19 +40,13 @@ public final class PeltCollector extends CardImpl {
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector. // Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector.
this.addAbility(new PeltCollectorAbility()); this.addAbility(new PeltCollectorTriggeredAbility());
// As long as Pelt Collector has three or more +1/+1 counters on it, it has trample. // As long as Pelt Collector has three or more +1/+1 counters on it, it has trample.
this.addAbility(new SimpleStaticAbility( this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD, new ConditionalContinuousEffect(new GainAbilitySourceEffect(
new ConditionalContinuousEffect( TrampleAbility.getInstance(), Duration.WhileOnBattlefield
new GainAbilitySourceEffect( ), condition, "As long as {this} has three or more +1/+1 counters on it, it has trample.")
TrampleAbility.getInstance(),
Duration.WhileOnBattlefield
), new SourceHasCounterCondition(CounterType.P1P1, 3),
"As long as {this} has three or more +1/+1 "
+ "counters on it, it has trample."
)
)); ));
} }
@ -66,43 +60,52 @@ public final class PeltCollector extends CardImpl {
} }
} }
class PeltCollectorAbility extends TriggeredAbilityImpl { class PeltCollectorTriggeredAbility extends TriggeredAbilityImpl {
public PeltCollectorAbility() { PeltCollectorTriggeredAbility() {
super(Zone.BATTLEFIELD, new PeltCollectorEffect()); super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()));
} }
public PeltCollectorAbility(PeltCollectorAbility ability) { private PeltCollectorTriggeredAbility(PeltCollectorTriggeredAbility ability) {
super(ability); super(ability);
} }
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) return (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD)
|| (event.getType() == GameEvent.EventType.ZONE_CHANGE || (event.getType() == GameEvent.EventType.ZONE_CHANGE
&& ((ZoneChangeEvent) event).isDiesEvent()) ; && ((ZoneChangeEvent) event).isDiesEvent());
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(this.getSourceId())) { if (event.getTargetId().equals(this.getSourceId())
|| !event.getPlayerId().equals(getControllerId())) {
return false; return false;
} }
Permanent triggeringCreature = game.getPermanentOrLKIBattlefield(event.getTargetId()); Permanent triggeringCreature = game.getPermanentOrLKIBattlefield(event.getTargetId());
Permanent sourceCreature = game.getPermanent(this.getSourceId()); if (triggeringCreature == null) {
if (isPowerGreater(sourceCreature, triggeringCreature) return false;
&& triggeringCreature.isCreature()
&& triggeringCreature.isControlledBy(this.getControllerId())) {
this.getEffects().setTargetPointer(new FixedTarget(triggeringCreature, game));
return true;
} }
return false; this.getEffects().setValue("permanentEnteredOrDied", triggeringCreature);
return true;
} }
public static boolean isPowerGreater(Permanent sourceCreature, Permanent newCreature) { @Override
return sourceCreature != null && newCreature != null public boolean checkInterveningIfClause(Game game) {
&& newCreature.getPower().getValue() Permanent sourcePerm = getSourcePermanentIfItStillExists(game);
> sourceCreature.getPower().getValue(); if (sourcePerm == null) {
return false;
}
Permanent permanent = null;
for (Effect effect : this.getEffects()) {
Object obj = effect.getValue("permanentEnteredOrDied");
if (obj instanceof Permanent) {
permanent = (Permanent) obj;
break;
}
}
return permanent != null && permanent.getPower().getValue() > sourcePerm.getPower().getValue();
} }
@Override @Override
@ -113,33 +116,7 @@ class PeltCollectorAbility extends TriggeredAbilityImpl {
} }
@Override @Override
public PeltCollectorAbility copy() { public PeltCollectorTriggeredAbility copy() {
return new PeltCollectorAbility(this); return new PeltCollectorTriggeredAbility(this);
}
}
class PeltCollectorEffect extends OneShotEffect {
public PeltCollectorEffect() {
super(Outcome.BoostCreature);
}
public PeltCollectorEffect(final PeltCollectorEffect effect) {
super(effect);
}
@Override
public PeltCollectorEffect copy() {
return new PeltCollectorEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent triggeringCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (!PeltCollectorAbility.isPowerGreater(sourceCreature, triggeringCreature)) {
return false;
}
return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
} }
} }

View file

@ -3,16 +3,24 @@ package org.mage.test.cards.single.grn;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.Filter; import mage.filter.Filter;
import org.junit.Test; import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
/** /**
* * @author LevelX2, TheElk801
* @author LevelX2
*/ */
public class PeltCollectorTest extends CardTestPlayerBase { public class PeltCollectorTest extends CardTestPlayerBase {
private static final String pltclctr = "Pelt Collector";
private static final String slvrctln = "Silvercoat Lion";
private static final String trstn = "Trostani Discordant";
private static final String grzlybrs = "Grizzly Bears";
private static final String mrdr = "Murder";
private static final String cntrcrsr = "Centaur Courser";
private static final String gntgrwth = "Giant Growth";
@Test @Test
public void test_Simple() { public void test_Simple() {
setStrictChooseMode(true); setStrictChooseMode(true);
@ -21,13 +29,13 @@ public class PeltCollectorTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
// Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector. // Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector.
// As long as Pelt Collector has three or more +1/+1 counters on it, it has trample. // As long as Pelt Collector has three or more +1/+1 counters on it, it has trample.
addCard(Zone.HAND, playerA, "Pelt Collector", 1); // Creature {G} addCard(Zone.HAND, playerA, pltclctr, 1); // Creature {G}
addCard(Zone.HAND, playerA, "Silvercoat Lion", 1); // Creature {1}{W} addCard(Zone.HAND, playerA, slvrctln, 1); // Creature {1}{W}
addCard(Zone.BATTLEFIELD, playerB, "Pelt Collector", 1);// Creature {G} addCard(Zone.BATTLEFIELD, playerB, pltclctr, 1);// Creature {G}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Pelt Collector"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, pltclctr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, slvrctln);
setStopAt(1, PhaseStep.BEGIN_COMBAT); setStopAt(1, PhaseStep.BEGIN_COMBAT);
@ -35,13 +43,12 @@ public class PeltCollectorTest extends CardTestPlayerBase {
assertAllCommandsUsed(); assertAllCommandsUsed();
assertPowerToughness(playerB, "Pelt Collector", 1, 1); assertPowerToughness(playerB, pltclctr, 1, 1);
assertPowerToughness(playerA, "Silvercoat Lion", 2, 2);
assertPowerToughness(playerA, "Pelt Collector", 2, 2);
assertAbility(playerA, "Pelt Collector", TrampleAbility.getInstance(), false);
assertAbility(playerB, "Pelt Collector", TrampleAbility.getInstance(), false);
assertPowerToughness(playerA, slvrctln, 2, 2);
assertPowerToughness(playerA, pltclctr, 2, 2);
assertAbility(playerA, pltclctr, TrampleAbility.getInstance(), false);
assertAbility(playerB, pltclctr, TrampleAbility.getInstance(), false);
} }
/** /**
@ -50,7 +57,7 @@ public class PeltCollectorTest extends CardTestPlayerBase {
* static abilities (such as that of Trostani Discordant) that modify its * static abilities (such as that of Trostani Discordant) that modify its
* power. * power.
*/ */
@Test @Test
public void test_TrostaniDiscordant() { public void test_TrostaniDiscordant() {
setStrictChooseMode(true); setStrictChooseMode(true);
@ -58,19 +65,19 @@ public class PeltCollectorTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); addCard(Zone.BATTLEFIELD, playerA, "Plains", 3);
// Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector. // Whenever another creature you control enters the battlefield or dies, if that creature's power is greater than Pelt Collector's, put a +1/+1 counter on Pelt Collector.
// As long as Pelt Collector has three or more +1/+1 counters on it, it has trample. // As long as Pelt Collector has three or more +1/+1 counters on it, it has trample.
addCard(Zone.HAND, playerA, "Pelt Collector", 1); // Creature {G} addCard(Zone.HAND, playerA, pltclctr, 1); // Creature {G}
addCard(Zone.HAND, playerA, "Silvercoat Lion", 1); // Creature {1}{W} addCard(Zone.HAND, playerA, slvrctln, 1); // Creature {1}{W}
// Other creatures you control get +1/+1. // Other creatures you control get +1/+1.
// When Trostani Discordant enters the battlefield, create two 1/1 white Soldier creature tokens with lifelink. // When Trostani Discordant enters the battlefield, create two 1/1 white Soldier creature tokens with lifelink.
// At the beginning of your end step, each player gains control of all creatures they own. // At the beginning of your end step, each player gains control of all creatures they own.
addCard(Zone.HAND, playerA, "Trostani Discordant", 1); // Creature {3}{G}{W} /1/4) addCard(Zone.HAND, playerA, trstn, 1); // Creature {3}{G}{W} /1/4)
addCard(Zone.BATTLEFIELD, playerB, "Pelt Collector", 1);// Creature {G}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Trostani Discordant"); addCard(Zone.BATTLEFIELD, playerB, pltclctr, 1);// Creature {G}
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Pelt Collector"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, trstn);
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion");
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, pltclctr);
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, slvrctln);
setStopAt(3, PhaseStep.BEGIN_COMBAT); setStopAt(3, PhaseStep.BEGIN_COMBAT);
@ -78,14 +85,120 @@ public class PeltCollectorTest extends CardTestPlayerBase {
assertAllCommandsUsed(); assertAllCommandsUsed();
assertPowerToughness(playerB, "Pelt Collector", 1, 1); assertPowerToughness(playerB, pltclctr, 1, 1);
assertPowerToughness(playerA, "Soldier", 2, 2, Filter.ComparisonScope.All); assertPowerToughness(playerA, "Soldier", 2, 2, Filter.ComparisonScope.All);
assertPowerToughness(playerA, "Silvercoat Lion", 3, 3);
assertPowerToughness(playerA, "Pelt Collector", 3, 3);
assertAbility(playerA, "Pelt Collector", TrampleAbility.getInstance(), false);
assertAbility(playerB, "Pelt Collector", TrampleAbility.getInstance(), false);
} assertPowerToughness(playerA, slvrctln, 3, 3);
assertPowerToughness(playerA, pltclctr, 3, 3);
assertAbility(playerA, pltclctr, TrampleAbility.getInstance(), false);
assertAbility(playerB, pltclctr, TrampleAbility.getInstance(), false);
}
@Test
public void testEntersTrigger() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, pltclctr);
addCard(Zone.HAND, playerA, grzlybrs);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, grzlybrs);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, pltclctr, 2, 2);
assertCounterCount(pltclctr, CounterType.P1P1, 1);
}
@Test
public void testDiesTrigger() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, pltclctr);
addCard(Zone.HAND, playerA, grzlybrs);
addCard(Zone.HAND, playerA, mrdr);
addCard(Zone.BATTLEFIELD, playerA, "Bayou", 5);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, grzlybrs);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, mrdr, grzlybrs);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, pltclctr, 2, 2);
assertCounterCount(pltclctr, CounterType.P1P1, 1);
}
@Test
public void testDiesTrigger2() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, pltclctr);
addCard(Zone.HAND, playerA, cntrcrsr);
addCard(Zone.HAND, playerA, mrdr);
addCard(Zone.BATTLEFIELD, playerA, "Bayou", 6);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, cntrcrsr);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, mrdr, cntrcrsr);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, pltclctr, 3, 3);
assertCounterCount(pltclctr, CounterType.P1P1, 2);
}
@Test
public void testInterveningIf() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, pltclctr);
addCard(Zone.HAND, playerA, grzlybrs);
addCard(Zone.HAND, playerA, gntgrwth);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, grzlybrs);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, gntgrwth, pltclctr);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, pltclctr, 4, 4);
assertCounterCount(pltclctr, CounterType.P1P1, 0);
}
@Test
public void testInterveningIf2() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, pltclctr);
addCard(Zone.HAND, playerA, grzlybrs);
addCard(Zone.HAND, playerA, "Scar");
addCard(Zone.BATTLEFIELD, playerA, "Bayou", 3);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, grzlybrs);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Scar", grzlybrs);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, pltclctr, 1, 1);
assertCounterCount(pltclctr, CounterType.P1P1, 0);
}
} }