mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
parent
10cf884923
commit
708b4e872a
2 changed files with 311 additions and 118 deletions
|
|
@ -1,17 +1,17 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import mage.Mana;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpecialAction;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.costs.mana.ActivationManaAbilityStep;
|
||||
import mage.abilities.costs.mana.AlternateManaPaymentAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.hint.ValueHint;
|
||||
import mage.abilities.mana.ManaOptions;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.AbilityType;
|
||||
|
|
@ -19,62 +19,67 @@ import mage.constants.ManaType;
|
|||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.filter.predicate.permanent.TappedPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.players.ManaPool;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/*
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 502.46. Convoke
|
||||
*
|
||||
* <p>
|
||||
* 502.46a Convoke is a static ability that functions while the spell is on the stack. "Convoke"
|
||||
* means "As an additional cost to play this spell, you may tap any number of untapped creatures
|
||||
* you control. Each creature tapped this way reduces the cost to play this spell by {1} or by
|
||||
* one mana of any of that creature's colors." Using the convoke ability follows the rules for
|
||||
* paying additional costs in rules 409.1b and 4091f-h.
|
||||
*
|
||||
* <p>
|
||||
* Example: You play Guardian of Vitu-Ghazi, a spell with convoke that costs {3}{G}{W}. You announce
|
||||
* that you're going to tap an artifact creature, a red creature, and a green-and-white creature to
|
||||
* help pay for it. The artifact creature and the red creature each reduce the spell's cost by {1}.
|
||||
* You choose whether the green-white creature reduces the spell's cost by {1}, {G}, or {W}. Then
|
||||
* the creatures become tapped as you pay Guardian of Vitu-Ghazi's cost.
|
||||
*
|
||||
* <p>
|
||||
* 502.46b Convoke can't reduce the cost to play a spell to less than 0.
|
||||
*
|
||||
* <p>
|
||||
* 502.46c Multiple instances of convoke on the same spell are redundant.
|
||||
*
|
||||
* <p>
|
||||
* You can tap only untapped creatures you control to reduce the cost of a spell with convoke
|
||||
* that you play.
|
||||
*
|
||||
* <p>
|
||||
* While playing a spell with convoke, if you control a creature that taps to produce mana, you
|
||||
* can either tap it for mana or tap it to reduce the cost of the spell, but not both.
|
||||
*
|
||||
* <p>
|
||||
* If you tap a multicolored creature to reduce the cost of a spell with convoke, you reduce
|
||||
* the cost by {1} or by one mana of your choice of any of that creature's colors.
|
||||
*
|
||||
* <p>
|
||||
* Convoke doesn't change a spell's mana cost or converted mana cost.
|
||||
*
|
||||
*
|
||||
* @author LevelX2
|
||||
* @author LevelX2, JayDi85
|
||||
*/
|
||||
public class ConvokeAbility extends SimpleStaticAbility implements AlternateManaPaymentAbility {
|
||||
|
||||
private static final FilterCreaturePermanent filterUntapped = new FilterCreaturePermanent();
|
||||
private static final FilterControlledCreaturePermanent filterUntapped = new FilterControlledCreaturePermanent();
|
||||
|
||||
static {
|
||||
filterUntapped.add(Predicates.not(TappedPredicate.instance));
|
||||
}
|
||||
|
||||
public ConvokeAbility() {
|
||||
super(Zone.STACK, null);
|
||||
super(Zone.ALL, null); // all AlternateManaPaymentAbility must use ALL zone to calculate playable abilities
|
||||
this.setRuleAtTheTop(true);
|
||||
this.addHint(new ValueHint("Untapped creatures you control", new PermanentsOnBattlefieldCount(filterUntapped)));
|
||||
}
|
||||
|
||||
public ConvokeAbility(final ConvokeAbility ability) {
|
||||
|
|
@ -86,14 +91,25 @@ public class ConvokeAbility extends SimpleStaticAbility implements AlternateMana
|
|||
return new ConvokeAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Convoke <i>(Your creatures can help cast this spell. Each creature you tap while casting this spell pays for {1} or one mana of that creature's color.)</i>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivationManaAbilityStep useOnActivationManaAbilityStep() {
|
||||
return ActivationManaAbilityStep.AFTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpecialAction(Ability source, Game game, ManaCost unpaid) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null && game.getBattlefield().contains(filterUntapped, controller.getId(), 1, game)) {
|
||||
if (source.getAbilityType() == AbilityType.SPELL) {
|
||||
SpecialAction specialAction = new ConvokeSpecialAction(unpaid);
|
||||
SpecialAction specialAction = new ConvokeSpecialAction(unpaid, this);
|
||||
specialAction.setControllerId(source.getControllerId());
|
||||
specialAction.setSourceId(source.getSourceId());
|
||||
|
||||
// create filter for possible creatures to tap
|
||||
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
|
||||
filter.add(Predicates.not(TappedPredicate.instance));
|
||||
|
|
@ -117,7 +133,7 @@ public class ConvokeAbility extends SimpleStaticAbility implements AlternateMana
|
|||
filter.add(Predicates.or(colorPredicates));
|
||||
}
|
||||
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
|
||||
target.setTargetName("creature to convoke");
|
||||
target.setTargetName("tap creature card as convoke's pay");
|
||||
specialAction.addTarget(target);
|
||||
if (specialAction.canActivate(source.getControllerId(), game).canActivate()) {
|
||||
game.getState().getSpecialActions().add(specialAction);
|
||||
|
|
@ -127,15 +143,36 @@ public class ConvokeAbility extends SimpleStaticAbility implements AlternateMana
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Convoke <i>(Your creatures can help cast this spell. Each creature you tap while casting this spell pays for {1} or one mana of that creature's color.)</i>";
|
||||
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
|
||||
ManaOptions options = new ManaOptions();
|
||||
FilterControlledCreaturePermanent filterBasic = new FilterControlledCreaturePermanent();
|
||||
|
||||
// each creature can give {1} or color mana
|
||||
game.getBattlefield().getActivePermanents(filterBasic, source.getControllerId(), source.getSourceId(), game)
|
||||
.stream()
|
||||
.filter(permanent -> !permanent.isTapped())
|
||||
.forEach(permanent -> {
|
||||
ManaOptions permMana = new ManaOptions();
|
||||
permMana.add(Mana.GenericMana(1));
|
||||
for (ObjectColor color : permanent.getColor(game).getColors()) {
|
||||
if (color.isBlack()) permMana.add(Mana.BlackMana(1));
|
||||
if (color.isBlue()) permMana.add(Mana.BlueMana(1));
|
||||
if (color.isGreen()) permMana.add(Mana.GreenMana(1));
|
||||
if (color.isRed()) permMana.add(Mana.RedMana(1));
|
||||
if (color.isWhite()) permMana.add(Mana.WhiteMana(1));
|
||||
}
|
||||
options.addMana(permMana);
|
||||
});
|
||||
|
||||
options.removeDuplicated();
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
class ConvokeSpecialAction extends SpecialAction {
|
||||
|
||||
public ConvokeSpecialAction(ManaCost unpaid) {
|
||||
super(Zone.ALL, true);
|
||||
public ConvokeSpecialAction(ManaCost unpaid, AlternateManaPaymentAbility manaAbility) {
|
||||
super(Zone.ALL, manaAbility);
|
||||
setRuleVisible(false);
|
||||
this.addEffect(new ConvokeEffect(unpaid));
|
||||
}
|
||||
|
|
@ -157,7 +194,7 @@ class ConvokeEffect extends OneShotEffect {
|
|||
public ConvokeEffect(ManaCost unpaid) {
|
||||
super(Outcome.Benefit);
|
||||
this.unpaid = unpaid;
|
||||
this.staticText = "Convoke (Your creatures can help cast this spell. Each creature you tap while casting this spell pays for {C} or one mana of that creature's color.)";
|
||||
this.staticText = "Convoke (Your creatures can help cast this spell. Each creature you tap while casting this spell pays for {1} or one mana of that creature's color.)";
|
||||
}
|
||||
|
||||
public ConvokeEffect(final ConvokeEffect effect) {
|
||||
|
|
@ -173,7 +210,8 @@ class ConvokeEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Spell spell = game.getStack().getSpell(source.getSourceId());
|
||||
if (controller != null && spell != null) {
|
||||
for (UUID creatureId : this.getTargetPointer().getTargets(game, source)) {
|
||||
Permanent perm = game.getPermanent(creatureId);
|
||||
if (perm == null) {
|
||||
|
|
@ -225,8 +263,10 @@ class ConvokeEffect extends OneShotEffect {
|
|||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CONVOKED, perm.getId(), source.getSourceId(), source.getControllerId()));
|
||||
game.informPlayers("Convoke: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay one " + manaName + " mana");
|
||||
}
|
||||
|
||||
// can't use mana abilities after that (convoke cost must be payed after mana abilities only)
|
||||
spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue