mirror of
https://github.com/magefree/mage.git
synced 2025-12-29 23:12:10 -08:00
new NextSpellCastHasAbilityEffect
cleanup Wand of the Worldsoul, Flockchaser Phantom to use it text adjustments for gain abilities
This commit is contained in:
parent
817e1a813a
commit
6fafbf0d93
7 changed files with 173 additions and 141 deletions
|
|
@ -12,6 +12,7 @@ import mage.constants.*;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -150,12 +151,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
|
|||
if (quotes) {
|
||||
sb.append('"');
|
||||
}
|
||||
String abilityRuleText = ability.getRule("This " + targetObjectName);
|
||||
if (abilityRuleText.endsWith(")</i>")) {
|
||||
// remove reminder text for this rule generation
|
||||
abilityRuleText = abilityRuleText.substring(0, abilityRuleText.indexOf(" <i>("));
|
||||
}
|
||||
sb.append(abilityRuleText);
|
||||
sb.append(CardUtil.stripReminderText(ability.getRule("This " + targetObjectName)));
|
||||
if (quotes) {
|
||||
sb.append('"');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import mage.game.permanent.Permanent;
|
|||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author Styxo
|
||||
|
|
@ -23,7 +24,7 @@ public class GainAbilityControlledSpellsEffect extends ContinuousEffectImpl {
|
|||
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
this.ability = ability;
|
||||
this.filter = filter;
|
||||
staticText = filter.getMessage() + " have " + ability.getRule();
|
||||
staticText = filter.getMessage() + " have " + CardUtil.getTextWithFirstCharLowerCase(CardUtil.stripReminderText(ability.getRule()));
|
||||
}
|
||||
|
||||
private GainAbilityControlledSpellsEffect(final GainAbilityControlledSpellsEffect effect) {
|
||||
|
|
@ -78,10 +79,9 @@ public class GainAbilityControlledSpellsEffect extends ContinuousEffectImpl {
|
|||
}
|
||||
// TODO: Distinguish "you cast" to exclude copies
|
||||
Card card = game.getCard(stackObject.getSourceId());
|
||||
if (card == null || !filter.match((Spell) stackObject, game)) {
|
||||
continue;
|
||||
if (card != null && filter.match((Spell) stackObject, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.*;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.watchers.common.SpellsCastWatcher;
|
||||
|
||||
/**
|
||||
* @author xenohedron
|
||||
*/
|
||||
public class NextSpellCastHasAbilityEffect extends ContinuousEffectImpl {
|
||||
|
||||
private int spellsCast;
|
||||
private final Ability ability;
|
||||
private final FilterCard filter;
|
||||
|
||||
public NextSpellCastHasAbilityEffect(Ability ability) {
|
||||
this(ability, StaticFilters.FILTER_CARD);
|
||||
}
|
||||
|
||||
public NextSpellCastHasAbilityEffect(Ability ability, FilterCard filter) {
|
||||
super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
this.ability = ability;
|
||||
this.filter = filter;
|
||||
staticText = "the next spell you cast this turn has " + CardUtil.getTextWithFirstCharLowerCase(CardUtil.stripReminderText(ability.getRule()));
|
||||
}
|
||||
|
||||
private NextSpellCastHasAbilityEffect(final NextSpellCastHasAbilityEffect effect) {
|
||||
super(effect);
|
||||
this.spellsCast = effect.spellsCast;
|
||||
this.ability = effect.ability;
|
||||
this.filter = effect.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NextSpellCastHasAbilityEffect copy() {
|
||||
return new NextSpellCastHasAbilityEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
|
||||
if (watcher != null) {
|
||||
spellsCast = watcher.getCount(source.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
|
||||
if (player == null || watcher == null) {
|
||||
return false;
|
||||
}
|
||||
//check if a spell was cast before
|
||||
if (watcher.getCount(source.getControllerId()) > spellsCast) {
|
||||
discard(); // only one use
|
||||
return false;
|
||||
}
|
||||
for (Card card : game.getExile().getAllCardsByRange(game, source.getControllerId())) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getLibrary().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getHand().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
for (Card card : player.getGraveyard().getCards(game)) {
|
||||
if (filter.match(card, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
// workaround to gain cost reduction abilities to commanders before cast (make it playable)
|
||||
game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY)
|
||||
.stream()
|
||||
.filter(card -> filter.match(card, game))
|
||||
.forEach(card -> game.getState().addOtherAbility(card, ability));
|
||||
|
||||
for (StackObject stackObject : game.getStack()) {
|
||||
if (!(stackObject instanceof Spell) || !stackObject.isControlledBy(source.getControllerId())) {
|
||||
continue;
|
||||
}
|
||||
// TODO: Distinguish "you cast" to exclude copies
|
||||
Card card = game.getCard(stackObject.getSourceId());
|
||||
if (card != null && filter.match((Spell) stackObject, game)) {
|
||||
game.getState().addOtherAbility(card, ability);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -983,6 +983,10 @@ public final class CardUtil {
|
|||
return "<i>" + text + "</i> — ";
|
||||
}
|
||||
|
||||
public static String stripReminderText(String text) {
|
||||
return text.endsWith(")</i>") ? text.substring(0, text.indexOf(" <i>(")) : text;
|
||||
}
|
||||
|
||||
public static Set<UUID> getAllSelectedTargets(Ability ability, Game game) {
|
||||
return ability.getModes().getSelectedModes()
|
||||
.stream()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue