-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package mage.cards.b; | ||
|
||
import mage.abilities.Ability; | ||
import mage.abilities.common.SimpleStaticAbility; | ||
import mage.abilities.condition.Condition; | ||
import mage.abilities.decorator.ConditionalRestrictionEffect; | ||
import mage.abilities.effects.common.AttachEffect; | ||
import mage.abilities.effects.common.combat.CantBeBlockedAttachedEffect; | ||
import mage.abilities.effects.common.continuous.BoostEnchantedEffect; | ||
import mage.abilities.effects.common.continuous.ControlEnchantedEffect; | ||
import mage.abilities.hint.ConditionHint; | ||
import mage.abilities.hint.Hint; | ||
import mage.abilities.keyword.EnchantAbility; | ||
import mage.cards.CardImpl; | ||
import mage.cards.CardSetInfo; | ||
import mage.constants.AttachmentType; | ||
import mage.constants.CardType; | ||
import mage.constants.Outcome; | ||
import mage.constants.SubType; | ||
import mage.filter.FilterPermanent; | ||
import mage.filter.common.FilterCreaturePermanent; | ||
import mage.filter.predicate.Predicates; | ||
import mage.filter.predicate.mageobject.CommanderPredicate; | ||
import mage.game.Game; | ||
import mage.game.permanent.Permanent; | ||
import mage.target.TargetPermanent; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @author TheElk801 | ||
*/ | ||
public final class BecomeThePilot extends CardImpl { | ||
|
||
private static final FilterPermanent filter = new FilterCreaturePermanent("noncommander creature"); | ||
|
||
static { | ||
filter.add(Predicates.not(CommanderPredicate.instance)); | ||
} | ||
|
||
public BecomeThePilot(UUID ownerId, CardSetInfo setInfo) { | ||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{U}{U}"); | ||
|
||
this.subtype.add(SubType.AURA); | ||
|
||
// Enchant noncommander creature | ||
TargetPermanent auraTarget = new TargetPermanent(filter); | ||
this.getSpellAbility().addTarget(auraTarget); | ||
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); | ||
this.addAbility(new EnchantAbility(auraTarget)); | ||
|
||
// You control enchanted creature. | ||
this.addAbility(new SimpleStaticAbility(new ControlEnchantedEffect())); | ||
|
||
// Enchanted creature gets +2/+2 and can't be blocked unless it's attacking its owner or a permanent its owner controls. | ||
Ability ability = new SimpleStaticAbility(new BoostEnchantedEffect(2, 2)); | ||
ability.addEffect(new ConditionalRestrictionEffect( | ||
new CantBeBlockedAttachedEffect(AttachmentType.AURA), BecomeThePilotCondition.instance, | ||
"and can't be blocked unless it's attacking its owner or a permanent its owner controls" | ||
)); | ||
this.addAbility(ability.addHint(BecomeThePilotCondition.getHint())); | ||
} | ||
|
||
private BecomeThePilot(final BecomeThePilot card) { | ||
super(card); | ||
} | ||
|
||
@Override | ||
public BecomeThePilot copy() { | ||
return new BecomeThePilot(this); | ||
} | ||
} | ||
|
||
enum BecomeThePilotCondition implements Condition { | ||
instance; | ||
private static final Hint hint = new ConditionHint( | ||
instance, "Enchanted creature is not " + | ||
"attacking its owner or a permanent its owner controls" | ||
); | ||
|
||
public static Hint getHint() { | ||
return hint; | ||
} | ||
|
||
@Override | ||
public boolean apply(Game game, Ability source) { | ||
Permanent permanent = Optional | ||
.ofNullable(source.getSourcePermanentIfItStillExists(game)) | ||
.filter(Objects::nonNull) | ||
.map(Permanent::getAttachedTo) | ||
.map(game::getPermanent) | ||
.orElse(null); | ||
if (permanent == null) { | ||
return false; | ||
} | ||
UUID defenderId = game.getCombat().getDefenderId(permanent.getId()); | ||
return defenderId == null | ||
|| (!permanent.isOwnedBy(defenderId) && !permanent.isOwnedBy(game.getControllerId(defenderId))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters