Merge pull request #2248 from Dilnu/master

Implement Skullbriar, the Walking Grave
This commit is contained in:
LevelX2 2016-09-11 09:38:22 +02:00 committed by GitHub
commit c95646db8e
12 changed files with 268 additions and 20 deletions

View file

@ -0,0 +1,149 @@
/*
* 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.sets.commander;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.StaticAbility;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
import mage.constants.*;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
/**
*
* @author anonymous
*/
public class SkullbriarTheWalkingGrave extends CardImpl {
private Counters counters;
public SkullbriarTheWalkingGrave(UUID ownerId) {
super(ownerId, 227, "Skullbriar, the Walking Grave", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{B}{G}");
this.expansionSetCode = "CMD";
this.supertype.add("Legendary");
this.subtype.add("Zombie");
this.subtype.add("Elemental");
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// Haste
this.addAbility(HasteAbility.getInstance());
// Whenever Skullbriar, the Walking Grave deals combat damage to a player, put a +1/+1 counter on it.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false));
// Counters remain on Skullbriar as it moves to any zone other than a player's hand or library.
this.addAbility(new SimpleStaticAbility(Zone.ALL, new SkullbriarEffect()));
}
public SkullbriarTheWalkingGrave(SkullbriarTheWalkingGrave card) { super(card); }
@Override
public SkullbriarTheWalkingGrave copy() {
return new SkullbriarTheWalkingGrave(this);
}
@Override
public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
boolean skullBriarEffectApplied = false;
if (event.getToZone() != Zone.HAND && event.getToZone() != Zone.LIBRARY) {
for (StaticAbility ability : getAbilities (game).getStaticAbilities(event.getFromZone())) {
for (Effect effect : ability.getEffects(game, EffectType.REPLACEMENT)) {
if (effect instanceof SkullbriarEffect && event.getAppliedEffects().contains(effect.getId())) {
skullBriarEffectApplied = true;
}
}
}
}
Counters copyFrom = null;
if (skullBriarEffectApplied) {
if (event.getTarget() != null && event.getFromZone() == Zone.BATTLEFIELD) {
copyFrom = new Counters(event.getTarget().getCounters(game));
} else {
copyFrom = new Counters(this.getCounters(game));
}
}
super.updateZoneChangeCounter(game, event);
Counters copyTo = null;
if (event.getTarget() != null && event.getToZone() == Zone.BATTLEFIELD) {
if (event.getFromZone() != Zone.BATTLEFIELD) {
copyTo = event.getTarget().getCounters(game);
}
} else {
copyTo = this.getCounters(game);
}
if (copyTo != null && copyFrom != null) {
for(Counter counter : copyFrom.values()) {
copyTo.addCounter(counter);
}
}
}
}
class SkullbriarEffect extends ReplacementEffectImpl {
public SkullbriarEffect() {
super(Duration.EndOfGame, Outcome.Benefit);
staticText = "Counters remain on {this} as it moves to any zone other than a player's hand or library.";
}
public SkullbriarEffect(SkullbriarEffect effect) {
super(effect);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return false;
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return source.getSourceId().equals(event.getTargetId());
}
@Override
public ContinuousEffect copy() {
return new SkullbriarEffect(this);
}
}

View file

