From 3fce6a5f2ce2adc4a7bf7019489a8429d3e93ba8 Mon Sep 17 00:00:00 2001 From: swordshine Date: Wed, 12 Mar 2014 04:42:59 +0000 Subject: [PATCH] - Move TargetsWithRelatedProperty to canTarget --- .../forge/game/ability/AbilityFactory.java | 3 -- .../forge/game/spellability/SpellAbility.java | 21 ++++++++++++++ .../game/spellability/TargetRestrictions.java | 16 ---------- .../forge/gui/player/TargetSelection.java | 29 ------------------- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/AbilityFactory.java b/forge-game/src/main/java/forge/game/ability/AbilityFactory.java index b56b82e1c43..f00a6481e00 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityFactory.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityFactory.java @@ -255,9 +255,6 @@ public final class AbilityFactory { if (mapParams.containsKey("TargetsAtRandom")) { abTgt.setRandomTarget(true); } - if (mapParams.containsKey("TargetsWithRelatedProperty")) { - abTgt.setRelatedProperty(mapParams.get("TargetsWithRelatedProperty")); - } if (mapParams.containsKey("TargetingPlayer")) { abTgt.setMandatory(true); } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java index ca9f5cad388..376e7e678a9 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java @@ -1046,6 +1046,27 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit } } } + if (hasParam("TargetsWithRelatedProperty") && entity instanceof Card) { + final String related = getParam("TargetsWithRelatedProperty"); + final Card c = (Card) entity; + Card parentTarget = null; + for (GameObject o : this.getUniqueTargets()) { + if (o instanceof Card) { + parentTarget = (Card) o; + break; + } + } + if (parentTarget == null) { + return false; + } + switch (related) { + case "LEPower" : + return c.getNetAttack() <= parentTarget.getNetAttack(); + case "LECMC" : + return c.getCMC() <= parentTarget.getCMC(); + } + } + if (hasParam("TargetingPlayerControls") && entity instanceof Card) { final Card c = (Card) entity; if (!c.getController().equals(targetingPlayer)) { diff --git a/forge-game/src/main/java/forge/game/spellability/TargetRestrictions.java b/forge-game/src/main/java/forge/game/spellability/TargetRestrictions.java index a98434de3d6..4dbfe146343 100644 --- a/forge-game/src/main/java/forge/game/spellability/TargetRestrictions.java +++ b/forge-game/src/main/java/forge/game/spellability/TargetRestrictions.java @@ -63,7 +63,6 @@ public class TargetRestrictions { private boolean withoutSameCreatureType = false; private boolean singleTarget = false; private boolean randomTarget = false; - private String relatedProperty = null; // How many can be targeted? private String minTargets; @@ -100,7 +99,6 @@ public class TargetRestrictions { this.differentZone = target.isDifferentZone(); this.sameController = target.isSameController(); this.withoutSameCreatureType = target.isWithoutSameCreatureType(); - this.relatedProperty = target.getRelatedProperty(); this.singleTarget = target.isSingleTarget(); this.randomTarget = target.isRandomTarget(); } @@ -630,20 +628,6 @@ public class TargetRestrictions { public final void setSameController(final boolean same) { this.sameController = same; } - - /** - * @return the relatedProperty - */ - public String getRelatedProperty() { - return relatedProperty; - } - - /** - * @param related the relatedProperty to set - */ - public void setRelatedProperty(String related) { - this.relatedProperty = related; - } /** * @return the singleTarget diff --git a/forge-gui/src/main/java/forge/gui/player/TargetSelection.java b/forge-gui/src/main/java/forge/gui/player/TargetSelection.java index 3edab9988e0..39254fa7aa7 100644 --- a/forge-gui/src/main/java/forge/gui/player/TargetSelection.java +++ b/forge-gui/src/main/java/forge/gui/player/TargetSelection.java @@ -178,35 +178,6 @@ public class TargetSelection { }); } } - // If second target has properties related to the first - if (tgt.getRelatedProperty() != null && !targetedObjects.isEmpty()) { - final List list = new ArrayList(); - 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() { - @Override - public boolean apply(final Card c) { - return c.getNetAttack() <= card.getNetAttack(); - } - }); - } - if ("LECMC".equals(related)) { - choices = CardLists.filter(choices, new Predicate() { - @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());