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;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.SourceHasCounterCondition;
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.counter.AddCountersSourceEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.constants.SubType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class PeltCollector extends CardImpl {
private static final Condition condition = new SourceHasCounterCondition(CounterType.P1P1, 3);
public PeltCollector(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}");
@ -40,19 +40,13 @@ public final class PeltCollector extends CardImpl {
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.
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.
this.addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD,
new ConditionalContinuousEffect(
new GainAbilitySourceEffect(
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."
)
new ConditionalContinuousEffect(new GainAbilitySourceEffect(
TrampleAbility.getInstance(), Duration.WhileOnBattlefield
), condition, "As long as {this} has three or more +1/+1 counters on it, it has trample.")
));
}
@ -66,13 +60,13 @@ public final class PeltCollector extends CardImpl {
}
}
class PeltCollectorAbility extends TriggeredAbilityImpl {
class PeltCollectorTriggeredAbility extends TriggeredAbilityImpl {
public PeltCollectorAbility() {
super(Zone.BATTLEFIELD, new PeltCollectorEffect());
PeltCollectorTriggeredAbility() {
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()));
}
public PeltCollectorAbility(PeltCollectorAbility ability) {
private PeltCollectorTriggeredAbility(PeltCollectorTriggeredAbility ability) {
super(ability);
}
@ -80,29 +74,38 @@ class PeltCollectorAbility extends TriggeredAbilityImpl {
public boolean checkEventType(GameEvent event, Game game) {
return (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD)
|| (event.getType() == GameEvent.EventType.ZONE_CHANGE
&& ((ZoneChangeEvent) event).isDiesEvent()) ;
&& ((ZoneChangeEvent) event).isDiesEvent());
}
@Override
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;
}
Permanent triggeringCreature = game.getPermanentOrLKIBattlefield(event.getTargetId());
Permanent sourceCreature = game.getPermanent(this.getSourceId());
if (isPowerGreater(sourceCreature, triggeringCreature)
&& triggeringCreature.isCreature()
&& triggeringCreature.isControlledBy(this.getControllerId())) {
this.getEffects().setTargetPointer(new FixedTarget(triggeringCreature, game));
return true;
}
if (triggeringCreature == null) {
return false;
}
this.getEffects().setValue("permanentEnteredOrDied", triggeringCreature);
return true;
}
public static boolean isPowerGreater(Permanent sourceCreature, Permanent newCreature) {
return sourceCreature != null && newCreature != null
&& newCreature.getPower().getValue()
> sourceCreature.getPower().getValue();
@Override
public boolean checkInterveningIfClause(Game game) {
Permanent sourcePerm = getSourcePermanentIfItStillExists(game);
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
@ -113,33 +116,7 @@ class PeltCollectorAbility extends TriggeredAbilityImpl {
}
@Override
public PeltCollectorAbility copy() {
return new PeltCollectorAbility(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);
public PeltCollectorTriggeredAbility copy() {
return new PeltCollectorTriggeredAbility(this);
}
}

View file

@ -3,16 +3,24 @@ package org.mage.test.cards.single.grn;
import mage.abilities.keyword.TrampleAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.Filter;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
* @author LevelX2, TheElk801
*/
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
public void test_Simple() {
setStrictChooseMode(true);
@ -21,13 +29,13 @@ public class PeltCollectorTest extends CardTestPlayerBase {
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.
// 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, "Silvercoat Lion", 1); // Creature {1}{W}
addCard(Zone.HAND, playerA, pltclctr, 1); // Creature {G}
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, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, pltclctr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, slvrctln);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
@ -35,13 +43,12 @@ public class PeltCollectorTest extends CardTestPlayerBase {
assertAllCommandsUsed();
assertPowerToughness(playerB, "Pelt Collector", 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(playerB, pltclctr, 1, 1);
assertPowerToughness(playerA, slvrctln, 2, 2);
assertPowerToughness(playerA, pltclctr, 2, 2);
assertAbility(playerA, pltclctr, TrampleAbility.getInstance(), false);
assertAbility(playerB, pltclctr, TrampleAbility.getInstance(), false);
}
/**
@ -58,19 +65,19 @@ public class PeltCollectorTest extends CardTestPlayerBase {
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.
// 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, "Silvercoat Lion", 1); // Creature {1}{W}
addCard(Zone.HAND, playerA, pltclctr, 1); // Creature {G}
addCard(Zone.HAND, playerA, slvrctln, 1); // Creature {1}{W}
// Other creatures you control get +1/+1.
// 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.
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}
addCard(Zone.BATTLEFIELD, playerB, pltclctr, 1);// Creature {G}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Trostani Discordant");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, trstn);
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Pelt Collector");
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);
@ -78,14 +85,120 @@ public class PeltCollectorTest extends CardTestPlayerBase {
assertAllCommandsUsed();
assertPowerToughness(playerB, "Pelt Collector", 1, 1);
assertPowerToughness(playerB, pltclctr, 1, 1);
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);
}
}