use of mage.abilities.costs.common.PayVariableLoyaltyCost in project mage by magefree.
the class TezzeretTheSeekerEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
cmc = ((PayVariableLoyaltyCost) cost).getAmount();
}
}
FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.abilities.costs.common.PayVariableLoyaltyCost in project mage by magefree.
the class CostModificationTest method test_PlaneswalkerLoyalty_CostModification_Single.
@Test
public void test_PlaneswalkerLoyalty_CostModification_Single() {
// Carth the Lion
// Planeswalkers' loyalty abilities you activate cost an additional {+1} to activate.
addCard(Zone.BATTLEFIELD, playerA, "Carth the Lion", 1);
//
// Vivien Reid
// 5 Loyalty
// +1, -3, -8 Abilities
addCard(Zone.BATTLEFIELD, playerA, "Vivien Reid", 1);
//
// Huatli, Warrior Poet
// 3 Loyalty
// Testing X Ability
// −X: Huatli, Warrior Poet deals X damage divided as you choose among any number of target creatures. Creatures dealt damage this way can’t block this turn.
addCard(Zone.BATTLEFIELD, playerA, "Huatli, Warrior Poet", 1);
//
// 2 toughness creatures for Huatli to kill
addCard(Zone.BATTLEFIELD, playerB, "Grizzly Bears", 1);
addCard(Zone.BATTLEFIELD, playerB, "Ghitu Lavarunner", 1);
// Vivien: make cost +2 instead +1 (total 7 counters)
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Look at the top four");
setChoice(playerA, false);
checkPermanentCounters("Vivien Reid counter check", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Vivien Reid", CounterType.LOYALTY, 7);
// loyalty cost modification doesn't affect card rule's text, so it still shown an old cost value for a user
// Vivien: make cost -7 instead -8
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "-8: You get an emblem");
// Huatli: check x cost changes
runCode("check x cost", 3, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
Permanent huatli = game.getBattlefield().getAllActivePermanents().stream().filter(p -> p.getName().equals("Huatli, Warrior Poet")).findFirst().orElse(null);
Assert.assertNotNull("must have huatli on battlefield", huatli);
LoyaltyAbility ability = (LoyaltyAbility) huatli.getAbilities(game).stream().filter(a -> a.getRule().startsWith("-X: ")).findFirst().orElse(null);
Assert.assertNotNull("must have loyalty ability", ability);
// counters: 3
// cost modification: +1
// max possible X to pay: 3 + 1 = 4
PayVariableLoyaltyCost cost = (PayVariableLoyaltyCost) ability.getCosts().get(0);
Assert.assertEquals("must have max possible X as 4", 4, cost.getMaxValue(ability, game));
});
// Huatli: make x cost -3 instead -4
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "-X: {this} deals X damage divided as you choose");
setChoice(playerA, "X=4");
addTargetAmount(playerA, "Grizzly Bears", 2);
addTargetAmount(playerA, "Ghitu Lavarunner", 2);
setStrictChooseMode(true);
setStopAt(3, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, "Vivien Reid", 1);
assertGraveyardCount(playerA, "Huatli, Warrior Poet", 1);
assertGraveyardCount(playerB, "Grizzly Bears", 1);
assertGraveyardCount(playerB, "Ghitu Lavarunner", 1);
}
use of mage.abilities.costs.common.PayVariableLoyaltyCost in project mage by magefree.
the class LoyaltyAbility method increaseLoyaltyCost.
/**
* Change loyalty cost by amount value
*
* @param amount
*/
public void increaseLoyaltyCost(int amount) {
// loyalty cost modification rules from Carth the Lion
// If a planeswalker’s loyalty ability normally has a cost of [+1], Carth’s ability makes it cost [+2] instead.
// A cost of [0] would become [+1], and a cost of [-6] would become [-5].
// (2021-06-18)
//
// If you somehow manage to control two Carths (perhaps because of Spark Double), the cost-changing effect is
// cumulative. In total, loyalty abilities will cost an additional [+2] to activate.
// (2021-06-18)
//
// The total cost of a planeswalker’s loyalty ability is calculated before any counters are added or removed.
// If a loyalty ability normally costs [-3] to activate, you do not remove three counters from it and then
// put one counter on it. You remove two counters at one time when you pay the cost.
// (2021-06-18)
//
// If an effect replaces the number of counters that would be placed on a planeswalker, such as that of
// Vorinclex, Monstrous Raider, that replacement happens only once, at the time payment is made.
// (2021-06-18)
// cost modification support only 1 cost item
int staticCount = 0;
for (Cost cost : costs) {
if (cost instanceof PayLoyaltyCost) {
// static cost
PayLoyaltyCost staticCost = (PayLoyaltyCost) cost;
staticCost.setAmount(staticCost.getAmount() + amount);
staticCount++;
} else if (cost instanceof PayVariableLoyaltyCost) {
// x cost (after x announce: x cost + static cost)
PayVariableLoyaltyCost xCost = (PayVariableLoyaltyCost) cost;
xCost.setCostModification(xCost.getCostModification() + amount);
}
}
if (staticCount > 1) {
throw new IllegalArgumentException(String.format("Loyalty ability must have only 1 static cost, but has %d: %s", staticCount, this.getRule()));
}
}
use of mage.abilities.costs.common.PayVariableLoyaltyCost in project mage by magefree.
the class UginTheSpiritDragonEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
cmc = ((PayVariableLoyaltyCost) cost).getAmount();
}
}
FilterPermanent filter = new FilterPermanent("permanent with mana value X or less that's one or more colors");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
filter.add(Predicates.not(ColorlessPredicate.instance));
Set<Card> permanentsToExile = new HashSet<>();
permanentsToExile.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game));
controller.moveCards(permanentsToExile, Zone.EXILED, source, game);
return true;
}
Aggregations