diff --git a/Mage.Sets/src/mage/cards/b/BrassKnuckles.java b/Mage.Sets/src/mage/cards/b/BrassKnuckles.java index 830e18e7cf1..6faa50a2209 100644 --- a/Mage.Sets/src/mage/cards/b/BrassKnuckles.java +++ b/Mage.Sets/src/mage/cards/b/BrassKnuckles.java @@ -1,8 +1,8 @@ package mage.cards.b; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.Condition; +import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.common.CastSourceTriggeredAbility; import mage.abilities.effects.common.CopySourceSpellEffect; @@ -13,20 +13,25 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.AttachmentType; import mage.constants.CardType; +import mage.constants.ComparisonType; import mage.constants.SubType; -import mage.game.Game; -import mage.game.permanent.Permanent; +import mage.filter.FilterPermanent; +import mage.filter.predicate.permanent.AttachedToAttachedPredicate; -import java.util.Collection; -import java.util.Objects; -import java.util.Optional; import java.util.UUID; -import java.util.stream.Stream; /** * @author TheElk801 */ public final class BrassKnuckles extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent("Equipment attached to it"); + + static { + filter.add(SubType.EQUIPMENT.getPredicate()); + filter.add(AttachedToAttachedPredicate.instance); + } + + private static final Condition twoEquipmentAttachedToAttached = new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.OR_GREATER, 2); public BrassKnuckles(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); @@ -40,7 +45,7 @@ public final class BrassKnuckles extends CardImpl { this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( new GainAbilityAttachedEffect( DoubleStrikeAbility.getInstance(), AttachmentType.EQUIPMENT - ), BrassKnucklesCondition.instance, "equipped creature has double strike " + + ), twoEquipmentAttachedToAttached, "equipped creature has double strike " + "as long as two or more Equipment are attached to it" ))); @@ -57,23 +62,3 @@ public final class BrassKnuckles extends CardImpl { return new BrassKnuckles(this); } } - -enum BrassKnucklesCondition implements Condition { - instance; - - @Override - public boolean apply(Game game, Ability source) { - return Optional - .ofNullable(source.getSourcePermanentIfItStillExists(game)) - .map(Permanent::getAttachedTo) - .map(game::getPermanent) - .map(Permanent::getAttachments) - .map(Collection::stream) - .map(stream -> stream.map(game::getPermanent)) - .map(stream -> stream.filter(Objects::nonNull)) - .map(stream -> stream.filter(p -> p.hasSubtype(SubType.EQUIPMENT, game))) - .map(Stream::count) - .map(x -> x >= 2) - .orElse(false); - } -} diff --git a/Mage.Sets/src/mage/cards/g/GolemSkinGauntlets.java b/Mage.Sets/src/mage/cards/g/GolemSkinGauntlets.java index a61526367c8..2ca99ec2e71 100644 --- a/Mage.Sets/src/mage/cards/g/GolemSkinGauntlets.java +++ b/Mage.Sets/src/mage/cards/g/GolemSkinGauntlets.java @@ -1,36 +1,44 @@ package mage.cards.g; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.dynamicvalue.common.StaticValue; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.continuous.BoostEquippedEffect; import mage.abilities.keyword.EquipAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; -import mage.game.Game; -import mage.game.permanent.Permanent; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.filter.FilterPermanent; +import mage.filter.predicate.permanent.AttachedToAttachedPredicate; -import java.util.List; import java.util.UUID; /** - * * @author North */ public final class GolemSkinGauntlets extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent("Equipment attached to it"); + + static { + filter.add(SubType.EQUIPMENT.getPredicate()); + filter.add(AttachedToAttachedPredicate.instance); + } + + private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter); public GolemSkinGauntlets(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{1}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}"); this.subtype.add(SubType.EQUIPMENT); // Equipped creature gets +1/+0 for each Equipment attached to it. + this.addAbility(new SimpleStaticAbility(new BoostEquippedEffect(xValue, StaticValue.get(0)))); + // Equip 2 (2: Attach to target creature you control. Equip only as a sorcery. This card enters the battlefield unattached and stays on the battlefield if the creature leaves.) - this.addAbility(new SimpleStaticAbility(new BoostEquippedEffect(new GolemSkinGauntletsAttachedCount(), StaticValue.get(0), Duration.WhileOnBattlefield))); this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(2))); } @@ -43,49 +51,3 @@ public final class GolemSkinGauntlets extends CardImpl { return new GolemSkinGauntlets(this); } } - -// we can't use GolemSkinGauntletsAttachedCount -// compare to Goblin Gaveleer -class GolemSkinGauntletsAttachedCount implements DynamicValue { - - GolemSkinGauntletsAttachedCount() { - } - - private GolemSkinGauntletsAttachedCount(final GolemSkinGauntletsAttachedCount dynamicValue) { - } - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - int count = 0; - Permanent equipment = game.getPermanent(sourceAbility.getSourceId()); - if (equipment != null) { - Permanent permanent = game.getPermanent(equipment.getAttachedTo()); - if (permanent != null) { - List attachments = permanent.getAttachments(); - for (UUID attachmentId : attachments) { - Permanent attached = game.getPermanent(attachmentId); - if (attached != null && attached.hasSubtype(SubType.EQUIPMENT, game)) { - count++; - } - } - } - - } - return count; - } - - @Override - public GolemSkinGauntletsAttachedCount copy() { - return new GolemSkinGauntletsAttachedCount(this); - } - - @Override - public String toString() { - return "1"; - } - - @Override - public String getMessage() { - return "Equipment attached to it"; - } -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/GolemSkinGauntletsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/GolemSkinGauntletsTest.java index f6e16f29cde..f9d4088ddd4 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/GolemSkinGauntletsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/equipped/GolemSkinGauntletsTest.java @@ -2,8 +2,6 @@ package org.mage.test.cards.abilities.equipped; import mage.constants.PhaseStep; import mage.constants.Zone; -import mage.game.permanent.Permanent; -import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -19,27 +17,24 @@ public class GolemSkinGauntletsTest extends CardTestPlayerBase { @Test public void testBoostOnEquip() { addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); - // Equipped creature doesn't untap during its controller's untap step. - // Equipped creature has "{T}: This creature deals 2 damage to any target." - // Equip {4) - addCard(Zone.BATTLEFIELD, playerA, "Heavy Arbalest"); - addCard(Zone.BATTLEFIELD, playerA, "Golem-Skin Gauntlets"); - addCard(Zone.BATTLEFIELD, playerA, "Elite Vanguard"); + addCard(Zone.BATTLEFIELD, playerA, "Heavy Arbalest"); // Equip {4} + addCard(Zone.BATTLEFIELD, playerA, "Golem-Skin Gauntlets"); // +1/+0 per attached equipment, Equip {2} + addCard(Zone.BATTLEFIELD, playerA, "Shuko"); // +1/+0, Equip {0} + addCard(Zone.BATTLEFIELD, playerA, "Elite Vanguard"); // Creature 2/1 activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {4}", "Elite Vanguard"); waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {2}", "Elite Vanguard"); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN); + checkPT("Gauntlets equipped", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elite Vanguard", 4, 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {0}", "Elite Vanguard"); setStopAt(1, PhaseStep.BEGIN_COMBAT); + setStrictChooseMode(true); execute(); - assertLife(playerA, 20); - assertLife(playerB, 20); - - Permanent eliteVanguard = getPermanent("Elite Vanguard", playerA.getId()); - Assert.assertTrue(eliteVanguard.getAttachments().size() == 2); - Assert.assertEquals(4, eliteVanguard.getPower().getValue()); - Assert.assertEquals(1, eliteVanguard.getToughness().getValue()); + assertPowerToughness(playerA, "Elite Vanguard", 6, 1); } }