- Move TargetsWithRelatedProperty to canTarget

This commit is contained in:
swordshine
2014-03-12 04:42:59 +00:00
parent 96e03e5fcf
commit 3fce6a5f2c
4 changed files with 21 additions and 48 deletions

View File

@@ -255,9 +255,6 @@ public final class AbilityFactory {
if (mapParams.containsKey("TargetsAtRandom")) { if (mapParams.containsKey("TargetsAtRandom")) {
abTgt.setRandomTarget(true); abTgt.setRandomTarget(true);
} }
if (mapParams.containsKey("TargetsWithRelatedProperty")) {
abTgt.setRelatedProperty(mapParams.get("TargetsWithRelatedProperty"));
}
if (mapParams.containsKey("TargetingPlayer")) { if (mapParams.containsKey("TargetingPlayer")) {
abTgt.setMandatory(true); abTgt.setMandatory(true);
} }

View File

@@ -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) { if (hasParam("TargetingPlayerControls") && entity instanceof Card) {
final Card c = (Card) entity; final Card c = (Card) entity;
if (!c.getController().equals(targetingPlayer)) { if (!c.getController().equals(targetingPlayer)) {

View File

@@ -63,7 +63,6 @@ public class TargetRestrictions {
private boolean withoutSameCreatureType = false; private boolean withoutSameCreatureType = false;
private boolean singleTarget = false; private boolean singleTarget = false;
private boolean randomTarget = false; private boolean randomTarget = false;
private String relatedProperty = null;
// How many can be targeted? // How many can be targeted?
private String minTargets; private String minTargets;
@@ -100,7 +99,6 @@ public class TargetRestrictions {
this.differentZone = target.isDifferentZone(); this.differentZone = target.isDifferentZone();
this.sameController = target.isSameController(); this.sameController = target.isSameController();
this.withoutSameCreatureType = target.isWithoutSameCreatureType(); this.withoutSameCreatureType = target.isWithoutSameCreatureType();
this.relatedProperty = target.getRelatedProperty();
this.singleTarget = target.isSingleTarget(); this.singleTarget = target.isSingleTarget();
this.randomTarget = target.isRandomTarget(); this.randomTarget = target.isRandomTarget();
} }
@@ -631,20 +629,6 @@ public class TargetRestrictions {
this.sameController = 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 * @return the singleTarget
*/ */

View File

@@ -178,35 +178,6 @@ 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 all cards must be from the same zone
if (tgt.isSingleZone() && !targeted.isEmpty()) { if (tgt.isSingleZone() && !targeted.isEmpty()) {
choices = CardLists.filterControlledBy(choices, targeted.get(0).getController()); choices = CardLists.filterControlledBy(choices, targeted.get(0).getController());