@ -0,0 +1,93 @@
/*
* 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 org.mage.test.cards.replacement;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author Dilnu
*/
public class SkullbriarTest extends CardTestPlayerBase {
/**
* Skullbriar retains counters even when Humility is on the field.
*/
@Test
public void testSkullbriarCloudshift() {
// Counters remain on Skullbriar as it moves to any zone other than a player's hand or library.
addCard(Zone.BATTLEFIELD, playerB, "Skullbriar, the Walking Grave");
addCard(Zone.BATTLEFIELD, playerB, "Plains");
addCard(Zone.BATTLEFIELD, playerB, "Forest");
// Put a +1/+1 counter on target creature.
addCard(Zone.HAND, playerB, "Battlegrowth");
// Exile target creature you control, then return that card to the battlefield under your control.
addCard(Zone.HAND, playerB, "Cloudshift");
castSpell(1, PhaseStep.UPKEEP, playerB, "Battlegrowth", "Skullbriar, the Walking Grave");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cloudshift", "Skullbriar, the Walking Grave");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertCounterCount("Skullbriar, the Walking Grave", CounterType.P1P1, 1);
}
/**
* Skullbriar should not retain counters when Humility is on the field.
*/
@Test
public void testHumilityAndSkullbriarCloudshift() {
// Counters remain on Skullbriar as it moves to any zone other than a player's hand or library.
addCard(Zone.BATTLEFIELD, playerB, "Skullbriar, the Walking Grave");
// Enchantment {2}{W}{W}
// All creatures lose all abilities and are 1/1.
addCard(Zone.BATTLEFIELD, playerA, "Humility");
addCard(Zone.BATTLEFIELD, playerB, "Plains");
addCard(Zone.BATTLEFIELD, playerB, "Forest");
// Put a +1/+1 counter on target creature.
addCard(Zone.HAND, playerB, "Battlegrowth");
// Exile target creature you control, then return that card to the battlefield under your control.
addCard(Zone.HAND, playerB, "Cloudshift");
castSpell(1, PhaseStep.UPKEEP, playerB, "Battlegrowth", "Skullbriar, the Walking Grave");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cloudshift", "Skullbriar, the Walking Grave");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertCounterCount("Skullbriar, the Walking Grave", CounterType.P1P1, 0);
}
}

View file

@ -10,6 +10,7 @@ import mage.abilities.costs.mana.ManaCosts;
import mage.cards.FrameStyle; import mage.cards.FrameStyle;
import mage.constants.CardType; import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
public interface MageObject extends MageItem, Serializable { public interface MageObject extends MageItem, Serializable {
@ -75,7 +76,7 @@ public interface MageObject extends MageItem, Serializable {
int getZoneChangeCounter(Game game); int getZoneChangeCounter(Game game);
void updateZoneChangeCounter(Game game); void updateZoneChangeCounter(Game game, ZoneChangeEvent event);
void setZoneChangeCounter(int value, Game game); void setZoneChangeCounter(int value, Game game);

View file

@ -42,6 +42,7 @@ import mage.abilities.mana.ManaAbility;
import mage.cards.FrameStyle; import mage.cards.FrameStyle;
import mage.constants.CardType; import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.util.GameLog; import mage.util.GameLog;
@ -287,7 +288,7 @@ public abstract class MageObjectImpl implements MageObject {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
game.getState().updateZoneChangeCounter(objectId); game.getState().updateZoneChangeCounter(objectId);
} }

View file

@ -174,8 +174,9 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
if (targetCard != null || targetPermanent != null || targetPlayer != null) { if (targetCard != null || targetPermanent != null || targetPlayer != null) {
card = game.getCard(event.getTargetId()); card = game.getCard(event.getTargetId());
card.removeFromZone(game, fromZone, sourceId); card.removeFromZone(game, fromZone, sourceId);
card.updateZoneChangeCounter(game);
PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game); PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game);
ZoneChangeEvent zoneChangeEvent = new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD);
permanent.updateZoneChangeCounter(game, zoneChangeEvent);
game.getBattlefield().addPermanent(permanent); game.getBattlefield().addPermanent(permanent);
card.setZone(Zone.BATTLEFIELD, game); card.setZone(Zone.BATTLEFIELD, game);
if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) { if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) {
@ -188,7 +189,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
} }
game.applyEffects(); game.applyEffects();
game.fireEvent(new ZoneChangeEvent(permanent, controllerId, fromZone, Zone.BATTLEFIELD)); game.fireEvent(zoneChangeEvent);
return true; return true;
} }

View file

