forked from magefree/mage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'magefree:master' into magefree#13243-faulty_implementat…
…ion_mirko_obsessive_theorist
- Loading branch information
Showing
3 changed files
with
158 additions
and
1 deletion.
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,156 @@ | ||
package mage.cards.k; | ||
|
||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import mage.MageInt; | ||
import mage.abilities.Ability; | ||
import mage.abilities.common.DealsDamageToAPlayerAllTriggeredAbility; | ||
import mage.abilities.common.EntersBattlefieldTriggeredAbility; | ||
import mage.abilities.effects.OneShotEffect; | ||
import mage.abilities.effects.common.DrawCardSourceControllerEffect; | ||
import mage.cards.*; | ||
import mage.constants.*; | ||
import mage.abilities.keyword.HasteAbility; | ||
import mage.filter.FilterCard; | ||
import mage.filter.common.FilterControlledCreaturePermanent; | ||
import mage.filter.predicate.Predicate; | ||
import mage.filter.predicate.mageobject.NamePredicate; | ||
import mage.game.Game; | ||
import mage.game.permanent.Permanent; | ||
import mage.players.Player; | ||
import mage.target.TargetCard; | ||
import mage.target.common.TargetCardInLibrary; | ||
|
||
/** | ||
* | ||
* @author Grath | ||
*/ | ||
public final class KassandraEagleBearer extends CardImpl { | ||
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); | ||
|
||
static { | ||
filter.add(KassandraEagleBearerPredicate.instance); | ||
} | ||
|
||
public KassandraEagleBearer(UUID ownerId, CardSetInfo setInfo) { | ||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}{W}"); | ||
|
||
this.supertype.add(SuperType.LEGENDARY); | ||
this.subtype.add(SubType.HUMAN); | ||
this.subtype.add(SubType.ASSASSIN); | ||
this.subtype.add(SubType.WARRIOR); | ||
this.power = new MageInt(2); | ||
this.toughness = new MageInt(2); | ||
|
||
// Haste | ||
this.addAbility(HasteAbility.getInstance()); | ||
|
||
// When Kassandra enters the battlefield, search your graveyard, hand, and library for a card named The Spear of Leonidas, put it onto the battlefield, then shuffle. | ||
this.addAbility(new EntersBattlefieldTriggeredAbility(new KassandraEagleBearerEffect(), false)); | ||
|
||
// Whenever a creature you control with a legendary Equipment attached to it deals combat damage to a player, draw a card. | ||
this.addAbility(new DealsDamageToAPlayerAllTriggeredAbility(new DrawCardSourceControllerEffect(1), | ||
filter, false, SetTargetPointer.NONE, true).setTriggerPhrase( | ||
"Whenever a creature you control with a legendary Equipment attached to it deals combat damage to a player, ")); | ||
} | ||
|
||
private KassandraEagleBearer(final KassandraEagleBearer card) { | ||
super(card); | ||
} | ||
|
||
@Override | ||
public KassandraEagleBearer copy() { | ||
return new KassandraEagleBearer(this); | ||
} | ||
} | ||
|
||
class KassandraEagleBearerEffect extends OneShotEffect { | ||
private static final String spearName = "The Spear of Leonidas"; | ||
|
||
KassandraEagleBearerEffect() { | ||
super(Outcome.PutCardInPlay); | ||
this.staticText = "search your graveyard, hand and/or library for a card named The Spear of Leonidas," + | ||
" put it onto the battlefield, then shuffle."; | ||
} | ||
|
||
private KassandraEagleBearerEffect(final KassandraEagleBearerEffect effect) { | ||
super(effect); | ||
} | ||
|
||
@Override | ||
public KassandraEagleBearerEffect copy() { | ||
return new KassandraEagleBearerEffect(this); | ||
} | ||
|
||
@Override | ||
public boolean apply(Game game, Ability source) { | ||
Player controller = game.getPlayer(source.getControllerId()); | ||
if (controller == null) { | ||
return false; | ||
} | ||
Card spearCard = null; | ||
FilterCard filter = new FilterCard("card named The Spear of Leonidas"); | ||
filter.add(new NamePredicate(spearName)); | ||
TargetCardInLibrary libraryTarget = new TargetCardInLibrary(filter); | ||
if (controller.searchLibrary(libraryTarget, source, game)) { | ||
for (UUID id : libraryTarget.getTargets()) { | ||
spearCard = game.getCard(id); | ||
} | ||
} | ||
|
||
if (spearCard == null) { | ||
FilterCard filter2 = new FilterCard("card from your hand named The Spear of Leonidas"); | ||
filter2.add(new NamePredicate(spearName)); | ||
Cards spears = new CardsImpl(); | ||
spears.addAllCards(controller.getHand().getCards(filter, source.getControllerId(), source, game)); | ||
Set<Card> spearsInGraveyard = controller.getGraveyard().getCards(filter, source.getControllerId(), source, game); | ||
TargetCard target; | ||
if (spearsInGraveyard.isEmpty()) { | ||
// Hand is a hidden zone - you may fail to find a Spear of Leonidas that's in your hand. | ||
// 701.19b. If a player is searching a hidden zone for cards with a stated quality, such as a card with a | ||
// certain card type or color, that player isn't required to find some or all of those cards even if they're | ||
// present in that zone. | ||
// This is true even if your hand is revealed: | ||
// 400.2. ... Hidden zones are zones in which not all players can be expected to see the cards' faces. | ||
// Library and hand are hidden zones, even if all the cards in one such zone happen to be revealed. | ||
target = new TargetCard(0, 1, Zone.HAND, filter); | ||
} else { | ||
spears.addAllCards(spearsInGraveyard); | ||
// You cannot fail to find a spear if there is one in your graveyard, because the graveyard is not hidden. | ||
target = new TargetCard(1, 1, Zone.HAND, filter); | ||
} | ||
target.withNotTarget(true); | ||
if (!spears.isEmpty()) { | ||
controller.choose(outcome, spears, target, source, game); | ||
for (UUID id : target.getTargets()) { | ||
spearCard = game.getCard(id); | ||
} | ||
} | ||
} | ||
|
||
if (spearCard != null) { | ||
controller.moveCards(spearCard, Zone.BATTLEFIELD, source, game); | ||
} | ||
controller.shuffleLibrary(source, game); | ||
return true; | ||
} | ||
} | ||
|
||
enum KassandraEagleBearerPredicate implements Predicate<Permanent> { | ||
instance; | ||
|
||
@Override | ||
public boolean apply(Permanent input, Game game) { | ||
return input.getAttachments() | ||
.stream() | ||
.map(game::getPermanentOrLKIBattlefield) | ||
.filter(Objects::nonNull) | ||
.anyMatch(attachment -> attachment.hasSubtype(SubType.EQUIPMENT, game) && attachment.isLegendary()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "creature you control with a legendary Equipment attached to it"; | ||
} | ||
} |
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
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