forked from External/mage
Refactor implementation of spell copies for cards like Twinning Staff as well as refactor handling of target changing (WIP) (#7662)
* refactored createCopyOnStack to be void * added new interface for modifying copied spellsspells * update implementation of Fork to use new applier * reworked epic effect * add applier to spell copy code * updated implementation of Beamsplitter Mage * updated cards which copy for each possible target * added support for additional copies having targets changed * fixed/ignored failing tests * updated target changing to prevent unnecessary choosing * added test for Twinning Staff * updated implementation of spell copy applier * added new method for choosing order of copies on stack * fixed test failures * [TSR] various text fixes * fixed a test failure * [SLD] fixed Rick, Steadfast Leader only counting Human creatures * updated test framework to handle skips without affecting starting player choice * fixed another test failure * updated copy messaging for consistency * added copy messaging to stack abilities
This commit is contained in:
parent
b51915f6e8
commit
9c56a98dc9
47 changed files with 972 additions and 1092 deletions
|
|
@ -13,10 +13,14 @@ import mage.abilities.keyword.BestowAbility;
|
|||
import mage.abilities.keyword.MorphAbility;
|
||||
import mage.abilities.text.TextPart;
|
||||
import mage.cards.*;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.*;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.mageobject.MageObjectReferencePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.MageObjectAttribute;
|
||||
|
|
@ -32,9 +36,11 @@ import mage.util.CardUtil;
|
|||
import mage.util.GameLog;
|
||||
import mage.util.ManaUtil;
|
||||
import mage.util.SubTypes;
|
||||
import mage.util.functions.SpellCopyApplier;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -1057,27 +1063,128 @@ public class Spell extends StackObjImpl implements Card {
|
|||
}
|
||||
|
||||
@Override
|
||||
public StackObject createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets) {
|
||||
return createCopyOnStack(game, source, newControllerId, chooseNewTargets, 1);
|
||||
public void createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets) {
|
||||
createCopyOnStack(game, source, newControllerId, chooseNewTargets, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackObject createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets, int amount) {
|
||||
Spell spellCopy = null;
|
||||
public void createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets, int amount) {
|
||||
createCopyOnStack(game, source, newControllerId, chooseNewTargets, amount, null);
|
||||
}
|
||||
|
||||
private static final class PredicateIterator implements Iterator<MageObjectReferencePredicate> {
|
||||
private final SpellCopyApplier applier;
|
||||
private final Player player;
|
||||
private final int amount;
|
||||
private final Game game;
|
||||
private Map<String, MageObjectReferencePredicate> predicateMap = null;
|
||||
private int anyCount = 0;
|
||||
private int setCount = 0;
|
||||
private Iterator<MageObjectReferencePredicate> iterator = null;
|
||||
private Choice choice = null;
|
||||
|
||||
private PredicateIterator(Game game, UUID newControllerId, int amount, SpellCopyApplier applier) {
|
||||
this.applier = applier;
|
||||
this.player = game.getPlayer(newControllerId);
|
||||
this.amount = amount;
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void makeMap() {
|
||||
if (predicateMap != null) {
|
||||
return;
|
||||
}
|
||||
predicateMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
MageObjectReferencePredicate predicate = applier.getNextPredicate();
|
||||
if (predicate == null) {
|
||||
anyCount++;
|
||||
String message = "Any target";
|
||||
if (anyCount > 1) {
|
||||
message += " (" + anyCount + ")";
|
||||
}
|
||||
predicateMap.put(message, predicate);
|
||||
continue;
|
||||
}
|
||||
setCount++;
|
||||
predicateMap.put(predicate.getName(game), predicate);
|
||||
}
|
||||
if ((setCount == 1 && anyCount == 0) || setCount == 0) {
|
||||
iterator = predicateMap.values().stream().collect(Collectors.toList()).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
private void makeChoice() {
|
||||
if (choice != null) {
|
||||
return;
|
||||
}
|
||||
choice = new ChoiceImpl(false);
|
||||
choice.setMessage("Choose the order of copies to go on the stack");
|
||||
choice.setSubMessage("Press cancel to put the rest in any order");
|
||||
choice.setChoices(new HashSet<>(predicateMap.keySet()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MageObjectReferencePredicate next() {
|
||||
if (player == null || applier == null) {
|
||||
return null;
|
||||
}
|
||||
makeMap();
|
||||
if (iterator != null) {
|
||||
return iterator.hasNext() ? iterator.next() : null;
|
||||
}
|
||||
makeChoice();
|
||||
if (choice.getChoices().size() < 2) {
|
||||
iterator = choice.getChoices().stream().map(predicateMap::get).iterator();
|
||||
return next();
|
||||
}
|
||||
choice.clearChoice();
|
||||
player.choose(Outcome.AIDontUseIt, choice, game);
|
||||
String chosen = choice.getChoice();
|
||||
if (chosen == null) {
|
||||
iterator = choice.getChoices().stream().map(predicateMap::get).iterator();
|
||||
return next();
|
||||
}
|
||||
choice.getChoices().remove(chosen);
|
||||
return predicateMap.get(chosen);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets, int amount, SpellCopyApplier applier) {
|
||||
GameEvent gameEvent = new CopyStackObjectEvent(source, this, newControllerId, amount);
|
||||
if (game.replaceEvent(gameEvent)) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
Iterator<MageObjectReferencePredicate> predicates = new PredicateIterator(game, newControllerId, gameEvent.getAmount(), applier);
|
||||
for (int i = 0; i < gameEvent.getAmount(); i++) {
|
||||
spellCopy = this.copySpell(game, source, newControllerId);
|
||||
Spell spellCopy = this.copySpell(game, source, newControllerId);
|
||||
if (applier != null) {
|
||||
applier.modifySpell(spellCopy, game);
|
||||
}
|
||||
spellCopy.setZone(Zone.STACK, game); // required for targeting ex: Nivmagus Elemental
|
||||
game.getStack().push(spellCopy);
|
||||
if (chooseNewTargets) {
|
||||
Predicate predicate = predicates.next();
|
||||
if (predicate != null) {
|
||||
spellCopy.chooseNewTargets(game, newControllerId, true, false, predicate);
|
||||
} else if (chooseNewTargets || applier != null) { // if applier is non-null but predicate is null then it's extra
|
||||
spellCopy.chooseNewTargets(game, newControllerId);
|
||||
}
|
||||
game.fireEvent(new CopiedStackObjectEvent(this, spellCopy, newControllerId));
|
||||
}
|
||||
return spellCopy;
|
||||
Player player = game.getPlayer(newControllerId);
|
||||
if (player != null) {
|
||||
game.informPlayers(
|
||||
player.getName() + " created " + CardUtil.numberToText(gameEvent.getAmount(), "a")
|
||||
+ " cop" + (gameEvent.getAmount() == 1 ? "y" : "ies") + " of " + getIdName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue