mirror of
https://github.com/magefree/mage.git
synced 2025-12-29 06:52:02 -08:00
refactor some cards which attach permanents
This commit is contained in:
parent
6521f0b978
commit
a02313a015
6 changed files with 189 additions and 241 deletions
|
|
@ -4,7 +4,8 @@ import mage.MageInt;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.common.EquippedMultipleSourceCondition;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.decorator.ConditionalContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -15,6 +16,10 @@ import mage.cards.CardImpl;
|
|||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterEquipmentPermanent;
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
|
|
@ -25,7 +30,14 @@ import java.util.UUID;
|
|||
*/
|
||||
public final class BalanWanderingKnight extends CardImpl {
|
||||
|
||||
private static final String rule = "{this} has double strike as long as two or more Equipment are attached to it.";
|
||||
private static final FilterPermanent filter = new FilterEquipmentPermanent();
|
||||
|
||||
static {
|
||||
filter.add(BalanWanderingKnightPredicate.instance);
|
||||
}
|
||||
|
||||
private static final Condition condition
|
||||
= new PermanentsOnTheBattlefieldCondition(filter, ComparisonType.MORE_THAN, 1, false);
|
||||
|
||||
public BalanWanderingKnight(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}{W}");
|
||||
|
|
@ -38,8 +50,10 @@ public final class BalanWanderingKnight extends CardImpl {
|
|||
this.addAbility(FirstStrikeAbility.getInstance());
|
||||
|
||||
// Balan, Wandering Knight has double strike as long as two or more Equipment are attached to it.
|
||||
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainAbilitySourceEffect(DoubleStrikeAbility.getInstance()), EquippedMultipleSourceCondition.instance, rule);
|
||||
this.addAbility(new SimpleStaticAbility(effect));
|
||||
this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(
|
||||
new GainAbilitySourceEffect(DoubleStrikeAbility.getInstance()), condition,
|
||||
"{this} has double strike as long as two or more Equipment are attached to it."
|
||||
)));
|
||||
|
||||
// {1}{W}: Attach all Equipment you control to Balan.
|
||||
this.addAbility(new SimpleActivatedAbility(new BalanWanderingKnightEffect(), new ManaCostsImpl<>("{1}{W}")));
|
||||
|
|
@ -54,39 +68,44 @@ public final class BalanWanderingKnight extends CardImpl {
|
|||
return new BalanWanderingKnight(this);
|
||||
}
|
||||
|
||||
static class BalanWanderingKnightEffect extends OneShotEffect {
|
||||
}
|
||||
|
||||
public BalanWanderingKnightEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "Attach all Equipment you control to {this}.";
|
||||
}
|
||||
enum BalanWanderingKnightPredicate implements ObjectSourcePlayerPredicate<Permanent> {
|
||||
instance;
|
||||
|
||||
private BalanWanderingKnightEffect(final BalanWanderingKnightEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BalanWanderingKnightEffect copy() {
|
||||
return new BalanWanderingKnightEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent balan = game.getPermanent(source.getSourceId());
|
||||
if (balan != null) {
|
||||
FilterPermanent filter = new FilterPermanent();
|
||||
filter.add(SubType.EQUIPMENT.getPredicate());
|
||||
for (Permanent equipment : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
||||
if (equipment != null) {
|
||||
//If an Equipment can't equip, it isn't attached, and it doesn't become unattached (if it's attached to a creature).
|
||||
if (!balan.cantBeAttachedBy(equipment, source, game, false)) {
|
||||
balan.addAttachment(equipment.getId(), source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
|
||||
return input.getObject().isAttachedTo(input.getSourceId());
|
||||
}
|
||||
}
|
||||
|
||||
class BalanWanderingKnightEffect extends OneShotEffect {
|
||||
|
||||
BalanWanderingKnightEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "attach all Equipment you control to {this}.";
|
||||
}
|
||||
|
||||
private BalanWanderingKnightEffect(final BalanWanderingKnightEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BalanWanderingKnightEffect copy() {
|
||||
return new BalanWanderingKnightEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
for (Permanent equipment : game.getBattlefield().getActivePermanents(
|
||||
StaticFilters.FILTER_CONTROLLED_PERMANENT_EQUIPMENT, source.getControllerId(), source, game
|
||||
)) {
|
||||
permanent.addAttachment(equipment.getId(), source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package mage.cards.c;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.costs.common.TapSourceCost;
|
||||
|
|
@ -11,7 +10,7 @@ import mage.cards.CardSetInfo;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.common.FilterEnchantmentPermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
|
|
@ -23,10 +22,11 @@ import mage.players.Player;
|
|||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author spjspj
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class CrownOfTheAges extends CardImpl {
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ class CrownOfTheAgesEffect extends OneShotEffect {
|
|||
|
||||
CrownOfTheAgesEffect() {
|
||||
super(Outcome.BoostCreature);
|
||||
this.staticText = "Attach target Aura attached to a creature to another creature";
|
||||
this.staticText = "attach target Aura attached to a creature to another creature";
|
||||
}
|
||||
|
||||
private CrownOfTheAgesEffect(final CrownOfTheAgesEffect effect) {
|
||||
|
|
@ -75,47 +75,27 @@ class CrownOfTheAgesEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent aura = game.getPermanent(source.getFirstTarget());
|
||||
Permanent aura = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (aura == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (fromPermanent == null || controller == null) {
|
||||
FilterPermanent filter = new FilterCreaturePermanent("another creature");
|
||||
filter.add(Predicates.not(new PermanentIdPredicate(aura.getAttachedTo())));
|
||||
if (!game.getBattlefield().contains(filter, source, game, 1)) {
|
||||
return false;
|
||||
}
|
||||
boolean passed = true;
|
||||
FilterCreaturePermanent filterChoice = new FilterCreaturePermanent("another creature");
|
||||
filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
|
||||
|
||||
Target chosenCreatureToAttachAura = new TargetPermanent(filterChoice);
|
||||
chosenCreatureToAttachAura.withNotTarget(true);
|
||||
|
||||
if (chosenCreatureToAttachAura.canChoose(source.getControllerId(), source, game)
|
||||
&& controller.choose(Outcome.Neutral, chosenCreatureToAttachAura, source, game)) {
|
||||
Permanent creatureToAttachAura = game.getPermanent(chosenCreatureToAttachAura.getFirstTarget());
|
||||
if (creatureToAttachAura != null) {
|
||||
if (passed) {
|
||||
// Check the target filter
|
||||
Target target = aura.getSpellAbility().getTargets().get(0);
|
||||
if (target instanceof TargetPermanent) {
|
||||
if (!target.getFilter().match(creatureToAttachAura, game)) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
// Check for protection
|
||||
MageObject auraObject = game.getObject(aura.getId());
|
||||
if (auraObject != null && creatureToAttachAura.cantBeAttachedBy(auraObject, source, game, true)) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
if (passed) {
|
||||
fromPermanent.removeAttachment(aura.getId(), source, game);
|
||||
creatureToAttachAura.addAttachment(aura.getId(), source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
Target target = new TargetPermanent(filter);
|
||||
target.withNotTarget(true);
|
||||
controller.choose(Outcome.Neutral, target, source, game);
|
||||
return Optional
|
||||
.ofNullable(target)
|
||||
.map(Target::getFirstTarget)
|
||||
.map(game::getPermanent)
|
||||
.map(permanent -> permanent.addAttachment(aura.getId(), source, game))
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package mage.cards.g;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
|
@ -16,17 +15,18 @@ import mage.filter.FilterPermanent;
|
|||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author jeffwadsworth
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class GlamerSpinners extends CardImpl {
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ public final class GlamerSpinners extends CardImpl {
|
|||
Ability ability = new EntersBattlefieldTriggeredAbility(new GlamerSpinnersEffect(), false);
|
||||
ability.addTarget(new TargetPermanent());
|
||||
this.addAbility(ability);
|
||||
|
||||
}
|
||||
|
||||
private GlamerSpinners(final GlamerSpinners card) {
|
||||
|
|
@ -79,69 +78,43 @@ class GlamerSpinnersEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
/*
|
||||
5/1/2008 When Glamer Spinners enters the battlefield, you target only one permanent: the one that will be losing its Auras. You don't choose the permanent that will be receiving the Auras until the ability resolves.
|
||||
5/1/2008 You may target a permanent that has no Auras enchanting it.
|
||||
5/1/2008 When the ability resolves, you choose the permanent that will be receiving the Auras. It can't be the targeted permanent, it must have the same controller as the targeted permanent, and it must be able to be enchanted by all the Auras attached to the targeted permanent. If you can't choose a permanent that meets all those criteria, the Auras won't move.
|
||||
*/
|
||||
|
||||
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent glamerSpinners = game.getPermanent(source.getSourceId());
|
||||
if (targetPermanent != null
|
||||
&& controller != null
|
||||
&& glamerSpinners != null) {
|
||||
boolean passed = true;
|
||||
FilterPermanent filterChoice = new FilterPermanent("a different permanent with the same controller as the target to attach the enchantments to");
|
||||
filterChoice.add(new ControllerIdPredicate(targetPermanent.getControllerId()));
|
||||
filterChoice.add(Predicates.not(new PermanentIdPredicate(targetPermanent.getId())));
|
||||
|
||||
Target chosenPermanentToAttachAuras = new TargetPermanent(filterChoice);
|
||||
chosenPermanentToAttachAuras.withNotTarget(true);
|
||||
|
||||
LinkedList<UUID> auras = new LinkedList<>();
|
||||
auras.addAll(targetPermanent.getAttachments());
|
||||
if (source.getSourceObjectZoneChangeCounter() == glamerSpinners.getZoneChangeCounter(game) // not blinked
|
||||
&& chosenPermanentToAttachAuras.canChoose(source.getControllerId(), source, game)
|
||||
&& controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source, game)) {
|
||||
Permanent permanentToAttachAuras = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
|
||||
if (permanentToAttachAuras != null) {
|
||||
for (UUID auraId : auras) {
|
||||
Permanent aura = game.getPermanent(auraId);
|
||||
if (aura != null
|
||||
&& passed) {
|
||||
// Check the target filter
|
||||
Target target = aura.getSpellAbility().getTargets().get(0);
|
||||
if (target instanceof TargetPermanent) {
|
||||
if (!target.getFilter().match(permanentToAttachAuras, game)) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
// Check for protection
|
||||
MageObject auraObject = game.getObject(auraId);
|
||||
if (auraObject != null) {
|
||||
if (permanentToAttachAuras.cantBeAttachedBy(auraObject, source, game, true)) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (passed) {
|
||||
LinkedList<UUID> aurasToAttach = new LinkedList<>();
|
||||
aurasToAttach.addAll(auras);
|
||||
|
||||
for (UUID auraId : aurasToAttach) {
|
||||
Permanent auraToAttachToPermanent = game.getPermanent(auraId);
|
||||
targetPermanent.removeAttachment(auraToAttachToPermanent.getId(), source, game);
|
||||
permanentToAttachAuras.addAttachment(auraToAttachToPermanent.getId(), source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
game.informPlayers("Glamer Spinners" + ": No enchantments were moved from the target permanent.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (targetPermanent == null
|
||||
|| targetPermanent
|
||||
.getAttachments()
|
||||
.stream()
|
||||
.map(game::getPermanent)
|
||||
.filter(Objects::nonNull)
|
||||
.noneMatch(p -> p.hasSubtype(SubType.AURA, game))) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
FilterPermanent filter = new FilterPermanent(
|
||||
"permanent" + Optional
|
||||
.ofNullable(targetPermanent)
|
||||
.map(Controllable::getControllerId)
|
||||
.map(game::getPlayer)
|
||||
.map(Player::getName)
|
||||
.map(s -> " controlled by" + s)
|
||||
.orElse("")
|
||||
);
|
||||
filter.add(new ControllerIdPredicate(targetPermanent.getControllerId()));
|
||||
filter.add(Predicates.not(new PermanentIdPredicate(targetPermanent.getId())));
|
||||
if (!game.getBattlefield().contains(filter, source.getControllerId(), source, game, 1)) {
|
||||
return false;
|
||||
}
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
target.withNotTarget(true);
|
||||
Optional.ofNullable(source)
|
||||
.map(Controllable::getControllerId)
|
||||
.map(game::getPlayer)
|
||||
.ifPresent(player -> player.choose(outcome, target, source, game));
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
for (UUID attachmentId : targetPermanent.getAttachments()) {
|
||||
permanent.addAttachment(attachmentId, source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ import mage.abilities.keyword.DoubleStrikeAbility;
|
|||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
|
|
@ -32,6 +35,11 @@ import java.util.UUID;
|
|||
*/
|
||||
public final class HeavenlyBlademaster extends CardImpl {
|
||||
|
||||
private static final DynamicValue totalAmount = new AdditiveDynamicValue(
|
||||
new EquipmentAttachedCount(1),
|
||||
new AuraAttachedCount(1)
|
||||
);
|
||||
|
||||
public HeavenlyBlademaster(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{W}");
|
||||
|
||||
|
|
@ -46,15 +54,9 @@ public final class HeavenlyBlademaster extends CardImpl {
|
|||
this.addAbility(DoubleStrikeAbility.getInstance());
|
||||
|
||||
// When Heavenly Blademaster enters the battlefield, you may attach any number of Auras and Equipment you control to it.
|
||||
this.addAbility(new EntersBattlefieldTriggeredAbility(
|
||||
new HeavenlyBlademasterEffect(), true
|
||||
));
|
||||
this.addAbility(new EntersBattlefieldTriggeredAbility(new HeavenlyBlademasterEffect()));
|
||||
|
||||
// Other creatures you control get +1/+1 for each Aura and Equipment attached to Heavenly Blademaster.
|
||||
DynamicValue totalAmount = new AdditiveDynamicValue(
|
||||
new EquipmentAttachedCount(1),
|
||||
new AuraAttachedCount(1)
|
||||
);
|
||||
this.addAbility(new SimpleStaticAbility(
|
||||
new BoostControlledEffect(
|
||||
totalAmount, totalAmount, Duration.WhileOnBattlefield,
|
||||
|
|
@ -101,33 +103,16 @@ class HeavenlyBlademasterEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (sourcePermanent == null || player == null) {
|
||||
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (player == null || sourcePermanent == null) {
|
||||
return false;
|
||||
}
|
||||
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
|
||||
if (!player.choose(outcome, target, source, game)) {
|
||||
return false;
|
||||
player.choose(outcome, target, source, game);
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
sourcePermanent.addAttachment(targetId, source, game);
|
||||
}
|
||||
target.getTargets().stream().map(
|
||||
attachmentId -> game.getPermanent(attachmentId)
|
||||
).filter(
|
||||
attachment -> attachment != null
|
||||
).forEachOrdered((attachment) -> {
|
||||
if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
|
||||
if (attachment.getAttachedTo() != sourcePermanent.getId()) {
|
||||
if (attachment.getAttachedTo() != null) {
|
||||
Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
|
||||
if (fromPermanent != null) {
|
||||
fromPermanent.removeAttachment(attachment.getId(), source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
sourcePermanent.addAttachment(attachment.getId(), source, game);
|
||||
game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,24 +13,25 @@ import mage.constants.CardType;
|
|||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.common.FilterEnchantmentPermanent;
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.other.AnotherTargetPredicate;
|
||||
import mage.filter.predicate.permanent.AttachedToPredicate;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetImpl;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -39,12 +40,12 @@ import java.util.UUID;
|
|||
public final class SimicGuildmage extends CardImpl {
|
||||
|
||||
private static final FilterPermanent filter = new FilterCreaturePermanent("another target creature with the same controller");
|
||||
private static final FilterEnchantmentPermanent auraFilter = new FilterEnchantmentPermanent("Aura");
|
||||
private static final FilterPermanent auraFilter = new FilterPermanent(SubType.AURA, "Aura enchanting a permanent");
|
||||
|
||||
static {
|
||||
filter.add(new AnotherTargetPredicate(2));
|
||||
filter.add(SameControllerPredicate.instance);
|
||||
auraFilter.add(SubType.AURA.getPredicate());
|
||||
auraFilter.add(new AttachedToPredicate(StaticFilters.FILTER_PERMANENT));
|
||||
}
|
||||
|
||||
public SimicGuildmage(UUID ownerId, CardSetInfo setInfo) {
|
||||
|
|
@ -129,40 +130,33 @@ class MoveAuraEffect extends OneShotEffect {
|
|||
*/
|
||||
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Permanent aura = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (aura == null) {
|
||||
return true;
|
||||
}
|
||||
Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
|
||||
if (fromPermanent == null) {
|
||||
return false;
|
||||
}
|
||||
boolean passed = true;
|
||||
Target chosenPermanentToAttachAuras = aura.getSpellAbility().getTargets().get(0).copy();
|
||||
chosenPermanentToAttachAuras.withNotTarget(true);
|
||||
Filter filterChoice = chosenPermanentToAttachAuras.getFilter();
|
||||
filterChoice.add(new ControllerIdPredicate(fromPermanent.getControllerId()));
|
||||
filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
|
||||
chosenPermanentToAttachAuras.withTargetName("a different " + filterChoice.getMessage() + " with the same controller as the " + filterChoice.getMessage() + " the target aura is attached to");
|
||||
if (chosenPermanentToAttachAuras.canChoose(source.getControllerId(), source, game)
|
||||
&& controller.choose(Outcome.Neutral, chosenPermanentToAttachAuras, source, game)) {
|
||||
Permanent permanentToAttachAura = game.getPermanent(chosenPermanentToAttachAuras.getFirstTarget());
|
||||
if (permanentToAttachAura != null) {
|
||||
// Check for protection
|
||||
if (permanentToAttachAura.cantBeAttachedBy(aura, source, game, true)) {
|
||||
passed = false;
|
||||
}
|
||||
if (passed) {
|
||||
fromPermanent.removeAttachment(aura.getId(), source, game);
|
||||
permanentToAttachAura.addAttachment(aura.getId(), source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
Permanent aura = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (controller == null || aura == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
FilterPermanent filter = new FilterPermanent(
|
||||
"permanent" + Optional
|
||||
.ofNullable(aura)
|
||||
.map(Permanent::getAttachedTo)
|
||||
.map(game::getControllerId)
|
||||
.map(game::getPlayer)
|
||||
.map(Player::getName)
|
||||
.map(s -> " controlled by" + s)
|
||||
.orElse("")
|
||||
);
|
||||
filter.add(new ControllerIdPredicate(game.getControllerId(aura.getAttachedTo())));
|
||||
filter.add(Predicates.not(new PermanentIdPredicate(aura.getAttachedTo())));
|
||||
if (!game.getBattlefield().contains(filter, source.getControllerId(), source, game, 1)) {
|
||||
return false;
|
||||
}
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
target.withNotTarget(true);
|
||||
controller.choose(outcome, target, source, game);
|
||||
return Optional
|
||||
.ofNullable(target)
|
||||
.map(TargetImpl::getFirstTarget)
|
||||
.map(game::getPermanent)
|
||||
.map(permanent -> permanent.addAttachment(aura.getId(), source, game))
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import mage.cards.CardSetInfo;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
|
|
@ -30,6 +30,7 @@ public final class VulshokBattlemaster extends CardImpl {
|
|||
|
||||
// Haste
|
||||
this.addAbility(HasteAbility.getInstance());
|
||||
|
||||
// When Vulshok Battlemaster enters the battlefield, attach all Equipment on the battlefield to it.
|
||||
this.addAbility(new EntersBattlefieldTriggeredAbility(new VulshokBattlemasterEffect()));
|
||||
}
|
||||
|
|
@ -43,39 +44,35 @@ public final class VulshokBattlemaster extends CardImpl {
|
|||
return new VulshokBattlemaster(this);
|
||||
}
|
||||
|
||||
static class VulshokBattlemasterEffect extends OneShotEffect {
|
||||
}
|
||||
|
||||
public VulshokBattlemasterEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "attach all Equipment on the battlefield to it";
|
||||
}
|
||||
class VulshokBattlemasterEffect extends OneShotEffect {
|
||||
|
||||
private VulshokBattlemasterEffect(final VulshokBattlemasterEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
VulshokBattlemasterEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "attach all Equipment on the battlefield to it";
|
||||
}
|
||||
|
||||
@Override
|
||||
public VulshokBattlemasterEffect copy() {
|
||||
return new VulshokBattlemasterEffect(this);
|
||||
}
|
||||
private VulshokBattlemasterEffect(final VulshokBattlemasterEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent battlemaster = game.getPermanent(source.getSourceId());
|
||||
if (battlemaster != null) {
|
||||
FilterPermanent filter = new FilterPermanent();
|
||||
filter.add(SubType.EQUIPMENT.getPredicate());
|
||||
for (Permanent equipment : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
|
||||
if (equipment != null) {
|
||||
//If an Equipment can't equip Vulshok Battlemaster, it isn't attached to the Battlemaster, and it doesn't become unattached (if it's attached to a creature). (https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=48125)
|
||||
if (!battlemaster.cantBeAttachedBy(equipment, source, game, false)) {
|
||||
battlemaster.addAttachment(equipment.getId(), source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public VulshokBattlemasterEffect copy() {
|
||||
return new VulshokBattlemasterEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
for (Permanent equipment : game.getBattlefield().getActivePermanents(
|
||||
StaticFilters.FILTER_PERMANENT_EQUIPMENT, source.getControllerId(), source, game
|
||||
)) {
|
||||
permanent.addAttachment(equipment.getId(), source, game);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue