Pull in targeting changes to forge-m-base

This commit is contained in:
drdev
2014-03-12 22:28:26 +00:00
parent 93d9663e0a
commit 2491d0782e
2 changed files with 50 additions and 69 deletions

View File

@@ -24,7 +24,6 @@ import forge.game.Game;
import forge.game.GameObject;
import forge.game.card.Card;
import forge.game.card.CardLists;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityStackInstance;
import forge.game.spellability.TargetRestrictions;
@@ -191,61 +190,7 @@ public class TargetSelection {
});
}
}
// If second target has properties related to the first
if (tgt.getRelatedProperty() != null && !targetedObjects.isEmpty()) {
final List<Card> list = new ArrayList<Card>();
final String related = tgt.getRelatedProperty();
for (final Object o : targetedObjects) {
if (o instanceof Card) {
list.add((Card) o);
}
}
if (!list.isEmpty()) {
final Card card = list.get(0);
if ("LEPower".equals(related)) {
choices = CardLists.filter(choices, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getNetAttack() <= card.getNetAttack();
}
});
}
if ("LECMC".equals(related)) {
choices = CardLists.filter(choices, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getCMC() <= card.getCMC();
}
});
}
}
}
// If all cards must be from the same zone
if (tgt.isSingleZone() && !targeted.isEmpty()) {
choices = CardLists.filterControlledBy(choices, targeted.get(0).getController());
}
// If all cards must be from different zones
if (tgt.isDifferentZone() && !targeted.isEmpty()) {
choices = CardLists.filterControlledBy(choices, targeted.get(0).getController().getOpponent());
}
// If all cards must have different controllers
if (tgt.isDifferentControllers() && !targeted.isEmpty()) {
final List<Player> availableControllers = new ArrayList<Player>(game.getPlayers());
for (int i = 0; i < targeted.size(); i++) {
availableControllers.remove(targeted.get(i).getController());
}
choices = CardLists.filterControlledBy(choices, availableControllers);
}
// If the cards can't share a creature type
if (tgt.isWithoutSameCreatureType() && !targeted.isEmpty()) {
final Card card = targeted.get(0);
choices = CardLists.filter(choices, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return !c.sharesCreatureTypeWith(card);
}
});
}
return choices;
}

View File

@@ -1,6 +1,7 @@
package forge.screens.match.input;
import forge.game.GameEntity;
import forge.game.GameObject;
import forge.game.ability.ApiType;
import forge.game.card.Card;
import forge.game.player.Player;
@@ -9,6 +10,7 @@ import forge.game.spellability.TargetRestrictions;
import forge.screens.match.FControl;
import forge.toolbox.GuiChoose;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -20,6 +22,7 @@ public final class InputSelectTargets extends InputSyncronizedBase {
private final Map<GameEntity, Integer> targetDepth = new HashMap<GameEntity, Integer>();
private final TargetRestrictions tgt;
private final SpellAbility sa;
private Card lastTarget = null;
private boolean bCancel = false;
private boolean bOk = false;
private final boolean mandatory;
@@ -110,6 +113,39 @@ public final class InputSelectTargets extends InputSyncronizedBase {
showMessage(sa.getHostCard() + " - Cannot target this card (Shroud? Protection? Restrictions).");
return;
}
// If all cards must be from the same zone
if (tgt.isSingleZone() && lastTarget != null && !card.getController().equals(lastTarget.getController())) {
showMessage(sa.getHostCard() + " - Cannot target this card (not in the same zone)");
return;
}
// If all cards must be from different zones
if (tgt.isDifferentZone() && lastTarget != null && !card.getController().equals(lastTarget.getController().getOpponent())) {
showMessage(sa.getHostCard() + " - Cannot target this card (not in different zones)");
return;
}
// If the cards can't share a creature type
if (tgt.isWithoutSameCreatureType() && lastTarget != null && card.sharesCreatureTypeWith(lastTarget)) {
showMessage(sa.getHostCard() + " - Cannot target this card (should not share a creature type)");
return;
}
// If all cards must have different controllers
if (tgt.isDifferentControllers()) {
final List<Player> targetedControllers = new ArrayList<Player>();
for (GameObject o : targetDepth.keySet()) {
if (o instanceof Card) {
Player p = ((Card) o).getController();
targetedControllers.add(p);
}
}
if (targetedControllers.contains(card.getController())) {
showMessage(sa.getHostCard() + " - Cannot target this card (must have different controllers)");
return;
}
}
if (!choices.contains(card)) {
if (card.isPlaneswalker() && sa.getApi() == ApiType.DealDamage) {
showMessage(sa.getHostCard() + " - To deal an opposing Planeswalker direct damage, target its controller and then redirect the damage on resolution.");