Merge pull request #4370 from mathieupouedras/master

Implements Brood of Cockroaches
This commit is contained in:
LevelX2 2018-01-08 19:03:08 +01:00 committed by GitHub
commit 884b3ee492
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 215 additions and 0 deletions

View file

@ -0,0 +1,110 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards.b;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.LoseLifeSourceControllerEffect;
import mage.abilities.effects.common.ReturnToHandTargetEffect;
import mage.constants.SubType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.game.Game;
import mage.target.targetpointer.FixedTarget;
import static mage.constants.Outcome.Benefit;
/**
*
* @author mpouedras
*/
public class BroodOfCockroaches extends CardImpl {
public BroodOfCockroaches(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}");
this.subtype.add(SubType.INSECT);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// When Brood of Cockroaches is put into your graveyard from the battlefield,
// at the beginning of the next end step,
// you lose 1 life
// and return Brood of Cockroaches to your hand.
this.addAbility(new DiesTriggeredAbility(new BroodOfCockroachesEffect()));
}
public BroodOfCockroaches(final BroodOfCockroaches card) {
super(card);
}
@Override
public BroodOfCockroaches copy() {
return new BroodOfCockroaches(this);
}
}
class BroodOfCockroachesEffect extends OneShotEffect {
private static final String effectText = "at the beginning of the next end step, you lose 1 life and return Brood of Cockroaches to your hand.";
BroodOfCockroachesEffect() {
super(Benefit);
staticText = effectText;
}
BroodOfCockroachesEffect(BroodOfCockroachesEffect broodOfCockroachesEffect) {
super(broodOfCockroachesEffect);
}
@Override
public boolean apply(Game game, Ability source) {
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedLifeLost =
new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new LoseLifeSourceControllerEffect(1));
game.addDelayedTriggeredAbility(delayedLifeLost, source);
Effect effect = new ReturnToHandTargetEffect();
effect.setText("return {this} to your hand.");
effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
@Override
public Effect copy() {
return new BroodOfCockroachesEffect(this);
}
}

View file

@ -63,6 +63,7 @@ public class Visions extends ExpansionSet {
cards.add(new SetCardInfo("Brass-Talon Chimera", 142, Rarity.UNCOMMON, mage.cards.b.BrassTalonChimera.class));
cards.add(new SetCardInfo("Breathstealer's Crypt", 127, Rarity.RARE, mage.cards.b.BreathstealersCrypt.class));
cards.add(new SetCardInfo("Breezekeeper", 27, Rarity.COMMON, mage.cards.b.Breezekeeper.class));
cards.add(new SetCardInfo("Brood of Cockroaches", 3, Rarity.UNCOMMON, mage.cards.b.BroodOfCockroaches.class));
cards.add(new SetCardInfo("Bull Elephant", 51, Rarity.COMMON, mage.cards.b.BullElephant.class));
cards.add(new SetCardInfo("Chronatog", 28, Rarity.RARE, mage.cards.c.Chronatog.class));
cards.add(new SetCardInfo("City of Solitude", 52, Rarity.RARE, mage.cards.c.CityOfSolitude.class));

View file

@ -0,0 +1,104 @@
package org.mage.test.cards.single.vis;
import mage.game.permanent.Permanent;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static mage.constants.Zone.*;
import static mage.constants.PhaseStep.*;
public class BroodOfCockroachesTest extends CardTestPlayerBase {
private static final int TURN_1 = 1;
private static final int ANY_LIFE_TOTAL = 17;
private static final String BROOD_OF_COCKROACHES = "Brood of Cockroaches";
private static final String SHOCK = "Shock";
@Test
public void should_display_correct_text() {
String expectedText = "When {this} dies, at the beginning of the next end step, you lose 1 life and return Brood of Cockroaches to your hand.";
playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase();
setStopAt(TURN_1, END_TURN);
execute();
Permanent permanent = getPermanent(BROOD_OF_COCKROACHES, playerA);
assertThat(permanent.getAbilities().get(1).toString(), is(expectedText));
}
@Test
public void should_reduce_life_of_playerA_by_1_at_the_beginning_of_the_next_end_step() {
playerA.setLife(ANY_LIFE_TOTAL, currentGame);
playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase();
brood_of_cockroaches_diesat_precombat_main_phase();
setStopAt(TURN_1, END_TURN);
execute();
assertLife(playerA, ANY_LIFE_TOTAL - 1);
}
@Test
public void should_not_reduce_life_of_playerA_by_1_at_post_combat_main_step() {
playerA.setLife(ANY_LIFE_TOTAL, currentGame);
playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase();
brood_of_cockroaches_diesat_precombat_main_phase();
setStopAt(TURN_1, PRECOMBAT_MAIN);
execute();
assertLife(playerA, ANY_LIFE_TOTAL );
}
@Test
public void should_return_Brood_of_Cockroaches_to_playerA_hand_end_of_turn() {
playerA.setLife(ANY_LIFE_TOTAL, currentGame);
playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase();
brood_of_cockroaches_diesat_precombat_main_phase();
setStopAt(TURN_1, END_TURN);
execute();
assertHandCount(playerA, BROOD_OF_COCKROACHES, 1);
}
@Test
public void should_not_return_Brood_of_Cockroaches_to_playerA_at_post_combat_step() {
playerA.setLife(ANY_LIFE_TOTAL, currentGame);
playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase();
brood_of_cockroaches_diesat_precombat_main_phase();
setStopAt(TURN_1, POSTCOMBAT_MAIN);
execute();
assertHandCount(playerA, BROOD_OF_COCKROACHES, 0);
}
private void brood_of_cockroaches_diesat_precombat_main_phase() {
addCard(BATTLEFIELD, playerB, "Mountain", 1);
addCard(HAND, playerB, SHOCK, 1);
castSpell(TURN_1, PRECOMBAT_MAIN, playerB, SHOCK, BROOD_OF_COCKROACHES);
}
private void playerA_casts_Brood_of_Cockroaches_at_precombat_main_phase() {
addCard(BATTLEFIELD, playerA, "Swamp", 2);
addCard(HAND, playerA, BROOD_OF_COCKROACHES, 1);
castSpell(TURN_1, PRECOMBAT_MAIN, playerA, BROOD_OF_COCKROACHES);
}
}