@ -36,8 +36,6 @@ import mage.counters.Counter;
import mage.game.Game; import mage.game.Game;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentMeld;
import mage.players.Player;
/** /**
* *
@ -192,20 +190,20 @@ public abstract class MeldCard extends CardImpl {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
if (isCopy() || !isMelded()) { if (isCopy() || !isMelded()) {
super.updateZoneChangeCounter(game); super.updateZoneChangeCounter(game, event);
return; return;
} }
game.getState().updateZoneChangeCounter(objectId); game.getState().updateZoneChangeCounter(objectId);
if (topLastZoneChangeCounter == topHalfCard.getZoneChangeCounter(game) if (topLastZoneChangeCounter == topHalfCard.getZoneChangeCounter(game)
&& halves.contains(topHalfCard.getId())) { && halves.contains(topHalfCard.getId())) {
topHalfCard.updateZoneChangeCounter(game); topHalfCard.updateZoneChangeCounter(game, event);
topLastZoneChangeCounter = topHalfCard.getZoneChangeCounter(game); topLastZoneChangeCounter = topHalfCard.getZoneChangeCounter(game);
} }
if (bottomLastZoneChangeCounter == bottomHalfCard.getZoneChangeCounter(game) if (bottomLastZoneChangeCounter == bottomHalfCard.getZoneChangeCounter(game)
&& halves.contains(bottomHalfCard.getId())) { && halves.contains(bottomHalfCard.getId())) {
bottomHalfCard.updateZoneChangeCounter(game); bottomHalfCard.updateZoneChangeCounter(game, event);
bottomLastZoneChangeCounter = bottomHalfCard.getZoneChangeCounter(game); bottomLastZoneChangeCounter = bottomHalfCard.getZoneChangeCounter(game);
} }
} }

View file

@ -73,6 +73,7 @@ public class ZonesHandler {
toZone = subInfo.event.getToZone(); toZone = subInfo.event.getToZone();
placeInDestinationZone(subInfo, game); placeInDestinationZone(subInfo, game);
} }
// We arbitrarily prefer the bottom half card. This should never be relevant.
if (toZone != null) { if (toZone != null) {
game.setZone(unmelded.event.getTargetId(), toZone); game.setZone(unmelded.event.getTargetId(), toZone);
} }
@ -180,7 +181,8 @@ public class ZonesHandler {
if (unmelded.subInfo.isEmpty()) { if (unmelded.subInfo.isEmpty()) {
return false; return false;
} }
meld.updateZoneChangeCounter(game); // We arbitrarily prefer the bottom half card. This should never be relevant.
meld.updateZoneChangeCounter(game, unmelded.subInfo.get(unmelded.subInfo.size() - 1).event);
return true; return true;
} }
// Handle all normal cases // Handle all normal cases
@ -235,9 +237,9 @@ public class ZonesHandler {
} }
if (success) { if (success) {
if (event.getToZone() == Zone.BATTLEFIELD && event.getTarget() != null) { if (event.getToZone() == Zone.BATTLEFIELD && event.getTarget() != null) {
event.getTarget().updateZoneChangeCounter(game); event.getTarget().updateZoneChangeCounter(game, event);
} else { } else {
card.updateZoneChangeCounter(game); card.updateZoneChangeCounter(game, event);
} }
} }
return success; return success;

View file

@ -42,6 +42,7 @@ import mage.cards.Card;
import mage.cards.FrameStyle; import mage.cards.FrameStyle;
import mage.constants.CardType; import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog; import mage.util.GameLog;
public class Commander implements CommandObject { public class Commander implements CommandObject {
@ -214,8 +215,8 @@ public class Commander implements CommandObject {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
card.updateZoneChangeCounter(game); card.updateZoneChangeCounter(game, event);
} }
@Override @Override

View file

@ -41,6 +41,7 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.cards.FrameStyle; import mage.cards.FrameStyle;
import mage.constants.CardType; import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog; import mage.util.GameLog;
/** /**
@ -233,7 +234,7 @@ public class Emblem implements CommandObject {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
throw new UnsupportedOperationException("Unsupported operation"); throw new UnsupportedOperationException("Unsupported operation");
} }

View file

@ -240,8 +240,8 @@ public class PermanentCard extends PermanentImpl {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
card.updateZoneChangeCounter(game); card.updateZoneChangeCounter(game, event);
zoneChangeCounter = card.getZoneChangeCounter(game); zoneChangeCounter = card.getZoneChangeCounter(game);
} }

View file

@ -778,7 +778,7 @@ public class Spell extends StackObjImpl implements Card {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
throw new UnsupportedOperationException("Unsupported operation"); throw new UnsupportedOperationException("Unsupported operation");
} }

View file

@ -58,6 +58,7 @@ import mage.constants.Zone;
import mage.constants.ZoneDetail; import mage.constants.ZoneDetail;
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.players.Player; import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.Targets; import mage.target.Targets;
@ -557,7 +558,7 @@ public class StackAbility extends StackObjImpl implements Ability {
} }
@Override @Override
public void updateZoneChangeCounter(Game game) { public void updateZoneChangeCounter(Game game, ZoneChangeEvent event) {
throw new UnsupportedOperationException("Not supported."); throw new UnsupportedOperationException("Not supported.");
} }