From 36123326072235ec39e92d9d03d39faba6989827 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 14 Sep 2016 15:16:40 +0200 Subject: [PATCH] [KLD] Added Speedway Fanatic. Added tests for crew keyword. --- .../mage/sets/kaladesh/SpeedwayFanatic.java | 113 ++++++++++++++++++ .../cards/abilities/keywords/CrewTest.java | 84 +++++++++++++ .../mage/abilities/keyword/CrewAbility.java | 9 +- .../main/java/mage/game/events/GameEvent.java | 8 +- 4 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/kaladesh/SpeedwayFanatic.java create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CrewTest.java diff --git a/Mage.Sets/src/mage/sets/kaladesh/SpeedwayFanatic.java b/Mage.Sets/src/mage/sets/kaladesh/SpeedwayFanatic.java new file mode 100644 index 00000000000..9ee0b872b04 --- /dev/null +++ b/Mage.Sets/src/mage/sets/kaladesh/SpeedwayFanatic.java @@ -0,0 +1,113 @@ +/* + * 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.kaladesh; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; +import mage.abilities.keyword.HasteAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.targetpointer.FixedTarget; + +/** + * + * @author LevelX2 + */ +public class SpeedwayFanatic extends CardImpl { + + public SpeedwayFanatic(UUID ownerId) { + super(ownerId, 132, "Speedway Fanatic", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{1}{R}"); + this.expansionSetCode = "KLD"; + this.subtype.add("Human"); + this.subtype.add("Pilot"); + this.power = new MageInt(2); + this.toughness = new MageInt(1); + + // Haste + this.addAbility(HasteAbility.getInstance()); + + // Whenever Speedway Fanatic crews a Vehicle, that Vehicle gains haste until end of turn. + this.addAbility(new CrewsVehicleSourceTriggeredAbility(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn, + "that Vehicle gains haste until end of turn"))); + } + + public SpeedwayFanatic(final SpeedwayFanatic card) { + super(card); + } + + @Override + public SpeedwayFanatic copy() { + return new SpeedwayFanatic(this); + } +} + +class CrewsVehicleSourceTriggeredAbility extends TriggeredAbilityImpl { + + public CrewsVehicleSourceTriggeredAbility(Effect effect) { + super(Zone.BATTLEFIELD, effect, false); + } + + public CrewsVehicleSourceTriggeredAbility(final CrewsVehicleSourceTriggeredAbility ability) { + super(ability); + } + + @Override + public CrewsVehicleSourceTriggeredAbility copy() { + return new CrewsVehicleSourceTriggeredAbility(this); + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.CREWED_VEHICLE; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getTargetId().equals(getSourceId())) { + for (Effect effect : getEffects()) { + // set the vehicle id as target + effect.setTargetPointer(new FixedTarget(event.getSourceId())); + } + return true; + } + return false; + } + + @Override + public String getRule() { + return "When {this} crews a Vehicle, " + super.getRule(); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CrewTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CrewTest.java new file mode 100644 index 00000000000..74c545302e7 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CrewTest.java @@ -0,0 +1,84 @@ +/* + * 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.abilities.keywords; + +import mage.abilities.keyword.HasteAbility; +import mage.constants.CardType; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +// http://magic.wizards.com/en/articles/archive/feature/kaladesh-mechanics-2016-09-02 +public class CrewTest extends CardTestPlayerBase { + + @Test + public void crewBasicTest() { + // {T}: Add one mana of any color to your mana pool. + // Crew 3 (Tap any number of creatures you control with total power 3 or more: This Vehicle becomes an artifact creature until end of turn.)"; + addCard(Zone.BATTLEFIELD, playerA, "Cultivator's Caravan", 1); + + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crew 3"); + setChoice(playerA, "Silvercoat Lion^Silvercoat Lion"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertTappedCount("Silvercoat Lion", true, 2); + assertPowerToughness(playerA, "Cultivator's Caravan", 5, 5); + assertType("Cultivator's Caravan", CardType.CREATURE, "Vehicle"); + } + + @Test + public void crewTriggerPilotTest() { + // Flying + // Whenever Smuggler's Copter attacks or blocks, you may draw a card. If you do, discard a card. + // Crew 1 (Tap any number of creatures you control with total power 3 or more: This Vehicle becomes an artifact creature until end of turn.)"; + addCard(Zone.BATTLEFIELD, playerA, "Smuggler's Copter", 1); + + addCard(Zone.BATTLEFIELD, playerA, "Speedway Fanatic", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crew 1"); + setChoice(playerA, "Speedway Fanatic"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertTappedCount("Speedway Fanatic", true, 1); + assertPowerToughness(playerA, "Smuggler's Copter", 3, 3); + assertAbility(playerA, "Smuggler's Copter", HasteAbility.getInstance(), true); + assertType("Smuggler's Copter", CardType.CREATURE, "Vehicle"); + } + +} diff --git a/Mage/src/main/java/mage/abilities/keyword/CrewAbility.java b/Mage/src/main/java/mage/abilities/keyword/CrewAbility.java index 65215877da9..d1f7c63fc43 100644 --- a/Mage/src/main/java/mage/abilities/keyword/CrewAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/CrewAbility.java @@ -41,6 +41,7 @@ import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.permanent.TappedPredicate; import mage.game.Game; +import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.target.Target; import mage.target.common.TargetControlledCreaturePermanent; @@ -77,6 +78,7 @@ public class CrewAbility extends SimpleActivatedAbility { class CrewCost extends CostImpl { private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("untapped creature you control"); + static { filter.add(Predicates.not(new TappedPredicate())); } @@ -104,6 +106,11 @@ class CrewCost extends CostImpl { } } paid = sumPower >= value; + if (paid) { + for (UUID targetId : target.getTargets()) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREWED_VEHICLE, targetId, sourceId, controllerId)); + } + } } return paid; } @@ -124,4 +131,4 @@ class CrewCost extends CostImpl { public CrewCost copy() { return new CrewCost(this); } -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 8c6856acdc1..aeda7470146 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -97,7 +97,7 @@ public class GameEvent implements Serializable { CLASH, CLASHED, DAMAGE_PLAYER, /* DAMAGED_PLAYER - targetId the id of the damged player + targetId the id of the damaged player sourceId sourceId of the ability which caused the damage playerId the id of the damged player amount amount of damage @@ -109,6 +109,12 @@ public class GameEvent implements Serializable { GAIN_LIFE, GAINED_LIFE, LOSE_LIFE, LOST_LIFE, PLAY_LAND, LAND_PLAYED, + CREWED_VEHICLE, + /* CREWED_VEHICLE + targetId the id of the creature that crewed a vehicle + sourceId sourceId of the vehicle + playerId the id of the controlling player + */ CAST_SPELL, /* SPELL_CAST x-Costs are already defined