Allow Ink-Treader Nephilim's ability's controller to choose the order in which copies go on the stack.

This commit is contained in:
Duncan Townsend 2015-01-21 22:24:17 -05:00
parent 00e79f2fdd
commit e27a504348
No known key found for this signature in database
GPG key ID: C00ECDF315F7A593

View file

@ -27,6 +27,9 @@
*/
package mage.sets.guildpact;
import java.util.Collection;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
@ -48,8 +51,15 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import java.util.Map;
import java.util.Set;
import java.util.List;
import mage.MageObject;
import mage.target.Target;
import mage.abilities.Modes;
import mage.filter.predicate.ObjectPlayer;
import mage.filter.predicate.ObjectPlayerPredicate;
import mage.target.TargetPermanent;
/**
@ -170,9 +180,11 @@ class InkTreaderNephilimEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Spell spell = (Spell) getValue("TriggeringSpell");
if (spell != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
Map<UUID, Spell> targetable = new HashMap<>();
UUID controller = source.getControllerId();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller, source.getSourceId(), game)) {
Spell copy = spell.copySpell();
copy.setControllerId(source.getControllerId());
copy.setControllerId(controller);
copy.setCopiedSpell(true);
if (permanent.getId().equals(source.getSourceId())) {
continue; // copy only for other creatures
@ -200,7 +212,32 @@ class InkTreaderNephilimEffect extends OneShotEffect {
}
}
}
game.getStack().push(copy);
targetable.put(permanent.getId(), copy);
}
}
while (targetable.size() > 0) {
TargetPermanent target = new TargetPermanent(0, 1,
new FilterPermanentFromSet("creature that spell could target ("+Integer.toString(targetable.size())+" remaining)",
targetable.keySet()),
true);
if (target.possibleTargets(controller, game).size() > 1
&& target.canChoose(source.getSourceId(), controller, game)) {
game.getPlayer(controller).choose(Outcome.Neutral, target, source.getId(), game);
}
Collection<UUID> chosen = target.getTargets();
if (chosen.size() == 0) {
chosen = targetable.keySet();
}
List<UUID> toDelete = new ArrayList<>();
for (UUID chosenId : chosen) {
Spell chosenCopy = targetable.get(chosenId);
if (chosenCopy != null) {
game.getStack().push(chosenCopy);
toDelete.add(chosenId);
}
}
for (UUID id : toDelete) {
targetable.remove(id);
}
}
return true;
@ -214,3 +251,32 @@ class InkTreaderNephilimEffect extends OneShotEffect {
}
}
class FromSetPredicate<T extends ObjectPlayer<MageObject>> implements ObjectPlayerPredicate<T> {
protected Set<UUID> set;
public FromSetPredicate(Set<UUID> set) {
this.set = set;
}
public boolean apply(T input, Game game) {
return set.contains(input.getObject().getId());
}
}
class FilterPermanentFromSet extends FilterPermanent {
public FilterPermanentFromSet(Set<UUID> set) {
super();
this.extraPredicates.add(new FromSetPredicate(set));
}
public FilterPermanentFromSet(String name, Set<UUID> set) {
super(name);
this.extraPredicates.add(new FromSetPredicate(set));
}
public FilterPermanentFromSet(String subtype, String name, Set<UUID> set) {
super(subtype, name);
this.extraPredicates.add(new FromSetPredicate(set));
}
}