mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Use AttachedToAttachedPredicate from 49a3b11 for GolemSkinGauntlets and BrassKnuckles, improve GolemSkinGauntletsTest
This commit is contained in:
parent
49d65c1a88
commit
ff5e7f2d16
3 changed files with 40 additions and 98 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
package mage.cards.b;
|
package mage.cards.b;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.condition.Condition;
|
import mage.abilities.condition.Condition;
|
||||||
|
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
|
||||||
import mage.abilities.decorator.ConditionalContinuousEffect;
|
import mage.abilities.decorator.ConditionalContinuousEffect;
|
||||||
import mage.abilities.effects.common.CastSourceTriggeredAbility;
|
import mage.abilities.effects.common.CastSourceTriggeredAbility;
|
||||||
import mage.abilities.effects.common.CopySourceSpellEffect;
|
import mage.abilities.effects.common.CopySourceSpellEffect;
|
||||||
|
|
@ -13,20 +13,25 @@ import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.AttachmentType;
|
import mage.constants.AttachmentType;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
|
import mage.constants.ComparisonType;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.game.Game;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.game.permanent.Permanent;
|
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.UUID;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @author TheElk801
|
||||||
*/
|
*/
|
||||||
public final class BrassKnuckles extends CardImpl {
|
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) {
|
public BrassKnuckles(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
|
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
|
||||||
|
|
@ -40,7 +45,7 @@ public final class BrassKnuckles extends CardImpl {
|
||||||
this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(
|
this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(
|
||||||
new GainAbilityAttachedEffect(
|
new GainAbilityAttachedEffect(
|
||||||
DoubleStrikeAbility.getInstance(), AttachmentType.EQUIPMENT
|
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"
|
"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);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,44 @@
|
||||||
|
|
||||||
package mage.cards.g;
|
package mage.cards.g;
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
|
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
||||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||||
import mage.abilities.effects.Effect;
|
|
||||||
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
|
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
|
||||||
import mage.abilities.keyword.EquipAbility;
|
import mage.abilities.keyword.EquipAbility;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.CardType;
|
||||||
import mage.game.Game;
|
import mage.constants.Outcome;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.constants.SubType;
|
||||||
|
import mage.filter.FilterPermanent;
|
||||||
|
import mage.filter.predicate.permanent.AttachedToAttachedPredicate;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public final class GolemSkinGauntlets extends CardImpl {
|
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) {
|
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);
|
this.subtype.add(SubType.EQUIPMENT);
|
||||||
|
|
||||||
// Equipped creature gets +1/+0 for each Equipment attached to it.
|
// 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.)
|
// 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)));
|
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,49 +51,3 @@ public final class GolemSkinGauntlets extends CardImpl {
|
||||||
return new GolemSkinGauntlets(this);
|
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<UUID> 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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package org.mage.test.cards.abilities.equipped;
|
||||||
|
|
||||||
import mage.constants.PhaseStep;
|
import mage.constants.PhaseStep;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
|
@ -19,27 +17,24 @@ public class GolemSkinGauntletsTest extends CardTestPlayerBase {
|
||||||
@Test
|
@Test
|
||||||
public void testBoostOnEquip() {
|
public void testBoostOnEquip() {
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
|
||||||
// Equipped creature doesn't untap during its controller's untap step.
|
addCard(Zone.BATTLEFIELD, playerA, "Heavy Arbalest"); // Equip {4}
|
||||||
// Equipped creature has "{T}: This creature deals 2 damage to any target."
|
addCard(Zone.BATTLEFIELD, playerA, "Golem-Skin Gauntlets"); // +1/+0 per attached equipment, Equip {2}
|
||||||
// Equip {4)
|
addCard(Zone.BATTLEFIELD, playerA, "Shuko"); // +1/+0, Equip {0}
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Heavy Arbalest");
|
addCard(Zone.BATTLEFIELD, playerA, "Elite Vanguard"); // Creature 2/1
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Golem-Skin Gauntlets");
|
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Elite Vanguard");
|
|
||||||
|
|
||||||
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {4}", "Elite Vanguard");
|
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {4}", "Elite Vanguard");
|
||||||
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
|
||||||
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Equip {2}", "Elite Vanguard");
|
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);
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
setStrictChooseMode(true);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
assertLife(playerA, 20);
|
assertPowerToughness(playerA, "Elite Vanguard", 6, 1);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue