mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Pull in targeting changes to forge-m-base
This commit is contained in:
@@ -21,13 +21,12 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
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;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardLists;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.screens.match.input.InputSelectTargets;
|
||||
@@ -188,67 +187,13 @@ public class TargetSelection {
|
||||
public boolean apply(final Card c) {
|
||||
return c.sharesControllerWith(card);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* chooseCardFromList.
|
||||
|
||||
@@ -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;
|
||||
@@ -109,7 +112,40 @@ public final class InputSelectTargets extends InputSyncronizedBase {
|
||||
if (!card.canBeTargetedBy(sa)) {
|
||||
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.");
|
||||
|
||||
Reference in New Issue
Block a user