[CLB] Implement Commander Liara Portyr

This commit is contained in:
theelk801 2025-06-02 21:23:26 -04:00
parent 74c885a331
commit 1cb421ece7
3 changed files with 136 additions and 3 deletions

View file

@ -0,0 +1,120 @@
package mage.cards.c;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksWithCreaturesTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.cards.*;
import mage.constants.*;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Optional;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class CommanderLiaraPortyr extends CardImpl {
public CommanderLiaraPortyr(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}{W}");
this.supertype.add(SuperType.LEGENDARY);
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.SOLDIER);
this.power = new MageInt(5);
this.toughness = new MageInt(3);
// Whenever you attack, spells you cast from exile this turn cost {X} less to cast, where X is the number of players being attacked. Exile the top X cards of your library. Until end of turn, you may cast spells from among those exiled cards.
Ability ability = new AttacksWithCreaturesTriggeredAbility(new CommanderLiaraPortyrCostEffect(), 1);
ability.addEffect(new CommanderLiaraPortyrExileEffect());
this.addAbility(ability);
}
private CommanderLiaraPortyr(final CommanderLiaraPortyr card) {
super(card);
}
@Override
public CommanderLiaraPortyr copy() {
return new CommanderLiaraPortyr(this);
}
}
class CommanderLiaraPortyrCostEffect extends CostModificationEffectImpl {
CommanderLiaraPortyrCostEffect() {
super(Duration.EndOfTurn, Outcome.Benefit, CostModificationType.REDUCE_COST);
staticText = "spells you cast from exile this turn cost {X} less to cast, " +
"where X is the number of players being attacked";
}
private CommanderLiaraPortyrCostEffect(final CommanderLiaraPortyrCostEffect effect) {
super(effect);
}
@Override
public CommanderLiaraPortyrCostEffect copy() {
return new CommanderLiaraPortyrCostEffect(this);
}
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
Optional.ofNullable((Integer) getValue(AttacksWithCreaturesTriggeredAbility.VALUEKEY_NUMBER_DEFENDING_PLAYERS))
.ifPresent(i -> CardUtil.reduceCost(abilityToModify, 1));
return true;
}
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
return Optional
.ofNullable(abilityToModify)
.map(Ability::getSourceId)
.map(game::getSpell)
.map(Spell::getFromZone)
.filter(Zone.EXILED::match)
.isPresent();
}
}
class CommanderLiaraPortyrExileEffect extends OneShotEffect {
CommanderLiaraPortyrExileEffect() {
super(Outcome.Benefit);
staticText = "Exile the top X cards of your library. Until end of turn, " +
"you may cast spells from among those exiled cards";
}
private CommanderLiaraPortyrExileEffect(final CommanderLiaraPortyrExileEffect effect) {
super(effect);
}
@Override
public CommanderLiaraPortyrExileEffect copy() {
return new CommanderLiaraPortyrExileEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
int count = Optional.ofNullable((Integer) getValue(
AttacksWithCreaturesTriggeredAbility.VALUEKEY_NUMBER_DEFENDING_PLAYERS
)).orElse(0);
if (player == null || count < 1) {
return true;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, count));
if (cards.isEmpty()) {
return false;
}
player.moveCards(cards, Zone.EXILED, source, game);
for (Card card : cards.getCards(game)) {
CardUtil.makeCardPlayable(game, source, card, true, Duration.EndOfTurn, false);
}
return true;
}
}

View file

@ -206,9 +206,9 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet {
cards.add(new SetCardInfo("Cloudkill", 121, Rarity.UNCOMMON, mage.cards.c.Cloudkill.class));
cards.add(new SetCardInfo("Colossal Badger", 223, Rarity.COMMON, mage.cards.c.ColossalBadger.class));
cards.add(new SetCardInfo("Command Tower", 351, Rarity.COMMON, mage.cards.c.CommandTower.class));
//cards.add(new SetCardInfo("Commander Liara Portyr", 270, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Commander Liara Portyr", 418, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Commander Liara Portyr", 529, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Commander Liara Portyr", 270, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Commander Liara Portyr", 418, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Commander Liara Portyr", 529, Rarity.UNCOMMON, mage.cards.c.CommanderLiaraPortyr.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Compulsive Research", 715, Rarity.COMMON, mage.cards.c.CompulsiveResearch.class));
cards.add(new SetCardInfo("Cone of Cold", 61, Rarity.UNCOMMON, mage.cards.c.ConeOfCold.class));
cards.add(new SetCardInfo("Consuming Aberration", 840, Rarity.RARE, mage.cards.c.ConsumingAberration.class));

View file

@ -1,5 +1,6 @@
package mage.abilities.common;
import mage.MageItem;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
@ -23,6 +24,7 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl {
// retrieve the number of attackers in triggered effects with getValue
public static final String VALUEKEY_NUMBER_ATTACKERS = "number_attackers";
public static final String VALUEKEY_NUMBER_DEFENDING_PLAYERS = "number_defending_players";
private final FilterPermanent filter;
private final int minAttackers;
@ -91,6 +93,17 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl {
return false;
}
getEffects().setValue(VALUEKEY_NUMBER_ATTACKERS, attackers.size());
getEffects().setValue(
VALUEKEY_NUMBER_DEFENDING_PLAYERS,
attackers.stream()
.map(MageItem::getId)
.map(game.getCombat()::getDefenderId)
.distinct()
.map(game::getPlayer)
.filter(Objects::nonNull)
.mapToInt(x -> 1)
.sum()
);
if (setTargetPointer) {
getEffects().setTargetPointer(new FixedTargets(new ArrayList<>(attackers), game));
}