Merge pull request #7302 from weirddan455/pyre

[KHM] Implemented Pyre of Heroes
This commit is contained in:
Oleg Agafonov 2020-12-27 12:33:09 +01:00 committed by GitHub
commit 6422bd3586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,127 @@
package mage.cards.p;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.ActivateAsSorceryActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.ComparisonType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetControlledCreaturePermanent;
/**
*
* @author weirddan455
*/
public final class PyreOfHeroes extends CardImpl {
public PyreOfHeroes(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}");
// {2}, {T}, Sacrifice a creature: Search your library for a creature card that shares a creature type with the sacrificed creature and has converted mana cost equal to 1 plus that creature's converted mana cost.
// Put that card onto the battlefield, then shuffle your library. Activate this ability only any time you could cast a sorcery.
Ability ability = new ActivateAsSorceryActivatedAbility(
Zone.BATTLEFIELD, new PyreOfHeroesEffect(), new GenericManaCost(2)
);
ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(
StaticFilters.FILTER_CONTROLLED_CREATURE_SHORT_TEXT
)));
this.addAbility(ability);
}
private PyreOfHeroes(final PyreOfHeroes card) {
super(card);
}
@Override
public PyreOfHeroes copy() {
return new PyreOfHeroes(this);
}
}
class PyreOfHeroesEffect extends OneShotEffect {
PyreOfHeroesEffect() {
super(Outcome.Benefit);
staticText = "Search your library for a creature card that shares a creature type with the sacrificed creature and has converted mana cost equal to 1 " +
"plus that creature's converted mana cost. Put that card " +
"onto the battlefield, then shuffle your library";
}
private PyreOfHeroesEffect(final PyreOfHeroesEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getConvertedManaCost() + 1;
FilterCard filter = new FilterCard("creature card with converted mana cost " + newConvertedCost);
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
filter.add(new PyreOfHeroesPredicate(sacrificedPermanent));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
@Override
public PyreOfHeroesEffect copy() {
return new PyreOfHeroesEffect(this);
}
}
class PyreOfHeroesPredicate implements Predicate<MageObject> {
private final Permanent sacrificedPermanent;
public PyreOfHeroesPredicate(Permanent sacrificedPermanent) {
this.sacrificedPermanent = sacrificedPermanent;
}
@Override
public boolean apply(MageObject input, Game game) {
return input.shareCreatureTypes(sacrificedPermanent, game);
}
@Override
public String toString() {
return "shares a creature type";
}
}

View file

@ -43,6 +43,7 @@ public final class Kaldheim extends ExpansionSet {
cards.add(new SetCardInfo("Gilded Assault Cart", 390, Rarity.UNCOMMON, mage.cards.g.GildedAssaultCart.class));
cards.add(new SetCardInfo("Gladewalker Ritualist", 392, Rarity.UNCOMMON, mage.cards.g.GladewalkerRitualist.class));
cards.add(new SetCardInfo("Hengegate Pathway", 260, Rarity.RARE, mage.cards.h.HengegatePathway.class));
cards.add(new SetCardInfo("Pyre of Heroes", 241, Rarity.RARE, mage.cards.p.PyreOfHeroes.class));
cards.add(new SetCardInfo("Kaya the Inexorable", 218, Rarity.MYTHIC, mage.cards.k.KayaTheInexorable.class));
cards.add(new SetCardInfo("Rampage of the Valkyries", 393, Rarity.UNCOMMON, mage.cards.r.RampageOfTheValkyries.class));
cards.add(new SetCardInfo("Realmwalker", 188, Rarity.RARE, mage.cards.r.Realmwalker.class));